Project

General

Profile

Download (6.45 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 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9 5b237745 Scott Ullrich
	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 1d333258 Scott Ullrich
/*
33 bc3fa9f1 Peter Bouwdewijn
	pfSense_BUILDER_BINARIES:	/usr/local/bin/wol
34 1d333258 Scott Ullrich
	pfSense_MODULE:	wol
35
*/
36 5b237745 Scott Ullrich
37 6b07c15a Matthew Grooms
##|+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 5b237745 Scott Ullrich
require("guiconfig.inc");
45 bc3fa9f1 Peter Bouwdewijn
require('classes/Form.class.php');
46 5b237745 Scott Ullrich
47
if (!is_array($config['wol']['wolentry'])) {
48
	$config['wol']['wolentry'] = array();
49
}
50
$a_wol = &$config['wol']['wolentry'];
51
52 bc3fa9f1 Peter Bouwdewijn
if($_GET['wakeall'] != "") {
53 4751361d Scott Ullrich
	$i = 0;
54
	$savemsg = "";
55
	foreach ($a_wol as $wolent) {
56
		$mac = $wolent['mac'];
57
		$if = $wolent['interface'];
58 1b197e55 stompro
		$description = $wolent['descr'];
59 2bf16ba2 Ermal
		$ipaddr = get_interface_ip($if);
60
		if (!is_ipaddr($ipaddr))
61
			continue;
62
		$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
63 1b197e55 stompro
		/* Execute wol command and check return code. */
64 2bf16ba2 Ermal
		if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}"))
65 8cd558b6 ayvis
			$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'),$mac, $description, ".<br />");
66 2bf16ba2 Ermal
		else
67 8cd558b6 ayvis
			$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 4751361d Scott Ullrich
	}
69
}
70
71 5b237745 Scott Ullrich
if ($_POST || $_GET['mac']) {
72
	unset($input_errors);
73 f0fe3d30 Scott Ullrich
74 5b237745 Scott Ullrich
	if ($_GET['mac']) {
75 bc3fa9f1 Peter Bouwdewijn
			/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
76
			$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
77 5b237745 Scott Ullrich
		$mac = $_GET['mac'];
78
		$if = $_GET['if'];
79
	} else {
80 bc3fa9f1 Peter Bouwdewijn
			/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
81
			$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
82 4f3401e0 Bill Marquette
		$mac = $_POST['mac'];
83 5b237745 Scott Ullrich
		$if = $_POST['interface'];
84
	}
85
86
	/* input validation */
87
	if (!$mac || !is_macaddr($mac))
88 d58dbf67 Rafael Lucas
		$input_errors[] = gettext("A valid MAC address must be specified.");
89 5b237745 Scott Ullrich
	if (!$if)
90 d58dbf67 Rafael Lucas
		$input_errors[] = gettext("A valid interface must be specified.");
91 5b237745 Scott Ullrich
92 f0fe3d30 Scott Ullrich
	if (!$input_errors) {
93 5b237745 Scott Ullrich
		/* determine broadcast address */
94 2bf16ba2 Ermal
		$ipaddr = get_interface_ip($if);
95
		if (!is_ipaddr($ipaddr))
96
			$input_errors[] = gettext("A valid ip could not be found!");
97 1b197e55 stompro
		else {
98 2bf16ba2 Ermal
			$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
99
			/* Execute wol command and check return code. */
100 d31ca336 Renato Botelho
			if(!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac)))
101 2bf16ba2 Ermal
				$savemsg .= sprintf(gettext("Sent magic packet to %s."),$mac);
102
			else
103 8cd558b6 ayvis
				$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 />");
104 1b197e55 stompro
		}
105 5b237745 Scott Ullrich
	}
