1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* services_wol.php
|
4 |
191cb31d
|
Stephen Beaver
|
*
|
5 |
c5d81585
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
6 |
81299b5c
|
Renato Botelho
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
8 |
b9043cdc
|
Stephen Beaver
|
*
|
9 |
c5d81585
|
Renato Botelho
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
10 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11 |
|
|
* All rights reserved.
|
12 |
b9043cdc
|
Stephen Beaver
|
*
|
13 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
14 |
|
|
* you may not use this file except in compliance with the License.
|
15 |
|
|
* You may obtain a copy of the License at
|
16 |
b9043cdc
|
Stephen Beaver
|
*
|
17 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
18 |
b9043cdc
|
Stephen Beaver
|
*
|
19 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
20 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
21 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22 |
|
|
* See the License for the specific language governing permissions and
|
23 |
|
|
* limitations under the License.
|
24 |
c9df279d
|
Stephen Beaver
|
*/
|
25 |
5b237745
|
Scott Ullrich
|
|
26 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
27 |
|
|
##|*IDENT=page-services-wakeonlan
|
28 |
7ca42d47
|
k-paulius
|
##|*NAME=Services: Wake-on-LAN
|
29 |
|
|
##|*DESCR=Allow access to the 'Services: Wake-on-LAN' page.
|
30 |
6b07c15a
|
Matthew Grooms
|
##|*MATCH=services_wol.php*
|
31 |
|
|
##|-PRIV
|
32 |
|
|
|
33 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
34 |
5b237745
|
Scott Ullrich
|
if (!is_array($config['wol']['wolentry'])) {
|
35 |
|
|
$config['wol']['wolentry'] = array();
|
36 |
|
|
}
|
37 |
|
|
$a_wol = &$config['wol']['wolentry'];
|
38 |
|
|
|
39 |
13541a81
|
Steve Beaver
|
if ($_REQUEST['wakeall'] != "") {
|
40 |
4751361d
|
Scott Ullrich
|
$i = 0;
|
41 |
|
|
$savemsg = "";
|
42 |
|
|
foreach ($a_wol as $wolent) {
|
43 |
|
|
$mac = $wolent['mac'];
|
44 |
|
|
$if = $wolent['interface'];
|
45 |
1b197e55
|
stompro
|
$description = $wolent['descr'];
|
46 |
2bf16ba2
|
Ermal
|
$ipaddr = get_interface_ip($if);
|
47 |
56463a6c
|
Phil Davis
|
if (!is_ipaddr($ipaddr)) {
|
48 |
2bf16ba2
|
Ermal
|
continue;
|
49 |
56463a6c
|
Phil Davis
|
}
|
50 |
2bf16ba2
|
Ermal
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
51 |
1b197e55
|
stompro
|
/* Execute wol command and check return code. */
|
52 |
56463a6c
|
Phil Davis
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")) {
|
53 |
4bfc3f7d
|
Phil Davis
|
$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s).'), $mac, $description) . "<br />";
|
54 |
f78bbe16
|
Phil Davis
|
$class = 'success';
|
55 |
56463a6c
|
Phil Davis
|
} else {
|
56 |
4bfc3f7d
|
Phil Davis
|
$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s (%4$s) did not complete successfully.'), '<a href="/status_logs.php">', '</a>', $description, $mac) . "<br />";
|
57 |
f78bbe16
|
Phil Davis
|
$class = 'warning';
|
58 |
56463a6c
|
Phil Davis
|
}
|
59 |
4751361d
|
Scott Ullrich
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
13541a81
|
Steve Beaver
|
if ($_POST['Submit'] || $_POST['mac']) {
|
63 |
5b237745
|
Scott Ullrich
|
unset($input_errors);
|
64 |
f0fe3d30
|
Scott Ullrich
|
|
65 |
13541a81
|
Steve Beaver
|
if ($_POST['mac']) {
|
66 |
56463a6c
|
Phil Davis
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
67 |
13541a81
|
Steve Beaver
|
$mac = strtolower(str_replace("-", ":", $_POST['mac']));
|
68 |
|
|
$if = $_POST['if'];
|
69 |
5b237745
|
Scott Ullrich
|
}
|
70 |
|
|
|
71 |
|
|
/* input validation */
|
72 |
56463a6c
|
Phil Davis
|
if (!$mac || !is_macaddr($mac)) {
|
73 |
d58dbf67
|
Rafael Lucas
|
$input_errors[] = gettext("A valid MAC address must be specified.");
|
74 |
56463a6c
|
Phil Davis
|
}
|
75 |
13541a81
|
Steve Beaver
|
|
76 |
56463a6c
|
Phil Davis
|
if (!$if) {
|
77 |
d58dbf67
|
Rafael Lucas
|
$input_errors[] = gettext("A valid interface must be specified.");
|
78 |
56463a6c
|
Phil Davis
|
}
|
79 |
5b237745
|
Scott Ullrich
|
|
80 |
f0fe3d30
|
Scott Ullrich
|
if (!$input_errors) {
|
81 |
5b237745
|
Scott Ullrich
|
/* determine broadcast address */
|
82 |
2bf16ba2
|
Ermal
|
$ipaddr = get_interface_ip($if);
|
83 |
56463a6c
|
Phil Davis
|
if (!is_ipaddr($ipaddr)) {
|
84 |
2bf16ba2
|
Ermal
|
$input_errors[] = gettext("A valid ip could not be found!");
|
85 |
56463a6c
|
Phil Davis
|
} else {
|
86 |
2bf16ba2
|
Ermal
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
87 |
|
|
/* Execute wol command and check return code. */
|
88 |
56463a6c
|
Phil Davis
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac))) {
|
89 |
|
|
$savemsg .= sprintf(gettext("Sent magic packet to %s."), $mac);
|
90 |
f78bbe16
|
Phil Davis
|
$class = 'success';
|
91 |
56463a6c
|
Phil Davis
|
} else {
|
92 |
4bfc3f7d
|
Phil Davis
|
$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s did not complete successfully.'), '<a href="/status_logs.php">', '</a>', $mac) . "<br />";
|
93 |
f78bbe16
|
Phil Davis
|
$class = 'warning';
|
94 |
56463a6c
|
Phil Davis
|
}
|
95 |
1b197e55
|
stompro
|
}
|
96 |
5b237745
|
Scott Ullrich
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
13541a81
|
Steve Beaver
|
if ($_POST['act'] == "del") {
|
100 |
|
|
if ($a_wol[$_POST['id']]) {
|
101 |
|
|
unset($a_wol[$_POST['id']]);
|
102 |
b525d581
|
doktornotor
|
write_config(gettext("Deleted a device from WOL configuration."));
|
103 |
5b237745
|
Scott Ullrich
|
header("Location: services_wol.php");
|
104 |
|
|
exit;
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
4df96eff
|
Scott Ullrich
|
|
108 |
7ca42d47
|
k-paulius
|
$pgtitle = array(gettext("Services"), gettext("Wake-on-LAN"));
|
109 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
110 |
f78bbe16
|
Phil Davis
|
?>
|
111 |
c95dabdd
|
Stephen Beaver
|
<div class="infoblock blockopen">
|
112 |
f78bbe16
|
Phil Davis
|
<?php
|
113 |
4bfc3f7d
|
Phil Davis
|
print_info_box(gettext('This service can be used to wake up (power on) computers by sending special "Magic Packets".') . '<br />' .
|
114 |
7ca42d47
|
k-paulius
|
gettext('The NIC in the computer that is to be woken up must support Wake-on-LAN and must be properly configured (WOL cable, BIOS settings).'),
|
115 |
4bfc3f7d
|
Phil Davis
|
'info', false);
|
116 |
5b237745
|
Scott Ullrich
|
|
117 |
6658142a
|
Stephen Beaver
|
?>
|
118 |
f78bbe16
|
Phil Davis
|
</div>
|
119 |
bc3fa9f1
|
Peter Bouwdewijn
|
<?php
|
120 |
|
|
|
121 |
20db3e1a
|
Phil Davis
|
if ($input_errors) {
|
122 |
bc3fa9f1
|
Peter Bouwdewijn
|
print_input_errors($input_errors);
|
123 |
20db3e1a
|
Phil Davis
|
}
|
124 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
125 |
20db3e1a
|
Phil Davis
|
if ($savemsg) {
|
126 |
f78bbe16
|
Phil Davis
|
print_info_box($savemsg, $class);
|
127 |
20db3e1a
|
Phil Davis
|
}
|
128 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
129 |
37676f4e
|
jim-p
|
$form = new Form(false);
|
130 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
131 |
7ca42d47
|
k-paulius
|
$section = new Form_Section('Wake-on-LAN');
|
132 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
133 |
|
|
$section->addInput(new Form_Select(
|
134 |
9cc7e37b
|
PiBa-NL
|
'if',
|
135 |
24b82516
|
Phil Davis
|
'*Interface',
|
136 |
c9be8d9f
|
peter
|
(link_interface_to_bridge($if) ? null : $if),
|
137 |
bc3fa9f1
|
Peter Bouwdewijn
|
get_configured_interface_with_descr()
|
138 |
|
|
))->setHelp('Choose which interface the host to be woken up is connected to.');
|
139 |
|
|
|
140 |
|
|
$section->addInput(new Form_Input(
|
141 |
|
|
'mac',
|
142 |
24b82516
|
Phil Davis
|
'*MAC address',
|
143 |
ba8749ed
|
Peter Bouwdewijn
|
'text',
|
144 |
|
|
$mac
|
145 |
314a088a
|
Phil Davis
|
))->setHelp('Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx');
|
146 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
147 |
e8a37c87
|
jim-p
|
$form->add($section);
|
148 |
|
|
|
149 |
|
|
$form->addGlobal(new Form_Button(
|
150 |
37676f4e
|
jim-p
|
'Submit',
|
151 |
faab522f
|
Renato Botelho
|
'Send',
|
152 |
37676f4e
|
jim-p
|
null,
|
153 |
|
|
'fa-power-off'
|
154 |
|
|
))->addClass('btn-primary');
|
155 |
|
|
|
156 |
bc3fa9f1
|
Peter Bouwdewijn
|
print $form;
|
157 |
|
|
?>
|
158 |
|
|
|
159 |
|
|
<div class="panel panel-default">
|
160 |
|
|
<div class="panel-heading">
|
161 |
7ca42d47
|
k-paulius
|
<h2 class="panel-title"><?=gettext("Wake-on-LAN Devices");?></h2>
|
162 |
bc3fa9f1
|
Peter Bouwdewijn
|
</div>
|
163 |
|
|
|
164 |
|
|
<div class="panel-body">
|
165 |
|
|
<p><?=gettext("Click the MAC address to wake up an individual device.")?></p>
|
166 |
f0b20c3f
|
Peter Bouwdewijn
|
<div class="table-responsive">
|
167 |
1c10ce97
|
PiBa-NL
|
<table class="table table-striped table-hover table-rowdblclickedit">
|
168 |
f0b20c3f
|
Peter Bouwdewijn
|
<thead>
|
169 |
bc3fa9f1
|
Peter Bouwdewijn
|
<tr>
|
170 |
f0b20c3f
|
Peter Bouwdewijn
|
<th><?=gettext("Interface")?></th>
|
171 |
|
|
<th><?=gettext("MAC address")?></th>
|
172 |
|
|
<th><?=gettext("Description")?></th>
|
173 |
70dc5cd6
|
Phil Davis
|
<th><?=gettext("Actions")?></th>
|
174 |
bc3fa9f1
|
Peter Bouwdewijn
|
</tr>
|
175 |
f0b20c3f
|
Peter Bouwdewijn
|
</thead>
|
176 |
|
|
<tbody>
|
177 |
|
|
<?php foreach ($a_wol as $i => $wolent): ?>
|
178 |
|
|
<tr>
|
179 |
|
|
<td>
|
180 |
|
|
<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
|
181 |
|
|
</td>
|
182 |
|
|
<td>
|
183 |
9cc7e37b
|
PiBa-NL
|
<a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>" usepost><?=strtolower($wolent['mac']);?></a>
|
184 |
f0b20c3f
|
Peter Bouwdewijn
|
</td>
|
185 |
|
|
<td>
|
186 |
|
|
<?=htmlspecialchars($wolent['descr']);?>
|
187 |
|
|
</td>
|
188 |
|
|
<td>
|
189 |
e8a37c87
|
jim-p
|
<a class="fa fa-pencil" title="<?=gettext('Edit Device')?>" href="services_wol_edit.php?id=<?=$i?>"></a>
|
190 |
13541a81
|
Steve Beaver
|
<a class="fa fa-trash" title="<?=gettext('Delete Device')?>" href="services_wol.php?act=del&id=<?=$i?>" usepost></a>
|
191 |
|
|
<a class="fa fa-power-off" title="<?=gettext('Wake Device')?>" href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>" usepost></a>
|
192 |
f0b20c3f
|
Peter Bouwdewijn
|
</td>
|
193 |
|
|
</tr>
|
194 |
|
|
<?php endforeach?>
|
195 |
|
|
</tbody>
|
196 |
|
|
</table>
|
197 |
|
|
</div>
|
198 |
bc3fa9f1
|
Peter Bouwdewijn
|
</div>
|
199 |
|
|
<div class="panel-footer">
|
200 |
|
|
<a class="btn btn-success" href="services_wol_edit.php">
|
201 |
37676f4e
|
jim-p
|
<i class="fa fa-plus icon-embed-btn"></i>
|
202 |
4bb7c0d1
|
bruno
|
<?=gettext("Add");?>
|
203 |
bc3fa9f1
|
Peter Bouwdewijn
|
</a>
|
204 |
|
|
|
205 |
|
|
<a href="services_wol.php?wakeall=true" role="button" class="btn btn-primary">
|
206 |
37676f4e
|
jim-p
|
<i class="fa fa-power-off icon-embed-btn"></i>
|
207 |
e8a37c87
|
jim-p
|
<?=gettext("Wake All Devices")?>
|
208 |
bc3fa9f1
|
Peter Bouwdewijn
|
</a>
|
209 |
|
|
</div>
|
210 |
|
|
</div>
|
211 |
|
|
|
212 |
|
|
<?php
|
213 |
|
|
|
214 |
370358b8
|
heper
|
include("foot.inc");
|