2 <!-- ++ BEGIN ++ Dynamic DNS ++ overview_status.htm ++ -->
3 <script type="text/javascript">//<![CDATA[
5 // variables to store version information
11 // helper to extract section from objects id
12 // cbi.ddns.SECTION._xyz
13 function _id2section(id) {
14 var x = id.split(".");
18 // helper to move status data to the relevant
20 // called by XHR.poll and onclick_startstop
21 function _data2elements(data) {
23 // fill Version informations
24 luci_version = data[0].luci_ver
25 luci_build = data[0].luci_build
26 ddns_version = data[0].script_ver
27 ddns_required = data[0].script_min
30 for( i = 1; i < data.length; i++ )
32 var section = data[i].section // Section to handle
33 var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
34 var btn = document.getElementById("cbid.ddns." + section + "._startstop"); // Start/Stop button
35 var rip = document.getElementById("cbid.ddns." + section + "._domainIP.two"); // Registered IP
36 var lup = document.getElementById("cbid.ddns." + section + "._update.one"); // Last Update
37 var nup = document.getElementById("cbid.ddns." + section + "._update.two"); // Next Update
38 if ( !(cbx && btn && rip && lup && nup) ) { return; } // security check
41 if (data[i].pid > 0) {
42 // stop always possible if process running
43 btn.value = "PID: " + data[i].pid;
44 btn.className = "cbi-button cbi-input-reset";
46 // default Start / enabled
47 btn.value = "<%:Start%>";
48 btn.className = "cbi-button cbi-input-apply";
50 btn.disabled = false; // button enabled
53 switch (data[i].datelast) {
55 lup.innerHTML = '<em><%:Unknown error%></em>' ;
58 lup.innerHTML = '<em><%:Never%></em>' ;
61 lup.innerHTML = data[i].datelast;
66 switch (data[i].datenext) {
68 nup.innerHTML = '<em><%:Unknown error%></em>' ;
71 nup.innerHTML = '<em><%:Verify%></em>';
76 if (cbx.checked && data[i].datenext == "_runonce_") {
77 nup.innerHTML = '<em><%:Run once%></em>';
78 } else if (cbx.checked) {
79 nup.innerHTML = '<em><%:Stopped%></em>';
81 nup.innerHTML = '<em><%:Disabled%></em>';
82 btn.value = '----------';
83 btn.className = "cbi-button cbi-input-button"; // no image
84 btn.disabled = true; // disabled
88 nup.innerHTML = data[i].datenext;
93 // (data[i].domain ignored here
96 // rip.innerHTML = "Registered IP";
97 if (data[i].domain == "_nodomain_")
99 else if (data[i].reg_ip == "_nodata_")
100 rip.innerHTML = '<em><%:No data%></em>';
102 rip.innerHTML = data[i].reg_ip;
104 // monitored interfacce
105 // data[i].iface ignored here
109 // event handler for enabled checkbox
110 function onchange_enabled(id) {
111 // run original function in cbi.js
112 // whatever is done there
115 var section = _id2section(id);
116 var cbx = document.getElementById("cbid.ddns." + section + ".enabled");
117 var btn = document.getElementById("cbid.ddns." + section + "._startstop");
118 if ( !(cbx && btn) ) { return; } // security check
120 var pid_txt = btn.value;
121 var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
124 // btn.value = "PID: 0000";
125 btn.className = "cbi-button cbi-button-reset";
126 btn.disabled = false;
127 } else if (cbx.checked) {
128 btn.value = "<%:Start%>";
129 btn.className = "cbi-button cbi-button-apply";
130 btn.disabled = false;
132 btn.value = '----------';
133 btn.className = "cbi-button cbi-input-button"; // no image
134 btn.disabled = true; // disabled
138 // event handler for map.title link
139 function onclick_maptitle() {
140 var str = "<%:Version Information%>";
141 str += "\n\nluci-app-ddns:";
142 str += "\n\t<%:Version%>:\t" + luci_version;
143 str += "\n\t<%:Build%>:\t" + luci_build;
144 str += "\n\nddns-scripts <%:installed%>:";
145 str += "\n\t<%:Version%>:\t" + ddns_version;
146 str += "\n\nddns-scripts <%:required%>:";
147 str += "\n\t<%:Version%>:\t" + ddns_required + " <%:or greater%>";
152 // event handler for start/stop button
153 function onclick_startstop(id) {
155 var section = _id2section(id);
157 var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
158 var obj = document.getElementById("cbi-ddns-overview-status-legend"); // objext defined below to make in-/visible
159 if ( !(obj && cbx) ) { return; } // security check
162 obj.parentNode.style.display = "block";
165 var btnXHR = new XHR();
166 btnXHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "startstop")%>/' + section + '/' + cbx.checked, null,
168 if (x.responseText == "_uncommited_") {
169 // we need a trick to display Ampersand "&" in stead of "&" or "&"
171 txt="<%:Please [Save & Apply] your changes first%>";
172 alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
174 // should have data because status changed
177 _data2elements(data);
180 obj.parentNode.style.display = "none";
185 // force to immediate show status on page load (not waiting for XHR.poll)
186 XHR.get('<%=luci.dispatcher.build_url("admin", "services", "ddns", "status")%>', null,
188 _data2elements(data);
192 // define only ONE XHR.poll in a page because if one is running it blocks the other one
193 // optimum is to define on Map or Section Level from here you can reach all elements
194 // we need update every 15 seconds only
195 XHR.poll(15, '<%=luci.dispatcher.build_url("admin", "services", "ddns", "status")%>', null,
197 _data2elements(data);
203 <fieldset class="cbi-section" style="display:none">
204 <legend id="cbi-ddns-overview-status-legend"><%:Applying changes%></legend>
205 <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
206 <span id="cbi-ddns-overview-status-text"><%:Waiting for changes to be applied...%></span>
208 <!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->