Project

General

Profile

Download (7.36 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
function clone_inuse($cloneif) {
49
	global $config;
50

    
51
	$iflist = get_configured_interface_list(false, true);
52
	foreach ($iflist as $if) {
53
		if ($config['interfaces'][$if]['if'] == $cloneif)
54
			return true;
55
	}
56

    
57
	return false;
58
}
59

    
60
function clone_compare($a, $b) {
61
	return strcmp($a['cloneif'], $b['cloneif']);
62
}
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
			if (clone_inuse($a_clones[$id]['if'])) {
115
				if ($clone['if'] != $a_clones[$id]['if'])
116
					$input_errors[] = "This wireless clone cannot be modified because it is still being used as an interface.";
117
				else if ($clone['mode'] != $a_clones[$id]['mode'])
118
					$input_errors[] = "Use the configuration page for the assigned interface to change the mode.";
119
			} else if ($clone['if'] != $a_clones[$id]['if'])
120
				$input_errors[] = "Changing the parent interface is not currently supported.  Create a new clone on the new parent and delete the old clone on the previous parent.";
121
		}
122
		if (!$input_errors) {
123
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
124
				$input_errors[] = "Error creating interface with mode {$clone['mode']}.  The {$clone['if']} interface may not support creating more clones with the selected mode.";
125
			} else {
126
				if (isset($id) && $a_clones[$id]) {
127
					$input_errors[] = "Created with id {$id}";
128
					$a_clones[$id] = $clone;
129
				} else {
130
					$input_errors[] = "Created without id";
131
					$a_clones[] = $clone;
132
				}
133

    
134
				usort($a_clones, "clone_compare");
135
				write_config();
136

    
137
				header("Location: interfaces_wireless.php");
138
				exit;
139
			}
140
		}
141
	}
142
}
143

    
144
$pgtitle = array("Firewall","Wireless","Edit");
145
include("head.inc");
146

    
147
?>
148

    
149
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
150
<?php include("fbegin.inc"); ?>
151
<?php if ($input_errors) print_input_errors($input_errors); ?>
152
            <form action="interfaces_wireless_edit.php" method="post" name="iform" id="iform">
153
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
154
                <tr>
155
                  <td colspan="2" valign="top" class="listtopic">Wireless clone configuration</td>
156
                </tr>
157
                <tr>
158
                  <td width="22%" valign="top" class="vncellreq">Parent interface</td>
159
                  <td width="78%" class="vtable">
160
                    <select name="if" class="formselect">
161
                      <?php
162
                      foreach ($portlist as $ifn => $ifinfo)
163
                        if (is_interface_wireless($ifn) && !stristr($ifn, "_wlan")) {
164
                            echo "<option value=\"{$ifn}\"";
165
                            if ($ifn == $pconfig['if'])
166
                                echo "selected";
167
                            echo ">";
168
                            echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
169
                            echo "</option>";
170
                        }
171
                      ?>
172
                    </select></td>
173
                </tr>
174
                <tr>
175
                  <td valign="top" class="vncellreq">Mode</td>
176
                  <td class="vtable">
177
                    <select name="mode" class="formselect">
178
                      <option <? if ($pconfig['mode'] == 'bss') echo "selected";?> value="bss">Infrastructure (BSS)</option>
179
                      <option <? if ($pconfig['mode'] == 'adhoc') echo "selected";?> value="adhoc">Ad-hoc (IBSS)</option>
180
                      <option <? if ($pconfig['mode'] == 'hostap') echo "selected";?> value="hostap">Access Point</option>
181
                    </select></td>
182
                </tr>
183
                <tr>
184
                  <td width="22%" valign="top" class="vncell">Description</td>
185
                  <td width="78%" class="vtable">
186
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
187
                    <br> <span class="vexpl">You may enter a description here
188
                    for your reference (not parsed).</span></td>
189
                </tr>
190
                <tr>
191
                  <td width="22%" valign="top">&nbsp;</td>
192
                  <td width="78%">
193
                    <input type="hidden" name="cloneif" value="<?=$pconfig['cloneif']; ?>">
194
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" value="Cancel" onclick="history.back()">
195
                    <?php if (isset($id) && $a_clones[$id]): ?>
196
                    <input name="id" type="hidden" value="<?=$id;?>">
197
                    <?php endif; ?>
198
                  </td>
199
                </tr>
200
              </table>
201
</form>
202
<?php include("fend.inc"); ?>
203
</body>
204
</html>
(98-98/217)