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 (isset($_POST['referer'])) {
|
45
|
$referer = $_POST['referer'];
|
46
|
} else {
|
47
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_wireless.php');
|
48
|
}
|
49
|
|
50
|
if (!is_array($config['wireless'])) {
|
51
|
$config['wireless'] = array();
|
52
|
}
|
53
|
if (!is_array($config['wireless']['clone'])) {
|
54
|
$config['wireless']['clone'] = array();
|
55
|
}
|
56
|
|
57
|
$a_clones = &$config['wireless']['clone'];
|
58
|
|
59
|
function clone_inuse($num) {
|
60
|
global $config, $a_clones;
|
61
|
|
62
|
$iflist = get_configured_interface_list(false, true);
|
63
|
foreach ($iflist as $if) {
|
64
|
if ($config['interfaces'][$if]['if'] == $a_clones[$num]['cloneif']) {
|
65
|
return true;
|
66
|
}
|
67
|
}
|
68
|
|
69
|
return false;
|
70
|
}
|
71
|
|
72
|
function clone_compare($a, $b) {
|
73
|
return strnatcmp($a['cloneif'], $b['cloneif']);
|
74
|
}
|
75
|
|
76
|
$portlist = get_interface_list();
|
77
|
|
78
|
if (is_numericint($_GET['id'])) {
|
79
|
$id = $_GET['id'];
|
80
|
}
|
81
|
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
|
82
|
$id = $_POST['id'];
|
83
|
}
|
84
|
|
85
|
if (isset($id) && $a_clones[$id]) {
|
86
|
$pconfig['if'] = $a_clones[$id]['if'];
|
87
|
$pconfig['cloneif'] = $a_clones[$id]['cloneif'];
|
88
|
$pconfig['mode'] = $a_clones[$id]['mode'];
|
89
|
$pconfig['descr'] = $a_clones[$id]['descr'];
|
90
|
}
|
91
|
|
92
|
if ($_POST) {
|
93
|
|
94
|
unset($input_errors);
|
95
|
$pconfig = $_POST;
|
96
|
|
97
|
/* input validation */
|
98
|
$reqdfields = explode(" ", "if mode");
|
99
|
$reqdfieldsn = array(gettext("Parent interface"), gettext("Mode"));
|
100
|
|
101
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
102
|
|
103
|
if (!$input_errors) {
|
104
|
$clone = array();
|
105
|
$clone['if'] = $_POST['if'];
|
106
|
$clone['mode'] = $_POST['mode'];
|
107
|
$clone['descr'] = $_POST['descr'];
|
108
|
|
109
|
if (isset($id) && $a_clones[$id]) {
|
110
|
if ($clone['if'] == $a_clones[$id]['if']) {
|
111
|
$clone['cloneif'] = $a_clones[$id]['cloneif'];
|
112
|
}
|
113
|
}
|
114
|
if (!$clone['cloneif']) {
|
115
|
$clone_id = 1;
|
116
|
do {
|
117
|
$clone_exists = false;
|
118
|
$clone['cloneif'] = "{$_POST['if']}_wlan{$clone_id}";
|
119
|
foreach ($a_clones as $existing) {
|
120
|
if ($clone['cloneif'] == $existing['cloneif']) {
|
121
|
$clone_exists = true;
|
122
|
$clone_id++;
|
123
|
break;
|
124
|
}
|
125
|
}
|
126
|
} while ($clone_exists);
|
127
|
}
|
128
|
|
129
|
if (isset($id) && $a_clones[$id]) {
|
130
|
if (clone_inuse($id)) {
|
131
|
if ($clone['if'] != $a_clones[$id]['if']) {
|
132
|
$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
|
133
|
} else if ($clone['mode'] != $a_clones[$id]['mode']) {
|
134
|
$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
if (!$input_errors) {
|
139
|
if (!interface_wireless_clone($clone['cloneif'], $clone)) {
|
140
|
$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']);
|
141
|
} else {
|
142
|
if (isset($id) && $a_clones[$id]) {
|
143
|
if ($clone['if'] != $a_clones[$id]['if']) {
|
144
|
mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
|
145
|
}
|
146
|
$input_errors[] = sprintf(gettext("Created with id %s"), $id);
|
147
|
$a_clones[$id] = $clone;
|
148
|
} else {
|
149
|
$input_errors[] = gettext("Created without id");
|
150
|
$a_clones[] = $clone;
|
151
|
}
|
152
|
|
153
|
usort($a_clones, "clone_compare");
|
154
|
write_config();
|
155
|
|
156
|
header("Location: interfaces_wireless.php");
|
157
|
exit;
|
158
|
}
|
159
|
}
|
160
|
}
|
161
|
}
|
162
|
|
163
|
$pgtitle = array(gettext("Interfaces"), gettext("Wireless"), gettext("Edit"));
|
164
|
include("head.inc");
|
165
|
|
166
|
?>
|
167
|
|
168
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
169
|
<?php include("fbegin.inc"); ?>
|
170
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
171
|
<form action="interfaces_wireless_edit.php" method="post" name="iform" id="iform">
|
172
|
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces wireless edit">
|
173
|
<tr>
|
174
|
<td colspan="2" valign="top" class="listtopic"><?=gettext("Wireless clone configuration");?></td>
|
175
|
</tr>
|
176
|
<tr>
|
177
|
<td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
|
178
|
<td width="78%" class="vtable">
|
179
|
<select name="if" class="formselect">
|
180
|
<?php
|
181
|
foreach ($portlist as $ifn => $ifinfo) {
|
182
|
if (preg_match($g['wireless_regex'], $ifn)) {
|
183
|
echo "<option value=\"{$ifn}\"";
|
184
|
if ($ifn == $pconfig['if']) {
|
185
|
echo " selected=\"selected\"";
|
186
|
}
|
187
|
echo ">";
|
188
|
echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
|
189
|
echo "</option>";
|
190
|
}
|
191
|
}
|
192
|
?>
|
193
|
</select>
|
194
|
</td>
|
195
|
</tr>
|
196
|
<tr>
|
197
|
<td valign="top" class="vncellreq"><?=gettext("Mode");?></td>
|
198
|
<td class="vtable">
|
199
|
<select name="mode" class="formselect">
|
200
|
<option <?php if ($pconfig['mode'] == 'bss') echo "selected=\"selected\"";?> value="bss"><?=gettext("Infrastructure (BSS)");?></option>
|
201
|
<option <?php if ($pconfig['mode'] == 'adhoc') echo "selected=\"selected\"";?> value="adhoc"><?=gettext("Ad-hoc (IBSS)");?></option>
|
202
|
<option <?php if ($pconfig['mode'] == 'hostap') echo "selected=\"selected\"";?> value="hostap"><?=gettext("Access Point");?></option>
|
203
|
</select>
|
204
|
</td>
|
205
|
</tr>
|
206
|
<tr>
|
207
|
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
208
|
<td width="78%" class="vtable">
|
209
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
|
210
|
<br />
|
211
|
<span class="vexpl"><?=gettext("You may enter a description here for your reference (not parsed).");?></span>
|
212
|
</td>
|
213
|
</tr>
|
214
|
<tr>
|
215
|
<td width="22%" valign="top"> </td>
|
216
|
<td width="78%">
|
217
|
<input type="hidden" name="cloneif" value="<?=htmlspecialchars($pconfig['cloneif']); ?>" />
|
218
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
|
219
|
<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
|
220
|
<input name="referer" type="hidden" value="<?=$referer;?>" />
|
221
|
<?php if (isset($id) && $a_clones[$id]): ?>
|
222
|
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
|
223
|
<?php endif; ?>
|
224
|
</td>
|
225
|
</tr>
|
226
|
</table>
|
227
|
</form>
|
228
|
<?php include("fend.inc"); ?>
|
229
|
</body>
|
230
|
</html>
|