global.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 CTRL = require "luci.controller.ddns" -- this application's controller
  8. local DDNS = require "luci.tools.ddns" -- ddns multiused functions
  9. -- cbi-map definition -- #######################################################
  10. local m = Map("ddns")
  11. m.title = CTRL.app_title_back()
  12. m.description = CTRL.app_description()
  13. m.redirect = DISP.build_url("admin", "services", "ddns")
  14. function m.commit_handler(self)
  15. if self.changed then -- changes ?
  16. local command = CTRL.luci_helper .. " -- reload"
  17. os.execute(command) -- reload configuration
  18. end
  19. end
  20. -- cbi-section definition -- ###################################################
  21. local ns = m:section( NamedSection, "global", "ddns",
  22. translate("Global Settings"),
  23. translate("Configure here the details for all Dynamic DNS services including this LuCI application.")
  24. .. [[<br /><strong>]]
  25. .. translate("It is NOT recommended for casual users to change settings on this page.")
  26. .. [[</strong><br />]]
  27. .. [[<a href="http://wiki.openwrt.org/doc/uci/ddns#version_2x1" target="_blank">]]
  28. .. translate("For detailed information about parameter settings look here.")
  29. .. [[</a>]]
  30. )
  31. -- section might not exist
  32. function ns.cfgvalue(self, section)
  33. if not self.map:get(section) then
  34. self.map:set(section, nil, self.sectiontype)
  35. end
  36. return self.map:get(section)
  37. end
  38. -- upd_privateip -- ###########################################################
  39. local ali = ns:option(Flag, "upd_privateip")
  40. ali.title = translate("Allow non-public IP's")
  41. ali.description = translate("Non-public and by default blocked IP's") .. ":"
  42. .. [[<br /><strong>IPv4: </strong>]]
  43. .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16"
  44. .. [[<br /><strong>IPv6: </strong>]]
  45. .. "::/32, f000::/4"
  46. ali.default = "0"
  47. -- ddns_dateformat -- #########################################################
  48. local df = ns:option(Value, "ddns_dateformat")
  49. df.title = translate("Date format")
  50. df.description = [[<a href="http://www.cplusplus.com/reference/ctime/strftime/" target="_blank">]]
  51. .. translate("For supported codes look here")
  52. .. [[</a>]]
  53. df.template = "ddns/global_value"
  54. df.default = "%F %R"
  55. df.date_string = ""
  56. function df.cfgvalue(self, section)
  57. local value = AbstractValue.cfgvalue(self, section) or self.default
  58. local epoch = os.time()
  59. self.date_string = DDNS.epoch2date(epoch, value)
  60. return value
  61. end
  62. function df.parse(self, section, novld)
  63. DDNS.value_parse(self, section, novld)
  64. end
  65. -- ddns_rundir -- #############################################################
  66. local rd = ns:option(Value, "ddns_rundir")
  67. rd.title = translate("Status directory")
  68. rd.description = translate("Directory contains PID and other status information for each running section")
  69. rd.default = "/var/run/ddns"
  70. -- no need to validate. if empty default is used everything else created by dns-scripts
  71. function rd.parse(self, section, novld)
  72. DDNS.value_parse(self, section, novld)
  73. end
  74. -- ddns_logdir -- #############################################################
  75. local ld = ns:option(Value, "ddns_logdir")
  76. ld.title = translate("Log directory")
  77. ld.description = translate("Directory contains Log files for each running section")
  78. ld.default = "/var/log/ddns"
  79. -- no need to validate. if empty default is used everything else created by dns-scripts
  80. function ld.parse(self, section, novld)
  81. DDNS.value_parse(self, section, novld)
  82. end
  83. -- ddns_loglines -- ###########################################################
  84. local ll = ns:option(Value, "ddns_loglines")
  85. ll.title = translate("Log length")
  86. ll.description = translate("Number of last lines stored in log files")
  87. ll.default = "250"
  88. function ll.validate(self, value)
  89. local n = tonumber(value)
  90. if not n or math.floor(n) ~= n or n < 1 then
  91. return nil, self.title .. ": " .. translate("minimum value '1'")
  92. end
  93. return value
  94. end
  95. function ll.parse(self, section, novld)
  96. DDNS.value_parse(self, section, novld)
  97. end
  98. -- use_curl -- ################################################################
  99. if (SYS.call([[ grep -i "\+ssl" /usr/bin/wget >/dev/null 2>&1 ]]) == 0)
  100. and NXFS.access("/usr/bin/curl") then
  101. local pc = ns:option(Flag, "use_curl")
  102. pc.title = translate("Use cURL")
  103. pc.description = translate("If both cURL and GNU Wget are installed, Wget is used by default.")
  104. .. [[<br />]]
  105. .. translate("To use cURL activate this option.")
  106. pc.orientation = "horizontal"
  107. pc.default = "0"
  108. end
  109. return m