Project

General

Profile

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