Project

General

Profile

Download (5.9 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
if (!is_array($config['wireless']))
45
	$config['wireless'] = array();
46

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

    
50
$a_clones = &$config['wireless']['clone'];
51

    
52
function clone_inuse($num) {
53
	global $config, $a_clones;
54

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

    
61
	return false;
62
}
63

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

    
68
$portlist = get_interface_list();
69

    
70
if (is_numericint($_GET['id']))
71
	$id = $_GET['id'];
72

    
73
if (isset($_POST['id']) && is_numericint($_POST['id']))
74
	$id = $_POST['id'];
75

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

    
83
if ($_POST) {
84
	unset($input_errors);
85
	$pconfig = $_POST;
86

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

    
91
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
92

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

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

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

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

    
128
		if (!$input_errors) {
129
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
130
				$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']);
131
			} else {
132
				if (isset($id) && $a_clones[$id]) {
133
					if ($clone['if'] != $a_clones[$id]['if'])
134
						mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
135
					$input_errors[] = sprintf(gettext("Created with id %s"), $id);
136
					$a_clones[$id] = $clone;
137
				} else {
138
					$input_errors[] = gettext("Created without id");
139
					$a_clones[] = $clone;
140
				}
141

    
142
				usort($a_clones, "clone_compare");
143
				write_config();
144

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

    
152
function build_parent_list() {
153
	global $g;
154

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

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

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

    
174
if ($input_errors)
175
	print_input_errors($input_errors);
176

    
177
require('classes/Form.class.php');
178

    
179
$form = new Form();
180

    
181
$section = new Form_Section('Wireless Interface');
182

    
183
$section->addInput(new Form_Select(
184
	'parent',
185
	'Parent Interface',
186
	$pconfig['if'],
187
	build_parent_list()
188
));
189

    
190
$section->addInput(new Form_Select(
191
	'mode',
192
	'Mode',
193
	$pconfig['mode'],
194
	array(
195
		'bss' => 'Infrastructure (BSS)',
196
		'adhoc' => 'Ad-hoc (IBSS)',
197
		'hostap' => 'Access Point'
198
	)
199
));
200

    
201
$section->addInput(new Form_Input(
202
	'descr',
203
	'Description',
204
	'text',
205
	$pconfig['descr']
206
))->setHelp('You may enter a description here for your reference (not parsed).');
207

    
208
$section->addInput(new Form_Input(
209
	'cloneif',
210
	null,
211
	'hidden',
212
	$pconfig['cloneif']
213
));
214

    
215
if (isset($id) && $a_clones[$id]) {
216
	$section->addInput(new Form_Input(
217
		'id',
218
		null,
219
		'hidden',
220
		$id
221
	));
222
}
223

    
224
$form->add($section);
225
print($form);
226

    
227
include("foot.inc");
(101-101/237)