Project

General

Profile

Download (7.59 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($num) {
49
	global $config, $a_clones;
50

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

    
57
	return false;
58
}
59

    
60
function clone_compare($a, $b) {
61
	return strnatcmp($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 = array(gettext("Parent interface"),gettext("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($id)) {
115
				if ($clone['if'] != $a_clones[$id]['if'])
116
					$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
117
				else if ($clone['mode'] != $a_clones[$id]['mode'])
118
					$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
119
			}
120
		}
121
		if (!$input_errors) {
122
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
123
				$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']);
124
			} else {
125
				if (isset($id) && $a_clones[$id]) {
126
					if ($clone['if'] != $a_clones[$id]['if'])
127
						mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
128
					$input_errors[] = sprintf(gettext("Created with id %s"), $id);
129
					$a_clones[$id] = $clone;
130
				} else {
131
					$input_errors[] = gettext("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(gettext("Firewall"),gettext("Wireless"),gettext("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"><?=gettext("Wireless clone configuration");?></td>
157
                </tr>
158
                <tr>
159
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
160
                  <td width="78%" class="vtable">
161
                    <select name="if" class="formselect">
162
                      <?php
163
                      foreach ($portlist as $ifn => $ifinfo)
164
                        if (preg_match($g['wireless_regex'], $ifn)) {
165
                            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"><?=gettext("Mode");?></td>
177
                  <td class="vtable">
178
                    <select name="mode" class="formselect">
179
                      <option <? if ($pconfig['mode'] == 'bss') echo "selected";?> value="bss"><?=gettext("Infrastructure (BSS)");?></option>
180
                      <option <? if ($pconfig['mode'] == 'adhoc') echo "selected";?> value="adhoc"><?=gettext("Ad-hoc (IBSS)");?></option>
181
                      <option <? if ($pconfig['mode'] == 'hostap') echo "selected";?> value="hostap"><?=gettext("Access Point");?></option>
182
                    </select></td>
183
                </tr>
184
                <tr>
185
                  <td width="22%" valign="top" class="vncell"><?=gettext("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"><?=gettext("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="<?=htmlspecialchars($pconfig['cloneif']); ?>">
195
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
196
                    <?php if (isset($id) && $a_clones[$id]): ?>
197
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
198
                    <?php endif; ?>
199
                  </td>
200
                </tr>
201
              </table>
202
</form>
203
<?php include("fend.inc"); ?>
204
</body>
205
</html>
(100-100/220)