106
}
107
108
if ($_GET['act'] == "del") {
109
	if ($a_wol[$_GET['id']]) {
110
		unset($a_wol[$_GET['id']]);
111
		write_config();
112
		header("Location: services_wol.php");
113
		exit;
114
	}
115
}
116 4df96eff Scott Ullrich
117 d58dbf67 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"));
118 4df96eff Scott Ullrich
include("head.inc");
119
120 5b237745 Scott Ullrich
?>
121
122 ba8749ed Peter Bouwdewijn
<p><?=gettext("This service can be used to wake up (power on) computers by sending special") . '\'' . gettext("Magic Packets") . '\'' . 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). ")?></p>
123 bc3fa9f1 Peter Bouwdewijn
124
<?php
125
126
if ($input_errors)
127
	print_input_errors($input_errors);
128
129
if ($savemsg)
130
	print_info_box($savemsg);
131
132 38e06c66 Sjon Hortensius
$form = new Form('Send');
133 bc3fa9f1 Peter Bouwdewijn
134 ba8749ed Peter Bouwdewijn
$section = new Form_Section('Wake on LAN');
135 bc3fa9f1 Peter Bouwdewijn
136
$section->addInput(new Form_Select(
137
	'interface',
138 ba8749ed Peter Bouwdewijn
	'Interface',
139 c9be8d9f peter
	(link_interface_to_bridge($if) ? null : $if),
140 bc3fa9f1 Peter Bouwdewijn
	get_configured_interface_with_descr()
141
))->setHelp('Choose which interface the host to be woken up is connected to.');
142
143
$section->addInput(new Form_Input(
144
	'mac',
145 ba8749ed Peter Bouwdewijn
	'MAC address',
146
	'text',
147
	$mac
148 bc3fa9f1 Peter Bouwdewijn
))->setHelp(gettext('Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx'));
149
150
$form->add($section);
151
print $form;
152
?>
153
154
<div class="panel panel-default">
155
	<div class="panel-heading">
156
		<h2 class="panel-title">Wake on LAN devices</h2>
157
	</div>
158
159
	<div class="panel-body">
160
		<p><?=gettext("Click the MAC address to wake up an individual device.")?></p>
161 f0b20c3f Peter Bouwdewijn
		<div class="table-responsive">
162 0c9eb13b Peter Bouwdewijn
			<table class="table table-striped table-hover">
163 f0b20c3f Peter Bouwdewijn
				<thead>
164 bc3fa9f1 Peter Bouwdewijn
					<tr>
165 f0b20c3f Peter Bouwdewijn
						<th><?=gettext("Interface")?></th>
166
						<th><?=gettext("MAC address")?></th>
167
						<th><?=gettext("Description")?></th>
168
						<th></th>
169 bc3fa9f1 Peter Bouwdewijn
					</tr>
170 f0b20c3f Peter Bouwdewijn
				</thead>
171
				<tbody>
172
					<?php foreach ($a_wol as $i => $wolent): ?>
173
						<tr>
174
							<td>
175
								<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
176
							</td>
177
							<td>
178
								<a href="?mac=<?=$wolent['mac'];?>&amp;if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
179
							</td>
180
							<td>
181
								<?=htmlspecialchars($wolent['descr']);?>
182
							</td>
183
							<td>
184
								<a class="btn btn-xs btn-primary" href="services_wol_edit.php?id=<?=$i?>">
185
									edit
186
								</a>
187 42328d90 peter
								<a class="btn btn-xs btn-danger" href="services_wol.php?act=del&amp;id=<?=$i?>">
188 f0b20c3f Peter Bouwdewijn
									delete
189
								</a>
190
							</td>
191
						</tr>
192
					<?php endforeach?>
193
				</tbody>
194
			</table>
195
		</div>
196 bc3fa9f1 Peter Bouwdewijn
	</div>
197
	<div class="panel-footer">
198
		<a class="btn btn-success" href="services_wol_edit.php">
199
			Add
200
		</a>
201
202
		<a href="services_wol.php?wakeall=true" role="button" class="btn btn-primary">
203
			<?=gettext("Wake all devices")?>
204
		</a>
205
	</div>
206
</div>
207
208
<?php
209
210
include("foot.inc");