Project

General

Profile

Download (7.76 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']))
44
	$config['wireless'] = array();
45
if (!is_array($config['wireless']['clone']))
46
	$config['wireless']['clone'] = array();
47

    
48
$a_clones = &$config['wireless']['clone'];
49

    
50
function clone_inuse($num) {
51
	global $config, $a_clones;
52

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

    
59
	return false;
60
}
61

    
62
function clone_compare($a, $b) {
63
	return strnatcmp($a['cloneif'], $b['cloneif']);
64
}
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
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Mode"));
87

    
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
			if (clone_inuse($id)) {
117
				if ($clone['if'] != $a_clones[$id]['if'])
118
					$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
119
				else if ($clone['mode'] != $a_clones[$id]['mode'])
120
					$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
121
			}
122
		}
123
		if (!$input_errors) {
124
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
125
				$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
			} else {
127
				if (isset($id) && $a_clones[$id]) {
128
					if ($clone['if'] != $a_clones[$id]['if'])
129
						mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
130
					$input_errors[] = sprintf(gettext("Created with id %s"), $id);
131
					$a_clones[$id] = $clone;
132
				} else {
133
					$input_errors[] = gettext("Created without id");
134
					$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
$pgtitle = array(gettext("Interfaces"),gettext("Wireless"),gettext("Edit"));
148
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
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces wireless edit">
157
                <tr>
158
                  <td colspan="2" valign="top" class="listtopic"><?=gettext("Wireless clone configuration");?></td>
159
                </tr>
160
                <tr>
161
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
162
                  <td width="78%" class="vtable">
163
                    <select name="if" class="formselect">
164
                      <?php
165
                      foreach ($portlist as $ifn => $ifinfo)
166
                        if (preg_match($g['wireless_regex'], $ifn)) {
167
                            echo "<option value=\"{$ifn}\"";
168
                            if ($ifn == $pconfig['if'])
169
                                echo " selected=\"selected\"";
170
                            echo ">";
171
                            echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
172
                            echo "</option>";
173
                        }
174
                      ?>
175
                    </select></td>
176
                </tr>
177
                <tr>
178
                  <td valign="top" class="vncellreq"><?=gettext("Mode");?></td>
179
                  <td class="vtable">
180
                    <select name="mode" class="formselect">
181
                      <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
                    </select></td>
185
                </tr>
186
                <tr>
187
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
188
                  <td width="78%" class="vtable">
189
                    <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
                    "for your reference (not parsed).");?></span></td>
192
                </tr>
193
                <tr>
194
                  <td width="22%" valign="top">&nbsp;</td>
195
                  <td width="78%">
196
                    <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
                    <?php if (isset($id) && $a_clones[$id]): ?>
199
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
200
                    <?php endif; ?>
201
                  </td>
202
                </tr>
203
              </table>
204
</form>
205
<?php include("fend.inc"); ?>
206
</body>
207
</html>
(112-112/246)