Project

General

Profile

Download (8.15 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
<?php
2
/*
3
	services_wol.php
4
*/
5 b9043cdc Stephen Beaver
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 191cb31d Stephen Beaver
 *
8 cb41dd63 Renato Botelho
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10 b9043cdc Stephen Beaver
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	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
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21
 *
22
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26
 *
27
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31
 *
32
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
 *
42
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *	====================================================================
56
 *
57 c9df279d Stephen Beaver
 */
58 5b237745 Scott Ullrich
59 6b07c15a Matthew Grooms
##|+PRIV
60
##|*IDENT=page-services-wakeonlan
61 7ca42d47 k-paulius
##|*NAME=Services: Wake-on-LAN
62
##|*DESCR=Allow access to the 'Services: Wake-on-LAN' page.
63 6b07c15a Matthew Grooms
##|*MATCH=services_wol.php*
64
##|-PRIV
65
66 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
67 5b237745 Scott Ullrich
if (!is_array($config['wol']['wolentry'])) {
68
	$config['wol']['wolentry'] = array();
69
}
70
$a_wol = &$config['wol']['wolentry'];
71
72 20db3e1a Phil Davis
if ($_GET['wakeall'] != "") {
73 4751361d Scott Ullrich
	$i = 0;
74
	$savemsg = "";
75
	foreach ($a_wol as $wolent) {
76
		$mac = $wolent['mac'];
77
		$if = $wolent['interface'];
78 1b197e55 stompro
		$description = $wolent['descr'];
79 2bf16ba2 Ermal
		$ipaddr = get_interface_ip($if);
80 56463a6c Phil Davis
		if (!is_ipaddr($ipaddr)) {
81 2bf16ba2 Ermal
			continue;
82 56463a6c Phil Davis
		}
83 2bf16ba2 Ermal
		$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
84 1b197e55 stompro
		/* Execute wol command and check return code. */
85 56463a6c Phil Davis
		if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")) {
86 4bfc3f7d Phil Davis
			$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s).'), $mac, $description) . "<br />";
87 f78bbe16 Phil Davis
			$class = 'success';
88 56463a6c Phil Davis
		} else {
89 4bfc3f7d Phil Davis
			$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s (%4$s) did not complete successfully.'), '<a href="/status_logs.php">', '</a>', $description, $mac) . "<br />";
90 f78bbe16 Phil Davis
			$class = 'warning';
91 56463a6c Phil Davis
		}
92 4751361d Scott Ullrich
	}
93
}
94
95 5b237745 Scott Ullrich
if ($_POST || $_GET['mac']) {
96
	unset($input_errors);
97 f0fe3d30 Scott Ullrich
98 5b237745 Scott Ullrich
	if ($_GET['mac']) {
99 56463a6c Phil Davis
		/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
100
		$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
101 5b237745 Scott Ullrich
		$mac = $_GET['mac'];
102
		$if = $_GET['if'];
103
	} else {
104 56463a6c Phil Davis
		/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
105
		$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
106 4f3401e0 Bill Marquette
		$mac = $_POST['mac'];
107 5b237745 Scott Ullrich
		$if = $_POST['interface'];
108
	}
109
110
	/* input validation */
111 56463a6c Phil Davis
	if (!$mac || !is_macaddr($mac)) {
112 d58dbf67 Rafael Lucas
		$input_errors[] = gettext("A valid MAC address must be specified.");
113 56463a6c Phil Davis
	}
114
	if (!$if) {
115 d58dbf67 Rafael Lucas
		$input_errors[] = gettext("A valid interface must be specified.");
116 56463a6c Phil Davis
	}
117 5b237745 Scott Ullrich
118 f0fe3d30 Scott Ullrich
	if (!$input_errors) {
119 5b237745 Scott Ullrich
		/* determine broadcast address */
120 2bf16ba2 Ermal
		$ipaddr = get_interface_ip($if);
121 56463a6c Phil Davis
		if (!is_ipaddr($ipaddr)) {
122 2bf16ba2 Ermal
			$input_errors[] = gettext("A valid ip could not be found!");
123 56463a6c Phil Davis
		} else {
124 2bf16ba2 Ermal
			$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
125
			/* Execute wol command and check return code. */
126 56463a6c Phil Davis
			if (!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac))) {
127
				$savemsg .= sprintf(gettext("Sent magic packet to %s."), $mac);
128 f78bbe16 Phil Davis
				$class = 'success';
129 56463a6c Phil Davis
			} else {
130 4bfc3f7d Phil Davis
				$savemsg .= sprintf(gettext('Please check the %1$ssystem log%2$s, the wol command for %3$s did not complete successfully.'), '<a href="/status_logs.php">', '</a>', $mac) . "<br />";
131 f78bbe16 Phil Davis
				$class = 'warning';
132 56463a6c Phil Davis
			}
133 1b197e55 stompro
		}
134 5b237745 Scott Ullrich
	}
135
}
136
137
if ($_GET['act'] == "del") {
138
	if ($a_wol[$_GET['id']]) {
139
		unset($a_wol[$_GET['id']]);
140
		write_config();
141
		header("Location: services_wol.php");
142
		exit;
143
	}
144
}
145 4df96eff Scott Ullrich
146 7ca42d47 k-paulius
$pgtitle = array(gettext("Services"), gettext("Wake-on-LAN"));
147 4df96eff Scott Ullrich
include("head.inc");
148 f78bbe16 Phil Davis
?>
149 c95dabdd Stephen Beaver
<div class="infoblock blockopen">
150 f78bbe16 Phil Davis
<?php
151 4bfc3f7d Phil Davis
print_info_box(gettext('This service can be used to wake up (power on) computers by sending special "Magic Packets".') . '<br />' .
152 7ca42d47 k-paulius
			   gettext('The NIC in the computer that is to be woken up must support Wake-on-LAN and must be properly configured (WOL cable, BIOS settings).'),
153 4bfc3f7d Phil Davis
			   'info', false);
