Project

General

Profile

Download (8.13 KB) Statistics
| Branch: | Tag: | Revision:
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
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 4751361d Scott Ullrich
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 5b237745 Scott Ullrich
if ($_POST || $_GET['mac']) {
54
	unset($input_errors);
55 f0fe3d30 Scott Ullrich
56 5b237745 Scott Ullrich
	if ($_GET['mac']) {
57 4f3401e0 Bill Marquette
        	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
58
        	$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
59 5b237745 Scott Ullrich
		$mac = $_GET['mac'];
60
		$if = $_GET['if'];
61
	} else {
62 4f3401e0 Bill Marquette
        	/* 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 5b237745 Scott Ullrich
		$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 f0fe3d30 Scott Ullrich
	if (!$input_errors) {
75 5b237745 Scott Ullrich
		/* determine broadcast address */
76
		$bcip = gen_subnet_max($config['interfaces'][$if]['ipaddr'],
77
			$config['interfaces'][$if]['subnet']);
78 f0fe3d30 Scott Ullrich
79 5b237745 Scott Ullrich
		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 4df96eff Scott Ullrich
93
$pgtitle = "Services: Wake on LAN";
94
include("head.inc");
95
96 5b237745 Scott Ullrich
?>
97
98
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
99
<?php include("fbegin.inc"); ?>
100 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
101 5b237745 Scott Ullrich
<?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 f0fe3d30 Scott Ullrich
			  <tr>
106 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
107
                  <td width="78%" class="vtable">
108 25d3fbd5 Scott Ullrich
		     <select name="interface" class="formfld">
109 5b237745 Scott Ullrich
                      <?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 f0fe3d30 Scott Ullrich
                      <option value="<?=$iface;?>" <?php if ($iface == $if) echo "selected"; ?>>
117 5b237745 Scott Ullrich
                      <?=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 4f3401e0 Bill Marquette
                      <input name="mac" type="text" class="formfld" id="mac" size="20" value="<?=htmlspecialchars($mac);?>">
127 5b237745 Scott Ullrich
                      <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">&nbsp;</td>
131 f0fe3d30 Scott Ullrich
				  <td width="78%">
132 5b237745 Scott Ullrich
                    <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 &quot;Magic Packets&quot;. 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 f0fe3d30 Scott Ullrich
                      <br>
139 5b237745 Scott Ullrich
                      You may store MAC addresses below for your convenience.
140
Click the MAC address to wake up a computer. <br>
141 474d1649 Holger Bauer
&nbsp;<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
&nbsp;<br>
144 5b237745 Scott Ullrich
<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"></td>
150
				</tr>
151
			  <?php $i = 0; foreach ($a_wol as $wolent): ?>
152
                <tr>
153 5f9c0e68 Bill Marquette
                  <td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
154 5b237745 Scott Ullrich
                    <?php if ($wolent['interface'] == "lan")
155
							   echo "LAN";
156
						   else
157
						       echo $config['interfaces'][$wolent['interface']]['descr'];
158
					?>&nbsp;
159
                  </td>
160 5f9c0e68 Bill Marquette
                  <td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
161 5b237745 Scott Ullrich
                    <a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>&nbsp;
162
                  </td>
163 5f9c0e68 Bill Marquette
                  <td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
164 f0fe3d30 Scott Ullrich
                    <font color="#FFFFFF"><?=htmlspecialchars($wolent['descr']);?>&nbsp;
165 5b237745 Scott Ullrich
                  </td>
166 2d4a7bb1 Bill Marquette
                  <td valign="middle" nowrap class="list">
167
                    <table border="0" cellspacing="0" cellpadding="1">
168
                      <tr>
169 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>
170
                        <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>
171 2d4a7bb1 Bill Marquette
                      </tr>
172
                    </table>
173
                  </td>
174
		</tr>
175
	        <?php $i++; endforeach; ?>
176 f0fe3d30 Scott Ullrich
                <tr>
177 5b237745 Scott Ullrich
                  <td class="list" colspan="3"></td>
178 2d4a7bb1 Bill Marquette
                  <td class="list">
179
                    <table border="0" cellspacing="0" cellpadding="1">
180
                      <tr>
181 b7028110 Scott Ullrich
                        <td valign="middle">
182
				<a href="services_wol_edit.php"><img src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a>
183 474d1649 Holger Bauer
				
184 b7028110 Scott Ullrich
			</td>
185 474d1649 Holger Bauer
186 2d4a7bb1 Bill Marquette
                      </tr>
187
                    </table>
188
                  </td>
189 474d1649 Holger Bauer
                  			
190 2d4a7bb1 Bill Marquette
		</tr>
191 5b237745 Scott Ullrich
              </table>
192
</form>
193
<?php include("fend.inc"); ?>
194
</body>
195
</html>