1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
services_wol.php
|
5 |
|
|
*/
|
6 |
b9043cdc
|
Stephen Beaver
|
/* ====================================================================
|
7 |
|
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
8 |
191cb31d
|
Stephen Beaver
|
*
|
9 |
|
|
* Some or all of this file is based on the m0n0wall project which is
|
10 |
|
|
* Copyright (c) 2004 Manuel Kasper (BSD 2 clause)
|
11 |
b9043cdc
|
Stephen Beaver
|
*
|
12 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
13 |
|
|
* are permitted provided that the following conditions are met:
|
14 |
|
|
*
|
15 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
* this list of conditions and the following disclaimer.
|
17 |
|
|
*
|
18 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
19 |
|
|
* notice, this list of conditions and the following disclaimer in
|
20 |
|
|
* the documentation and/or other materials provided with the
|
21 |
|
|
* distribution.
|
22 |
|
|
*
|
23 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
24 |
|
|
* must display the following acknowledgment:
|
25 |
|
|
* "This product includes software developed by the pfSense Project
|
26 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
27 |
|
|
*
|
28 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
29 |
|
|
* endorse or promote products derived from this software without
|
30 |
|
|
* prior written permission. For written permission, please contact
|
31 |
|
|
* coreteam@pfsense.org.
|
32 |
|
|
*
|
33 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
34 |
|
|
* nor may "pfSense" appear in their names without prior written
|
35 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
36 |
|
|
*
|
37 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
38 |
|
|
* acknowledgment:
|
39 |
|
|
*
|
40 |
|
|
* "This product includes software developed by the pfSense Project
|
41 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
42 |
|
|
*
|
43 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
44 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
45 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
46 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
47 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
48 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
49 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
50 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
51 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
52 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
53 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
54 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
55 |
|
|
*
|
56 |
|
|
* ====================================================================
|
57 |
|
|
*
|
58 |
c9df279d
|
Stephen Beaver
|
*/
|
59 |
1d333258
|
Scott Ullrich
|
/*
|
60 |
bc3fa9f1
|
Peter Bouwdewijn
|
pfSense_BUILDER_BINARIES: /usr/local/bin/wol
|
61 |
1d333258
|
Scott Ullrich
|
pfSense_MODULE: wol
|
62 |
|
|
*/
|
63 |
5b237745
|
Scott Ullrich
|
|
64 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
65 |
|
|
##|*IDENT=page-services-wakeonlan
|
66 |
|
|
##|*NAME=Services: Wake on LAN page
|
67 |
|
|
##|*DESCR=Allow access to the 'Services: Wake on LAN' page.
|
68 |
|
|
##|*MATCH=services_wol.php*
|
69 |
|
|
##|-PRIV
|
70 |
|
|
|
71 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
72 |
ad2879b8
|
PiBa-NL
|
require_once('classes/Form.class.php');
|
73 |
5b237745
|
Scott Ullrich
|
|
74 |
|
|
if (!is_array($config['wol']['wolentry'])) {
|
75 |
|
|
$config['wol']['wolentry'] = array();
|
76 |
|
|
}
|
77 |
|
|
$a_wol = &$config['wol']['wolentry'];
|
78 |
|
|
|
79 |
bc3fa9f1
|
Peter Bouwdewijn
|
if($_GET['wakeall'] != "") {
|
80 |
4751361d
|
Scott Ullrich
|
$i = 0;
|
81 |
|
|
$savemsg = "";
|
82 |
|
|
foreach ($a_wol as $wolent) {
|
83 |
|
|
$mac = $wolent['mac'];
|
84 |
|
|
$if = $wolent['interface'];
|
85 |
1b197e55
|
stompro
|
$description = $wolent['descr'];
|
86 |
2bf16ba2
|
Ermal
|
$ipaddr = get_interface_ip($if);
|
87 |
56463a6c
|
Phil Davis
|
if (!is_ipaddr($ipaddr)) {
|
88 |
2bf16ba2
|
Ermal
|
continue;
|
89 |
56463a6c
|
Phil Davis
|
}
|
90 |
2bf16ba2
|
Ermal
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
91 |
1b197e55
|
stompro
|
/* Execute wol command and check return code. */
|
92 |
56463a6c
|
Phil Davis
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")) {
|
93 |
|
|
$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'), $mac, $description, ".<br />");
|
94 |
|
|
} else {
|
95 |
|
|
$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s (%4$s) did not complete successfully%5$s'), '<a href="/diag_logs.php">', '</a>', $description, $mac, ".<br />");
|
96 |
|
|
}
|
97 |
4751361d
|
Scott Ullrich
|
}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
5b237745
|
Scott Ullrich
|
if ($_POST || $_GET['mac']) {
|
101 |
|
|
unset($input_errors);
|
102 |
f0fe3d30
|
Scott Ullrich
|
|
103 |
5b237745
|
Scott Ullrich
|
if ($_GET['mac']) {
|
104 |
56463a6c
|
Phil Davis
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
105 |
|
|
$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
|
106 |
5b237745
|
Scott Ullrich
|
$mac = $_GET['mac'];
|
107 |
|
|
$if = $_GET['if'];
|
108 |
|
|
} else {
|
109 |
56463a6c
|
Phil Davis
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
110 |
|
|
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
|
111 |
4f3401e0
|
Bill Marquette
|
$mac = $_POST['mac'];
|
112 |
5b237745
|
Scott Ullrich
|
$if = $_POST['interface'];
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
/* input validation */
|
116 |
56463a6c
|
Phil Davis
|
if (!$mac || !is_macaddr($mac)) {
|
117 |
d58dbf67
|
Rafael Lucas
|
$input_errors[] = gettext("A valid MAC address must be specified.");
|
118 |
56463a6c
|
Phil Davis
|
}
|
119 |
|
|
if (!$if) {
|
120 |
d58dbf67
|
Rafael Lucas
|
$input_errors[] = gettext("A valid interface must be specified.");
|
121 |
56463a6c
|
Phil Davis
|
}
|
122 |
5b237745
|
Scott Ullrich
|
|
123 |
f0fe3d30
|
Scott Ullrich
|
if (!$input_errors) {
|
124 |
5b237745
|
Scott Ullrich
|
/* determine broadcast address */
|
125 |
2bf16ba2
|
Ermal
|
$ipaddr = get_interface_ip($if);
|
126 |
56463a6c
|
Phil Davis
|
if (!is_ipaddr($ipaddr)) {
|
127 |
2bf16ba2
|
Ermal
|
$input_errors[] = gettext("A valid ip could not be found!");
|
128 |
56463a6c
|
Phil Davis
|
} else {
|
129 |
2bf16ba2
|
Ermal
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
130 |
|
|
/* Execute wol command and check return code. */
|
131 |
56463a6c
|
Phil Davis
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac))) {
|
132 |
|
|
$savemsg .= sprintf(gettext("Sent magic packet to %s."), $mac);
|
133 |
|
|
} else {
|
134 |
|
|
$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s did not complete successfully%4$s'), '<a href="/diag_logs.php">', '</a>', $mac, ".<br />");
|
135 |
|
|
}
|
136 |
1b197e55
|
stompro
|
}
|
137 |
5b237745
|
Scott Ullrich
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
if ($_GET['act'] == "del") {
|
141 |
|
|
if ($a_wol[$_GET['id']]) {
|
142 |
|
|
unset($a_wol[$_GET['id']]);
|
143 |
|
|
write_config();
|
144 |
|
|
header("Location: services_wol.php");
|
145 |
|
|
exit;
|
146 |
|
|
}
|
147 |
|
|
}
|
148 |
4df96eff
|
Scott Ullrich
|
|
149 |
56463a6c
|
Phil Davis
|
$pgtitle = array(gettext("Services"), gettext("Wake on LAN"));
|
150 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
151 |
|
|
|
152 |
6658142a
|
Stephen Beaver
|
print_info_box(gettext('This service can be used to wake up (power on) computers by sending special') . ' "' . gettext('Magic Packets') . '"<br />' .
|
153 |
|
|
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).'));
|
154 |
5b237745
|
Scott Ullrich
|
|
155 |
6658142a
|
Stephen Beaver
|
?>
|
156 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
157 |
|
|
<?php
|
158 |
|
|
|
159 |
|
|
if ($input_errors)
|
160 |
|
|
print_input_errors($input_errors);
|
161 |
|
|
|
162 |
|
|
if ($savemsg)
|
163 |
|
|
print_info_box($savemsg);
|
164 |
|
|
|
165 |
38e06c66
|
Sjon Hortensius
|
$form = new Form('Send');
|
166 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
167 |
ba8749ed
|
Peter Bouwdewijn
|
$section = new Form_Section('Wake on LAN');
|
168 |
bc3fa9f1
|
Peter Bouwdewijn
|
|
169 |
|
|
$section->addInput(new Form_Select(
|
170 |
|
|
'interface',
|
171 |
ba8749ed
|
Peter Bouwdewijn
|
'Interface',
|
172 |
c9be8d9f
|
peter
|
(link_interface_to_bridge($if) ? null : $if),
|
173 |
bc3fa9f1
|
Peter Bouwdewijn
|
get_configured_interface_with_descr()
|
174 |
|
|
))->setHelp('Choose which interface the host to be woken up is connected to.');
|
175 |
|
|
|
176 |
|
|
$section->addInput(new Form_Input(
|
177 |
|
|
'mac',
|
178 |
ba8749ed
|
Peter Bouwdewijn
|
'MAC address',
|
179 |
|
|
'text',
|
180 |
|
|
$mac
|
181 |
bc3fa9f1
|
Peter Bouwdewijn
|
))->setHelp(gettext('Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx'));
|
182 |
|
|
|
183 |
|
|
$form->add($section);
|
184 |
|
|
print $form;
|
185 |
|
|
?>
|
186 |
|
|
|
187 |
|
|
<div class="panel panel-default">
|
188 |
|
|
<div class="panel-heading">
|
189 |
|
|
<h2 class="panel-title">Wake on LAN devices</h2>
|
190 |
|
|
</div>
|
191 |
|
|
|
192 |
|
|
<div class="panel-body">
|
193 |
|
|
<p><?=gettext("Click the MAC address to wake up an individual device.")?></p>
|
194 |
f0b20c3f
|
Peter Bouwdewijn
|
<div class="table-responsive">
|
195 |
0c9eb13b
|
Peter Bouwdewijn
|
<table class="table table-striped table-hover">
|
196 |
f0b20c3f
|
Peter Bouwdewijn
|
<thead>
|
197 |
bc3fa9f1
|
Peter Bouwdewijn
|
<tr>
|
198 |
f0b20c3f
|
Peter Bouwdewijn
|
<th><?=gettext("Interface")?></th>
|
199 |
|
|
<th><?=gettext("MAC address")?></th>
|
200 |
|
|
<th><?=gettext("Description")?></th>
|
201 |
|
|
<th></th>
|
202 |
bc3fa9f1
|
Peter Bouwdewijn
|
</tr>
|
203 |
f0b20c3f
|
Peter Bouwdewijn
|
</thead>
|
204 |
|
|
<tbody>
|
205 |
|
|
<?php foreach ($a_wol as $i => $wolent): ?>
|
206 |
|
|
<tr>
|
207 |
|
|
<td>
|
208 |
|
|
<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
|
209 |
|
|
</td>
|
210 |
|
|
<td>
|
211 |
|
|
<a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
|
212 |
|
|
</td>
|
213 |
|
|
<td>
|
214 |
|
|
<?=htmlspecialchars($wolent['descr']);?>
|
215 |
|
|
</td>
|
216 |
|
|
<td>
|
217 |
370358b8
|
heper
|
<a class="fa fa-pencil" title="<?=gettext('Edit device')?>" href="services_wol_edit.php?id=<?=$i?>"></a>
|
218 |
33f0b0d5
|
Stephen Beaver
|
<a class="fa fa-trash" title="<?=gettext('Delete device')?>" href="services_wol.php?act=del&id=<?=$i?>"></a>
|
219 |
f0b20c3f
|
Peter Bouwdewijn
|
</td>
|
220 |
|
|
</tr>
|
221 |
|
|
<?php endforeach?>
|
222 |
|
|
</tbody>
|
223 |
|
|
</table>
|
224 |
|
|
</div>
|
225 |
bc3fa9f1
|
Peter Bouwdewijn
|
</div>
|
226 |
|
|
<div class="panel-footer">
|
227 |
|
|
<a class="btn btn-success" href="services_wol_edit.php">
|
228 |
|
|
Add
|
229 |
|
|
</a>
|
230 |
|
|
|
231 |
|
|
<a href="services_wol.php?wakeall=true" role="button" class="btn btn-primary">
|
232 |
|
|
<?=gettext("Wake all devices")?>
|
233 |
|
|
</a>
|
234 |
|
|
</div>
|
235 |
|
|
</div>
|
236 |
|
|
|
237 |
|
|
<?php
|
238 |
|
|
|
239 |
370358b8
|
heper
|
include("foot.inc");
|