Turn off the swap on unmounting; unmount ALL mountpoints; show swap active status...
[tomato.git] / release / src / router / www / nas-usb.asp
blob096535d050672ea03c26169cf9992fd11f43f40a
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 <title>[<% ident(); %>] NAS: USB Support</title>
14 <link rel='stylesheet' type='text/css' href='tomato.css'>
15 <link rel='stylesheet' type='text/css' href='color.css'>
16 <script type='text/javascript' src='tomato.js'></script>
18 <!-- / / / -->
20 <style type='text/css'>
21 textarea {
22 width: 98%;
23 height: 5em;
25 </style>
27 <style type='text/css'>
28 #dev-grid .co1 {
29 width: 10%;
31 #dev-grid .co2 {
32 width: 7%;
34 #dev-grid .co3 {
35 width: 18%;
37 #dev-grid .co4 {
38 width: 53%;
40 #dev-grid .co5 {
41 width: 14%;
42 text-align: center;
44 #dev-grid .header {
45 text-align: left;
47 </style>
49 <script type='text/javascript' src='debug.js'></script>
51 <script type='text/javascript'>
53 // <% nvram("usb_enable,usb_uhci,usb_ohci,usb_usb2,usb_storage,usb_printer,usb_printer_bidirect,usb_automount,usb_fs_ext3,usb_fs_fat,script_usbmount,script_usbumount,script_usbhotplug"); %>
54 /* NTFS-BEGIN */
55 // <% nvram("usb_fs_ntfs"); %>
56 /* NTFS-END */
57 // <% usbdevices(); %>
59 list = [];
61 var xob = null;
63 function _umountHost(host)
65 form.submitHidden('usbcmd.cgi', { remove: host });
68 function _mountHost(host)
70 form.submitHidden('usbcmd.cgi', { mount: host });
73 function _forceRefresh()
75 var e;
76 if ((e = E('refresh-button')) != null) {
77 if (e.value == 'Refresh' && (!e.disabled)) {
78 ref.once = 1;
79 ref.toggle();
84 function umountHost(a, host)
86 if (xob) return;
88 if ((xob = new XmlHttp()) == null) {
89 _umountHost(host);
90 return;
93 a = E(a);
94 a.innerHTML = 'Please wait...';
96 xob.onCompleted = function(text, xml) {
97 eval(text);
98 if (usb.length == 1) {
99 if (usb[0] != 0)
100 ferror.set(a, 'The device is busy. Please make sure no applications are using it, and try again.', 0);
102 xob = null;
103 _forceRefresh();
106 xob.onError = function() {
107 xob = null;
108 _forceRefresh();
111 xob.post('usbcmd.cgi', 'remove=' + host);
114 function mountHost(a, host)
116 if (xob) return;
118 if ((xob = new XmlHttp()) == null) {
119 _mountHost(host);
120 return;
123 a = E(a);
124 a.innerHTML = 'Please wait...';
126 xob.onCompleted = function(text, xml) {
127 eval(text);
128 if (usb.length == 1) {
129 if (usb[0] == 0)
130 ferror.set(a, 'Failed to mount. Verify the device is plugged in, and try again.', 0);
132 xob = null;
133 _forceRefresh();
136 xob.onError = function() {
137 xob = null;
138 _forceRefresh();
141 xob.post('usbcmd.cgi', 'mount=' + host);
144 var ref = new TomatoRefresh('update.cgi', 'exec=usbdevices', 0, 'nas_usb_refresh');
146 ref.refresh = function(text)
148 try {
149 eval(text);
151 catch (ex) {
152 return;
154 dg.removeAllData();
155 dg.populate();
156 dg.resort();
159 var dg = new TomatoGrid();
161 dg.sortCompare = function(a, b) {
162 var col = this.sortColumn;
163 var ra = a.getRowData();
164 var rb = b.getRowData();
165 var r;
167 switch (col) {
168 case 1:
169 if (ra.type == 'Storage' && ra.type == rb.type)
170 r = cmpInt(ra.host, rb.host);
171 else
172 r = cmpText(ra.host, rb.host);
173 break;
174 default:
175 r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
177 return this.sortAscending ? r : -r;
180 dg.populate = function()
182 var i, j, k, a, b, c, e, s, desc, d, parts, p;
184 list = [];
186 for (i = 0; i < list.length; ++i) {
187 list[i].type = '';
188 list[i].host = '';
189 list[i].vendor = '';
190 list[i].product = '';
191 list[i].serial = '';
192 list[i].discs = [];
193 list[i].is_mounted = 0;
196 for (i = usbdev.length - 1; i >= 0; --i) {
197 a = usbdev[i];
198 e = {
199 type: a[0],
200 host: a[1],
201 vendor: a[2],
202 product: a[3],
203 serial: a[4],
204 discs: a[5],
205 is_mounted: a[6]
207 list.push(e);
210 for (i = list.length - 1; i >= 0; --i) {
211 e = list[i];
213 if (e.type != 'Storage')
214 s = '&nbsp<br><small>&nbsp</small>';
215 else {
216 if (xob)
217 s = ((e.is_mounted == 0) ? 'No' : 'Yes') + '<br><small>Please wait...</small>';
218 else if (e.is_mounted == 0)
219 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>';
220 else
221 s = 'Yes<br><small><a href="javascript:umountHost(\'L' + i + '\',\'' + e.host + '\')" title="Safely Remove Storage Device" id="L' + i + '">[ Unmount ]</a></small>';
223 desc = e.product + '<small>'; // + (e.serial == '' ? '' : '<br>Serial No: ' + e.serial);
224 if (e.discs) {
225 for (j = 0; j <= e.discs.length - 1; ++j) {
226 d = e.discs[j];
227 parts = d[1];
228 for (k = 0; k <= parts.length - 1; ++k) {
229 p = parts[k];
230 if (p) {
231 desc = desc + '<br>Partition \'' + p[0] + '\'' + (p[3] != '' ? ' ' + p[3] : '') +
232 (p[5] != '0' && p[5] != '' ? ' (' + p[5] + ' MB)' : '') +
233 ((p[1] != 0) ? ((p[1] == 2) ? ' is active ' : ' is mounted ') +
234 ((p[2] != '') ? 'on ' : '') : ' is not mounted ') + p[2];
239 desc = desc + '</small>';
240 this.insert(-1, e, [e.type, e.host, e.vendor, desc, s], false);
243 list = [];
246 dg.setup = function()
248 this.init('dev-grid', 'sort');
249 this.headerSet(['Type', 'Host', 'Vendor', 'Description', 'Mounted?']);
250 this.populate();
251 this.sort(1);
254 function earlyInit()
256 dg.setup();
259 function init()
261 dg.recolor();
262 ref.initPage();
265 function verifyFields(focused, quiet)
267 var b = !E('_f_usb').checked;
268 var a = !E('_f_storage').checked;
270 E('_f_uhci').disabled = b;
271 E('_f_ohci').disabled = b;
272 E('_f_usb2').disabled = b;
273 E('_f_print').disabled = b;
274 E('_f_storage').disabled = b;
276 E('_f_ext3').disabled = b || a;
277 E('_f_fat').disabled = b || a;
278 /* NTFS-BEGIN */
279 E('_f_ntfs').disabled = b || a;
280 /* NTFS-END */
281 E('_f_automount').disabled = b || a;
282 E('_f_bprint').disabled = b || !E('_f_print').checked;
284 elem.display(PR('_f_automount'), !b && !a);
285 elem.display(PR('_script_usbmount'), !b && !a && E('_f_automount').checked);
286 elem.display(PR('_script_usbumount'), !b && !a && E('_f_automount').checked);
287 elem.display(PR('_script_usbhotplug'), !b && (!a || E('_f_print').checked));
289 if (!v_length('_script_usbmount', quiet, 0, 2048)) return 0;
290 if (!v_length('_script_usbumount', quiet, 0, 2048)) return 0;
291 if (!v_length('_script_usbhotplug', quiet, 0, 2048)) return 0;
293 return 1;
296 function save()
298 var fom;
300 if (!verifyFields(null, 0)) return;
302 fom = E('_fom');
303 fom.usb_enable.value = E('_f_usb').checked ? 1 : 0;
304 fom.usb_uhci.value = E('_f_uhci').checked ? 1 : 0;
305 fom.usb_ohci.value = E('_f_ohci').checked ? 1 : 0;
306 fom.usb_usb2.value = E('_f_usb2').checked ? 1 : 0;
307 fom.usb_storage.value = E('_f_storage').checked ? 1 : 0;
308 fom.usb_printer.value = E('_f_print').checked ? 1 : 0;
309 fom.usb_printer_bidirect.value = E('_f_bprint').checked ? 1 : 0;
310 fom.usb_fs_ext3.value = E('_f_ext3').checked ? 1 : 0;
311 fom.usb_fs_fat.value = E('_f_fat').checked ? 1 : 0;
312 /* NTFS-BEGIN */
313 fom.usb_fs_ntfs.value = E('_f_ntfs').checked ? 1 : 0;
314 /* NTFS-END */
315 fom.usb_automount.value = E('_f_automount').checked ? 1 : 0;
317 form.submit(fom, 1);
320 function submit_complete()
322 reloadPage();
324 </script>
326 </head>
327 <body onload='init()'>
328 <form id='_fom' method='post' action='tomato.cgi'>
329 <table id='container' cellspacing=0>
330 <tr><td colspan=2 id='header'>
331 <div class='title'>Tomato</div>
332 <div class='version'>Version <% version(); %></div>
333 </td></tr>
334 <tr id='body'><td id='navi'><script type='text/javascript'>navi()</script></td>
335 <td id='content'>
336 <div id='ident'><% ident(); %></div>
338 <!-- / / / -->
340 <input type='hidden' name='_nextpage' value='nas-usb.asp'>
341 <input type='hidden' name='_service' value='usb-restart'>
343 <input type='hidden' name='usb_enable'>
344 <input type='hidden' name='usb_uhci'>
345 <input type='hidden' name='usb_ohci'>
346 <input type='hidden' name='usb_usb2'>
347 <input type='hidden' name='usb_storage'>
348 <input type='hidden' name='usb_printer'>
349 <input type='hidden' name='usb_printer_bidirect'>
350 <input type='hidden' name='usb_fs_ext3'>
351 <input type='hidden' name='usb_fs_fat'>
352 /* NTFS-BEGIN */
353 <input type='hidden' name='usb_fs_ntfs'>
354 /* NTFS-END */
355 <input type='hidden' name='usb_automount'>
357 <div class='section-title'>USB Support</div>
358 <div class='section'>
359 <script type='text/javascript'>
361 createFieldTable('', [
362 { title: 'Core USB Support', name: 'f_usb', type: 'checkbox', value: nvram.usb_enable == 1 },
363 { title: 'USB 1.1 Support (OHCI)', name: 'f_ohci', type: 'checkbox', value: nvram.usb_ohci == 1 },
364 { title: 'USB 1.1 Support (UHCI)', name: 'f_uhci', type: 'checkbox', value: nvram.usb_uhci == 1 },
365 { title: 'USB 2.0 Support', name: 'f_usb2', type: 'checkbox', value: nvram.usb_usb2 == 1 },
366 null,
367 { title: 'USB Printer Support', name: 'f_print', type: 'checkbox', value: nvram.usb_printer == 1 },
368 { title: 'Bidirectional copying', indent: 2, name: 'f_bprint', type: 'checkbox', value: nvram.usb_printer_bidirect == 1 },
369 null,
370 { title: 'USB Storage Support', name: 'f_storage', type: 'checkbox', value: nvram.usb_storage == 1 },
371 { title: 'Ext2 / Ext3 File System Support', indent: 2, name: 'f_ext3', type: 'checkbox', value: nvram.usb_fs_ext3 == 1 },
372 { title: 'FAT File System Support', indent: 2, name: 'f_fat', type: 'checkbox', value: nvram.usb_fs_fat == 1 },
373 /* NTFS-BEGIN */
374 { title: 'NTFS File System Support', indent: 2, name: 'f_ntfs', type: 'checkbox', suffix: ' <small>(limited write support)</small>', value: nvram.usb_fs_ntfs == 1 },
375 /* NTFS-END */
376 { title: 'Automount', indent: 2, name: 'f_automount', type: 'checkbox',
377 suffix: ' <small>Automatically mount all partitions to sub-directories in <i>/mnt</i>.</small>', value: nvram.usb_automount == 1 },
378 { title: 'Run after mounting', indent: 2, name: 'script_usbmount', type: 'textarea', value: nvram.script_usbmount },
379 { title: 'Run before unmounting', indent: 2, name: 'script_usbumount', type: 'textarea', value: nvram.script_usbumount },
380 null,
381 { title: 'Hotplug script<br><small>(called when any USB device is attached or removed)</small>', name: 'script_usbhotplug', type: 'textarea', value: nvram.script_usbhotplug },
382 null,
383 { text: '<small>Some of the changes will take effect only after a restart.</small>' }
385 </script>
386 </div>
388 <!-- / / / -->
390 <div class='section-title'>Attached Devices</div>
391 <div class='section'>
392 <table id='dev-grid' class='tomato-grid' cellspacing=0></table>
393 <div id='usb-controls'>
394 <script type='text/javascript'>genStdRefresh(1,0,'ref.toggle()');</script>
395 </div>
396 <script type='text/javascript'></script>
397 </div>
399 <!-- / / / -->
401 </td></tr>
402 <tr><td id='footer' colspan=2>
403 <span id='footer-msg'></span>
404 <input type='button' value='Save' id='save-button' onclick='save()'>
405 <input type='button' value='Cancel' id='cancel-button' onclick='javascript:reloadPage();'>
406 </td></tr>
407 </table>
408 </form>
409 <script type='text/javascript'>earlyInit();verifyFields(null, 1);</script>
410 </body>
411 </html>