Project

General

Profile

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