Project

General

Profile

Download (4.21 KB) Statistics
| Branch: | Tag: | Revision:
1 bc3fa9f1 Peter Bouwdewijn
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	services_wol_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 bc3fa9f1 Peter Bouwdewijn
7 5b237745 Scott Ullrich
	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 bc3fa9f1 Peter Bouwdewijn
11 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13 bc3fa9f1 Peter Bouwdewijn
14 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16 bc3fa9f1 Peter Bouwdewijn
17 5b237745 Scott Ullrich
	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 bc3fa9f1 Peter Bouwdewijn
21 5b237745 Scott Ullrich
	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
	pfSense_MODULE:	wol
34
*/
35 5b237745 Scott Ullrich
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-services-wakeonlan-edit
38
##|*NAME=Services: Wake on LAN: Edit page
39
##|*DESCR=Allow access to the 'Services: Wake on LAN: Edit' page.
40
##|*MATCH=services_wol_edit.php*
41
##|-PRIV
42
43 4504a769 Ermal Lu?i
function wolcmp($a, $b) {
44
	return strcmp($a['descr'], $b['descr']);
45
}
46 0d64af59 Ermal Lu?i
47 4504a769 Ermal Lu?i
function wol_sort() {
48 bc3fa9f1 Peter Bouwdewijn
		global $config;
49 0d64af59 Ermal Lu?i
50 bc3fa9f1 Peter Bouwdewijn
		usort($config['wol']['wolentry'], "wolcmp");
51 0d64af59 Ermal Lu?i
}
52 6b07c15a Matthew Grooms
53 5b237745 Scott Ullrich
require("guiconfig.inc");
54 bc3fa9f1 Peter Bouwdewijn
require('classes/Form.class.php');
55 5b237745 Scott Ullrich
56
if (!is_array($config['wol']['wolentry'])) {
57
	$config['wol']['wolentry'] = array();
58
}
59
$a_wol = &$config['wol']['wolentry'];
60
61 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
62
	$id = $_GET['id'];
63
if (isset($_POST['id']) && is_numericint($_POST['id']))
64 5b237745 Scott Ullrich
	$id = $_POST['id'];
65
66
if (isset($id) && $a_wol[$id]) {
67
	$pconfig['interface'] = $a_wol[$id]['interface'];
68
	$pconfig['mac'] = $a_wol[$id]['mac'];
69
	$pconfig['descr'] = $a_wol[$id]['descr'];
70
}
71 7477df4f Scott Ullrich
else
72
{
73
	$pconfig['interface'] = $_GET['if'];
74
	$pconfig['mac'] = $_GET['mac'];
75
	$pconfig['descr'] = $_GET['descr'];
76
}
77 5b237745 Scott Ullrich
78
if ($_POST) {
79
80
	unset($input_errors);
81
	$pconfig = $_POST;
82
83
	/* input validation */
84
	$reqdfields = explode(" ", "interface mac");
85 593de5c8 Rafael Lucas
	$reqdfieldsn = array(gettext("Interface"),gettext("MAC address"));
86 bc3fa9f1 Peter Bouwdewijn
87 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
88 4f3401e0 Bill Marquette
89 bc3fa9f1 Peter Bouwdewijn
		/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
90
		$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
91
92 5b237745 Scott Ullrich
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
93 593de5c8 Rafael Lucas
		$input_errors[] = gettext("A valid MAC address must be specified.");
94 5b237745 Scott Ullrich
	}
95
96
	if (!$input_errors) {
97
		$wolent = array();
98
		$wolent['interface'] = $_POST['interface'];
99
		$wolent['mac'] = $_POST['mac'];
100
		$wolent['descr'] = $_POST['descr'];
101
102
		if (isset($id) && $a_wol[$id])
103
			$a_wol[$id] = $wolent;
104
		else
105
			$a_wol[] = $wolent;
106 0e3aa71c Erik Fonnesbeck
		wol_sort();
107 bc3fa9f1 Peter Bouwdewijn
108 5b237745 Scott Ullrich
		write_config();
109 bc3fa9f1 Peter Bouwdewijn
110 5b237745 Scott Ullrich
		header("Location: services_wol.php");
111
		exit;
112
	}
113
}
114 4df96eff Scott Ullrich
115 593de5c8 Rafael Lucas
$pgtitle = array(gettext("Services"),gettext("Wake on LAN"),gettext("Edit"));
116 4df96eff Scott Ullrich
include("head.inc");
117
118 bc3fa9f1 Peter Bouwdewijn
if ($input_errors)
119
	print_input_errors($input_errors);
120
121 ba8749ed Peter Bouwdewijn
$form = new Form;
122 bc3fa9f1 Peter Bouwdewijn
123
if (isset($id) && $a_wol[$id]) {
124
	$form->addGlobal(new Form_Input(
125
		'id',
126
		null,
127
		'hidden',
128
		$id
129
	));
130
}
131
132 ba8749ed Peter Bouwdewijn
$section = new Form_Section('Edit WOL entry');
133 bc3fa9f1 Peter Bouwdewijn
134
$section->addInput(new Form_Select(
135
	'interface',
136 ba8749ed Peter Bouwdewijn
	'Interface',
137 c9be8d9f peter
	(link_interface_to_bridge($pconfig['interface']) ? null : $pconfig['interface']),
138 bc3fa9f1 Peter Bouwdewijn
	get_configured_interface_with_descr()
139
))->setHelp('Choose which interface this host is connected to.');
140
141
$section->addInput(new Form_Input(
142
	'mac',
143 ba8749ed Peter Bouwdewijn
	'MAC address',
144 bc3fa9f1 Peter Bouwdewijn
	'text',
145 ba8749ed Peter Bouwdewijn
	$pconfig['mac']
146 bc3fa9f1 Peter Bouwdewijn
))->setHelp(gettext('Enter a MAC address in the following format: xx:xx:xx:xx:xx:xx'));
147
148
$section->addInput(new Form_Input(
149
	'descr',
150 ba8749ed Peter Bouwdewijn
	'Description',
151 bc3fa9f1 Peter Bouwdewijn
	'text',
152 ba8749ed Peter Bouwdewijn
	$pconfig['descr']
153 bc3fa9f1 Peter Bouwdewijn
))->setHelp(gettext('You may enter a description here for your reference (not parsed).'));
154
155
$form->add($section);
156
print $form;
157
158
include("foot.inc");