Project

General

Profile

Download (8.86 KB) Statistics
| Branch: | Tag: | Revision:
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
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	notice, this list of conditions and the following disclaimer in the
19
	documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*
33
	pfSense_BUILDER_BINARIES:	/usr/local/bin/wol
34
	pfSense_MODULE:	wol
35
*/
36

    
37
##|+PRIV
38
##|*IDENT=page-services-wakeonlan
39
##|*NAME=Services: Wake on LAN page
40
##|*DESCR=Allow access to the 'Services: Wake on LAN' page.
41
##|*MATCH=services_wol.php*
42
##|-PRIV
43

    
44
require("guiconfig.inc");
45

    
46
if (!is_array($config['wol']['wolentry'])) {
47
	$config['wol']['wolentry'] = array();
48
}
49
$a_wol = &$config['wol']['wolentry'];
50

    
51
if ($_GET['wakeall'] <> "") {
52
	$i = 0;
53
	$savemsg = "";
54
	foreach ($a_wol as $wolent) {
55
		$mac = $wolent['mac'];
56
		$if = $wolent['interface'];
57
		$description = $wolent['descr'];
58
		$ipaddr = get_interface_ip($if);
59
		if (!is_ipaddr($ipaddr)) {
60
			continue;
61
		}
62
		$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
63
		/* Execute wol command and check return code. */
64
		if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")) {
65
			$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'), $mac, $description, ".<br />");
66
		} else {
67
			$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 />");
68
		}
69
	}
70
}
71

    
72
if ($_POST || $_GET['mac']) {
73
	unset($input_errors);
74

    
75
	if ($_GET['mac']) {
76
		/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
77
		$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
78
		$mac = $_GET['mac'];
79
		$if = $_GET['if'];
80
	} else {
81
		/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
82
		$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
83
		$mac = $_POST['mac'];
84
		$if = $_POST['interface'];
85
	}
86

    
87
	/* input validation */
88
	if (!$mac || !is_macaddr($mac)) {
89
		$input_errors[] = gettext("A valid MAC address must be specified.");
90
	}
91
	if (!$if) {
92
		$input_errors[] = gettext("A valid interface must be specified.");
93
	}
94

    
95
	if (!$input_errors) {
96
		/* determine broadcast address */
97
		$ipaddr = get_interface_ip($if);
98
		if (!is_ipaddr($ipaddr)) {
99
			$input_errors[] = gettext("A valid ip could not be found!");
100
		} else {
101
			$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
102
			/* Execute wol command and check return code. */
103
			if (!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac))) {
104
				$savemsg .= sprintf(gettext("Sent magic packet to %s."), $mac);
105
			} else {
106
				$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 />");
107
			}
108
		}
109
	}
110
}
111

    
112
if ($_GET['act'] == "del") {
113
	if ($a_wol[$_GET['id']]) {
114
		unset($a_wol[$_GET['id']]);
115
		write_config();
116
		header("Location: services_wol.php");
117
		exit;
118
	}
119
}
120

    
121
$pgtitle = array(gettext("Services"), gettext("Wake on LAN"));
122
include("head.inc");
123

    
124
?>
125

    
126
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
127
<?php include("fbegin.inc"); ?>
128
<?php if ($input_errors) print_input_errors($input_errors); ?>
129
<?php if ($savemsg) print_info_box($savemsg); ?>
130
<form action="services_wol.php" method="post" name="iform" id="iform">
131
	<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="wake on lan">
132
		<tr>
133
			<td colspan="2" valign="top" class="listtopic"><?=gettext("Wake on LAN");?></td>
134
		</tr>
135
		<tr>
136
			<td width="22%" valign="top" class="vncellreq"><?=gettext("Interface");?></td>
137
			<td width="78%" class="vtable">
138
				<select name="interface" class="formselect">
139
				<?php
140
					$interfaces = get_configured_interface_with_descr();
141
					foreach ($interfaces as $iface => $ifacename): ?>
142
					<option value="<?=$iface;?>" <?php if (!link_interface_to_bridge($iface) && $iface == $if) echo "selected=\"selected\""; ?>>
143
						<?=htmlspecialchars($ifacename);?>
144
					</option>
145
				<?php endforeach; ?>
146
				</select>
147
				<br />
148
				<span class="vexpl"><?=gettext("Choose which interface the host to be woken up is connected to.");?></span>
149
			</td>
150
		</tr>
151
		<tr>
152
			<td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
153
			<td width="78%" class="vtable">
154
				<input name="mac" type="text" class="formfld unknown" id="mac" size="20" value="<?=htmlspecialchars($mac);?>" />
155
				<br />
156
				<?=gettext("Enter a MAC address ");?><span class="vexpl"> <?=gettext("in the following format: xx:xx:xx:xx:xx:xx");?></span>
157
			</td>
158
		</tr>
159
		<tr>
160
			<td width="22%" valign="top">&nbsp;</td>
161
			<td width="78%">
162
				<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Send");?>" />
163
			</td>
164
		</tr>
165
	</table>
166
	&nbsp;<br />
167
	<?=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" alt="wol all" /></a><br/>
168
	<?=gettext("Or Click the MAC address to wake up an individual device:");?>
169
	<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tabcont" summary="clients">
170
		<tr>
171
			<td width="15%" class="listhdrr"><?=gettext("Interface");?></td>
172
			<td width="25%" class="listhdrr"><?=gettext("MAC address");?></td>
173
			<td width="50%" class="listhdr"><?=gettext("Description");?></td>
174
			<td width="10%" class="list">
175
				<table border="0" cellspacing="0" cellpadding="1" summary="add">
176
					<tr>
177
						<td valign="middle" width="17"></td>
178
						<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" alt="add" /></a></td>
179
					</tr>
180
				</table>
181
			</td>
182
		</tr>
183
<?php
184
	$i = 0;
185
	foreach ($a_wol as $wolent):
186
?>
187
		<tr>
188
			<td class="listlr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
189
				<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
190
			</td>
191
			<td class="listr" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
192
				<a href="?mac=<?=$wolent['mac'];?>&amp;if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
193
			</td>
194
			<td class="listbg" ondblclick="document.location='services_wol_edit.php?id=<?=$i;?>';">
195
				<?=htmlspecialchars($wolent['descr']);?>
196
			</td>
197
			<td valign="middle" class="list nowrap">
198
				<table border="0" cellspacing="0" cellpadding="1" summary="icons">
199
					<tr>
200
						<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" alt="edit" /></a></td>
201
						<td valign="middle"><a href="services_wol.php?act=del&amp;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" alt="delete" /></a></td>
202
					</tr>
203
				</table>
204
			</td>
205
		</tr>
206
<?php
207
		$i++;
208
	endforeach;
209
?>
210
		<tr>
211
			<td class="list" colspan="3"></td>
212
			<td class="list">
213
				<table border="0" cellspacing="0" cellpadding="1" summary="add">
214
					<tr>
215
						<td valign="middle" width="17"></td>
216
						<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" alt="add" /></a></td>
217
					</tr>
218
				</table>
219
			</td>
220
		</tr>
221
	</table>
222
	<span class="vexpl">
223
		<span class="red">
224
			<strong>
225
				<?=gettext("Note:");?><br />
226
			</strong>
227
		</span>
228
		<?=gettext("This service can be used to wake up (power on) computers by sending special"); ?> &quot;<?=gettext("Magic Packets"); ?>&quot;. <?=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). ");?>
229
	</span>
230
</form>
231
<?php include("fend.inc"); ?>
232
</body>
233
</html>
(171-171/252)