Project

General

Profile

Download (8.03 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 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8 9f428275 Erik Fonnesbeck
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE:	interfaces
33
*/
34
35
##|+PRIV
36
##|*IDENT=page-interfaces-wireless-edit
37
##|*NAME=Interfaces: Wireless edit page
38
##|*DESCR=Allow access to the 'Interfaces: Wireless : Edit' page.
39
##|*MATCH=interfaces_wireless_edit.php*
40
##|-PRIV
41
42
require("guiconfig.inc");
43
44 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_wireless.php');
45
46 6ef2297b Erik Fonnesbeck
if (!is_array($config['wireless']))
47
	$config['wireless'] = array();
48 9f428275 Erik Fonnesbeck
if (!is_array($config['wireless']['clone']))
49
	$config['wireless']['clone'] = array();
50
51
$a_clones = &$config['wireless']['clone'];
52
53 16120707 Erik Fonnesbeck
function clone_inuse($num) {
54
	global $config, $a_clones;
55 9f428275 Erik Fonnesbeck
56 38b7d47d Erik Fonnesbeck
	$iflist = get_configured_interface_list(false, true);
57 9f428275 Erik Fonnesbeck
	foreach ($iflist as $if) {
58 16120707 Erik Fonnesbeck
		if ($config['interfaces'][$if]['if'] == $a_clones[$num]['cloneif'])
59 9f428275 Erik Fonnesbeck
			return true;
60
	}
61
62
	return false;
63
}
64
65
function clone_compare($a, $b) {
66 992ff4c2 Erik Fonnesbeck
	return strnatcmp($a['cloneif'], $b['cloneif']);
67 9f428275 Erik Fonnesbeck
}
68
69
$portlist = get_interface_list();
70
71 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
72
	$id = $_GET['id'];
73
if (isset($_POST['id']) && is_numericint($_POST['id']))
74 9f428275 Erik Fonnesbeck
	$id = $_POST['id'];
75
76
if (isset($id) && $a_clones[$id]) {
77
	$pconfig['if'] = $a_clones[$id]['if'];
78
	$pconfig['cloneif'] = $a_clones[$id]['cloneif'];
79
	$pconfig['mode'] = $a_clones[$id]['mode'];
80
	$pconfig['descr'] = $a_clones[$id]['descr'];
81
}
82
83
if ($_POST) {
84
85
	unset($input_errors);
86
	$pconfig = $_POST;
87
88
	/* input validation */
89
	$reqdfields = explode(" ", "if mode");
90 eb8dacf3 Rafael Lucas
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Mode"));
91 9f428275 Erik Fonnesbeck
92 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
93 9f428275 Erik Fonnesbeck
94
	if (!$input_errors) {
95
		$clone = array();
96
		$clone['if'] = $_POST['if'];
97
		$clone['mode'] = $_POST['mode'];
98
		$clone['descr'] = $_POST['descr'];
99
100
		if (isset($id) && $a_clones[$id]) {
101
			if ($clone['if'] == $a_clones[$id]['if'])
102
				$clone['cloneif'] = $a_clones[$id]['cloneif'];
103
		}
104
		if (!$clone['cloneif']) {
105
			$clone_id = 1;
106
			do {
107
				$clone_exists = false;
108
				$clone['cloneif'] = "{$_POST['if']}_wlan{$clone_id}";
109
				foreach ($a_clones as $existing) {
110
					if ($clone['cloneif'] == $existing['cloneif']) {
111
						$clone_exists = true;
112
						$clone_id++;
113
						break;
114
					}
115
				}
116
			} while ($clone_exists);
117
		}
118
119
		if (isset($id) && $a_clones[$id]) {
120 16120707 Erik Fonnesbeck
			if (clone_inuse($id)) {
121 9f428275 Erik Fonnesbeck
				if ($clone['if'] != $a_clones[$id]['if'])
122 eb8dacf3 Rafael Lucas
					$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
123 9f428275 Erik Fonnesbeck
				else if ($clone['mode'] != $a_clones[$id]['mode'])
124 eb8dacf3 Rafael Lucas
					$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
125 82fccf3a Erik Fonnesbeck
			}
126 9f428275 Erik Fonnesbeck
		}
127
		if (!$input_errors) {
128
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
129 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']);
130 9f428275 Erik Fonnesbeck
			} else {
131
				if (isset($id) && $a_clones[$id]) {
132 82fccf3a Erik Fonnesbeck
					if ($clone['if'] != $a_clones[$id]['if'])
133
						mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
134 161e42f0 Carlos Eduardo Ramos
					$input_errors[] = sprintf(gettext("Created with id %s"), $id);
135 9f428275 Erik Fonnesbeck
					$a_clones[$id] = $clone;
136
				} else {
137 eb8dacf3 Rafael Lucas
					$input_errors[] = gettext("Created without id");
138 9f428275 Erik Fonnesbeck
					$a_clones[] = $clone;
139
				}
140
141
				usort($a_clones, "clone_compare");
142
				write_config();
143
144
				header("Location: interfaces_wireless.php");
145
				exit;
146
			}
147
		}
148
	}
149
}
150
151 baca83aa gnhb
$pgtitle = array(gettext("Interfaces"),gettext("Wireless"),gettext("Edit"));
152 9f428275 Erik Fonnesbeck
include("head.inc");
153
154
?>
155
156
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
157
<?php include("fbegin.inc"); ?>
158
<?php if ($input_errors) print_input_errors($input_errors); ?>
159
            <form action="interfaces_wireless_edit.php" method="post" name="iform" id="iform">
