Project

General

Profile

Download (8.04 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces_wireless_edit.php
5

    
6
	Copyright (C) 2010 Erik Fonnesbeck
7
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
8
	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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_wireless.php');
45

    
46
if (!is_array($config['wireless']))
47
	$config['wireless'] = array();
48
if (!is_array($config['wireless']['clone']))
49
	$config['wireless']['clone'] = array();
50

    
51
$a_clones = &$config['wireless']['clone'];
52

    
53
function clone_inuse($num) {
54
	global $config, $a_clones;
55

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

    
62
	return false;
63
}
64

    
65
function clone_compare($a, $b) {
66
	return strnatcmp($a['cloneif'], $b['cloneif']);
67
}
68

    
69
$portlist = get_interface_list();
70

    
71
if (is_numericint($_GET['id']))
72
	$id = $_GET['id'];
73
if (isset($_POST['id']) && is_numericint($_POST['id']))
74
	$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
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Mode"));
91

    
92
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
93

    
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
			if (clone_inuse($id)) {
121
				if ($clone['if'] != $a_clones[$id]['if'])
122
					$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
123
				else if ($clone['mode'] != $a_clones[$id]['mode'])
124
					$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
125
			}
126
		}
127
		if (!$input_errors) {
128
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
129
				$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
			} else {
131
				if (isset($id) && $a_clones[$id]) {
132
					if ($clone['if'] != $a_clones[$id]['if'])
133
						mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
134
					$input_errors[] = sprintf(gettext("Created with id %s"), $id);
135
					$a_clones[$id] = $clone;
136
				} else {
137
					$input_errors[] = gettext("Created without id");
138
					$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
$pgtitle = array(gettext("Interfaces"),gettext("Wireless"),gettext("Edit"));
152
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
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces wireless edit">
161
                <tr>
162
                  <td colspan="2" valign="top" class="listtopic"><?=gettext("Wireless clone configuration");?></td>
163
                </tr>
164
                <tr>
165
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
166
                  <td width="78%" class="vtable">
167
                    <select name="if" class="formselect">
168
                      <?php
169
                      foreach ($portlist as $ifn => $ifinfo)
170
                        if (preg_match($g['wireless_regex'], $ifn)) {
171
                            echo "<option value=\"{$ifn}\"";
172
                            if ($ifn == $pconfig['if'])
173
                                echo " selected=\"selected\"";
174
                            echo ">";
175
                            echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
176
                            echo "</option>";
177
                        }
178
                      ?>
179
                    </select></td>
180
                </tr>
181
                <tr>
182
                  <td valign="top" class="vncellreq"><?=gettext("Mode");?></td>
183
                  <td class="vtable">
184
                    <select name="mode" class="formselect">
185
                      <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
                    </select></td>
189
                </tr>
190
                <tr>
191
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
192
                  <td width="78%" class="vtable">
193
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
194
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
195
                    "for your reference (not parsed).");?></span></td>
196
                </tr>
197
                <tr>
198
                  <td width="22%" valign="top">&nbsp;</td>
199
                  <td width="78%">
200
                    <input type="hidden" name="cloneif" value="<?=htmlspecialchars($pconfig['cloneif']); ?>" />
201
                    <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
                    <?php if (isset($id) && $a_clones[$id]): ?>
204
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
205
                    <?php endif; ?>
206
                  </td>
207
                </tr>
208
              </table>
209
</form>
210
<?php include("fend.inc"); ?>
211
</body>
212
</html>
(114-114/256)