forked from Jackysi/advancedtomato-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nas-usb.asp
400 lines (344 loc) · 12.4 KB
/
nas-usb.asp
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<!--
Tomato GUI
USB Support - !!TB
For use with Tomato Firmware only.
No part of this file may be used without permission.
--><title>USB Support</title>
<content>
<style>textarea { width: 100%; }</style>
<script type="text/javascript">
// <% 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"); %>
// <% usbdevices(); %>
list = [];
var xob = null;
function _umountHost(host)
{
form.submitHidden('usbcmd.cgi', { remove: host });
}
function _mountHost(host)
{
form.submitHidden('usbcmd.cgi', { mount: host });
}
function _forceRefresh()
{
if (!ref.running) ref.once = 1;
ref.start();
}
function umountHost(a, host)
{
if (xob) return;
if ((xob = new XmlHttp()) == null) {
_umountHost(host);
return;
}
a = E(a);
a.innerHTML = 'Please wait...';
xob.onCompleted = function(text, xml) {
eval(text);
if (usb.length == 1) {
if (usb[0] != 0)
ferror.set(a, 'The device is busy. Please make sure no applications are using it, and try again.', 0);
}
xob = null;
_forceRefresh();
}
xob.onError = function() {
xob = null;
_forceRefresh();
}
xob.post('usbcmd.cgi', 'remove=' + host);
}
function mountHost(a, host)
{
if (xob) return;
if ((xob = new XmlHttp()) == null) {
_mountHost(host);
return;
}
a = E(a);
a.innerHTML = 'Please wait...';
xob.onCompleted = function(text, xml) {
eval(text);
if (usb.length == 1) {
if (usb[0] == 0)
ferror.set(a, 'Failed to mount. Verify the device is plugged in, and try again.', 0);
}
xob = null;
_forceRefresh();
}
xob.onError = function() {
xob = null;
_forceRefresh();
}
xob.post('usbcmd.cgi', 'mount=' + host);
}
var ref = new TomatoRefresh('update.cgi', 'exec=usbdevices', 0, 'nas_usb_refresh');
ref.refresh = function(text)
{
try {
eval(text);
}
catch (ex) {
return;
}
dg.removeAllData();
dg.populate();
dg.resort();
}
var dg = new TomatoGrid();
dg.sortCompare = function(a, b) {
var col = this.sortColumn;
var ra = a.getRowData();
var rb = b.getRowData();
var r;
switch (col) {
case 1:
if (ra.type == 'Storage' && ra.type == rb.type)
r = cmpInt(ra.host, rb.host);
else
r = cmpText(ra.host, rb.host);
break;
default:
r = cmpText(a.cells[col].innerHTML, b.cells[col].innerHTML);
}
return this.sortAscending ? r : -r;
}
dg.populate = function()
{
var i, j, k, a, b, c, e, s, desc, d, parts, p;
list = [];
for (i = 0; i < list.length; ++i) {
list[i].type = '';
list[i].host = '';
list[i].vendor = '';
list[i].product = '';
list[i].serial = '';
list[i].discs = [];
list[i].is_mounted = 0;
}
for (i = usbdev.length - 1; i >= 0; --i) {
a = usbdev[i];
e = {
type: a[0],
host: a[1],
vendor: a[2],
product: a[3],
serial: a[4],
discs: a[5],
is_mounted: a[6]
};
list.push(e);
}
for (i = list.length - 1; i >= 0; --i) {
e = list[i];
if (e.type != 'Storage')
s = ' <br><small> </small>';
else {
if (xob)
s = ((e.is_mounted == 0) ? 'No' : 'Yes') + '<br><small>Please wait...</small>';
else if (e.is_mounted == 0)
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>';
else
s = 'Yes<br><small><a href="javascript:umountHost(\'L' + i + '\',\'' + e.host + '\')" title="Safely Remove Storage Device" id="L' + i + '">[ Unmount ]</a></small>';
}
desc = (e.vendor + ' ' + e.product).trim() + '<small>'; // + (e.serial == '' ? '' : '<br>Serial No: ' + e.serial);
if (e.discs) {
for (j = 0; j <= e.discs.length - 1; ++j) {
d = e.discs[j];
parts = d[1];
for (k = 0; k <= parts.length - 1; ++k) {
p = parts[k];
if (p) {
desc = desc + '<br>Partition \'' + p[0] + '\'' + (p[3] != '' ? ' ' + p[3] : '') +
((p[5] != 0) ? ' (' + doScaleSize((p[5] - p[6]), 0) +
((p[1] == 1) ? ' / ' + doScaleSize(p[5], 0) + ' used' : '') +
')' : '') + ' is ' +
((p[1] != 0) ? '' : 'not ') + ((p[3] == 'swap') ? 'active' : 'mounted') +
((p[2] != '') ? ' on ' + p[2] : '');
}
}
}
}
desc = desc + '</small>';
this.insert(-1, e, ['<i class="icon-drive icon-medium icon-middle"></i> ' + e.type, e.host, desc, s], false);
}
list = [];
}
dg.setup = function()
{
this.init('dev-grid', 'sort');
this.headerSet(['Type', 'Host', 'Description', 'Mounted?']);
this.populate();
this.sort(1);
}
function earlyInit() {
$('#last-box').after(genStdRefresh(1,0,'ref.toggle()'));
dg.setup();
init();
}
function init() {
dg.recolor();
ref.initPage();
}
function verifyFields(focused, quiet)
{
var b = !E('_f_usb').checked;
var a = !E('_f_storage').checked;
E('_f_uhci').disabled = b || nvram.usb_uhci == -1;
E('_f_ohci').disabled = b || nvram.usb_ohci == -1;
E('_f_usb2').disabled = b;
E('_f_print').disabled = b;
E('_f_storage').disabled = b;
/* LINUX26-BEGIN */
/* MICROSD-BEGIN */
E('_f_mmc').disabled = a || b || nvram.usb_mmc == -1;
elem.display(PR('_f_mmc'), nvram.usb_mmc != -1);
/* MICROSD-END */
/* LINUX26-END */
E('_f_ext3').disabled = b || a;
E('_f_fat').disabled = b || a;
/* LINUX26-BEGIN */
E('_f_idle_enable').disabled = b || a;
E('_f_usb_3g').disabled = b;
/* LINUX26-END */
/* NTFS-BEGIN */
E('_f_ntfs').disabled = b || a;
/* NTFS-END */
/* HFS-BEGIN */
E('_f_hfs').disabled = b || a; //!Victek
/* HFS-END */
E('_f_automount').disabled = b || a;
E('_f_bprint').disabled = b || !E('_f_print').checked;
elem.display(PR('_f_automount'), !b && !a);
elem.display(PR('_script_usbmount'), PR('_script_usbumount'), !b && !a && E('_f_automount').checked);
elem.display(PR('_script_usbhotplug'), !b && (!a || E('_f_print').checked));
if (!v_length('_script_usbmount', quiet, 0, 2048)) return 0;
if (!v_length('_script_usbumount', quiet, 0, 2048)) return 0;
if (!v_length('_script_usbhotplug', quiet, 0, 2048)) return 0;
return 1;
}
function save()
{
var fom;
if (!verifyFields(null, 0)) return;
fom = E('_fom');
fom.usb_enable.value = E('_f_usb').checked ? 1 : 0;
fom.usb_uhci.value = nvram.usb_uhci == -1 ? -1 : (E('_f_uhci').checked ? 1 : 0);
fom.usb_ohci.value = nvram.usb_ohci == -1 ? -1 : (E('_f_ohci').checked ? 1 : 0);
fom.usb_usb2.value = E('_f_usb2').checked ? 1 : 0;
fom.usb_storage.value = E('_f_storage').checked ? 1 : 0;
fom.usb_printer.value = E('_f_print').checked ? 1 : 0;
fom.usb_printer_bidirect.value = E('_f_bprint').checked ? 1 : 0;
/* LINUX26-BEGIN */
/* MICROSD-BEGIN */
fom.usb_mmc.value = nvram.usb_mmc == -1 ? -1 : (E('_f_mmc').checked ? 1 : 0);
/* MICROSD-END */
/* LINUX26-END */
fom.usb_fs_ext3.value = E('_f_ext3').checked ? 1 : 0;
fom.usb_fs_fat.value = E('_f_fat').checked ? 1 : 0;
/* NTFS-BEGIN */
fom.usb_fs_ntfs.value = E('_f_ntfs').checked ? 1 : 0;
/* NTFS-END */
/* HFS-BEGIN */
fom.usb_fs_hfs.value = E('_f_hfs').checked ? 1 : 0; //!Victek
/* HFS-END */
fom.usb_automount.value = E('_f_automount').checked ? 1 : 0;
/* LINUX26-BEGIN */
fom.idle_enable.value = E('_f_idle_enable').checked ? 1 : 0;
fom.usb_3g.value = E('_f_usb_3g').checked ? 1 : 0;
/* LINUX26-END */
form.submit(fom, 1);
}
function submit_complete()
{
reloadPage();
}
</script>
<form id="_fom" method="post" action="tomato.cgi">
<input type="hidden" name="_nextpage" value="/#nas-usb.asp">
<input type="hidden" name="_service" value="usb-restart">
<input type="hidden" name="usb_enable">
<input type="hidden" name="usb_uhci">
<input type="hidden" name="usb_ohci">
<input type="hidden" name="usb_usb2">
<input type="hidden" name="usb_mmc">
<input type="hidden" name="usb_storage">
<input type="hidden" name="usb_printer">
<input type="hidden" name="usb_printer_bidirect">
<input type="hidden" name="usb_fs_ext3">
<input type="hidden" name="usb_fs_fat">
/* NTFS-BEGIN */
<input type="hidden" name="usb_fs_ntfs">
/* NTFS-END */
/* HFS-BEGIN */
<input type="hidden" name="usb_fs_hfs">
/* HFS-END */
<input type="hidden" name="usb_automount">
/* LINUX26-BEGIN */
<input type="hidden" name="idle_enable">
<input type="hidden" name="usb_3g">
/* LINUX26-END */
<div class="box" data-box="usb-supp">
<div class="heading">USB Support</div>
<div class="content">
<div id="usbfields"></div>
<script type="text/javascript">
$('#usbfields').forms([
{ title: 'Core USB Support', name: 'f_usb', type: 'checkbox', value: nvram.usb_enable == 1 },
{ title: 'USB 2.0 Support', indent: 2, name: 'f_usb2', type: 'checkbox', value: nvram.usb_usb2 == 1 },
{ title: 'USB 1.1 Support', indent: 2, multi: [
{ suffix: ' OHCI ', name: 'f_ohci', type: 'checkbox', value: nvram.usb_ohci == 1 },
{ suffix: ' UHCI ', name: 'f_uhci', type: 'checkbox', value: nvram.usb_uhci == 1 }
] },
null,
{ title: 'USB Printer Support', name: 'f_print', type: 'checkbox', value: nvram.usb_printer == 1 },
{ title: 'Bidirectional copying', indent: 2, name: 'f_bprint', type: 'checkbox', value: nvram.usb_printer_bidirect == 1 },
null,
{ title: 'USB Storage Support', name: 'f_storage', type: 'checkbox', value: nvram.usb_storage == 1 },
{ title: 'File Systems Support', indent: 2, multi: [
{ suffix: ' Ext2 / Ext3 ', name: 'f_ext3', type: 'checkbox', value: nvram.usb_fs_ext3 == 1 },
/* NTFS-BEGIN */
{ suffix: ' NTFS ', name: 'f_ntfs', type: 'checkbox', value: nvram.usb_fs_ntfs == 1 },
/* NTFS-END */
{ suffix: ' FAT ', name: 'f_fat', type: 'checkbox', value: nvram.usb_fs_fat == 1 }
/* HFS-BEGIN */
,{ suffix: ' HFS / HFS+ ', name: 'f_hfs', type: 'checkbox', value: nvram.usb_fs_hfs == 1 }
/* HFS-END */
] },
/* LINUX26-BEGIN */
/* MICROSD-BEGIN */
{ title: 'SD/MMC Card Support', indent: 2, name: 'f_mmc', type: 'checkbox', value: nvram.usb_mmc == 1 },
/* MICROSD-END */
/* LINUX26-END */
{ title: 'Automount', indent: 2, name: 'f_automount', type: 'checkbox',
suffix: ' <small>Automatically mount all partitions to sub-directories in <i>/mnt</i>.</small>', value: nvram.usb_automount == 1 },
{ title: 'Run after mounting', indent: 2, name: 'script_usbmount', type: 'textarea', value: nvram.script_usbmount },
{ title: 'Run before unmounting', indent: 2, name: 'script_usbumount', type: 'textarea', value: nvram.script_usbumount },
null,
/* LINUX26-BEGIN */
{ title: 'HDD Spindown', name: 'f_idle_enable', type: 'checkbox',
suffix: ' <small>Spin down each HDD when idle. No need to use with flashdrive.</small>', value: nvram.idle_enable == 1 },
null,
{ title: 'USB 3G Modem support', name: 'f_usb_3g', type: 'checkbox',
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 },
null,
/* LINUX26-END */
{ title: 'Hotplug script<br><small>(called when any USB device is attached or removed)</small>', name: 'script_usbhotplug', type: 'textarea', value: nvram.script_usbhotplug },
null,
{ text: '<small>Some of the changes will take effect only after a restart.</small>' }
]);
</script>
</div>
</div>
<div class="box" id="last-box" data-box="attached-devices">
<div class="heading">Attached Devices</div>
<div class="content">
<table id="dev-grid" class="line-table"></table>
</div>
</div>
<button type="button" value="Save" id="save-button" onclick="save()" class="btn btn-primary">Save <i class="icon-check"></i></button>
<button type="button" value="Cancel" id="cancel-button" onclick="javascript:reloadPage();" class="btn">Cancel <i class="icon-cancel"></i></button>
<span id="footer-msg" class="alert alert-warning" style="visibility: hidden;"></span>
</form>
<script type="text/javascript">earlyInit(); verifyFields(null, 1);</script>
</content>