global.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. -- Copyright 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local NX = require "nixio"
  4. local NXFS = require "nixio.fs"
  5. local DISP = require "luci.dispatcher"
  6. local SYS = require "luci.sys"
  7. local DDNS = require "luci.tools.ddns" -- ddns multiused functions
  8. -- cbi-map definition -- #######################################################
  9. local m = Map("ddns")
  10. -- first need to close <a> from cbi map template our <a> closed by template
  11. m.title = [[</a><a href="]] .. DISP.build_url("admin", "services", "ddns") .. [[">]]
  12. .. translate("Dynamic DNS")
  13. m.description = translate("Dynamic DNS allows that your router can be reached with " ..
  14. "a fixed hostname while having a dynamically changing IP address.")
  15. m.redirect = DISP.build_url("admin", "services", "ddns")
  16. function m.commit_handler(self)
  17. if self.changed then -- changes ?
  18. os.execute("/etc/init.d/ddns reload &") -- reload configuration
  19. end
  20. end
  21. -- cbi-section definition -- ###################################################
  22. local ns = m:section( NamedSection, "global", "ddns",
  23. translate("Global Settings"),
  24. translate("Configure here the details for all Dynamic DNS services including this LuCI application.")
  25. .. [[<br /><strong>]]
  26. .. translate("It is NOT recommended for casual users to change settings on this page.")
  27. .. [[</strong><br />]]
  28. .. [[<a href="http://wiki.openwrt.org/doc/uci/ddns#version_2x1" target="_blank">]]
  29. .. translate("For detailed information about parameter settings look here.")
  30. .. [[</a>]]
  31. )
  32. -- section might not exist
  33. function ns.cfgvalue(self, section)
  34. if not self.map:get(section) then
  35. self.map:set(section, nil, self.sectiontype)
  36. end
  37. return self.map:get(section)
  38. end
  39. -- allow_local_ip -- ##########################################################
  40. local ali = ns:option(Flag, "allow_local_ip")
  41. ali.title = translate("Allow non-public IP's")
  42. ali.description = translate("Non-public and by default blocked IP's") .. ":"
  43. .. [[<br /><strong>IPv4: </strong>]]
  44. .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16"
  45. .. [[<br /><strong>IPv6: </strong>]]
  46. .. "::/32, f000::/4"
  47. ali.reempty = true
  48. ali.default = "0"
  49. function ali.parse(self, section)
  50. DDNS.flag_parse(self, section)
  51. end
  52. function ali.validate(self, value)
  53. if value == self.default then
  54. return "" -- default = empty
  55. end
  56. return value
  57. end
  58. -- date_format -- #############################################################
  59. local df = ns:option(Value, "date_format")
  60. df.title = translate("Date format")
  61. df.description = [[<a href="http://www.cplusplus.com/reference/ctime/strftime/" target="_blank">]]
  62. .. translate("For supported codes look here")
  63. .. [[</a>]]
  64. df.template = "ddns/global_value"
  65. df.rmempty = true
  66. df.default = "%F %R"
  67. df.date_string = ""
  68. function df.cfgvalue(self, section)
  69. local value = AbstractValue.cfgvalue(self, section) or self.default
  70. local epoch = os.time()
  71. self.date_string = DDNS.epoch2date(epoch, value)
  72. return value
  73. end
  74. function df.validate(self, value)
  75. if value == self.default then
  76. return "" -- default = empty
  77. end
  78. return value
  79. end
  80. -- run_dir -- #################################################################
  81. local rd = ns:option(Value, "run_dir")
  82. rd.title = translate("Status directory")
  83. rd.description = translate("Directory contains PID and other status information for each running section")
  84. rd.rmempty = true
  85. rd.default = "/var/run/ddns"
  86. function rd.validate(self, value)
  87. if value == self.default then
  88. return "" -- default = empty
  89. end
  90. return value
  91. end
  92. -- log_dir -- #################################################################
  93. local ld = ns:option(Value, "log_dir")
  94. ld.title = translate("Log directory")
  95. ld.description = translate("Directory contains Log files for each running section")
  96. ld.rmempty = true
  97. ld.default = "/var/log/ddns"
  98. function ld.validate(self, value)
  99. if value == self.default then
  100. return "" -- default = empty
  101. end
  102. return value
  103. end
  104. -- log_lines -- ###############################################################
  105. local ll = ns:option(Value, "log_lines")
  106. ll.title = translate("Log length")
  107. ll.description = translate("Number of last lines stored in log files")
  108. ll.rmempty = true
  109. ll.default = "250"
  110. function ll.validate(self, value)
  111. local n = tonumber(value)
  112. if not n or math.floor(n) ~= n or n < 1 then
  113. return nil, self.title .. ": " .. translate("minimum value '1'")
  114. end
  115. if value == self.default then
  116. return "" -- default = empty
  117. end
  118. return value
  119. end
  120. -- use_curl -- ################################################################
  121. if (SYS.call([[ grep -i "\+ssl" /usr/bin/wget >/dev/null 2>&1 ]]) == 0)
  122. and NXFS.access("/usr/bin/curl") then
  123. local pc = ns:option(Flag, "use_curl")
  124. pc.title = translate("Use cURL")
  125. pc.description = translate("If both cURL and GNU Wget are installed, Wget is used by default.")
  126. .. [[<br />]]
  127. .. translate("To use cURL activate this option.")
  128. pc.orientation = "horizontal"
  129. pc.rmempty = true
  130. pc.default = "0"
  131. function pc.parse(self, section)
  132. DDNS.flag_parse(self, section)
  133. end
  134. function pc.validate(self, value)
  135. if value == self.default then
  136. return "" -- default = empty
  137. end
  138. return value
  139. end
  140. end
  141. return m