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
|
'use strict';
'require view';
'require dom';
'require uci';
'require fs';
'require ui';
'require rpc';
'require form';
'require tools.widgets as widgets';
return view.extend({
formdata: { wol: {} },
callHostHints: rpc.declare({
object: 'luci-rpc',
method: 'getHostHints',
expect: { '': {} }
}),
load: function() {
return Promise.all([
L.resolveDefault(fs.stat('/usr/bin/etherwake')),
L.resolveDefault(fs.stat('/usr/bin/wol')),
this.callHostHints(),
uci.load('etherwake')
]);
},
render: function(data) {
var has_ewk = data[0],
has_wol = data[1],
hosts = data[2],
m, s, o;
this.formdata.has_ewk = has_ewk;
this.formdata.has_wol = has_wol;
m = new form.JSONMap(this.formdata, _('Wake on LAN'),
_('Wake on LAN is a mechanism to remotely boot computers in the local network.'));
s = m.section(form.NamedSection, 'wol');
if (has_ewk && has_wol) {
o = s.option(form.ListValue, 'executable', _('WoL program'),
_('Sometimes only one of the two tools works. If one fails, try the other one'));
o.value('/usr/bin/etherwake', 'Etherwake');
o.value('/usr/bin/wol', 'WoL');
}
if (has_ewk) {
o = s.option(widgets.DeviceSelect, 'iface', _('Network interface to use'),
_('Specifies the interface the WoL packet is sent on'));
o.default = uci.get('etherwake', 'setup', 'interface');
o.rmempty = false;
o.noaliases = true;
o.noinactive = true;
if (has_wol)
o.depends('executable', '/usr/bin/etherwake');
}
o = s.option(form.Value, 'mac', _('Host to wake up'),
_('Choose the host to wake up or enter a custom MAC address to use'));
o.rmempty = false;
L.sortedKeys(hosts).forEach(function(mac) {
o.value(mac, E([], [ mac, ' (', E('strong', [
hosts[mac].name ||
L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4)[0] ||
L.toArray(hosts[mac].ip6addrs || hosts[mac].ipv6)[0] ||
'?'
]), ')' ]));
});
if (has_ewk) {
o = s.option(form.Flag, 'broadcast', _('Send to broadcast address'));
if (has_wol)
o.depends('executable', '/usr/bin/etherwake');
}
return m.render();
},
handleWakeup: function(ev) {
var map = document.querySelector('#maincontent .cbi-map'),
data = this.formdata;
return dom.callClassMethod(map, 'save').then(function() {
if (!data.wol.mac)
return alert(_('No target host specified!'));
var bin = data.executable || (data.has_ewk ? '/usr/bin/etherwake' : '/usr/bin/wol'),
args = [];
if (bin == '/usr/bin/etherwake') {
args.push('-D', '-i', data.wol.iface);
if (data.wol.broadcast == '1')
args.push('-b');
args.push(data.wol.mac);
}
else {
args.push('-v', data.wol.mac);
}
ui.showModal(_('Waking host'), [
E('p', { 'class': 'spinning' }, [ _('Starting WoL utility…') ])
]);
return fs.exec(bin, args).then(function(res) {
ui.showModal(_('Waking host'), [
res.stderr ? E('p', [ res.stdout ]) : '',
res.stderr ? E('pre', [ res.stderr ]) : '',
E('div', { 'class': 'right' }, [
E('button', {
'class': 'cbi-button cbi-button-primary',
'click': ui.hideModal
}, [ _('Dismiss') ])
])
]);
}).catch(function(err) {
ui.hideModal();
ui.addNotification(null, [
E('p', [ _('Waking host failed: '), err ])
]);
});
});
},
addFooter: function() {
return E('div', { 'class': 'cbi-page-actions' }, [
E('button', {
'class': 'cbi-button cbi-button-save',
'click': L.ui.createHandlerFn(this, 'handleWakeup')
}, [ _('Wake up host') ])
]);
}
});
|