Tomato 1.28
[tomato/tomato-null.git] / release / src / router / www / basic-ddns.asp
blob0bcf8b120d7cfd3695da273ddb7d4f3e2072d32b
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
4 Copyright (C) 2006-2010 Jonathan Zarate
5 http://www.polarcloud.com/tomato/
7 For use with Tomato Firmware only.
8 No part of this file may be used without permission.
9 -->
10 <html>
11 <head>
12 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
13 <meta name='robots' content='noindex,nofollow'>
14 <title>[<% ident(); %>] Basic: DDNS</title>
15 <link rel='stylesheet' type='text/css' href='tomato.css'>
16 <link rel='stylesheet' type='text/css' href='color.css'>
17 <script type='text/javascript' src='tomato.js'></script>
19 <!-- / / / -->
21 <script type='text/javascript' src='debug.js'></script>
23 <script type='text/javascript'>
25 // <% nvram("ddnsx0,ddnsx1,ddnsx_ip,wan_dns,wan_get_dns,dns_addget,ddnsx_refresh,ddnsx_save"); %>
26 // <% ddnsx(); %>
28 /* REMOVE-BEGIN
30 t = hostname (top)
31 u = username/password
32 p = password
33 h = hostname
34 j = hostname (optional)
35 c = custom url
36 w = wildcard
37 m = MX
38 b = backup MX
39 o = use OpenDNS
40 a = freedns.afraid
41 z = can't use client-given IP address
42 s = save state checkbox
44 REMOVE-END */
46 var services = [
47 ['', 'None', '', ''],
48 ['3322', '3322', 'http://www.3322.org/', 'uhwmb'],
49 ['3322-static', '3322 - Static', 'http://www.3322.org/', 'uhwmb'],
50 ['dnsexit', 'DNS Exit', 'http://www.dnsexit.com/', 'uh'],
51 ['dnsomatic', 'DNS-O-Matic', 'http://www.dnsomatic.com/', 'u'],
52 ['dyndns', 'DynDNS - Dynamic', 'http://www.dyndns.com/', 'uhwmbs'],
53 ['dyndns-static', 'DynDNS - Static', 'http://www.dyndns.com/', 'uhwmbs'],
54 ['dyndns-custom', 'DynDNS - Custom', 'http://www.dyndns.com/', 'uhwmbs'],
55 ['sdyndns', 'DynDNS (https) - Dynamic', 'http://www.dyndns.com/', 'uhwmbs'],
56 ['sdyndns-static', 'DynDNS (https) - Static', 'http://www.dyndns.com/', 'uhwmbs'],
57 ['sdyndns-custom', 'DynDNS (https) - Custom', 'http://www.dyndns.com/', 'uhwmbs'],
58 ['dyns', 'DyNS', 'http://www.dyns.cx/', 'uh'],
59 ['easydns', 'easyDNS', 'http://www.easydns.com/', 'uhwm'],
60 ['seasydns', 'easyDNS (https)', 'http://www.easydns.com/', 'uhwm'],
61 ['editdns', 'EditDNS', 'http://www.editdns.net/', 'tpz'],
62 ['everydns', 'EveryDNS', 'http://www.everydns.net/', 'uj', null, null, 'Domain <small>(optional)</small>'],
63 ['enom', 'eNom', 'http://www.enom.com/', 'ut', 'Domain'],
64 ['afraid', 'FreeDNS (afraid.org)', 'http://freedns.afraid.org/', 'az'],
65 ['ieserver', 'ieServer.net', 'http://www.ieserver.net/', 'uhz', 'Username / Hostname', null, 'Domain'],
66 ['namecheap', 'namecheap', 'http://www.namecheap.com/', 'ut', 'Domain'],
67 ['noip', 'No-IP.com', 'http://www.no-ip.com/', 'uh', 'Email Address', null, 'Hostname / Group'],
68 ['opendns', 'OpenDNS', 'http://www.opendns.com/', 'uhoz', null, null, 'Network <small>(optional)</small>'],
69 ['tzo', 'TZO', 'http://www.tzo.com/', 'uh', 'Email Address', 'Password'],
70 ['zoneedit', 'ZoneEdit', 'http://www.zoneedit.com/', 'uh'],
71 ['custom', 'Custom URL', '', 'c']];
73 var opendns = ['208.67.222.222', '208.67.220.220'];
74 var opendnsInUse = 0;
76 function msgLoc(s)
78 var r;
80 s = s.replace(/\n+/g, ' ');
81 if (r = s.match(/^(.*?): (.*)/)) {
82 r[2] = r[2].replace(/#RETRY (\d+) (\d+)/,
83 function(s, min, num) {
84 return '<br><small>(' + ((num >= 1) ? (num + '/3: ') : '') + 'Automatically retrying in ' + min + ' minutes)</small>';
87 return '<small>' + (new Date(r[1])).toLocaleString() + ':</small><br>' + r[2];
89 else if (s.length == 0) {
90 return '-';
92 return s;
95 function mop(s)
97 var op, i;
99 op = {};
100 for (i = s.length - 1; i >= 0; --i) {
101 op[s.charAt(i)] = 1;
104 return op;
107 function verifyFields(focused, quiet)
109 var i;
110 var data, r, e;
111 var op;
112 var enabled;
113 var b;
115 b = E('_f_ddnsx_ip').value == 'custom';
116 elem.display(PR('_f_custom_ip'), b);
117 if ((b) && (!v_ip('_f_custom_ip', quiet))) return 0;
119 if (!v_range('_ddnsx_refresh', quiet, 0, 90)) return 0;
121 r = 1;
122 for (i = 0; i < 2; ++i) {
123 data = services[E('_f_service' + i).selectedIndex] || services[0];
124 enabled = (data[0] != '');
126 op = mop(data[3]);
128 elem.display(PR('url' + i), (enabled) && (data[0] != 'custom'));
129 elem.display('row_z' + i, op.z);
131 elem.display(PR('_f_hosttop' + i), op.t);
132 elem.display(PR('_f_user' + i), op.u);
133 elem.display(PR('_f_pass' + i), op.u || op.p);
134 elem.display(PR('_f_host' + i), op.h || op.j);
135 elem.display(PR('_f_cust' + i), 'custmsg' + i, op.c);
137 elem.display(PR('_f_wild' + i), op.w);
138 elem.display(PR('_f_mx' + i), op.m);
139 elem.display(PR('_f_bmx' + i), op.b);
140 elem.display(PR('_f_opendns' + i), op.o);
141 elem.display(PR('_f_afraid' + i), op.a);
142 elem.display(PR('_f_ddnsx_save' + i), op.s);
144 elem.display(PR('_f_force' + i), 'last-response' + i, enabled);
145 elem.display('last-update' + i, enabled && !op.z);
147 if (enabled) {
148 PR('_f_user' + i).cells[0].innerHTML = data[4] || 'Username';
149 PR('_f_pass' + i).cells[0].innerHTML = data[5] || 'Password';
150 PR('_f_host' + i).cells[0].innerHTML = data[6] || 'Hostname';
152 e = E('url' + i);
153 e.href = data[2];
154 e.innerHTML = data[2];
156 if (op.c) {
157 e = E('_f_cust' + i);
158 e.value = e.value.trim();
159 if (e.value == '') {
160 e.value = 'http://';
162 if (e.value.search(/http(s?):\/\/./) != 0) {
163 ferror.set(e, 'Expecting a URL -- http://... or https://...', quiet)
164 r = 0;
166 else {
167 ferror.clear(e);
170 else if (op.a) {
171 e = E('_f_afraid' + i);
172 e.value = e.value.trim();
173 if (e.value.match(/freedns\.afraid\.org\/dynamic\/update\.php\?([a-zA-Z0-9]+)/)) {
174 e.value = RegExp.$1;
176 if (e.value.search(/^[A-Za-z0-9]+/) == -1) {
177 ferror.set(e, 'Invalid hash or URL', quiet)
178 r = 0;
180 else {
181 ferror.clear(e);
184 else {
185 if (((op.u) && (!v_length('_f_user' + i, quiet, 1))) ||
186 (!v_length('_f_pass' + i, quiet, 1)) ||
187 ((op.h) && (!op.o) && (!v_length('_f_host' + i, quiet, 1))) ||
188 ((op.t) && (!v_length('_f_hosttop' + i, quiet, 1)))) {
189 r = 0;
195 // shouldn't do this twice, but...
196 if (E('_f_opendns0') == focused) E('_f_opendns1').checked = E('_f_opendns0').checked;
197 if (E('_f_opendns1') == focused) E('_f_opendns0').checked = E('_f_opendns1').checked;
199 if (E('_f_ddnsx_save0') == focused) E('_f_ddnsx_save1').checked = E('_f_ddnsx_save0').checked;
200 if (E('_f_ddnsx_save1') == focused) E('_f_ddnsx_save0').checked = E('_f_ddnsx_save1').checked;
202 return r;
205 function save()
207 var fom;
208 var i, j, s;
209 var data, a, b;
210 var setopendns;
211 var op;
213 if (!verifyFields(null, 0)) return;
215 fom = E('_fom')
216 fom.ddnsx_save.value = (nvram.ddnsx_save == 1) ? 1 : 0;
218 fom.ddnsx_ip.value = (E('_f_ddnsx_ip').value == 'custom') ? E('_f_custom_ip').value : E('_f_ddnsx_ip').value;
220 setopendns = -1;
221 for (i = 0; i < 2; ++i) {
222 s = [];
223 data = services[E('_f_service' + i).selectedIndex] || services[0];
224 s.push(data[0]);
225 if (data[0] != '') {
226 /* REMOVE-BEGIN
228 t = hostname (top)
229 u = username/password
230 h = hostname
231 c = custom url
232 w = wildcard
233 m = MX
234 b = backup MX
235 o = use OpenDNS
236 a = freedns.afraid
237 z = can't use client-given IP address
238 s = save state checkbox
244 username:password<
245 hostname<
246 wildcard<
248 backup mx<
249 custom url/afraid hash<
251 REMOVE-END */
252 op = mop(data[3]);
254 if ((op.u) || (op.p)) s.push(E('_f_user' + i).value + ':' + E('_f_pass' + i).value);
255 else s.push('');
257 if (op.t) {
258 s.push(E('_f_hosttop' + i).value);
260 else if ((op.h) || (op.j)) {
261 s.push(E('_f_host' + i).value);
263 else {
264 s.push('');
267 if (op.w) s.push(E('_f_wild' + i).checked ? 1 : 0);
268 else s.push('');
269 if (op.m) s.push(E('_f_mx' + i).value)
270 else s.push('');
271 if (op.b) s.push(E('_f_bmx' + i).checked ? 1 : 0);
272 else s.push('');
274 if (op.c) {
275 s.push(E('_f_cust' + i).value);
277 else if (op.a) {
278 s.push(E('_f_afraid' + i).value);
280 else {
281 s.push('');
284 if (op.s) {
285 fom.ddnsx_save.value = E('_f_ddnsx_save' + i).checked ? 1 : 0;
288 if (data[0] == 'opendns') setopendns = E('_f_opendns' + i).checked;
290 s = s.join('<');
291 fom['ddnsx' + i].value = s;
292 fom['ddnsx' + i + '_cache'].disabled = (!E('_f_force' + i).checked) && (s == nvram['ddnsx' + i]);
295 if (setopendns != -1) {
296 if (setopendns) {
297 if (opendnsInUse != opendns.length) {
298 fom.wan_dns.value = opendns.join(' ');
299 fom.wan_dns.disabled = 0;
300 fom._service.value += ',dns-restart';
303 else {
304 // not set if partial, do not remove if partial
305 if (opendnsInUse == opendns.length) {
306 a = nvram.wan_dns.split(/\s+/);
307 b = [];
308 for (i = a.length - 1; i >= 0; --i) {
309 for (j = opendns.length - 1; j >= 0; --j) {
310 if (a[i] == opendns[j]) {
311 a.splice(i, 1);
312 break;
316 fom.wan_dns.value = a.join(' ');
317 fom.wan_dns.disabled = 0;
318 fom._service.value += ',dns-restart';
323 form.submit(fom);
326 function init()
328 if ('<% psup("ddns-update"); %>' != 0) {
329 var e = E('footer-msg');
330 e.innerHTML = 'DDNS update is running. Please refresh after a few seconds.';
331 e.style.visibility = 'visible';
334 </script>
336 </head>
337 <body onload='init()'>
338 <form id='_fom' method='post' action='tomato.cgi'>
339 <table id='container' cellspacing=0>
340 <tr><td colspan=2 id='header'>
341 <div class='title'>Tomato</div>
342 <div class='version'>Version <% version(); %></div>
343 </td></tr>
344 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
345 <td id='content'>
346 <div id='ident'><% ident(); %></div>
348 <!-- / / / -->
350 <input type='hidden' name='_nextpage' value='basic-ddns.asp'>
351 <input type='hidden' name='_service' value='ddns-restart'>
352 <input type='hidden' name='_nextwait' value='8'>
354 <input type='hidden' name='ddnsx0' value=''>
355 <input type='hidden' name='ddnsx1' value=''>
356 <input type='hidden' name='ddnsx0_cache' value='' disabled>
357 <input type='hidden' name='ddnsx1_cache' value='' disabled>
358 <input type='hidden' name='wan_dns' value='' disabled>
359 <input type='hidden' name='ddnsx_ip' value=''>
360 <input type='hidden' name='ddnsx_save' value=''>
363 <div class='section-title'>Dynamic DNS</div>
364 <div class='section'>
365 <script type='text/javascript'>
366 s = nvram.ddnsx_ip;
367 a = (s != '') && (s.indexOf('@') != 0) && (s != '0.0.0.0') && (s != '1.1.1.1') && (s != '10.1.1.1');
368 createFieldTable('', [
369 { title: 'IP address', name: 'f_ddnsx_ip', type: 'select',
370 options: [
371 ['', 'Use WAN IP Address ' + ddnsx_ip + ' (recommended)'],
372 ['@', 'Use External IP Address Checker (every 10 minutes)'],
373 ['0.0.0.0', 'Offline (0.0.0.0)'],
374 ['1.1.1.1', 'Offline (1.1.1.1)'],
375 ['10.1.1.1', 'Offline (10.1.1.1)'],
376 ['custom', 'Custom IP Address...']
378 value: a ? 'custom' : nvram.ddnsx_ip },
379 { title: 'Custom IP address', indent: 2, name: 'f_custom_ip', type: 'text', maxlen: 15, size: 20,
380 value: a ? nvram.ddnsx_ip : '', hidden: !a },
381 { title: 'Auto refresh every', name: 'ddnsx_refresh', type: 'text', maxlen: 8, size: 8, suffix: ' days <small>(0 = disable)</small>', value: fixInt(nvram.ddnsx_refresh, 0, 90, 28) }
383 </script>
384 </div>
387 <script type='text/javascript'>
388 a = nvram.wan_dns.split(/\s+/);
389 for (i = 0; i < a.length; ++i) {
390 for (j = 0; j < opendns.length; ++j) {
391 if (a[i] == opendns[j]) ++opendnsInUse;
395 if (nvram.dns_addget == 1) {
396 dns = nvram.wan_dns + ' ' + nvram.wan_get_dns;
398 else if (nvram.wan_dns != '') {
399 dns = nvram.wan_dns;
401 else {
402 dns = nvram.wan_get_dns;
404 dns = dns.split(/\s+/);
405 for (i = 0; i < dns.length; ++i) {
406 for (j = 0; j < opendns.length; ++j) {
407 if (dns[i] == opendns[j]) {
408 dns[i] = '<i>' + dns[i] + '</i>';
409 break;
413 dns = dns.join(', ');
415 for (i = 0; i < 2; ++i) {
416 v = nvram['ddnsx' + i].split('<');
417 if (v.length != 7) v = ['', '', '', 0, '', 0, ''];
419 u = v[1].split(':');
420 if (u.length != 2) u = ['', ''];
421 h = (v[0] == '');
423 W('<div class="section-title">Dynamic DNS ' + (i + 1) + '</div><div class="section">');
424 createFieldTable('', [
425 { title: 'Service', name: 'f_service' + i, type: 'select', options: services, value: v[0] },
426 { title: 'URL', indent: 2, text: '<a href="" id="url' + i + '" target="tomato-ext-ddns"></a>', hidden: 1 },
427 { title: '&nbsp;', text: '<small>* This service determines the IP address using its own method.</small>', hidden: 1, rid: 'row_z' + i },
428 { title: 'Hostname', name: 'f_hosttop' + i, type: 'text', maxlen: 96, size: 35, value: v[2], hidden: 1 },
429 { title: 'Username', name: 'f_user' + i, type: 'text', maxlen: 64, size: 35, value: u[0], hidden: 1 },
430 { title: 'Password', name: 'f_pass' + i, type: 'password', maxlen: 64, size: 35, peekaboo: 1, value: u[1], hidden: 1 },
431 { title: 'Hostname', name: 'f_host' + i, type: 'text', maxlen: 255, size: 80, value: v[2], hidden: 1 },
432 { title: 'URL', name: 'f_cust' + i, type: 'text', maxlen: 255, size: 80, value: v[6], hidden: 1 },
433 { title: ' ', text: '(Use @IP for the current IP address)', rid: ('custmsg' + i), hidden: 1 },
434 { title: 'Wildcard', indent: 2, name: 'f_wild' + i, type: 'checkbox', value: v[3] != '0', hidden: 1 },
435 { title: 'MX', name: 'f_mx' + i, type: 'text', maxlen: 32, size: 35, value: v[4], hidden: 1 },
436 { title: 'Backup MX', indent: 2, name: 'f_bmx' + i, type: 'checkbox', value: v[5] != '0', hidden: 1 },
437 { title: 'Use as DNS', name: 'f_opendns' + i, type: 'checkbox', value: (opendnsInUse == opendns.length),
438 suffix: '<br><small>(Current DNS: ' + dns + ')</small>', hidden: 1 },
439 { title: 'Token / URL', name: 'f_afraid' + i, type: 'text', maxlen: 255, size: 80, value: v[6], hidden: 1 },
440 { title: 'Save state when IP changes (nvram commit)', name: 'f_ddnsx_save' + i, type: 'checkbox', value: nvram.ddnsx_save == '1', hidden: 1 },
441 { title: 'Force next update', name: 'f_force' + i, type: 'checkbox', value: 0, hidden: 1 },
442 null,
443 { title: 'Last IP Address', custom: msgLoc(ddnsx_last[i]), rid: 'last-update' + i, hidden: 1 },
444 { title: 'Last Result', custom: msgLoc(ddnsx_msg[i]), rid: 'last-response' + i, hidden: h }
446 W('</div>');
448 </script>
451 <!-- / / / -->
453 </td></tr>
454 <tr><td id='footer' colspan=2>
455 <span id='footer-msg'></span>
456 <input type='button' value='Save' id='save-button' onclick='save()'>
457 <input type='button' value='Cancel' id='cancel-button' onclick='reloadPage();'>
458 </td></tr>
459 </table>
460 <script type='text/javascript'>verifyFields(null, 1);</script>
461 </form>
462 </body>
463 </html>