1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
<!-- ++ BEGIN ++ Dynamic DNS ++ overview_status.htm ++ -->
<script type="text/javascript">//<![CDATA[
// helper to extract section from objects id
// cbi.ddns.SECTION._xyz
function _id2section(id) {
var x = id.split(".");
return x[2];
}
// helper to move status data to the relevant
// screen objects
// called by XHR.poll and onclick_startstop
function _data2elements(data) {
// Service sections
for( var i = 1; i < data.length; i++ )
{
var section = data[i].section // Section to handle
var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
var btn = document.getElementById("cbid.ddns." + section + "._startstop"); // Start/Stop button
var rip = document.getElementById("cbid.ddns." + section + "._lookupIP.two"); // Registered IP
var lup = document.getElementById("cbid.ddns." + section + "._update.one"); // Last Update
var nup = document.getElementById("cbid.ddns." + section + "._update.two"); // Next Update
if ( !(cbx && btn && rip && lup && nup) ) { return; } // security check
// process id
if (data[i].pid > 0) {
// stop always possible if process running
btn.value = "PID: " + data[i].pid;
btn.className = "cbi-button cbi-input-reset";
} else {
// default Start / enabled
btn.value = "<%:Start%>";
btn.className = "cbi-button cbi-input-apply";
}
btn.disabled = false; // button enabled
// last update
switch (data[i].datelast) {
case "_empty_":
lup.innerHTML = '<em><%:Unknown error%></em>' ;
break;
case "_never_":
lup.innerHTML = '<em><%:Never%></em>' ;
break;
default:
lup.innerHTML = data[i].datelast;
break;
}
// next update
switch (data[i].datenext) {
case "_empty_":
nup.innerHTML = '<em><%:Unknown error%></em>' ;
break;
case "_verify_":
nup.innerHTML = '<em><%:Verify%></em>';
break;
case "_runonce_":
case "_stopped_":
case "_disabled_":
if (cbx.checked && data[i].datenext == "_runonce_") {
nup.innerHTML = '<em><%:Run once%></em>';
} else if (cbx.checked) {
nup.innerHTML = '<em><%:Stopped%></em>';
} else {
nup.innerHTML = '<em><%:Disabled%></em>';
btn.value = '----------';
btn.className = "cbi-button cbi-input-button"; // no image
btn.disabled = true; // disabled
}
break;
default:
nup.innerHTML = data[i].datenext;
break;
}
// lookup
// (data[i].lookup ignored here
// registered IP
// rip.innerHTML = "Registered IP";
if (data[i].lookup == "_nolookup_")
rip.innerHTML = '';
else if (data[i].reg_ip == "_nodata_")
rip.innerHTML = '<em><%:No data%></em>';
else
rip.innerHTML = data[i].reg_ip;
// monitored interfacce
// data[i].iface ignored here
}
}
// event handler for enabled checkbox
function onchange_enabled(id) {
// run original function in cbi.js
// whatever is done there
cbi_d_update(id);
var section = _id2section(id);
var cbx = document.getElementById("cbid.ddns." + section + ".enabled");
var btn = document.getElementById("cbid.ddns." + section + "._startstop");
if ( !(cbx && btn) ) { return; } // security check
var pid_txt = btn.value;
var pid_found = ( pid_txt.search("PID") >= 0 ) ? true : false;
if (pid_found) {
// btn.value = "PID: 0000";
btn.className = "cbi-button cbi-button-reset";
btn.disabled = false;
} else if (cbx.checked) {
btn.value = "<%:Start%>";
btn.className = "cbi-button cbi-button-apply";
btn.disabled = false;
} else {
btn.value = '----------';
btn.className = "cbi-button cbi-input-button"; // no image
btn.disabled = true; // disabled
}
}
// event handler for start/stop button
function onclick_startstop(id) {
// extract section
var section = _id2section(id);
// get elements
var cbx = document.getElementById("cbid.ddns." + section + ".enabled"); // Enabled
var obj = document.getElementById("cbi-ddns-overview-status-legend"); // object defined below to make in-/visible
if ( !(obj && cbx) ) { return; } // security check
// make me visible
obj.parentNode.style.display = "block";
// do start/stop
var btnXHR = new XHR();
btnXHR.post('<%=url([[admin]], [[services]], [[ddns]], [[startstop]])%>/' + section + '/' + cbx.checked, { token: '<%=token%>' },
function(x, data) {
if (x.responseText == "_uncommitted_") {
// we need a trick to display Ampersand "&" in stead of "&" or "&"
// after translation
var txt="<%:Please [Save & Apply] your changes first%>";
alert( txt.replace(new RegExp("<%:&%>", "g"), "&") );
} else {
// should have data because status changed
// so update screen
if (data) { _data2elements(data); }
}
// make me invisible
obj.parentNode.style.display = "none";
}
);
}
// force to immediate show status on page load (not waiting for XHR.poll)
XHR.get('<%=url([[admin]], [[services]], [[ddns]], [[status]])%>', null,
function(x, data) {
if (data) { _data2elements(data); }
}
);
// define only ONE XHR.poll in a page because if one is running it blocks the other one
// optimum is to define on Map or Section Level from here you can reach all elements
// we need update every 15 seconds only
XHR.poll(5, '<%=url([[admin]], [[services]], [[ddns]], [[status]])%>', null,
function(x, data) {
if (data) { _data2elements(data); }
}
);
//]]></script>
<fieldset class="cbi-section" style="display:none">
<legend id="cbi-ddns-overview-status-legend"><%:Applying changes%></legend>
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
<span id="cbi-ddns-overview-status-text"><%:Waiting for changes to be applied...%></span>
</fieldset>
<!-- ++ END ++ Dynamic DNS ++ overview_status.htm ++ -->
|