Project

General

Profile

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