160 f04d6181 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces wireless edit">
161 9f428275 Erik Fonnesbeck
                <tr>
162 eb8dacf3 Rafael Lucas
                  <td colspan="2" valign="top" class="listtopic"><?=gettext("Wireless clone configuration");?></td>
163 9f428275 Erik Fonnesbeck
                </tr>
164
                <tr>
165 eb8dacf3 Rafael Lucas
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
166 9f428275 Erik Fonnesbeck
                  <td width="78%" class="vtable">
167
                    <select name="if" class="formselect">
168
                      <?php
169
                      foreach ($portlist as $ifn => $ifinfo)
170 94ca29a9 Erik Fonnesbeck
                        if (preg_match($g['wireless_regex'], $ifn)) {
171 9f428275 Erik Fonnesbeck
                            echo "<option value=\"{$ifn}\"";
172
                            if ($ifn == $pconfig['if'])
173 f04d6181 Colin Fleming
                                echo " selected=\"selected\"";
174 9f428275 Erik Fonnesbeck
                            echo ">";
175
                            echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
176
                            echo "</option>";
177
                        }
178
                      ?>
179
                    </select></td>
180
                </tr>
181
                <tr>
182 eb8dacf3 Rafael Lucas
                  <td valign="top" class="vncellreq"><?=gettext("Mode");?></td>
183 9f428275 Erik Fonnesbeck
                  <td class="vtable">
184
                    <select name="mode" class="formselect">
185 f04d6181 Colin Fleming
                      <option <?php if ($pconfig['mode'] == 'bss') echo "selected=\"selected\"";?> value="bss"><?=gettext("Infrastructure (BSS)");?></option>
186
                      <option <?php if ($pconfig['mode'] == 'adhoc') echo "selected=\"selected\"";?> value="adhoc"><?=gettext("Ad-hoc (IBSS)");?></option>
187
                      <option <?php if ($pconfig['mode'] == 'hostap') echo "selected=\"selected\"";?> value="hostap"><?=gettext("Access Point");?></option>
188 9f428275 Erik Fonnesbeck
                    </select></td>
189
                </tr>
190
                <tr>
191 eb8dacf3 Rafael Lucas
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
192 9f428275 Erik Fonnesbeck
                  <td width="78%" class="vtable">
193 f04d6181 Colin Fleming
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
194 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
195 eb8dacf3 Rafael Lucas
                    "for your reference (not parsed).");?></span></td>
196 9f428275 Erik Fonnesbeck
                </tr>
197
                <tr>
198
                  <td width="22%" valign="top">&nbsp;</td>
199
                  <td width="78%">
200 f04d6181 Colin Fleming
                    <input type="hidden" name="cloneif" value="<?=htmlspecialchars($pconfig['cloneif']); ?>" />
201 62424bdb Renato Botelho
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
202
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
203 9f428275 Erik Fonnesbeck
                    <?php if (isset($id) && $a_clones[$id]): ?>
204 f04d6181 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
205 9f428275 Erik Fonnesbeck
                    <?php endif; ?>
206
                  </td>
207
                </tr>
208
              </table>
209
</form>
210
<?php include("fend.inc"); ?>
211
</body>
212
</html>