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 |
|
|
|
32 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
33 |
|
|
##|*IDENT=page-services-wakeonlan
|
34 |
|
|
##|*NAME=Services: Wake on LAN page
|
35 |
|
|
##|*DESCR=Allow access to the 'Services: Wake on LAN' page.
|
36 |
|
|
##|*MATCH=services_wol.php*
|
37 |
|
|
##|-PRIV
|
38 |
|
|
|
39 |
|
|
|
40 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
41 |
|
|
|
42 |
|
|
if (!is_array($config['wol']['wolentry'])) {
|
43 |
|
|
$config['wol']['wolentry'] = array();
|
44 |
|
|
}
|
45 |
|
|
wol_sort();
|
46 |
|
|
$a_wol = &$config['wol']['wolentry'];
|
47 |
|
|
|
48 |
4751361d
|
Scott Ullrich
|
if($_GET['wakeall'] <> "") {
|
49 |
|
|
$i = 0;
|
50 |
|
|
$savemsg = "";
|
51 |
|
|
foreach ($a_wol as $wolent) {
|
52 |
|
|
$mac = $wolent['mac'];
|
53 |
|
|
$if = $wolent['interface'];
|
54 |
|
|
$bcip = gen_subnet_max($config['interfaces'][$if]['ipaddr'],
|
55 |
|
|
$config['interfaces'][$if]['subnet']);
|
56 |
|
|
mwexec("/usr/local/bin/wol -i {$bcip} {$mac}");
|
57 |
|
|
$savemsg .= "Sent magic packet to {$mac}.<br>";
|
58 |
|
|
}
|
59 |
|
|
}
|
60 |
|
|
|
61 |
5b237745
|
Scott Ullrich
|
if ($_POST || $_GET['mac']) {
|
62 |
|
|
unset($input_errors);
|
63 |
f0fe3d30
|
Scott Ullrich
|
|
64 |
5b237745
|
Scott Ullrich
|
if ($_GET['mac']) {
|
65 |
4f3401e0
|
Bill Marquette
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
66 |
|
|
$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
|
67 |
5b237745
|
Scott Ullrich
|
$mac = $_GET['mac'];
|
68 |
|
|
$if = $_GET['if'];
|
69 |
|
|
} else {
|
70 |
4f3401e0
|
Bill Marquette
|
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
|
71 |
|
|
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
|
72 |
|
|
$mac = $_POST['mac'];
|
73 |
5b237745
|
Scott Ullrich
|
$if = $_POST['interface'];
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/* input validation */
|
77 |
|
|
if (!$mac || !is_macaddr($mac))
|
78 |
|
|
$input_errors[] = "A valid MAC address must be specified.";
|
79 |
|
|
if (!$if)
|
80 |
|
|
$input_errors[] = "A valid interface must be specified.";
|
81 |
|
|
|
82 |
f0fe3d30
|
Scott Ullrich
|
if (!$input_errors) {
|
83 |
5b237745
|
Scott Ullrich
|
/* determine broadcast address */
|
84 |
|
|
$bcip = gen_subnet_max($config['interfaces'][$if]['ipaddr'],
|
85 |
|
|
$config['interfaces'][$if]['subnet']);
|
86 |
f0fe3d30
|
Scott Ullrich
|
|
87 |
5b237745
|
Scott Ullrich
|
mwexec("/usr/local/bin/wol -i {$bcip} {$mac}");
|
88 |
|
|
$savemsg = "Sent magic packet to {$mac}.";
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
if ($_GET['act'] == "del") {
|
93 |
|
|
if ($a_wol[$_GET['id']]) {
|
94 |
|
|
unset($a_wol[$_GET['id']]);
|
95 |
|
|
write_config();
|
96 |
|
|
header("Location: services_wol.php");
|
97 |
|
|
exit;
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
4df96eff
|
Scott Ullrich
|
|
101 |
d88c6a9f
|
Scott Ullrich
|
$pgtitle = array("Services","Wake on LAN");
|
102 |
4df96eff
|
Scott Ullrich
|
include("head.inc");
|
103 |
|
|
|
104 |
5b237745
|
Scott Ullrich
|
?>
|
105 |
|
|
|
106 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
107 |
|
|
<?php include("fbegin.inc"); ?>
|
108 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
109 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
110 |
|
|
<form action="services_wol.php" method="post" name="iform" id="iform">
|
111 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
112 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
113 |
5b237745
|
Scott Ullrich
|
<td width="22%" valign="top" class="vncellreq">Interface</td>
|
114 |
|
|
<td width="78%" class="vtable">
|
115 |
e47499d5
|
Scott Ullrich
|
<select name="interface" class="formselect">
|
116 |
|
|
<?php
|
117 |
3e321df2
|
Ermal Luçi
|
$interfaces = get_configured_interface_with_descr();
|
118 |
e47499d5
|
Scott Ullrich
|
foreach ($interfaces as $iface => $ifacename): ?>
|
119 |
3e321df2
|
Ermal Luçi
|
<option value="<?=$iface;?>" <?php if (!$config['interfaces'][$iface]['bridge'] && $iface == $if) echo "selected"; ?>>
|
120 |
5b237745
|
Scott Ullrich
|
<?=htmlspecialchars($ifacename);?>
|
121 |
|
|
</option>
|
122 |
|
|
<?php endforeach; ?>
|
123 |
|
|
</select> <br>
|
124 |
|
|
<span class="vexpl">Choose which interface the host to be woken up is connected to.</span></td>
|
125 |
|
|
</tr>
|
126 |
|
|
<tr>
|
127 |
|
|
<td width="22%" valign="top" class="vncellreq">MAC address</td>
|
128 |
|
|
<td width="78%" class="vtable">
|
129 |
b5c78501
|
Seth Mos
|
<input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($mac);?>">
|
130 |
5b237745
|
Scott Ullrich
|
<br>
|
131 |
|
|
Enter a MAC address <span class="vexpl"> in the following format: xx:xx:xx:xx:xx:xx</span></td></tr>
|
132 |
|
|
<tr>
|
133 |
|
|
<td width="22%" valign="top"> </td>
|
134 |
f0fe3d30
|
Scott Ullrich
|
<td width="78%">
|
135 |
5b237745
|
Scott Ullrich
|
<input name="Submit" type="submit" class="formbtn" value="Send">
|
136 |
|
|
</td>
|
137 |
|
|
</tr>
|
138 |
|
|
</table>
|
139 |
|
|
<span class="vexpl"><span class="red"><strong>Note:<br>
|
140 |
|
|
</strong></span>This service can be used to wake up (power on) computers by sending special "Magic Packets". 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). </span><br>
|
141 |
f0fe3d30
|
Scott Ullrich
|
<br>
|
142 |
5b237745
|
Scott Ullrich
|
You may store MAC addresses below for your convenience.
|
143 |
|
|
Click the MAC address to wake up a computer. <br>
|
144 |
474d1649
|
Holger Bauer
|
<br>
|
145 |
|
|
You also can 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><br>
|
146 |
|
|
<br>
|
147 |
5b237745
|
Scott Ullrich
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
148 |
|
|
<tr>
|
149 |
|
|
<td width="15%" class="listhdrr">Interface</td>
|
150 |
|
|
<td width="25%" class="listhdrr">MAC address</td>
|
151 |
|
|
<td width="50%" class="listhdr">Description</td>
|
152 |
d415d821
|
Seth Mos
|
<td width="10%" class="list">
|
153 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
154 |
|
|
<tr>
|
155 |
|
|
<td valign="middle" width="17"></td>
|
156 |
|
|
<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>
|
157 |
|
|
</tr>
|
158 |
|
|
</table>
|
159 |
|
|
</td>
|
160 |
|
|
</tr>
|
161 |
5b237745
|
Scott Ullrich
|
<?php $i = 0; foreach ($a_wol as $wolent): ?>
|
162 |
|
|
<tr>
|
163 |
5f9c0e68
|
Bill Marquette
|
<td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
164 |
5b237745
|
Scott Ullrich
|
<?php if ($wolent['interface'] == "lan")
|
165 |
|
|
echo "LAN";
|
166 |
|
|
else
|
167 |
|
|
echo $config['interfaces'][$wolent['interface']]['descr'];
|
168 |
|
|
?>
|
169 |
|
|
</td>
|
170 |
5f9c0e68
|
Bill Marquette
|
<td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
171 |
5b237745
|
Scott Ullrich
|
<a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
|
172 |
|
|
</td>
|
173 |
5f9c0e68
|
Bill Marquette
|
<td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
|
174 |
f0fe3d30
|
Scott Ullrich
|
<font color="#FFFFFF"><?=htmlspecialchars($wolent['descr']);?>
|
175 |
5b237745
|
Scott Ullrich
|
</td>
|
176 |
2d4a7bb1
|
Bill Marquette
|
<td valign="middle" nowrap class="list">
|
177 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
178 |
|
|
<tr>
|
179 |
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>
|
180 |
|
|
<td valign="middle"><a href="services_wol.php?act=del&id=<?=$i;?>" onclick="return confirm('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>
|
181 |
2d4a7bb1
|
Bill Marquette
|
</tr>
|
182 |
|
|
</table>
|
183 |
|
|
</td>
|
184 |
|
|
</tr>
|
185 |
|
|
<?php $i++; endforeach; ?>
|
186 |
f0fe3d30
|
Scott Ullrich
|
<tr>
|
187 |
5b237745
|
Scott Ullrich
|
<td class="list" colspan="3"></td>
|
188 |
2d4a7bb1
|
Bill Marquette
|
<td class="list">
|
189 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
190 |
|
|
<tr>
|
191 |
d415d821
|
Seth Mos
|
<td valign="middle" width="17"></td>
|
192 |
|
|
<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>
|
193 |
2d4a7bb1
|
Bill Marquette
|
</tr>
|
194 |
|
|
</table>
|
195 |
|
|
</td>
|
196 |
474d1649
|
Holger Bauer
|
|
197 |
2d4a7bb1
|
Bill Marquette
|
</tr>
|
198 |
5b237745
|
Scott Ullrich
|
</table>
|
199 |
|
|
</form>
|
200 |
|
|
<?php include("fend.inc"); ?>
|
201 |
|
|
</body>
|
202 |
|
|
</html>
|