Project

General

Profile

Download (6.09 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_wireless_edit.php
5

    
6
	Copyright (C) 2010 Erik Fonnesbeck
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, 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 the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE: interfaces
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-interfaces-wireless-edit
37
##|*NAME=Interfaces: Wireless edit page
38
##|*DESCR=Allow access to the 'Interfaces: Wireless : Edit' page.
39
##|*MATCH=interfaces_wireless_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43

    
44
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_wireless.php');
45

    
46
if (!is_array($config['wireless']))
47
	$config['wireless'] = array();
48

    
49
if (!is_array($config['wireless']['clone']))
50
	$config['wireless']['clone'] = array();
51

    
52
$a_clones = &$config['wireless']['clone'];
53

    
54
function clone_inuse($num) {
55
	global $config, $a_clones;
56

    
57
	$iflist = get_configured_interface_list(false, true);
58
	foreach ($iflist as $if) {
59
		if ($config['interfaces'][$if]['if'] == $a_clones[$num]['cloneif'])
60
			return true;
61
	}
62

    
63
	return false;
64
}
65

    
66
function clone_compare($a, $b) {
67
	return strnatcmp($a['cloneif'], $b['cloneif']);
68
}
69

    
70
$portlist = get_interface_list();
71

    
72
if (is_numericint($_GET['id']))
73
	$id = $_GET['id'];
74

    
75
if (isset($_POST['id']) && is_numericint($_POST['id']))
76
	$id = $_POST['id'];
77

    
78
if (isset($id) && $a_clones[$id]) {
79
	$pconfig['if'] = $a_clones[$id]['if'];
80
	$pconfig['cloneif'] = $a_clones[$id]['cloneif'];
81
	$pconfig['mode'] = $a_clones[$id]['mode'];
82
	$pconfig['descr'] = $a_clones[$id]['descr'];
83
}
84

    
85
if ($_POST) {
86
	unset($input_errors);
87
	$pconfig = $_POST;
88

    
89
	/* input validation */
90
	$reqdfields = explode(" ", "if mode");
91
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Mode"));
92

    
93
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
94

    
95
	if (!$input_errors) {
96
		$clone = array();
97
		$clone['if'] = $_POST['if'];
98
		$clone['mode'] = $_POST['mode'];
99
		$clone['descr'] = $_POST['descr'];
100

    
101
		if (isset($id) && $a_clones[$id]) {
102
			if ($clone['if'] == $a_clones[$id]['if'])
103
				$clone['cloneif'] = $a_clones[$id]['cloneif'];
104
		}
105

    
106
		if (!$clone['cloneif']) {
107
			$clone_id = 1;
108
			do {
109
				$clone_exists = false;
110
				$clone['cloneif'] = "{$_POST['if']}_wlan{$clone_id}";
111
				foreach ($a_clones as $existing) {
112
					if ($clone['cloneif'] == $existing['cloneif']) {
113
						$clone_exists = true;
114
						$clone_id++;
115
						break;
116
					}
117
				}
118
			} while ($clone_exists);
119
		}
120

    
121
		if (isset($id) && $a_clones[$id]) {
122
			if (clone_inuse($id)) {
123
				if ($clone['if'] != $a_clones[$id]['if'])
124
					$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
125
				else if ($clone['mode'] != $a_clones[$id]['mode'])
126
					$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
127
			}
128
		}
129

    
130
		if (!$input_errors) {
131
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
132
				$input_errors[] = sprintf(gettext('Error creating interface with mode %1$s.	 The %2$s interface may not support creating more clones with the selected mode.'), $wlan_modes[$clone['mode']], $clone['if']);
133
			} else {
134
				if (isset($id) && $a_clones[$id]) {
135
					if ($clone['if'] != $a_clones[$id]['if'])
136
						mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
137
					$input_errors[] = sprintf(gettext("Created with id %s"), $id);
138
					$a_clones[$id] = $clone;
139
				} else {
140
					$input_errors[] = gettext("Created without id");
141
					$a_clones[] = $clone;
142
				}
143

    
144
				usort($a_clones, "clone_compare");
145
				write_config();
146

    
147
				header("Location: interfaces_wireless.php");
148
				exit;
149
			}
150
		}
151
	}
152
}
153

    
154
function build_parent_list() {
155
	global $g;
156

    
157
	$parentlist = array();
158
	$portlist = get_possible_listen_ips();
159
	$count = 0;
160
	foreach ($portlist as $ifn => $ifinfo) {
161
		if (preg_match($g['wireless_regex'], $ifn)) {
162
			$parentlist[$ifn] = htmlspecialchars($ifn . '(' . $ifinfo['mac'] . ')');
163
			$count++;
164
		}
165
	}
166

    
167
	if($count > 0)
168
		return($parentlist);
169
	else
170
		return(array('0' => gettext('None available')));
171
}
172

    
173
$pgtitle = array(gettext("Interfaces"),gettext("Wireless"),gettext("Edit"));
174
include("head.inc");
175

    
176
if ($input_errors)
177
	print_input_errors($input_errors);
178

    
179
require('classes/Form.class.php');
180

    
181
$form = new Form();
182

    
183
$form->addGlobal(new Form_Button(
184
	'cancel',
185
	'Cancel',
186
	$referer
187
));
188

    
189
$section = new Form_Section('Wireless Interface');
190

    
191
$section->addInput(new Form_Select(
192
	'parent',
193
	'Parent Interface',
194
	$pconfig['if'],
195
	build_parent_list()
196
));
197

    
198
$section->addInput(new Form_Select(
199
	'mode',
200
	'Mode',
201
	$pconfig['mode'],
202
	array(
203
		'bss' => gettext("Infrastructure (BSS)"),
204
		'adhoc' => gettext("Ad-hoc (IBSS)"),
205
		'hostap' => gettext("Access Point")
206
	)
207
));
208

    
209
$section->addInput(new Form_Input(
210
	'descr',
211
	'Description',
212
	'text',
213
	$pconfig['descr']
214
))->setHelp('You may enter a description here for your reference (not parsed).');
215

    
216
$section->addInput(new Form_Input(
217
	'cloneif',
218
	null,
219
	'hidden',
220
	$pconfig['cloneif']
221
));
222

    
223
if (isset($id) && $a_clones[$id]) {
224
	$section->addInput(new Form_Input(
225
		'id',
226
		null,
227
		'hidden',
228
		$id
229
	));
230
}
231

    
232
$form->add($section);
233
print($form);
234

    
235
include("foot.inc");
(101-101/241)