Project

General

Profile

Download (7.68 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	services_wol.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *  Originally from m0n0wall, copyright 2004 Manuel Kasper (BSD 2 clause)
9
 *
10
 *	Redistribution and use in source and binary forms, with or without modification,
11
 *	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
18
 *		the documentation and/or other materials provided with the
19
 *		distribution.
20
 *
21
 *	3. All advertising materials mentioning features or use of this software
22
 *		must display the following acknowledgment:
23
 *		"This product includes software developed by the pfSense Project
24
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
25
 *
26
 *	4. The names "pfSense" and "pfSense Project" must not be used to
27
 *		 endorse or promote products derived from this software without
28
 *		 prior written permission. For written permission, please contact
29
 *		 coreteam@pfsense.org.
30
 *
31
 *	5. Products derived from this software may not be called "pfSense"
32
 *		nor may "pfSense" appear in their names without prior written
33
 *		permission of the Electric Sheep Fencing, LLC.
34
 *
35
 *	6. Redistributions of any form whatsoever must retain the following
36
 *		acknowledgment:
37
 *
38
 *	"This product includes software developed by the pfSense Project
39
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
40
 *
41
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
53
 *
54
 *	====================================================================
55
 *
56
 */
57
/*
58
	pfSense_BUILDER_BINARIES:	/usr/local/bin/wol
59
	pfSense_MODULE:	wol
60
*/
61

    
62
##|+PRIV
63
##|*IDENT=page-services-wakeonlan
64
##|*NAME=Services: Wake on LAN page
65
##|*DESCR=Allow access to the 'Services: Wake on LAN' page.
66
##|*MATCH=services_wol.php*
67
##|-PRIV
68

    
69
require("guiconfig.inc");
70
require_once('classes/Form.class.php');
71

    
72
if (!is_array($config['wol']['wolentry'])) {
73
	$config['wol']['wolentry'] = array();
74
}
75
$a_wol = &$config['wol']['wolentry'];
76

    
77
if($_GET['wakeall'] != "") {
78
	$i = 0;
79
	$savemsg = "";
80
	foreach ($a_wol as $wolent) {
81
		$mac = $wolent['mac'];
82
		$if = $wolent['interface'];
83
		$description = $wolent['descr'];
84
		$ipaddr = get_interface_ip($if);
85
		if (!is_ipaddr($ipaddr)) {
86
			continue;
87
		}
88
		$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
89
		/* Execute wol command and check return code. */
90
		if (!mwexec("/usr/local/bin/wol -i {$bcip} {$mac}")) {
91
			$savemsg .= sprintf(gettext('Sent magic packet to %1$s (%2$s)%3$s'), $mac, $description, ".<br />");
92
		} else {
93
			$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 />");
94
		}
95
	}
96
}
97

    
98
if ($_POST || $_GET['mac']) {
99
	unset($input_errors);
100

    
101
	if ($_GET['mac']) {
102
		/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
103
		$_GET['mac'] = strtolower(str_replace("-", ":", $_GET['mac']));
104
		$mac = $_GET['mac'];
105
		$if = $_GET['if'];
106
	} else {
107
		/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
108
		$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
109
		$mac = $_POST['mac'];
110
		$if = $_POST['interface'];
111
	}
112

    
113
	/* input validation */
114
	if (!$mac || !is_macaddr($mac)) {
115
		$input_errors[] = gettext("A valid MAC address must be specified.");
116
	}
117
	if (!$if) {
118
		$input_errors[] = gettext("A valid interface must be specified.");
119
	}
120

    
121
	if (!$input_errors) {
122
		/* determine broadcast address */
123
		$ipaddr = get_interface_ip($if);
124
		if (!is_ipaddr($ipaddr)) {
125
			$input_errors[] = gettext("A valid ip could not be found!");
126
		} else {
127
			$bcip = gen_subnet_max($ipaddr, get_interface_subnet($if));
128
			/* Execute wol command and check return code. */
129
			if (!mwexec("/usr/local/bin/wol -i {$bcip} " . escapeshellarg($mac))) {
130
				$savemsg .= sprintf(gettext("Sent magic packet to %s."), $mac);
131
			} else {
132
				$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 />");
133
			}
134
		}
135
	}
136
}
137

    
138
if ($_GET['act'] == "del") {
139
	if ($a_wol[$_GET['id']]) {
140
		unset($a_wol[$_GET['id']]);
141
		write_config();
142
		header("Location: services_wol.php");
143
		exit;
144
	}
145
}
146

    
147
$pgtitle = array(gettext("Services"), gettext("Wake on LAN"));
148
include("head.inc");
149

    
150
print_info_box(gettext('This service can be used to wake up (power on) computers by sending special') . ' "' . gettext('Magic Packets') . '"<br />' . 
151
			   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

    
153
?>
154

    
155
<?php
156

    
157
if ($input_errors)
158
	print_input_errors($input_errors);
159

    
160
if ($savemsg)
161
	print_info_box($savemsg);
162

    
163
$form = new Form('Send');
164

    
165
$section = new Form_Section('Wake on LAN');
166

    
167
$section->addInput(new Form_Select(
168
	'interface',
169
	'Interface',
170
	(link_interface_to_bridge($if) ? null : $if),
171
	get_configured_interface_with_descr()
172
))->setHelp('Choose which interface the host to be woken up is connected to.');
173

    
174
$section->addInput(new Form_Input(
175
	'mac',
176
	'MAC address',
177
	'text',
178
	$mac
179
))->setHelp(gettext('Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx'));
180

    
181
$form->add($section);
182
print $form;
183
?>
184

    
185
<div class="panel panel-default">
186
	<div class="panel-heading">
187
		<h2 class="panel-title">Wake on LAN devices</h2>
188
	</div>
189

    
190
	<div class="panel-body">
191
		<p><?=gettext("Click the MAC address to wake up an individual device.")?></p>
192
		<div class="table-responsive">
193
			<table class="table table-striped table-hover">
194
				<thead>
195
					<tr>
196
						<th><?=gettext("Interface")?></th>
197
						<th><?=gettext("MAC address")?></th>
198
						<th><?=gettext("Description")?></th>
199
						<th></th>
200
					</tr>
201
				</thead>
202
				<tbody>
203
					<?php foreach ($a_wol as $i => $wolent): ?>
204
						<tr>
205
							<td>
206
								<?=convert_friendly_interface_to_friendly_descr($wolent['interface']);?>
207
							</td>
208
							<td>
209
								<a href="?mac=<?=$wolent['mac'];?>&amp;if=<?=$wolent['interface'];?>"><?=strtolower($wolent['mac']);?></a>
210
							</td>
211
							<td>
212
								<?=htmlspecialchars($wolent['descr']);?>
213
							</td>
214
							<td>
215
								<a class="fa fa-pencil"	title="<?=gettext('Edit device')?>"	href="services_wol_edit.php?id=<?=$i?>"></a>
216
								<a class="fa fa-trash"	title="<?=gettext('Delete device')?>" href="services_wol.php?act=del&amp;id=<?=$i?>"></a>
217
							</td>
218
						</tr>
219
					<?php endforeach?>
220
				</tbody>
221
			</table>
222
		</div>
223
	</div>
224
	<div class="panel-footer">
225
		<a class="btn btn-success" href="services_wol_edit.php">
226
			Add
227
		</a>
228

    
229
		<a href="services_wol.php?wakeall=true" role="button" class="btn btn-primary">
230
			<?=gettext("Wake all devices")?>
231
		</a>
232
	</div>
233
</div>
234

    
235
<?php
236

    
237
include("foot.inc");
(157-157/234)