1
|
<?php
|
2
|
/*
|
3
|
* services_wol.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
|
9
|
* All rights reserved.
|
10
|
*
|
11
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
12
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13
|
* All rights reserved.
|
14
|
*
|
15
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
16
|
* you may not use this file except in compliance with the License.
|
17
|
* You may obtain a copy of the License at
|
18
|
*
|
19
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20
|
*
|
21
|
* Unless required by applicable law or agreed to in writing, software
|
22
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
23
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24
|
* See the License for the specific language governing permissions and
|
25
|
* limitations under the License.
|
26
|
*/
|
27
|
|
28
|
##|+PRIV
|
29
|
##|*IDENT=page-services-wakeonlan
|
30
|
##|*NAME=Services: Wake-on-LAN
|
31
|
##|*DESCR=Allow access to the 'Services: Wake-on-LAN' page.
|
32
|
##|*MATCH=services_wol.php*
|
33
|
##|-PRIV
|
34
|
|
35
|
require_once("guiconfig.inc");
|
36
|
|
37
|
init_config_arr(array('wol', 'wolentry'));
|
38
|
$a_wol = &$config['wol']['wolentry'];
|
39
|
|
40
|
if ($_REQUEST['wakeall'] != "") {
|
41
|
$i = 0;
|
42
|
$savemsg = "";
|
43
|
foreach ($a_wol as $wolent) {
|
44
|
$mac = $wolent['mac'];
|
45
|
$if = $wolent['interface'];
|
46
|
$description = $wolent['descr'];
|
47
|
$ipaddr = get_interface_ip($if);
|
48
|
if (!is_ipaddr($ipaddr)) {
|
49
|
continue;
|
50
|
}
|
51
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
52
|
/* Execute wol command and check return code. */
|
53
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")) {
|
54
|
$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s).'), $mac, $description) . "<br />";
|
55
|
$class = 'success';
|
56
|
} else {
|
57
|
$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 />";
|
58
|
$class = 'warning';
|
59
|
}
|
60
|
}
|
61
|
}
|
62
|
|
63
|
if ($_POST['Submit'] || $_POST['mac']) {
|
64
|
unset($input_errors);
|
65
|
|
66
|
if ($_POST['mac']) {
|
67
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
68
|
$mac = strtolower(str_replace("-", ":", $_POST['mac']));
|
69
|
$if = $_POST['if'];
|
70
|
}
|
71
|
|
72
|
/* input validation */
|
73
|
if (!$mac || !is_macaddr($mac)) {
|
74
|
$input_errors[] = gettext("A valid MAC address must be specified.");
|
75
|
}
|
76
|
|
77
|
if (!$if) {
|
78
|
$input_errors[] = gettext("A valid interface must be specified.");
|
79
|
}
|
80
|
|
81
|
if (!$input_errors) {
|
82
|
/* determine broadcast address */
|
83
|
$ipaddr = get_interface_ip($if);
|
84
|
if (!is_ipaddr($ipaddr)) {
|
85
|
$input_errors[] = gettext("A valid ip could not be found!");
|
86
|
} else {
|
87
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
88
|
/* Execute wol command and check return code. */
|
89
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac))) {
|
90
|
$savemsg .= sprintf(gettext("Sent magic packet to %s."), $mac);
|
91
|
$class = 'success';
|
92
|
} else {
|
93
|
$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 />";
|
94
|
$class = 'warning';
|
95
|
}
|
96
|
}
|
97
|
}
|
98
|
}
|
99
|
|
100
|
if ($_POST['act'] == "del") {
|
101
|
if ($a_wol[$_POST['id']]) {
|
102
|
unset($a_wol[$_POST['id']]);
|
103
|
write_config(gettext("Deleted a device from WOL configuration."));
|
104
|
header("Location: services_wol.php");
|
105
|
exit;
|
106
|
}
|
107
|
}
|
108
|
|
109
|
$pgtitle = array(gettext("Services"), gettext("Wake-on-LAN"));
|
110
|
include("head.inc");
|
111
|
?>
|
112
|
<div class="infoblock blockopen">
|
113
|
<?php
|
114
|
print_info_box(gettext('This service can be used to wake up (power on) computers by sending special "Magic Packets".') . '<br />' .
|
115
|
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).'),
|
116
|
'info', false);
|
117
|
|
118
|
?>
|
119
|
</div>
|
120
|
<?php
|
121
|
|
122
|
if ($input_errors) {
|
123
|
print_input_errors($input_errors);
|
124
|
}
|
125
|
|
126
|
if ($savemsg) {
|
127
|
print_info_box($savemsg, $class);
|
128
|
}
|
129
|
|
130
|
$selected_if = (empty($if) ? 'lan' : $if);
|
131
|
if (!isset(get_configured_interface_list(false)[$selected_if])) {
|
132
|
$selected_if = null;
|
133
|
}
|
134
|
|
135
|
$form = new Form(false);
|
136
|
|
137
|
$section = new Form_Section('Wake-on-LAN');
|
138
|
|
139
|
$section->addInput(new Form_Select(
|
140
|
'if',
|
141
|
'*Interface',
|
142
|
$selected_if,
|
143
|
get_configured_interface_with_descr()
|
144
|
))->setHelp('Choose which interface the host to be woken up is connected to.');
|
145
|
|
146
|
$section->addInput(new Form_Input(
|
147
|
'mac',
|
148
|
'*MAC address',
|
149
|
'text',
|
150
|
$mac
|
151
|
))->setHelp('Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx');
|
152
|
|
153
|
$form->add($section);
|
154
|
|
155
|
$form->addGlobal(new Form_Button(
|
156
|
'Submit',
|
157
|
'Send',
|
158
|
null,
|
159
|
'fa-power-off'
|
160
|
))->addClass('btn-primary');
|
161
|
|
162
|
print $form;
|
163
|
?>
|
164
|
|
165
|
<div class="panel panel-default">
|
166
|
<div class="panel-heading">
|
167
|
<h2 class="panel-title"><?=gettext("Wake-on-LAN Devices");?></h2>
|
168
|
</div>
|
169
|
|
170
|
<?php
|
171
|
// Add top buttons if more than 24 entries in the table
|
172
|
if (is_array($a_wol) && (count($a_wol) > 24)) {
|
173
|
?>
|
174
|
<div class="panel-footer">
|
175
|
<a class="btn btn-success" href="services_wol_edit.php">
|
176
|
<i class="fa fa-plus icon-embed-btn"></i>
|
177
|
<?=gettext("Add");?>
|
178
|
</a>
|
179
|
|
180
|
<a href="services_wol.php?wakeall=true" role="button" class="btn btn-primary">
|
181
|
<i class="fa fa-power-off icon-embed-btn"></i>
|
182
|
<?=gettext("Wake All Devices")?>
|
183
|
</a>
|
184
|
</div>
|
185
|
<?php } ?>
|
186
|
|
187
|
<div class="panel-body">
|
188
|
<p class="text-danger" style="margin-left: 8px;margin-bottom:0px;"><?=gettext("Click the MAC address to wake up an individual device.")?></p>
|
189
|
<div class="table-responsive">
|
190
|
<table class="table table-striped table-hover table-rowdblclickedit">
|
191
|
<thead>
|
192
|
<tr>
|
193
|
<th><?=gettext("Interface")?></th>
|
194
|
<th><?=gettext("MAC address")?></th>
|
195
|
<th><?=gettext("Description")?></th>
|
196
|
<th><?=gettext("Actions")?></th>
|
197
|
</tr>
|
198
|
</thead>
|
199
|
<tbody>
|
200
|
<?php foreach ($a_wol as $i => $wolent): ?>
|
201
|
<tr>
|
202
|
<td>
|
203
|
<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
|
204
|
</td>
|
205
|
<td>
|
206
|
<a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>" usepost><?=strtolower($wolent['mac']);?></a>
|
207
|
</td>
|
208
|
<td>
|
209
|
<?=htmlspecialchars($wolent['descr']);?>
|
210
|
</td>
|
211
|
<td>
|
212
|
<a class="fa fa-pencil" title="<?=gettext('Edit Device')?>" href="services_wol_edit.php?id=<?=$i?>"></a>
|
213
|
<a class="fa fa-trash" title="<?=gettext('Delete Device')?>" href="services_wol.php?act=del&id=<?=$i?>" usepost></a>
|
214
|
<a class="fa fa-power-off" title="<?=gettext('Wake Device')?>" href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>" usepost></a>
|
215
|
</td>
|
216
|
</tr>
|
217
|
<?php endforeach?>
|
218
|
</tbody>
|
219
|
</table>
|
220
|
</div>
|
221
|
</div>
|
222
|
<div class="panel-footer">
|
223
|
<a class="btn btn-success" href="services_wol_edit.php">
|
224
|
<i class="fa fa-plus icon-embed-btn"></i>
|
225
|
<?=gettext("Add");?>
|
226
|
</a>
|
227
|
|
228
|
<a href="services_wol.php?wakeall=true" role="button" class="btn btn-primary">
|
229
|
<i class="fa fa-power-off icon-embed-btn"></i>
|
230
|
<?=gettext("Wake All Devices")?>
|
231
|
</a>
|
232
|
</div>
|
233
|
</div>
|
234
|
|
235
|
<?php
|
236
|
|
237
|
include("foot.inc");
|