154 5b237745 Scott Ullrich
155 6658142a Stephen Beaver
?>
156 f78bbe16 Phil Davis
</div>
157 bc3fa9f1 Peter Bouwdewijn
<?php
158
159 20db3e1a Phil Davis
if ($input_errors) {
160 bc3fa9f1 Peter Bouwdewijn
	print_input_errors($input_errors);
161 20db3e1a Phil Davis
}
162 bc3fa9f1 Peter Bouwdewijn
163 20db3e1a Phil Davis
if ($savemsg) {
164 f78bbe16 Phil Davis
	print_info_box($savemsg, $class);
165 20db3e1a Phil Davis
}
166 bc3fa9f1 Peter Bouwdewijn
167 37676f4e jim-p
$form = new Form(false);
168 bc3fa9f1 Peter Bouwdewijn
169 7ca42d47 k-paulius
$section = new Form_Section('Wake-on-LAN');
170 bc3fa9f1 Peter Bouwdewijn
171
$section->addInput(new Form_Select(
172
	'interface',
173 ba8749ed Peter Bouwdewijn
	'Interface',
174 c9be8d9f peter
	(link_interface_to_bridge($if) ? null : $if),
175 bc3fa9f1 Peter Bouwdewijn
	get_configured_interface_with_descr()
176
))->setHelp('Choose which interface the host to be woken up is connected to.');
177
178
$section->addInput(new Form_Input(
179
	'mac',
180 ba8749ed Peter Bouwdewijn
	'MAC address',
181
	'text',
182
	$mac
183 bc3fa9f1 Peter Bouwdewijn
))->setHelp(gettext('Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx'));
184
185 e8a37c87 jim-p
$form->add($section);
186
187
$form->addGlobal(new Form_Button(
188 37676f4e jim-p
	'Submit',
189 faab522f Renato Botelho
	'Send',
190 37676f4e jim-p
	null,
191
	'fa-power-off'
192
))->addClass('btn-primary');
193
194 bc3fa9f1 Peter Bouwdewijn
print $form;
195
?>
196
197
<div class="panel panel-default">
198
	<div class="panel-heading">
199 7ca42d47 k-paulius
		<h2 class="panel-title"><?=gettext("Wake-on-LAN Devices");?></h2>
200 bc3fa9f1 Peter Bouwdewijn
	</div>
201
202
	<div class="panel-body">
203
		<p><?=gettext("Click the MAC address to wake up an individual device.")?></p>
204 f0b20c3f Peter Bouwdewijn
		<div class="table-responsive">
205 0c9eb13b Peter Bouwdewijn
			<table class="table table-striped table-hover">
206 f0b20c3f Peter Bouwdewijn
				<thead>
207 bc3fa9f1 Peter Bouwdewijn
					<tr>
208 f0b20c3f Peter Bouwdewijn
						<th><?=gettext("Interface")?></th>
209
						<th><?=gettext("MAC address")?></th>
210
						<th><?=gettext("Description")?></th>
211 70dc5cd6 Phil Davis
						<th><?=gettext("Actions")?></th>
212 bc3fa9f1 Peter Bouwdewijn
					</tr>
213 f0b20c3f Peter Bouwdewijn
				</thead>
214
				<tbody>
215
					<?php foreach ($a_wol as $i => $wolent): ?>
216
						<tr>
217
							<td>
218
								<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
219
							</td>
220
							<td>
221
								<a href="?mac=<?=$wolent['mac'];?>&amp;if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
222
							</td>
223
							<td>
224
								<?=htmlspecialchars($wolent['descr']);?>
225
							</td>
226
							<td>
227 e8a37c87 jim-p
								<a class="fa fa-pencil"	title="<?=gettext('Edit Device')?>"	href="services_wol_edit.php?id=<?=$i?>"></a>
228
								<a class="fa fa-trash"	title="<?=gettext('Delete Device')?>" href="services_wol.php?act=del&amp;id=<?=$i?>"></a>
229
								<a class="fa fa-power-off" title="<?=gettext('Wake Device')?>" href="?mac=<?=$wolent['mac'];?>&amp;if=<?=$wolent['interface'];?>"></a>
230 f0b20c3f Peter Bouwdewijn
							</td>
231
						</tr>
232
					<?php endforeach?>
233
				</tbody>
234
			</table>
235
		</div>
236 bc3fa9f1 Peter Bouwdewijn
	</div>
237
	<div class="panel-footer">
238
		<a class="btn btn-success" href="services_wol_edit.php">
239 37676f4e jim-p
			<i class="fa fa-plus icon-embed-btn"></i>
240 4bb7c0d1 bruno
			<?=gettext("Add");?>
241 bc3fa9f1 Peter Bouwdewijn
		</a>
242
243
		<a href="services_wol.php?wakeall=true" role="button" class="btn btn-primary">
244 37676f4e jim-p
			<i class="fa fa-power-off icon-embed-btn"></i>
245 e8a37c87 jim-p
			<?=gettext("Wake All Devices")?>
246 bc3fa9f1 Peter Bouwdewijn
		</a>
247
	</div>
248
</div>
249
250
<?php
251
252 370358b8 heper
include("foot.inc");