1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
services_wol.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
/*
|
32
|
pfSense_BUILDER_BINARIES: /usr/local/bin/wol
|
33
|
pfSense_MODULE: wol
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-services-wakeonlan
|
38
|
##|*NAME=Services: Wake on LAN page
|
39
|
##|*DESCR=Allow access to the 'Services: Wake on LAN' page.
|
40
|
##|*MATCH=services_wol.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
require("guiconfig.inc");
|
44
|
|
45
|
if (!is_array($config['wol']['wolentry'])) {
|
46
|
$config['wol']['wolentry'] = array();
|
47
|
}
|
48
|
$a_wol = &$config['wol']['wolentry'];
|
49
|
|
50
|
if($_GET['wakeall'] <> "") {
|
51
|
$i = 0;
|
52
|
$savemsg = "";
|
53
|
foreach ($a_wol as $wolent) {
|
54
|
$mac = $wolent['mac'];
|
55
|
$if = $wolent['interface'];
|
56
|
$description = $wolent['descr'];
|
57
|
$ipaddr = get_interface_ip($if);
|
58
|
if (!is_ipaddr($ipaddr))
|
59
|
continue;
|
60
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
61
|
/* Execute wol command and check return code. */
|
62
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}"))
|
63
|
$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'),$mac, $description, ".<br />");
|
64
|
else
|
65
|
$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 />");
|
66
|
}
|
67
|
}
|
68
|
|
69
|
if ($_POST || $_GET['mac']) {
|
70
|
unset($input_errors);
|
71
|
|
72
|
if ($_GET['mac']) {
|
73
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
74
|
$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
|
75
|
$mac = $_GET['mac'];
|
76
|
$if = $_GET['if'];
|
77
|
} else {
|
78
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
79
|
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
|
80
|
$mac = $_POST['mac'];
|
81
|
$if = $_POST['interface'];
|
82
|
}
|
83
|
|
84
|
/* input validation */
|
85
|
if (!$mac || !is_macaddr($mac))
|
86
|
$input_errors[] = gettext("A valid MAC address must be specified.");
|
87
|
if (!$if)
|
88
|
$input_errors[] = gettext("A valid interface must be specified.");
|
89
|
|
90
|
if (!$input_errors) {
|
91
|
/* determine broadcast address */
|
92
|
$ipaddr = get_interface_ip($if);
|
93
|
if (!is_ipaddr($ipaddr))
|
94
|
$input_errors[] = gettext("A valid ip could not be found!");
|
95
|
else {
|
96
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
97
|
/* Execute wol command and check return code. */
|
98
|
if(!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac)))
|
99
|
$savemsg .= sprintf(gettext("Sent magic packet to %s."),$mac);
|
100
|
else
|
101
|
$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 />");
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
|
106
|
if ($_GET['act'] == "del") {
|
107
|
if ($a_wol[$_GET['id']]) {
|
108
|
unset($a_wol[$_GET['id']]);
|
109
|
write_config();
|
110
|
header("Location: services_wol.php");
|
111
|
exit;
|
112
|
}
|
113
|
}
|
114
|
|
115
|
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"));
|
116
|
include("head.inc");
|
117
|
|
118
|
?>
|
119
|
|
120
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
121
|
<?php include("fbegin.inc"); ?>
|
122
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
123
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
124
|
<form action="services_wol.php" method="post" name="iform" id="iform">
|
125
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="wake on lan">
|
126
|
<tr>
|
127
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Wake on LAN");?></td>
|
128
|
</tr>
|
129
|
<tr>
|
130
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
|
131
|
<td width="78%" class="vtable">
|
132
|
<select name="interface" class="formselect">
|
133
|
<?php
|
134
|
$interfaces = get_configured_interface_with_descr();
|
135
|
foreach ($interfaces as $iface => $ifacename): ?>
|
136
|
<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $if) echo "selected=\"selected\""; ?>>
|
137
|
<?=htmlspecialchars($ifacename);?>
|
138
|
</option>
|
139
|
<?php endforeach; ?>
|
140
|
</select> <br />
|
141
|
<span class="vexpl"><?=gettext("Choose which interface the host to be woken up is connected to.");?></span></td>
|
142
|
</tr>
|
143
|
<tr>
|
144
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
|
145
|
<td width="78%" class="vtable">
|
146
|
<input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($mac);?>" />
|
147
|
<br />
|
148
|
<?=gettext("Enter a MAC address ");?><span class="vexpl"> <?=gettext("in the following format: xx:xx:xx:xx:xx:xx");?></span></td></tr>
|
149
|
<tr>
|
150
|
<td width="22%" valign="top"> </td>
|
151
|
<td width="78%">
|
152
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Send");?>" />
|
153
|
</td>
|
154
|
</tr>
|
155
|
</table>
|
156
|
<br />
|
157
|
<?=gettext("Wake all clients at once: ");?><a href="services_wol.php?wakeall=true"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_wol_all.gif" width="17" height="17" border="0" alt="wol all" /></a><br/>
|
158
|
<?=gettext("Or Click the MAC address to wake up an individual device:");?>
|
159
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont" summary="clients">
|
160
|
<tr>
|
161
|
<td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
|
162
|
<td width="25%" class="listhdrr"><?=gettext("MAC address");?></td>
|
163
|
<td width="50%" class="listhdr"><?=gettext("Description");?></td>
|
164
|
<td width="10%" class="list">
|
165
|
<table border="0" cellspacing="0" cellpadding="1" summary="add">
|
166
|
<tr>
|
167
|
<td valign="middle" width="17"></td>
|
168
|
<td valign="middle"><a href="services_wol_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
|
169
|
</tr>
|
170
|
</table>
|
171
|
</td>
|
172
|
</tr>
|
173
|
<?php $i = 0; foreach ($a_wol as $wolent): ?>
|
174
|
<tr>
|
175
|
<td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
176
|
<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
|
177
|
</td>
|
178
|
<td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
179
|
<a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
|
180
|
</td>
|
181
|
<td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
182
|
<?=htmlspecialchars($wolent['descr']);?>
|
183
|
</td>
|
184
|
<td valign="middle" class="list nowrap">
|
185
|
<table border="0" cellspacing="0" cellpadding="1" summary="icons">
|
186
|
<tr>
|
187
|
<td valign="middle"><a href="services_wol_edit.php?id=<?=$i;?>"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" alt="edit" /></a></td>
|
188
|
<td valign="middle"><a href="services_wol.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?");?>')"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" alt="delete" /></a></td>
|
189
|
</tr>
|
190
|
</table>
|
191
|
</td>
|
192
|
</tr>
|
193
|
<?php $i++; endforeach; ?>
|
194
|
<tr>
|
195
|
<td class="list" colspan="3"></td>
|
196
|
<td class="list">
|
197
|
<table border="0" cellspacing="0" cellpadding="1" summary="add">
|
198
|
<tr>
|
199
|
<td valign="middle" width="17"></td>
|
200
|
<td valign="middle"><a href="services_wol_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" alt="add" /></a></td>
|
201
|
</tr>
|
202
|
</table>
|
203
|
</td>
|
204
|
|
205
|
</tr>
|
206
|
</table>
|
207
|
<span class="vexpl">
|
208
|
<span class="red">
|
209
|
<strong>
|
210
|
<?=gettext("Note:");?><br />
|
211
|
</strong>
|
212
|
</span><?=gettext("This service can be used to wake up (power on) computers by sending special"); ?> "<?=gettext("Magic Packets"); ?>". <?=gettext("The NIC in the computer that is to be woken up must support Wake on LAN and has to be configured properly (WOL cable, BIOS settings). ");?>
|
213
|
</span>
|
214
|
|
215
|
</form>
|
216
|
<?php include("fend.inc"); ?>
|
217
|
</body>
|
218
|
</html>
|