7 'require tools.widgets as widgets';
10 formdata
: { wol
: {} },
12 callHostHints
: rpc
.declare({
14 method
: 'getHostHints',
20 L
.resolveDefault(fs
.stat('/usr/bin/etherwake')),
21 L
.resolveDefault(fs
.stat('/usr/bin/wol')),
27 render: function(data
) {
28 var has_ewk
= data
[0],
33 this.formdata
.has_ewk
= has_ewk
;
34 this.formdata
.has_wol
= has_wol
;
36 m
= new form
.JSONMap(this.formdata
, _('Wake on LAN'),
37 _('Wake on LAN is a mechanism to remotely boot computers in the local network.'));
39 s
= m
.section(form
.NamedSection
, 'wol');
41 if (has_ewk
&& has_wol
) {
42 o
= s
.option(form
.ListValue
, 'executable', _('WoL program'),
43 _('Sometimes only one of the two tools works. If one fails, try the other one'));
45 o
.value('/usr/bin/etherwake', 'Etherwake');
46 o
.value('/usr/bin/wol', 'WoL');
50 o
= s
.option(widgets
.DeviceSelect
, 'iface', _('Network interface to use'),
51 _('Specifies the interface the WoL packet is sent on'));
53 o
.default = uci
.get('etherwake', 'setup', 'interface');
59 o
.depends('executable', '/usr/bin/etherwake');
62 o
= s
.option(form
.Value
, 'mac', _('Host to wake up'),
63 _('Choose the host to wake up or enter a custom MAC address to use'));
67 Object
.keys(hosts
).sort().forEach(function(mac
) {
68 o
.value(mac
, E([], [ mac
, ' (', E('strong', [hosts
[mac
].name
|| hosts
[mac
].ipv4
|| hosts
[mac
].ipv6
|| '?']), ')' ]));
72 o
= s
.option(form
.Flag
, 'broadcast', ('Send to broadcast address'));
75 o
.depends('executable', '/usr/bin/etherwake');
81 handleWakeup: function(ev
) {
82 var map
= document
.querySelector('#maincontent .cbi-map'),
85 return L
.dom
.callClassMethod(map
, 'save').then(function() {
87 return alert(_('No target host specified!'));
89 var bin
= data
.executable
|| (data
.has_ewk
? '/usr/bin/etherwake' : '/usr/bin/wol'),
92 if (bin
== '/usr/bin/etherwake') {
93 args
.push('-D', '-i', data
.wol
.iface
);
95 if (data
.wol
.broadcast
== '1')
98 args
.push(data
.wol
.mac
);
101 args
.push('-v', data
.wol
.mac
);
104 ui
.showModal(_('Waking host'), [
105 E('p', { 'class': 'spinning' }, [ 'Starting WoL utility…' ])
108 return fs
.exec(bin
, args
).then(function(res
) {
109 ui
.showModal(_('Waking host'), [
110 res
.stderr
? E('p', [ res
.stdout
]) : '',
111 res
.stderr
? E('pre', [ res
.stderr
]) : '',
112 E('div', { 'class': 'right' }, [
114 'class': 'cbi-button cbi-button-primary',
115 'click': ui
.hideModal
119 }).catch(function(err
) {
121 ui
.addNotification(null, [
122 E('p', [ _('Waking host failed: '), err
])
128 addFooter: function() {
129 return E('div', { 'class': 'cbi-page-actions' }, [
131 'class': 'cbi-button cbi-button-save',
132 'click': L
.ui
.createHandlerFn(this, 'handleWakeup')
133 }, [ _('Wake up host') ])