Project

General

Profile

Download (7.72 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	services_wol.php
4
*/
5
/* ====================================================================
6
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *
8
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10
 *
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
 */
58
/*
59
	pfSense_BUILDER_BINARIES:	/usr/local/bin/wol
60
	pfSense_MODULE:	wol
61
*/
62

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

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

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

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

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

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

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

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

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

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

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

    
154
?>
155

    
156
<?php
157

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

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

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

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

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

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

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

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

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

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

    
236
<?php
237

    
238
include("foot.inc");
(158-158/235)