9 'require tools.widgets as widgets';
12 formdata
: { wol
: {} },
14 callHostHints
: rpc
.declare({
16 method
: 'getHostHints',
22 L
.resolveDefault(fs
.stat('/usr/bin/etherwake')),
23 L
.resolveDefault(fs
.stat('/usr/bin/wol')),
29 render: function(data
) {
30 var has_ewk
= data
[0],
35 this.formdata
.has_ewk
= has_ewk
;
36 this.formdata
.has_wol
= has_wol
;
38 m
= new form
.JSONMap(this.formdata
, _('Wake on LAN'),
39 _('Wake on LAN is a mechanism to remotely boot computers in the local network.'));
41 s
= m
.section(form
.NamedSection
, 'wol');
43 if (has_ewk
&& has_wol
) {
44 o
= s
.option(form
.ListValue
, 'executable', _('WoL program'),
45 _('Sometimes only one of the two tools works. If one fails, try the other one'));
47 o
.value('/usr/bin/etherwake', 'Etherwake');
48 o
.value('/usr/bin/wol', 'WoL');
52 o
= s
.option(widgets
.DeviceSelect
, 'iface', _('Network interface to use'),
53 _('Specifies the interface the WoL packet is sent on'));
55 o
.default = uci
.get('etherwake', 'setup', 'interface');
61 o
.depends('executable', '/usr/bin/etherwake');
64 o
= s
.option(form
.Value
, 'mac', _('Host to wake up'),
65 _('Choose the host to wake up or enter a custom MAC address to use'));
69 Object
.keys(hosts
).sort().forEach(function(mac
) {
70 o
.value(mac
, E([], [ mac
, ' (', E('strong', [hosts
[mac
].name
|| hosts
[mac
].ipv4
|| hosts
[mac
].ipv6
|| '?']), ')' ]));
74 o
= s
.option(form
.Flag
, 'broadcast', ('Send to broadcast address'));
77 o
.depends('executable', '/usr/bin/etherwake');
83 handleWakeup: function(ev
) {
84 var map
= document
.querySelector('#maincontent .cbi-map'),
87 return dom
.callClassMethod(map
, 'save').then(function() {
89 return alert(_('No target host specified!'));
91 var bin
= data
.executable
|| (data
.has_ewk
? '/usr/bin/etherwake' : '/usr/bin/wol'),
94 if (bin
== '/usr/bin/etherwake') {
95 args
.push('-D', '-i', data
.wol
.iface
);
97 if (data
.wol
.broadcast
== '1')
100 args
.push(data
.wol
.mac
);
103 args
.push('-v', data
.wol
.mac
);
106 ui
.showModal(_('Waking host'), [
107 E('p', { 'class': 'spinning' }, [ 'Starting WoL utility…' ])
110 return fs
.exec(bin
, args
).then(function(res
) {
111 ui
.showModal(_('Waking host'), [
112 res
.stderr
? E('p', [ res
.stdout
]) : '',
113 res
.stderr
? E('pre', [ res
.stderr
]) : '',
114 E('div', { 'class': 'right' }, [
116 'class': 'cbi-button cbi-button-primary',
117 'click': ui
.hideModal
121 }).catch(function(err
) {
123 ui
.addNotification(null, [
124 E('p', [ _('Waking host failed: '), err
])
130 addFooter: function() {
131 return E('div', { 'class': 'cbi-page-actions' }, [
133 'class': 'cbi-button cbi-button-save',
134 'click': L
.ui
.createHandlerFn(this, 'handleWakeup')
135 }, [ _('Wake up host') ])