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