1 |
9f428275
|
Erik Fonnesbeck
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
interfaces_wireless_edit.php
|
5 |
|
|
|
6 |
|
|
Copyright (C) 2010 Erik Fonnesbeck
|
7 |
|
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
Redistribution and use in source and binary forms, with or without
|
10 |
|
|
modification, are permitted provided that the following conditions are met:
|
11 |
|
|
|
12 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
this list of conditions and the following disclaimer.
|
14 |
|
|
|
15 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
notice, this list of conditions and the following disclaimer in the
|
17 |
|
|
documentation and/or other materials provided with the distribution.
|
18 |
|
|
|
19 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
29 |
|
|
*/
|
30 |
|
|
/*
|
31 |
|
|
pfSense_MODULE: interfaces
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
|
|
##|+PRIV
|
35 |
|
|
##|*IDENT=page-interfaces-wireless-edit
|
36 |
|
|
##|*NAME=Interfaces: Wireless edit page
|
37 |
|
|
##|*DESCR=Allow access to the 'Interfaces: Wireless : Edit' page.
|
38 |
|
|
##|*MATCH=interfaces_wireless_edit.php*
|
39 |
|
|
##|-PRIV
|
40 |
|
|
|
41 |
|
|
require("guiconfig.inc");
|
42 |
|
|
|
43 |
6ef2297b
|
Erik Fonnesbeck
|
if (!is_array($config['wireless']))
|
44 |
|
|
$config['wireless'] = array();
|
45 |
9f428275
|
Erik Fonnesbeck
|
if (!is_array($config['wireless']['clone']))
|
46 |
|
|
$config['wireless']['clone'] = array();
|
47 |
|
|
|
48 |
|
|
$a_clones = &$config['wireless']['clone'];
|
49 |
|
|
|
50 |
16120707
|
Erik Fonnesbeck
|
function clone_inuse($num) {
|
51 |
|
|
global $config, $a_clones;
|
52 |
9f428275
|
Erik Fonnesbeck
|
|
53 |
38b7d47d
|
Erik Fonnesbeck
|
$iflist = get_configured_interface_list(false, true);
|
54 |
9f428275
|
Erik Fonnesbeck
|
foreach ($iflist as $if) {
|
55 |
16120707
|
Erik Fonnesbeck
|
if ($config['interfaces'][$if]['if'] == $a_clones[$num]['cloneif'])
|
56 |
9f428275
|
Erik Fonnesbeck
|
return true;
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
return false;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
function clone_compare($a, $b) {
|
63 |
992ff4c2
|
Erik Fonnesbeck
|
return strnatcmp($a['cloneif'], $b['cloneif']);
|
64 |
9f428275
|
Erik Fonnesbeck
|
}
|
65 |
|
|
|
66 |
|
|
$portlist = get_interface_list();
|
67 |
|
|
|
68 |
|
|
$id = $_GET['id'];
|
69 |
|
|
if (isset($_POST['id']))
|
70 |
|
|
$id = $_POST['id'];
|
71 |
|
|
|
72 |
|
|
if (isset($id) && $a_clones[$id]) {
|
73 |
|
|
$pconfig['if'] = $a_clones[$id]['if'];
|
74 |
|
|
$pconfig['cloneif'] = $a_clones[$id]['cloneif'];
|
75 |
|
|
$pconfig['mode'] = $a_clones[$id]['mode'];
|
76 |
|
|
$pconfig['descr'] = $a_clones[$id]['descr'];
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
if ($_POST) {
|
80 |
|
|
|
81 |
|
|
unset($input_errors);
|
82 |
|
|
$pconfig = $_POST;
|
83 |
|
|
|
84 |
|
|
/* input validation */
|
85 |
|
|
$reqdfields = explode(" ", "if mode");
|
86 |
eb8dacf3
|
Rafael Lucas
|
$reqdfieldsn = array(gettext("Parent interface"),gettext("Mode"));
|
87 |
9f428275
|
Erik Fonnesbeck
|
|
88 |
|
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
89 |
|
|
|
90 |
|
|
if (!$input_errors) {
|
91 |
|
|
$clone = array();
|
92 |
|
|
$clone['if'] = $_POST['if'];
|
93 |
|
|
$clone['mode'] = $_POST['mode'];
|
94 |
|
|
$clone['descr'] = $_POST['descr'];
|
95 |
|
|
|
96 |
|
|
if (isset($id) && $a_clones[$id]) {
|
97 |
|
|
if ($clone['if'] == $a_clones[$id]['if'])
|
98 |
|
|
$clone['cloneif'] = $a_clones[$id]['cloneif'];
|
99 |
|
|
}
|
100 |
|
|
if (!$clone['cloneif']) {
|
101 |
|
|
$clone_id = 1;
|
102 |
|
|
do {
|
103 |
|
|
$clone_exists = false;
|
104 |
|
|
$clone['cloneif'] = "{$_POST['if']}_wlan{$clone_id}";
|
105 |
|
|
foreach ($a_clones as $existing) {
|
106 |
|
|
if ($clone['cloneif'] == $existing['cloneif']) {
|
107 |
|
|
$clone_exists = true;
|
108 |
|
|
$clone_id++;
|
109 |
|
|
break;
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
} while ($clone_exists);
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
if (isset($id) && $a_clones[$id]) {
|
116 |
16120707
|
Erik Fonnesbeck
|
if (clone_inuse($id)) {
|
117 |
9f428275
|
Erik Fonnesbeck
|
if ($clone['if'] != $a_clones[$id]['if'])
|
118 |
eb8dacf3
|
Rafael Lucas
|
$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
|
119 |
9f428275
|
Erik Fonnesbeck
|
else if ($clone['mode'] != $a_clones[$id]['mode'])
|
120 |
eb8dacf3
|
Rafael Lucas
|
$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
|
121 |
82fccf3a
|
Erik Fonnesbeck
|
}
|
122 |
9f428275
|
Erik Fonnesbeck
|
}
|
123 |
|
|
if (!$input_errors) {
|
124 |
|
|
if (!interface_wireless_clone($clone['cloneif'], $clone)) {
|
125 |
ddc55e12
|
Erik Fonnesbeck
|
$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']);
|
126 |
9f428275
|
Erik Fonnesbeck
|
} else {
|
127 |
|
|
if (isset($id) && $a_clones[$id]) {
|
128 |
82fccf3a
|
Erik Fonnesbeck
|
if ($clone['if'] != $a_clones[$id]['if'])
|
129 |
|
|
mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
|
130 |
161e42f0
|
Carlos Eduardo Ramos
|
$input_errors[] = sprintf(gettext("Created with id %s"), $id);
|
131 |
9f428275
|
Erik Fonnesbeck
|
$a_clones[$id] = $clone;
|
132 |
|
|
} else {
|
133 |
eb8dacf3
|
Rafael Lucas
|
$input_errors[] = gettext("Created without id");
|
134 |
9f428275
|
Erik Fonnesbeck
|
$a_clones[] = $clone;
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
usort($a_clones, "clone_compare");
|
138 |
|
|
write_config();
|
139 |
|
|
|
140 |
|
|
header("Location: interfaces_wireless.php");
|
141 |
|
|
exit;
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
|
147 |
baca83aa
|
gnhb
|
$pgtitle = array(gettext("Interfaces"),gettext("Wireless"),gettext("Edit"));
|
148 |
9f428275
|
Erik Fonnesbeck
|
include("head.inc");
|
149 |
|
|
|
150 |
|
|
?>
|
151 |
|
|
|
152 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
153 |
|
|
<?php include("fbegin.inc"); ?>
|
154 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
155 |
|
|
<form action="interfaces_wireless_edit.php" method="post" name="iform" id="iform">
|
156 |
f04d6181
|
Colin Fleming
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces wireless edit">
|
157 |
9f428275
|
Erik Fonnesbeck
|
<tr>
|
158 |
eb8dacf3
|
Rafael Lucas
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Wireless clone configuration");?></td>
|
159 |
9f428275
|
Erik Fonnesbeck
|
</tr>
|
160 |
|
|
<tr>
|
161 |
eb8dacf3
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
|
162 |
9f428275
|
Erik Fonnesbeck
|
<td width="78%" class="vtable">
|
163 |
|
|
<select name="if" class="formselect">
|
164 |
|
|
<?php
|
165 |
|
|
foreach ($portlist as $ifn => $ifinfo)
|
166 |
94ca29a9
|
Erik Fonnesbeck
|
if (preg_match($g['wireless_regex'], $ifn)) {
|
167 |
9f428275
|
Erik Fonnesbeck
|
echo "<option value=\"{$ifn}\"";
|
168 |
|
|
if ($ifn == $pconfig['if'])
|
169 |
f04d6181
|
Colin Fleming
|
echo " selected=\"selected\"";
|
170 |
9f428275
|
Erik Fonnesbeck
|
echo ">";
|
171 |
|
|
echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
|
172 |
|
|
echo "</option>";
|
173 |
|
|
}
|
174 |
|
|
?>
|
175 |
|
|
</select></td>
|
176 |
|
|
</tr>
|
177 |
|
|
<tr>
|
178 |
eb8dacf3
|
Rafael Lucas
|
<td valign="top" class="vncellreq"><?=gettext("Mode");?></td>
|
179 |
9f428275
|
Erik Fonnesbeck
|
<td class="vtable">
|
180 |
|
|
<select name="mode" class="formselect">
|
181 |
f04d6181
|
Colin Fleming
|
<option <?php if ($pconfig['mode'] == 'bss') echo "selected=\"selected\"";?> value="bss"><?=gettext("Infrastructure (BSS)");?></option>
|
182 |
|
|
<option <?php if ($pconfig['mode'] == 'adhoc') echo "selected=\"selected\"";?> value="adhoc"><?=gettext("Ad-hoc (IBSS)");?></option>
|
183 |
|
|
<option <?php if ($pconfig['mode'] == 'hostap') echo "selected=\"selected\"";?> value="hostap"><?=gettext("Access Point");?></option>
|
184 |
9f428275
|
Erik Fonnesbeck
|
</select></td>
|
185 |
|
|
</tr>
|
186 |
|
|
<tr>
|
187 |
eb8dacf3
|
Rafael Lucas
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
188 |
9f428275
|
Erik Fonnesbeck
|
<td width="78%" class="vtable">
|
189 |
f04d6181
|
Colin Fleming
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
190 |
|
|
<br/> <span class="vexpl"><?=gettext("You may enter a description here ".
|
191 |
eb8dacf3
|
Rafael Lucas
|
"for your reference (not parsed).");?></span></td>
|
192 |
9f428275
|
Erik Fonnesbeck
|
</tr>
|
193 |
|
|
<tr>
|
194 |
|
|
<td width="22%" valign="top"> </td>
|
195 |
|
|
<td width="78%">
|
196 |
f04d6181
|
Colin Fleming
|
<input type="hidden" name="cloneif" value="<?=htmlspecialchars($pconfig['cloneif']); ?>" />
|
197 |
|
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> <input type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
|
198 |
9f428275
|
Erik Fonnesbeck
|
<?php if (isset($id) && $a_clones[$id]): ?>
|
199 |
f04d6181
|
Colin Fleming
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
200 |
9f428275
|
Erik Fonnesbeck
|
<?php endif; ?>
|
201 |
|
|
</td>
|
202 |
|
|
</tr>
|
203 |
|
|
</table>
|
204 |
|
|
</form>
|
205 |
|
|
<?php include("fend.inc"); ?>
|
206 |
|
|
</body>
|
207 |
|
|
</html>
|