Project

General

Profile

Download (8.96 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 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 8acfca38 stompro
		$bcip = gen_subnet_max(get_interface_ip($if),
58 a55e9c70 Ermal Lu?i
			get_interface_subnet($if));
59 1b197e55 stompro
		/* Execute wol command and check return code. */
60
		if(!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")){
61
			$savemsg .= "Sent magic packet to {$mac} ({$description}).<br>";
62
		}
63
		else {
64
			$savemsg .= "Please check the <a href=\"/diag_logs.php\">system log</a>, the wol command for {$description} ({$mac}) did not complete successfully.<br>";
65
		}
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
		$input_errors[] = "A valid MAC address must be specified.";
87
	if (!$if)
88
		$input_errors[] = "A valid interface must be specified.";
89
90 f0fe3d30 Scott Ullrich
	if (!$input_errors) {
91 5b237745 Scott Ullrich
		/* determine broadcast address */
92 a55e9c70 Ermal Lu?i
		$bcip = gen_subnet_max(get_interface_ip($if),
93
			get_interface_subnet($if));
94 1b197e55 stompro
		/* Execute wol command and check return code. */
95
		if(!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")){
96
			$savemsg .= "Sent magic packet to {$mac}.";
97
		}
98
		else {
99
			$savemsg .= "Please check the <a href=\"/diag_logs.php\">system log</a>, the wol command for {$mac} did not complete successfully.<br>";
100
		}
101 5b237745 Scott Ullrich
	}
102
}
103
104
if ($_GET['act'] == "del") {
105
	if ($a_wol[$_GET['id']]) {
106
		unset($a_wol[$_GET['id']]);
107
		write_config();
108
		header("Location: services_wol.php");
109
		exit;
110
	}
111
}
112 4df96eff Scott Ullrich
113 d88c6a9f Scott Ullrich
$pgtitle = array("Services","Wake on LAN");
114 4df96eff Scott Ullrich
include("head.inc");
115
116 5b237745 Scott Ullrich
?>
117
118
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
119
<?php include("fbegin.inc"); ?>
120
<?php if ($input_errors) print_input_errors($input_errors); ?>
121
<?php if ($savemsg) print_info_box($savemsg); ?>
122
			<form action="services_wol.php" method="post" name="iform" id="iform">
123
			  <table width="100%" border="0" cellpadding="6" cellspacing="0">
124 7f1b26bc Scott Ullrich
			<tr>
125
				<td colspan="2" valign="top" class="listtopic">Wake on LAN</td>
126
			</tr>
127 f0fe3d30 Scott Ullrich
			  <tr>
128 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
129
                  <td width="78%" class="vtable">
130 e47499d5 Scott Ullrich
		     		<select name="interface" class="formselect">
131
                      <?php 
132 3e321df2 Ermal Luçi
						$interfaces = get_configured_interface_with_descr();
133 e47499d5 Scott Ullrich
					  	foreach ($interfaces as $iface => $ifacename): ?>
134 7ec05d27 Ermal Luçi
                      	<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $if) echo "selected"; ?>>
135 5b237745 Scott Ullrich
                      <?=htmlspecialchars($ifacename);?>
136
                      </option>
137
                      <?php endforeach; ?>
138
                    </select> <br>
139
                    <span class="vexpl">Choose which interface the host to be woken up is connected to.</span></td>
140
                </tr>
141
                <tr>
142
				  <td width="22%" valign="top" class="vncellreq">MAC address</td>
143
				  <td width="78%" class="vtable">
144 b5c78501 Seth Mos
                      <input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($mac);?>">
145 5b237745 Scott Ullrich
                      <br>
146
                      Enter a MAC address <span class="vexpl"> in the following format: xx:xx:xx:xx:xx:xx</span></td></tr>
147
				<tr>
148
				  <td width="22%" valign="top">&nbsp;</td>
149 f0fe3d30 Scott Ullrich
				  <td width="78%">
150 5b237745 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Send">
151
				</td>
152
				</tr>
153
			</table>
154 1d333258 Scott Ullrich
			&nbsp;<br>
155
			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/>
156
			Or Click the MAC address to wake up an individual device:
157
			<table width="100%" border="0" cellpadding="0" cellspacing="0">
158 5b237745 Scott Ullrich
                <tr>
159
                  <td width="15%" class="listhdrr">Interface</td>
160
                  <td width="25%" class="listhdrr">MAC address</td>
161
                  <td width="50%" class="listhdr">Description</td>
162 d415d821 Seth Mos
                  <td width="10%" class="list">
163
                    <table border="0" cellspacing="0" cellpadding="1">
164
                      <tr>
165
			<td valign="middle" width="17"></td>
166
                        <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>
167
                      </tr>
168
                    </table>
169
		  </td>
170
		</tr>
171 5b237745 Scott Ullrich
			  <?php $i = 0; foreach ($a_wol as $wolent): ?>
172
                <tr>
173 5f9c0e68 Bill Marquette
                  <td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
174 5b237745 Scott Ullrich
                    <?php if ($wolent['interface'] == "lan")
175
							   echo "LAN";
176
						   else
177
						       echo $config['interfaces'][$wolent['interface']]['descr'];
178
					?>&nbsp;
179
                  </td>
180 5f9c0e68 Bill Marquette
                  <td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
181 5b237745 Scott Ullrich
                    <a href="?mac=<?=$wolent['mac'];?>&if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>&nbsp;
182
                  </td>
183 5f9c0e68 Bill Marquette
                  <td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
184 d4da6249 Scott Ullrich
                    <?=htmlspecialchars($wolent['descr']);?>&nbsp;
185 5b237745 Scott Ullrich
                  </td>
186 2d4a7bb1 Bill Marquette
                  <td valign="middle" nowrap class="list">
187
                    <table border="0" cellspacing="0" cellpadding="1">
188
                      <tr>
189 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>
190
                        <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>
191 2d4a7bb1 Bill Marquette
                      </tr>
192
                    </table>
193
                  </td>
194 1d333258 Scott Ullrich
			</tr>
195 2d4a7bb1 Bill Marquette
	        <?php $i++; endforeach; ?>
196 f0fe3d30 Scott Ullrich
                <tr>
197 5b237745 Scott Ullrich
                  <td class="list" colspan="3"></td>
198 2d4a7bb1 Bill Marquette
                  <td class="list">
199
                    <table border="0" cellspacing="0" cellpadding="1">
200
                      <tr>
201 d415d821 Seth Mos
			<td valign="middle" width="17"></td>
202
                        <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>
203 2d4a7bb1 Bill Marquette
                      </tr>
204
                    </table>
205
                  </td>
206 474d1649 Holger Bauer
                  			
207 1d333258 Scott Ullrich
			</tr>
208 5b237745 Scott Ullrich
              </table>
209 7f1b26bc Scott Ullrich
			<span class="vexpl">
210
					<span class="red">
211
						<strong>
212
							Note:<br>
213
            			</strong>
214
					</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). 
215
			</span>
216
217 5b237745 Scott Ullrich
</form>
218
<?php include("fend.inc"); ?>
219
</body>
220
</html>