Advertisement
rs232

admin-config.asp

Apr 27th, 2023 (edited)
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en-GB">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html;charset=utf-8">
  5. <meta name="robots" content="noindex,nofollow">
  6. <title>[<% ident(); %>] Admin: Configuration</title>
  7. <link rel="stylesheet" type="text/css" href="tomato.css">
  8. <% css(); %>
  9. <script src="tomato.js"></script>
  10. <script>
  11. //  <% nvram("lan_hwaddr,t_features,t_model_name,lan_hostname,lan_ipaddr,os_version"); %>
  12. //  <% nvstat(); %>
  13. var free_mem = nvstat.free / nvstat.size * 100.0;
  14. const now = new Date();
  15. var cmd = new XmlHttp();
  16. function backupNameChanged() {
  17. var name = fixFile(E('backup-name').value);
  18. if (name.length > 1)
  19. E('backup-link').href = 'cfg/'+name+'.cfg?_http_id='+nvram.http_id;
  20. else
  21. E('backup-link').href = '?';
  22. }
  23. function backupButton() {
  24. var name = fixFile(E('backup-name').value);
  25. if (name.length <= 1) {
  26. alert('Invalid filename');
  27. return;
  28. }
  29. location.href = 'cfg/'+name+'.cfg?_http_id='+nvram.http_id;
  30. }
  31. function restoreButton() {
  32. var name, i, f;
  33. name = fixFile(E('restore-name').value);
  34. name = name.toLowerCase();
  35. if ((name.indexOf('.cfg') != (name.length - 4)) && (name.indexOf('.cfg.gz') != (name.length - 7))) {
  36. alert('Incorrect filename. Expecting a ".cfg" file');
  37. return;
  38. }
  39. if (!confirm('Are you sure?'))
  40. return;
  41. E('restore-button').disabled = 1;
  42. f = E('restore-form');
  43. form.addIdAction(f);
  44. f.submit();
  45. }
  46. function resetButton() {
  47. var i;
  48. i = E('restore-mode').value;
  49. if (i == 0)
  50. return;
  51. if ((i == 2) && (features('!nve'))) {
  52. if (!confirm('WARNING: Erasing the NVRAM on a '+nvram.t_model_name+' router may be harmful. It may not be able to re-setup the NVRAM correctly after a complete erase. Proceeed anyway?'))
  53. return;
  54. }
  55. if (!confirm('Are you sure?'))
  56. return;
  57. E('reset-button').disabled = 1;
  58. form.submit('reset-form');
  59. }
  60. function init() {
  61. backupNameChanged();
  62. if (free_mem <= 5)
  63. E('notice-msg').innerHTML = '<div id="notice">The NVRAM free space is very low. It is strongly recommended to erase all data in NVRAM memory, and reconfigure the router manually in order to clean up all unused and obsolete entries.<\/div>';
  64. autorunStatus();
  65. }
  66.  
  67. function verifyFields(f) {
  68. return 1;
  69. }
  70.  
  71. function processCheckbox() {
  72.   var checkboxes = document.querySelectorAll('input[type=checkbox]:checked');
  73.   const fn = document.querySelector('#backup-plain').value
  74.   // var usb
  75.   var par = "";
  76.   for (var i = 0; i < checkboxes.length; i++) {
  77.     par += checkboxes[i].name + ' ';
  78.     if (checkboxes[i].name == 'usbrestore') { var usb = checkboxes[i].value; }
  79.   }
  80.   console.log(par);
  81.   console.log(fn);
  82.   console.log(usb);
  83.   const btn = document.getElementById("btn");
  84.   btn.disabled = true;
  85. if ( usb == 'on' ) {
  86.   document.querySelector('#btn').value = '๐Ÿ’พ The restore.autorun is being saved on USB';
  87.     } else {
  88.   document.querySelector('#btn').value = 'โฒ๏ธ Download is being prepared. Wait 15 seconds.';
  89.     }
  90.   setTimeout(function() { btn.disabled = false; }, 15000);
  91.   backmeUp(par,fn,usb);
  92. }
  93. function downloadURI(uri, name)
  94. {
  95.     var link = document.createElement("a");
  96.     link.download = name;
  97.     link.href = uri;
  98.     link.click();
  99. }  
  100. function backmeUp(para,fnm,usbr) {
  101.     var c = '/tmp/nvram_backup ' + para + ' >/var/wwwext/nvram_backup.htm' ;
  102.     cmd.post('shell.cgi', 'action=execute&command='+escapeCGI(c.replace(/\r/g, '')));
  103.     autorunStatus();
  104.     if ( usbr != 'on' ) {
  105.     setTimeout(function() { downloadURI('ext/nvram_backup.htm', fnm + '.nvram');
  106.         autorunStatus();
  107.         }, 15000);
  108.     }
  109.     setTimeout(function() {document.querySelector('#btn').value = '๐Ÿ“ƒ Backup plaintext';
  110.         autorunStatus();
  111.         }, 15000);
  112.     setTimeout(function() {
  113.         var c = 'rm -f /var/wwwext/nvram_backup.htm &>/dev/null';
  114.         cmd.post('shell.cgi', 'action=execute&command='+escapeCGI(c.replace(/\r/g, '')));
  115.     autorunStatus();
  116.     }, 20000);
  117.     autorunStatus();   
  118. }
  119. function removeAutorun() {
  120.     var c = '/tmp/nvram_backup removeautorun' ;
  121.     cmd.post('shell.cgi', 'action=execute&command='+escapeCGI(c.replace(/\r/g, '')));
  122.     setTimeout(function() {
  123.     autorunStatus();
  124.     }, 300);
  125. }
  126. function displayStatus() { 
  127. elem.setInnerHTML(E('status'), cmdresult );
  128. cmdresult = '';
  129. }
  130. function autorunStatus() {
  131.   var usbc = document.getElementById("usbrestore");
  132.   var sta = document.getElementById("status");
  133.   var backup = document.getElementById("backup-plain");
  134.   if (usbc.checked == true){
  135.     sta.style.display = "block";
  136.     backup.style.display = "none";
  137.   } else {
  138.     sta.style.display = "none";
  139.     backup.style.display = "block";
  140.   }
  141. cmd = new XmlHttp();
  142. cmd.onCompleted = function(text, xml) {
  143. eval(text);
  144. displayStatus();
  145. }
  146. var commands = '/tmp/nvram_backup status-autorun';
  147. cmd.post('shell.cgi', 'action=execute&command='+escapeCGI(commands.replace(/\r/g, '')));
  148. }
  149.  
  150. function restorePlain() {
  151. var name, i, f;
  152. name = fixFile(E('restore-plain').value);
  153. name = name.toLowerCase();
  154. if ((name.indexOf('.nvram') != (name.length - 6) )) {
  155. alert('Incorrect filename. Expecting a ".nvram" file');
  156. return;
  157. }
  158. if (!confirm('Are you sure?'))
  159. return;
  160. E('restore-plain').disabled = 1;
  161. f = E('restore-form');
  162. form.addIdAction(f);
  163. f.submit();
  164. }
  165. function toggle(source) {
  166.     var checkboxes = document.querySelectorAll('input[type="checkbox"]');
  167.     for (var i = 0; i < checkboxes.length; i++) {
  168.         if ((checkboxes[i].name == 'usbrestore' || checkboxes[i].name == 'erase')) { continue; }
  169.         if (checkboxes[i] != source)
  170.             checkboxes[i].checked = source.checked;
  171.     }
  172. }
  173.  
  174. </script>
  175. </head>
  176. <body onload="init()">
  177. <table id="container">
  178. <tr><td colspan="2" id="header">
  179. <div class="title">FreshTomato</div>
  180. <div class="version">Version <% version(); %> on <% nv("t_model_name"); %></div>
  181. </td></tr>
  182. <tr id="body"><td id="navi"><script>navi()</script></td>
  183. <td id="content">
  184. <div id="ident"><% ident(); %> | <script>wikiLink();</script></div>
  185. <div class="section-title">๐Ÿ““ Plaintext Configuration Backup</div>
  186. <div class="section">
  187. <input type="checkbox" onClick="toggle(this)"> Toggle all/none
  188. <form>
  189. <script>
  190.         createFieldTable('', [
  191.             { indent: 2, title: 'Credentials', name: 'sec', value: 1, type: 'checkbox', suffix: ' <small>(pass|crt|^ssh|https?)<\/small> '},
  192.             { indent: 2, title: 'IPv4', name: 'ipv4', value: 1,  type: 'checkbox', suffix: ' <small>(ipaddr|br|wan|domain|hostname|portforward|_pptp|ppp|^wan|^lan|^router)<\/small>' },
  193.             { indent: 2, title: 'IPv6', name: 'ipv6', value: 0,  type: 'checkbox', suffix: ' <small>(^ipv6)<\/small>' },
  194.             { indent: 2, title: 'VLAN', name: 'vlan', value: 0,  type: 'checkbox', suffix: ' <small>(vlan|^ctf||manual_boot_nv)<\/small>' },
  195.             { indent: 2, title: 'Time', name: 'time', value: 0,  type: 'checkbox', suffix: ' <small>(^ntp|^ntpd|^tm_)<\/small>' },
  196.             { indent: 2, title: 'DHCP', name: 'dhcp', value: 0,  type: 'checkbox', suffix: ' <small>(^dhcp_|^dhcpd_)<\/small>' },
  197.             { indent: 2, title: 'DNS', name: 'dns', value: 0,  type: 'checkbox', suffix: ' <small>(^dnsmasq_|^ddns|^dns_|^dnssec_|^mdns_)<\/small>' },
  198.             { indent: 2, title: 'Wireless', name: 'wl', value: 0,  type: 'checkbox', suffix: ' <small>(^wl|territory_code|^emf_)<\/small>' },
  199.             { indent: 2, title: 'Multicast', name: 'mcast', value: 0,  type: 'checkbox', suffix: ' <small>(^udpxy|^multicast|force_igmpv2)<\/small>' },
  200.             { indent: 2, title: 'Port', name: 'port', value: 0,  type: 'checkbox', suffix: ' <small>(^trigforward|upnp|^dmz|^portforward)<\/small>' },
  201.             { indent: 2, title: 'QoS', name: 'qos', value: 0,  type: 'checkbox', suffix: ' <small>(qos|limit|bwl_enable|DSCP_fix_enable|^ne_v)<\/small>' },
  202.             { indent: 2, title: 'USB', name: 'usb', value: 0,  type: 'checkbox', suffix: ' <small>(usb|smb|^bt|^ftp|_ftp|^ms_|gro_disable|txworkq|idle_enable)<\/small>' },
  203.             { indent: 2, title: 'Adblock', name: 'adblock', value: 0,  type: 'checkbox', suffix: ' <small>(^adblock)<\/small>' },
  204.             { indent: 2, title: 'Tor', name: 'tor', value: 0,  type: 'checkbox', suffix: ' <small>(^tor_)<\/small>' },
  205.             { indent: 2, title: 'VPN', name: 'vpn', value: 0,  type: 'checkbox', suffix: ' <small>(^vpn_|^pptp|tinc)<\/small>' },
  206.             { indent: 2, title: 'Web', name: 'web', value: 0,  type: 'checkbox', suffix: ' <small>(nginx_|^mysql_|^web_)<\/small>' },
  207.             { indent: 2, title: 'TomatoAnon', name: 'tomatoanon', value: 0,  type: 'checkbox', suffix: ' <small>(^tomatoanon)<\/small>' },
  208.             { indent: 2, title: 'Access Restriction', name: 'restriction', value: 0,  type: 'checkbox', suffix: ' <small>(^rrule)<\/small>' },
  209.             { indent: 2, title: 'Portal', name: 'portal', value: 0,  type: 'checkbox', suffix: ' <small>(^NC_|^web_)<\/small>' },
  210.             { indent: 2, title: 'Misc', name: 'misc', value: 0,  type: 'checkbox', suffix: ' <small>(^webmon|^jumbo|boot_wait|^console_|^fw_|^ne_|^nf_|router_name|^stealth|^telnetd_|wait_time|watchdog)<\/small>' },
  211.             { indent: 2, title: 'Admin', name: 'admin', value: 0,  type: 'checkbox', suffix: ' <small>(^script_|anport|ttb|^[r|^c]stats|^sesx|cifs|^jffs2|debug|^nfs_|^snmp_|^log|^sch_)<\/small>' },
  212.             { indent: 2, name: 'empty' },
  213.             { indent: 1, title: 'Erase NVRAM', id: 'erase', name: 'erase', value: 1,  type: 'checkbox', onclick: 'autorunStatus()', suffix: ' <small>Add nvram erase to the top of the backup file (affects restoring device only)<\/small>' },        
  214.             { indent: 1, title: 'USB restore.autorun', id: 'usbrestore', name: 'usbrestore', value: 0,  type: 'checkbox', onclick: 'autorunStatus()', suffix: ' <small>Save backup directly to USB (no download) for autorestore purpose<\/small>' },          
  215.         ]);</script>   
  216. <div class="section" id="status"></div>
  217. <div style="display: flex; align-items: center;">
  218. <div id="backup-plain">
  219. <script>
  220. W('<input type="text" size="65" maxlength="128" onchange="backupNameChanged()" value="FT_'+nvram.lan_hostname+'_'+nvram.lan_ipaddr+'_'+nvram.t_model_name.replace(/\/| /g, '_')+'_'+now.getFullYear()+('0'+(now.getMonth()+1)).slice(-2)+('0'+now.getDate()).slice(-2)+'">');
  221. W('<div style="display:inline">.nvram &nbsp;');
  222. </script>
  223. </div></div></div>
  224. <input type="button" value="Backup plaintext" id="btn" name="btn" onclick="processCheckbox();">
  225. </form>
  226. <p>
  227. <div class="section-title">๐Ÿ““ Plaintext Configuration Restore</div>
  228. <div class="section">
  229. Select the plaintext (.nvram) configuration file to restore:<br><br>
  230. <input type="file" id="restore-file" name="filename">
  231. <input type="button" name="f_restore_button" id="restore-plain" value="Restore plaintext" onclick="restorePlain()">
  232. </div>
  233. <div class="section-title">๐Ÿ” Encrypted Configuration Backup</div>
  234. <div class="section">
  235. <script>
  236. W('<input type="text" size="65" maxlength="128" id="backup-name" onchange="backupNameChanged()" value="FT_'+('<% version(); %>'.replace(/\./g, '_'))+'~m'+nvram.lan_hwaddr.replace(/:/g, '').substring(6, 12)+'~'+nvram.t_model_name.replace(/\/| /g, '_')+'~'+now.getFullYear()+('0'+(now.getMonth()+1)).slice(-2)+('0'+now.getDate()).slice(-2)+'">');
  237. </script>
  238. <div style="display:inline">.cfg &nbsp;<br>
  239. <input type="button" name="f_backup_button" id="backup-button" onclick="backupButton()" value="Backup encrypted">
  240. </div>
  241. <div><a href="#" id="backup-link">Link</a></div>
  242. </div>
  243. <div class="section-title">๐Ÿ” Encrypted Configuration Restore</div>
  244. <div class="section">
  245. <form id="restore-form" method="post" action="cfg/restore.cgi" enctype="multipart/form-data">
  246. <div>
  247. Select the encrypted (.cfg) configuration file to restore:<br><br>
  248. <input type="file" id="restore-name" name="filename">
  249. <input type="button" name="f_restore_button" id="restore-button" value="Restore encrypted" onclick="restoreButton()">
  250. </div>
  251. </form>
  252. </div>
  253. <div class="section-title">๐Ÿณ๏ธ Restore Default Configuration</div>
  254. <div class="section">
  255. <form id="reset-form" method="post" action="cfg/defaults.cgi">
  256. <div>
  257. <select name="mode" id="restore-mode">
  258. <option value="0">Select...</option>
  259. <option value="1">Restore default router settings (normal)</option>
  260. <option value="2">Erase all data in NVRAM memory (thorough)</option>
  261. </select>
  262. <input type="button" value="OK" onclick="resetButton()" id="reset-button">
  263. </div>
  264. </form>
  265. </div>
  266. <div class="section-title"></div>
  267. <div class="section">
  268. <script>
  269. createFieldTable('', [ { title: 'Total / Free NVRAM:', text: scaleSize(nvstat.size)+' / '+scaleSize(nvstat.free)+' <small>('+(free_mem).toFixed(2)+'%)<\/small>' } ]);
  270. </script>
  271. </div>
  272. <div id="notice-msg"></div>
  273. <div id="footer">
  274. &nbsp;
  275. </div>
  276. </td></tr>
  277. </table>
  278. </body>
  279. </html>
  280.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement