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