1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
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 |
1d333258
|
Scott Ullrich
|
/*
|
32 |
|
|
pfSense_BUILDER_BINARIES: /usr/local/bin/wol
|
33 |
|
|
pfSense_MODULE: wol
|
34 |
|
|
*/
|
35 |
5b237745
|
Scott Ullrich
|
|
36 |
6b07c15a
|
Matthew Grooms
|
##|+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 |
5b237745
|
Scott Ullrich
|
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 |
4751361d
|
Scott Ullrich
|
if($_GET['wakeall'] <> "") {
|
51 |
|
|
$i = 0;
|
52 |
|
|
$savemsg = "";
|
53 |
|
|
foreach ($a_wol as $wolent) {
|
54 |
|
|
$mac = $wolent['mac'];
|
55 |
|
|
$if = $wolent['interface'];
|
56 |
1b197e55
|
stompro
|
$description = $wolent['descr'];
|
57 |
2bf16ba2
|
Ermal
|
$ipaddr = get_interface_ip($if);
|
58 |
|
|
if (!is_ipaddr($ipaddr))
|
59 |
|
|
continue;
|
60 |
|
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
61 |
1b197e55
|
stompro
|
/* Execute wol command and check return code. */
|
62 |
2bf16ba2
|
Ermal
|
if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}"))
|
63 |
ddc55e12
|
Erik Fonnesbeck
|
$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'),$mac, $description, ".<br>");
|
64 |
2bf16ba2
|
Ermal
|
else
|
65 |
f5abb47d
|
Erik Fonnesbeck
|
$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 |
4751361d
|
Scott Ullrich
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
5b237745
|
Scott Ullrich
|
if ($_POST || $_GET['mac']) {
|
70 |
|
|
unset($input_errors);
|
71 |
f0fe3d30
|
Scott Ullrich
|
|
72 |
5b237745
|
Scott Ullrich
|
if ($_GET['mac']) {
|
73 |
4f3401e0
|
Bill Marquette
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
74 |
|
|
$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
|
75 |
5b237745
|
Scott Ullrich
|
$mac = $_GET['mac'];
|
76 |
|
|
$if = $_GET['if'];
|
77 |
|
|
} else {
|
78 |
4f3401e0
|
Bill Marquette
|
/* 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 |
5b237745
|
Scott Ullrich
|
$if = $_POST['interface'];
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
/* input validation */
|
85 |
|
|
if (!$mac || !is_macaddr($mac))
|
86 |
d58dbf67
|
Rafael Lucas
|
$input_errors[] = gettext("A valid MAC address must be specified.");
|
87 |
5b237745
|
Scott Ullrich
|
if (!$if)
|
88 |
d58dbf67
|
Rafael Lucas
|
$input_errors[] = gettext("A valid interface must be specified.");
|
89 |
5b237745
|
Scott Ullrich
|
|
90 |
f0fe3d30
|
Scott Ullrich
|
if (!$input_errors) {
|
91 |
5b237745
|
Scott Ullrich
|
/* determine broadcast address */
|
92 |
2bf16ba2
|
Ermal
|
$ipaddr = get_interface_ip($if);
|
93 |
|
|
if (!is_ipaddr($ipaddr))
|
94 |
|
|
$input_errors[] = gettext("A valid ip could not be found!");
|
95 |
1b197e55
|
stompro
|
else {
|
96 |
2bf16ba2
|
Ermal
|
$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
|
97 |
|
|
/* Execute wol command and check return code. */
|
98 |
d31ca336
|
Renato Botelho
|
if(!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac)))
|
99 |
2bf16ba2
|
Ermal
|
$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 |
1b197e55
|
stompro
|
}
|
103 |
5b237745
|
Scott Ullrich
|
}
|
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 |
4df96eff
|
Scott Ullrich
|
|
115 |
d58dbf67
|
Rafael Lucas
|
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"));
|
116 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
117 |
|
|
|
118 |
5b237745
|
Scott Ullrich
|
?>
|
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">
|
126 |
7f1b26bc
|
Scott Ullrich
|
<tr>
|
127 |
d58dbf67
|
Rafael Lucas
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Wake on LAN");?></td>
|
128 |
7f1b26bc
|
Scott Ullrich
|
</tr>
|
129 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
130 |
d58dbf67
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
|
131 |
5b237745
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
132 |
e47499d5
|
Scott Ullrich
|
<select name="interface" class="formselect">
|
133 |
|
|
<?php
|
134 |
3e321df2
|
Ermal Luçi
|
$interfaces = get_configured_interface_with_descr();
|
135 |
e47499d5
|
Scott Ullrich
|
foreach ($interfaces as $iface => $ifacename): ?>
|
136 |
7ec05d27
|
Ermal Luçi
|
<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $if) echo "selected"; ?>>
|
137 |
5b237745
|
Scott Ullrich
|
<?=htmlspecialchars($ifacename);?>
|
138 |
|
|
</option>
|
139 |
|
|
<?php endforeach; ?>
|
140 |
|
|
</select> <br>
|
141 |
d58dbf67
|
Rafael Lucas
|
<span class="vexpl"><?=gettext("Choose which interface the host to be woken up is connected to.");?></span></td>
|
142 |
5b237745
|
Scott Ullrich
|
</tr>
|
143 |
|
|
<tr>
|
144 |
d58dbf67
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
|
145 |
5b237745
|
Scott Ullrich
|
<td width="78%" class="vtable">
|
146 |
b5c78501
|
Seth Mos
|
<input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($mac);?>">
|
147 |
5b237745
|
Scott Ullrich
|
<br>
|
148 |
42256271
|
Carlos Eduardo Ramos
|
<?=gettext("Enter a MAC address ");?><span class="vexpl"> <?=gettext("in the following format: xx:xx:xx:xx:xx:xx");?></span></td></tr>
|
149 |
5b237745
|
Scott Ullrich
|
<tr>
|
150 |
|
|
<td width="22%" valign="top"> </td>
|
151 |
f0fe3d30
|
Scott Ullrich
|
<td width="78%">
|
152 |
d58dbf67
|
Rafael Lucas
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Send");?>">
|
153 |
5b237745
|
Scott Ullrich
|
</td>
|
154 |
|
|
</tr>
|
155 |
|
|
</table>
|
156 |
1d333258
|
Scott Ullrich
|
<br>
|
157 |
d58dbf67
|
Rafael Lucas
|
<?=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"></a><p/>
|
158 |
|
|
<?=gettext("Or Click the MAC address to wake up an individual device:");?>
|
159 |
17d5077f
|
Evgeny Yurchenko
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont">
|
160 |
5b237745
|
Scott Ullrich
|
<tr>
|
161 |
d58dbf67
|
Rafael Lucas
|
<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 |
d415d821
|
Seth Mos
|
<td width="10%" class="list">
|
165 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
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"></a></td>
|
169 |
|
|
</tr>
|
170 |
|
|
</table>
|
171 |
|
|
</td>
|
172 |
|
|
</tr>
|
173 |
5b237745
|
Scott Ullrich
|
<?php $i = 0; foreach ($a_wol as $wolent): ?>
|
174 |
|
|
<tr>
|
175 |
5f9c0e68
|
Bill Marquette
|
<td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
176 |
ae92e820
|
Charlie Marshall
|
<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
|
177 |
5b237745
|
Scott Ullrich
|
</td>
|
178 |
5f9c0e68
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
179 |
ae92e820
|
Charlie Marshall
|
<a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
|
180 |
5b237745
|
Scott Ullrich
|
</td>
|
181 |
5f9c0e68
|
Bill Marquette
|
<td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
182 |
ae92e820
|
Charlie Marshall
|
<?=htmlspecialchars($wolent['descr']);?>
|
183 |
5b237745
|
Scott Ullrich
|
</td>
|
184 |
2d4a7bb1
|
Bill Marquette
|
<td valign="middle" nowrap class="list">
|
185 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
186 |
|
|
<tr>
|
187 |
677c0869
|
Erik Kristensen
|
<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"></a></td>
|
188 |
d58dbf67
|
Rafael Lucas
|
<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"></a></td>
|
189 |
2d4a7bb1
|
Bill Marquette
|
</tr>
|
190 |
|
|
</table>
|
191 |
|
|
</td>
|
192 |
1d333258
|
Scott Ullrich
|
</tr>
|
193 |
2d4a7bb1
|
Bill Marquette
|
<?php $i++; endforeach; ?>
|
194 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
195 |
5b237745
|
Scott Ullrich
|
<td class="list" colspan="3"></td>
|
196 |
2d4a7bb1
|
Bill Marquette
|
<td class="list">
|
197 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
198 |
|
|
<tr>
|
199 |
d415d821
|
Seth Mos
|
<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"></a></td>
|
201 |
2d4a7bb1
|
Bill Marquette
|
</tr>
|
202 |
|
|
</table>
|
203 |
|
|
</td>
|
204 |
474d1649
|
Holger Bauer
|
|
205 |
1d333258
|
Scott Ullrich
|
</tr>
|
206 |
5b237745
|
Scott Ullrich
|
</table>
|
207 |
7f1b26bc
|
Scott Ullrich
|
<span class="vexpl">
|
208 |
|
|
<span class="red">
|
209 |
|
|
<strong>
|
210 |
16457bdd
|
Renato Botelho
|
<?=gettext("Note:");?><br>
|
211 |
7f1b26bc
|
Scott Ullrich
|
</strong>
|
212 |
42256271
|
Carlos Eduardo Ramos
|
</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 |
7f1b26bc
|
Scott Ullrich
|
</span>
|
214 |
|
|
|
215 |
5b237745
|
Scott Ullrich
|
</form>
|
216 |
|
|
<?php include("fend.inc"); ?>
|
217 |
|
|
</body>
|
218 |
|
|
</html>
|