1 -- Copyright 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
2 -- Licensed to the public under the Apache License 2.0.
4 local NX = require "nixio"
5 local NXFS = require "nixio.fs"
6 local DISP = require "luci.dispatcher"
7 local SYS = require "luci.sys"
8 local CTRL = require "luci.controller.ddns" -- this application's controller
9 local DDNS = require "luci.tools.ddns" -- ddns multiused functions
11 -- cbi-map definition -- #######################################################
13 m.title = CTRL.app_title_back()
14 m.description = CTRL.app_description()
15 m.redirect = DISP.build_url("admin", "services", "ddns")
17 function m.commit_handler(self)
18 if self.changed then -- changes ?
19 os.execute("/etc/init.d/ddns reload &") -- reload configuration
23 -- cbi-section definition -- ###################################################
24 local ns = m:section( NamedSection, "global", "ddns",
25 translate("Global Settings"),
26 translate("Configure here the details for all Dynamic DNS services including this LuCI application.")
28 .. translate("It is NOT recommended for casual users to change settings on this page.")
29 .. [[</strong><br />]]
30 .. [[<a href="http://wiki.openwrt.org/doc/uci/ddns#version_2x1" target="_blank">]]
31 .. translate("For detailed information about parameter settings look here.")
35 -- section might not exist
36 function ns.cfgvalue(self, section)
37 if not self.map:get(section) then
38 self.map:set(section, nil, self.sectiontype)
40 return self.map:get(section)
43 -- allow_local_ip -- ##########################################################
44 local ali = ns:option(Flag, "allow_local_ip")
45 ali.title = translate("Allow non-public IP's")
46 ali.description = translate("Non-public and by default blocked IP's") .. ":"
47 .. [[<br /><strong>IPv4: </strong>]]
48 .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16"
49 .. [[<br /><strong>IPv6: </strong>]]
53 -- date_format -- #############################################################
54 local df = ns:option(Value, "date_format")
55 df.title = translate("Date format")
56 df.description = [[<a href="http://www.cplusplus.com/reference/ctime/strftime/" target="_blank">]]
57 .. translate("For supported codes look here")
59 df.template = "ddns/global_value"
62 function df.cfgvalue(self, section)
63 local value = AbstractValue.cfgvalue(self, section) or self.default
64 local epoch = os.time()
65 self.date_string = DDNS.epoch2date(epoch, value)
68 function df.parse(self, section, novld)
69 DDNS.value_parse(self, section, novld)
72 -- run_dir -- #################################################################
73 local rd = ns:option(Value, "run_dir")
74 rd.title = translate("Status directory")
75 rd.description = translate("Directory contains PID and other status information for each running section")
76 rd.default = "/var/run/ddns"
77 -- no need to validate. if empty default is used everything else created by dns-scripts
78 function rd.parse(self, section, novld)
79 DDNS.value_parse(self, section, novld)
82 -- log_dir -- #################################################################
83 local ld = ns:option(Value, "log_dir")
84 ld.title = translate("Log directory")
85 ld.description = translate("Directory contains Log files for each running section")
86 ld.default = "/var/log/ddns"
87 -- no need to validate. if empty default is used everything else created by dns-scripts
88 function ld.parse(self, section, novld)
89 DDNS.value_parse(self, section, novld)
92 -- log_lines -- ###############################################################
93 local ll = ns:option(Value, "log_lines")
94 ll.title = translate("Log length")
95 ll.description = translate("Number of last lines stored in log files")
97 function ll.validate(self, value)
98 local n = tonumber(value)
99 if not n or math.floor(n) ~= n or n < 1 then
100 return nil, self.title .. ": " .. translate("minimum value '1'")
104 function ll.parse(self, section, novld)
105 DDNS.value_parse(self, section, novld)
108 -- use_curl -- ################################################################
109 if (SYS.call([[ grep -i "\+ssl" /usr/bin/wget >/dev/null 2>&1 ]]) == 0)
110 and NXFS.access("/usr/bin/curl") then
111 local pc = ns:option(Flag, "use_curl")
112 pc.title = translate("Use cURL")
113 pc.description = translate("If both cURL and GNU Wget are installed, Wget is used by default.")
115 .. translate("To use cURL activate this option.")
116 pc.orientation = "horizontal"