Merge branch 'Toastman-NRT' into Toastman-RT-AC
[tomato.git] / release / src / router / www / nas-usb.asp
blob91920b731992f6026d37b1ca8fb3d95603005ecc
1 <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN'>
2 <!--
3 Tomato GUI
4 USB Support - !!TB
6 For use with Tomato Firmware only.
7 No part of this file may be used without permission.
8 -->
9 <html>
10 <head>
11 <meta http-equiv='content-type' content='text/html;charset=utf-8'>
12 <meta name='robots' content='noindex,nofollow'>
13 <meta name="viewport" content="width=device-width">
14 <title>[<% ident(); %>] NAS: USB Support</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 <style type='text/css'>
22 textarea {
23 width: 98%;
24 height: 5em;
26 </style>
28 <style type='text/css'>
29 #dev-grid .co1 {
30 width: 10%;
32 #dev-grid .co2 {
33 width: 9%;
35 #dev-grid .co3 {
36 width: 65%;
38 #dev-grid .co4 {
39 width: 16%;
40 text-align: center;
42 #dev-grid .header {
43 text-align: left;
45 </style>
47 <script type='text/javascript' src='debug.js'></script>
49 <script type='text/javascript'>
51 // <% nvram("usb_enable,usb_uhci,usb_ohci,usb_usb2,usb_mmc,usb_storage,usb_printer,usb_printer_bidirect,usb_automount,usb_fs_ext3,usb_fs_fat,usb_fs_ntfs,usb_fs_hfs,script_usbmount,script_usbumount,script_usbhotplug,idle_enable,usb_3g"); %>
52 // <% usbdevices(); %>
54 list = [];
56 var xob = null;
58 function _umountHost(host)
60 form.submitHidden('usbcmd.cgi', { remove: host });
63 function _mountHost(host)
65 form.submitHidden('usbcmd.cgi', { mount: host });
68 function _forceRefresh()
70 if (!ref.running) ref.once = 1;
71 ref.start();
74 function umountHost(a, host)
76 if (xob) return;
78 if ((xob = new XmlHttp()) == null) {
79 _umountHost(host);
80 return;
83 a = E(a);
84 a.innerHTML = 'Please wait...';
86 xob.onCompleted = function(text, xml) {
87 eval(text);
88 if (usb.length == 1) {
89 if (usb[0] != 0)
90 ferror.set(a, 'The device is busy. Please make sure no applications are using it, and try again.', 0);
92 xob = null;
93 _forceRefresh();
96 xob.onError = function() {
97 xob = null;
98 _forceRefresh();
101 xob.post('usbcmd.cgi', 'remove=' + host);
104 function mountHost(a, host)
106 if (xob) return;
108 if ((xob = new XmlHttp()) == null) {
109 _mountHost(host);
110 return;
113 a = E(a);
114 a.innerHTML = 'Please wait...';
116 xob.onCompleted = function(text, xml) {
117 eval(text);
118 if (usb.length == 1) {
119 if (usb[0] == 0)
120 ferror.set(a, 'Failed to mount. Verify the device is plugged in, and try again.', 0);
122 xob = null;
123 _forceRefresh();
126 xob.onError = function() {
127 xob = null;
128 _forceRefresh();
131 xob.post('usbcmd.cgi', 'mount=' + host);
134 var ref = new TomatoRefresh('update.cgi', 'exec=usbdevices', 0, 'nas_usb_refresh');
136 ref.refresh = function(text)
138 try {
139 eval(text);
141 catch (ex) {
142 return;
144 dg.removeAllData();
145 dg.populate();
146 dg.resort();
149 var dg = new TomatoGrid();
151 dg.sortCompare = function(a, b) {
152 var col = this.sortColumn;
153 var ra = a.getRowData();
154 var rb = b.getRowData();
155 var r;
157 switch (col) {
158 case 1:
159 if (ra.type == 'Storage' && ra.type == rb.type)
160 r = cmpInt(ra.host, rb.host);
161 else
162 r = cmpText(ra.host, rb.host);
163 break;
164 default:
165 r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
167 return this.sortAscending ? r : -r;
170 dg.populate = function()
172 var i, j, k, a, b, c, e, s, desc, d, parts, p;
174 list = [];
176 for (i = 0; i < list.length; ++i) {
177 list[i].type = '';
178 list[i].host = '';
179 list[i].vendor = '';
180 list[i].product = '';
181 list[i].serial = '';
182 list[i].discs = [];
183 list[i].is_mounted = 0;
186 for (i = usbdev.length - 1; i >= 0; --i) {
187 a = usbdev[i];
188 e = {
189 type: a[0],
190 host: a[1],
191 vendor: a[2],
192 product: a[3],
193 serial: a[4],
194 discs: a[5],
195 is_mounted: a[6]
197 list.push(e);
200 for (i = list.length - 1; i >= 0; --i) {
201 e = list[i];
203 if (e.type != 'Storage')
204 s = '&nbsp<br><small>&nbsp</small>';
205 else {
206 if (xob)
207 s = ((e.is_mounted == 0) ? 'No' : 'Yes') + '<br><small>Please wait...</small>';
208 else if (e.is_mounted == 0)
209 s = 'No<br><small><a href="javascript:mountHost(\'L' + i + '\',\'' + e.host + '\')" title="Mount all Partitions of Storage Device" id="L' + i + '">[ Mount ]</a></small>';
210 else
211 s = 'Yes<br><small><a href="javascript:umountHost(\'L' + i + '\',\'' + e.host + '\')" title="Safely Remove Storage Device" id="L' + i + '">[ Unmount ]</a></small>';
213 desc = (e.vendor + ' ' + e.product).trim() + '<small>'; // + (e.serial == '' ? '' : '<br>Serial No: ' + e.serial);
214 if (e.discs) {
215 for (j = 0; j <= e.discs.length - 1; ++j) {
216 d = e.discs[j];
217 parts = d[1];
218 for (k = 0; k <= parts.length - 1; ++k) {
219 p = parts[k];
220 if (p) {
221 desc = desc + '<br>Partition \'' + p[0] + '\'' + (p[3] != '' ? ' ' + p[3] : '') +
222 ((p[5] != 0) ? ' (' + doScaleSize(p[5], 0) +
223 ((p[1] == 1) ? ' / ' + doScaleSize(p[6], 0) + ' free' : '') +
224 ')' : '') + ' is ' +
225 ((p[1] != 0) ? '' : 'not ') + ((p[3] == 'swap') ? 'active' : 'mounted') +
226 ((p[2] != '') ? ' on ' + p[2] : '');
231 desc = desc + '</small>';
232 this.insert(-1, e, [e.type, e.host, desc, s], false);
235 list = [];
238 dg.setup = function()
240 this.init('dev-grid', 'sort');
241 this.headerSet(['Type', 'Host', 'Description', 'Mounted?']);
242 this.populate();
243 this.sort(1);
246 function earlyInit()
248 dg.setup();
251 function init()
253 dg.recolor();
254 ref.initPage();
257 function verifyFields(focused, quiet)
259 var b = !E('_f_usb').checked;
260 var a = !E('_f_storage').checked;
262 E('_f_uhci').disabled = b || nvram.usb_uhci == -1;
263 E('_f_ohci').disabled = b || nvram.usb_ohci == -1;
264 E('_f_usb2').disabled = b;
265 E('_f_print').disabled = b;
266 E('_f_storage').disabled = b;
268 /* LINUX26-BEGIN */
269 /* MICROSD-BEGIN */
270 E('_f_mmc').disabled = a || b || nvram.usb_mmc == -1;
271 elem.display(PR('_f_mmc'), nvram.usb_mmc != -1);
272 /* MICROSD-END */
273 /* LINUX26-END */
275 E('_f_ext3').disabled = b || a;
276 E('_f_fat').disabled = b || a;
277 /* LINUX26-BEGIN */
278 E('_f_idle_enable').disabled = b || a;
279 E('_f_usb_3g').disabled = b;
280 /* LINUX26-END */
281 /* NTFS-BEGIN */
282 E('_f_ntfs').disabled = b || a;
283 /* NTFS-END */
284 /* HFS-BEGIN */
285 E('_f_hfs').disabled = b || a; //!Victek
286 /* HFS-END */
287 E('_f_automount').disabled = b || a;
288 E('_f_bprint').disabled = b || !E('_f_print').checked;
290 elem.display(PR('_f_automount'), !b && !a);
291 elem.display(PR('_script_usbmount'), PR('_script_usbumount'), !b && !a && E('_f_automount').checked);
292 elem.display(PR('_script_usbhotplug'), !b && (!a || E('_f_print').checked));
294 if (!v_length('_script_usbmount', quiet, 0, 2048)) return 0;
295 if (!v_length('_script_usbumount', quiet, 0, 2048)) return 0;
296 if (!v_length('_script_usbhotplug', quiet, 0, 2048)) return 0;
298 return 1;
301 function save()
303 var fom;
305 if (!verifyFields(null, 0)) return;
307 fom = E('_fom');
308 fom.usb_enable.value = E('_f_usb').checked ? 1 : 0;
309 fom.usb_uhci.value = nvram.usb_uhci == -1 ? -1 : (E('_f_uhci').checked ? 1 : 0);
310 fom.usb_ohci.value = nvram.usb_ohci == -1 ? -1 : (E('_f_ohci').checked ? 1 : 0);
311 fom.usb_usb2.value = E('_f_usb2').checked ? 1 : 0;
312 fom.usb_storage.value = E('_f_storage').checked ? 1 : 0;
313 fom.usb_printer.value = E('_f_print').checked ? 1 : 0;
314 fom.usb_printer_bidirect.value = E('_f_bprint').checked ? 1 : 0;
316 /* LINUX26-BEGIN */
317 /* MICROSD-BEGIN */
318 fom.usb_mmc.value = nvram.usb_mmc == -1 ? -1 : (E('_f_mmc').checked ? 1 : 0);
319 /* MICROSD-END */
320 /* LINUX26-END */
322 fom.usb_fs_ext3.value = E('_f_ext3').checked ? 1 : 0;
323 fom.usb_fs_fat.value = E('_f_fat').checked ? 1 : 0;
324 /* NTFS-BEGIN */
325 fom.usb_fs_ntfs.value = E('_f_ntfs').checked ? 1 : 0;
326 /* NTFS-END */
327 /* HFS-BEGIN */
328 fom.usb_fs_hfs.value = E('_f_hfs').checked ? 1 : 0; //!Victek
329 /* HFS-END */
330 fom.usb_automount.value = E('_f_automount').checked ? 1 : 0;
331 /* LINUX26-BEGIN */
332 fom.idle_enable.value = E('_f_idle_enable').checked ? 1 : 0;
333 fom.usb_3g.value = E('_f_usb_3g').checked ? 1 : 0;
334 /* LINUX26-END */
336 form.submit(fom, 1);
339 function submit_complete()
341 reloadPage();
343 </script>
345 </head>
346 <body onload='init()'>
347 <form id='_fom' method='post' action='tomato.cgi'>
348 <table id='container' cellspacing=0>
349 <tr><td colspan=2 id='header'>
350 <div class='title'>Tomato</div>
351 <div class='version'>Version <% version(); %></div>
352 </td></tr>
353 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
354 <td id='content'>
355 <div id='ident'><% ident(); %></div>
357 <!-- / / / -->
359 <input type='hidden' name='_nextpage' value='nas-usb.asp'>
360 <input type='hidden' name='_service' value='usb-restart'>
362 <input type='hidden' name='usb_enable'>
363 <input type='hidden' name='usb_uhci'>
364 <input type='hidden' name='usb_ohci'>
365 <input type='hidden' name='usb_usb2'>
366 <input type='hidden' name='usb_mmc'>
367 <input type='hidden' name='usb_storage'>
368 <input type='hidden' name='usb_printer'>
369 <input type='hidden' name='usb_printer_bidirect'>
370 <input type='hidden' name='usb_fs_ext3'>
371 <input type='hidden' name='usb_fs_fat'>
372 <!-- NTFS-BEGIN
373 <input type='hidden' name='usb_fs_ntfs'>
374 NTFS-END -->
375 <!-- HFS-BEGIN
376 <input type='hidden' name='usb_fs_hfs'>
377 HFS-END -->
378 <input type='hidden' name='usb_automount'>
379 /* LINUX26-BEGIN */
380 <input type='hidden' name='idle_enable'>
381 <input type='hidden' name='usb_3g'>
382 /* LINUX26-END */
384 <div class='section-title'>USB Support</div>
385 <div class='section'>
386 <script type='text/javascript'>
388 createFieldTable('', [
389 { title: 'Core USB Support', name: 'f_usb', type: 'checkbox', value: nvram.usb_enable == 1 },
390 { title: 'USB 2.0 Support', indent: 2, name: 'f_usb2', type: 'checkbox', value: nvram.usb_usb2 == 1 },
391 { title: 'USB 1.1 Support', indent: 2, multi: [
392 { suffix: '&nbsp; OHCI &nbsp;&nbsp;&nbsp;', name: 'f_ohci', type: 'checkbox', value: nvram.usb_ohci == 1 },
393 { suffix: '&nbsp; UHCI &nbsp;', name: 'f_uhci', type: 'checkbox', value: nvram.usb_uhci == 1 }
394 ] },
395 null,
396 { title: 'USB Printer Support', name: 'f_print', type: 'checkbox', value: nvram.usb_printer == 1 },
397 { title: 'Bidirectional copying', indent: 2, name: 'f_bprint', type: 'checkbox', value: nvram.usb_printer_bidirect == 1 },
398 null,
399 { title: 'USB Storage Support', name: 'f_storage', type: 'checkbox', value: nvram.usb_storage == 1 },
400 { title: 'File Systems Support', indent: 2, multi: [
401 { suffix: '&nbsp; Ext2 / Ext3 &nbsp;&nbsp;&nbsp;', name: 'f_ext3', type: 'checkbox', value: nvram.usb_fs_ext3 == 1 },
402 /* NTFS-BEGIN */
403 { suffix: '&nbsp; NTFS &nbsp;&nbsp;&nbsp;', name: 'f_ntfs', type: 'checkbox', value: nvram.usb_fs_ntfs == 1 },
404 /* NTFS-END */
405 { suffix: '&nbsp; FAT &nbsp;', name: 'f_fat', type: 'checkbox', value: nvram.usb_fs_fat == 1 }
406 /* HFS-BEGIN */
407 ,{ suffix: '&nbsp; HFS / HFS+ &nbsp;', name: 'f_hfs', type: 'checkbox', value: nvram.usb_fs_hfs == 1 }
408 /* HFS-END */
409 ] },
410 /* LINUX26-BEGIN */
411 /* MICROSD-BEGIN */
412 { title: 'SD/MMC Card Support', indent: 2, name: 'f_mmc', type: 'checkbox', value: nvram.usb_mmc == 1 },
413 /* MICROSD-END */
414 /* LINUX26-END */
415 { title: 'Automount', indent: 2, name: 'f_automount', type: 'checkbox',
416 suffix: ' <small>Automatically mount all partitions to sub-directories in <i>/mnt</i>.</small>', value: nvram.usb_automount == 1 },
417 { title: 'Run after mounting', indent: 2, name: 'script_usbmount', type: 'textarea', value: nvram.script_usbmount },
418 { title: 'Run before unmounting', indent: 2, name: 'script_usbumount', type: 'textarea', value: nvram.script_usbumount },
419 null,
420 /* LINUX26-BEGIN */
421 { title: 'HDD Spindown', name: 'f_idle_enable', type: 'checkbox',
422 suffix: ' <small>Spin down each HDD when idle. No need to use with flashdrive.</small>', value: nvram.idle_enable == 1 },
423 null,
424 { title: 'USB 3G Modem support', name: 'f_usb_3g', type: 'checkbox',
425 suffix: ' <small>Before disconnecting 3G Modem from USB port, remember to uncheck box. If modem used usbserial module, you have to reboot router before unplug modem.</small>', value: nvram.usb_3g == 1 },
426 null,
427 /* LINUX26-END */
428 { title: 'Hotplug script<br><small>(called when any USB device is attached or removed)</small>', name: 'script_usbhotplug', type: 'textarea', value: nvram.script_usbhotplug },
429 null,
430 { text: '<small>Some of the changes will take effect only after a restart.</small>' }
432 </script>
433 </div>
435 <!-- / / / -->
437 <div class='section-title'>Attached Devices</div>
438 <div class='section'>
439 <table id='dev-grid' class='tomato-grid' cellspacing=0></table>
440 <div id='usb-controls'>
441 <script type='text/javascript'>genStdRefresh(1,0,'ref.toggle()');</script>
442 </div>
443 <script type='text/javascript'></script>
444 </div>
446 <!-- / / / -->
448 </td></tr>
449 <tr><td id='footer' colspan=2>
450 <span id='footer-msg'></span>
451 <input type='button' value='Save' id='save-button' onclick='save()'>
452 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'>
453 </td></tr>
454 </table>
455 </form>
456 <script type='text/javascript'>earlyInit();verifyFields(null, 1);</script>
457 </body>
458 </html>