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