Project

General

Profile

Download (7.98 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / interfaces_wireless_edit.php @ a1b66bec

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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_wireless.php');
44

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

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

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

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

    
61
	return false;
62
}
63

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

    
68
$portlist = get_interface_list();
69

    
70
if (is_numericint($_GET['id']))
71
	$id = $_GET['id'];
72
if (isset($_POST['id']) && is_numericint($_POST['id']))
73
	$id = $_POST['id'];
74

    
75
if (isset($id) && $a_clones[$id]) {
76
	$pconfig['if'] = $a_clones[$id]['if'];
77
	$pconfig['cloneif'] = $a_clones[$id]['cloneif'];
78
	$pconfig['mode'] = $a_clones[$id]['mode'];
79
	$pconfig['descr'] = $a_clones[$id]['descr'];
80
}
81

    
82
if ($_POST) {
83

    
84
	unset($input_errors);
85
	$pconfig = $_POST;
86

    
87
	/* input validation */
88
	$reqdfields = explode(" ", "if mode");
89
	$reqdfieldsn = array(gettext("Parent interface"),gettext("Mode"));
90

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

    
93
	if (!$input_errors) {
94
		$clone = array();
95
		$clone['if'] = $_POST['if'];
96
		$clone['mode'] = $_POST['mode'];
97
		$clone['descr'] = $_POST['descr'];
98

    
99
		if (isset($id) && $a_clones[$id]) {
100
			if ($clone['if'] == $a_clones[$id]['if'])
101
				$clone['cloneif'] = $a_clones[$id]['cloneif'];
102
		}
103
		if (!$clone['cloneif']) {
104
			$clone_id = 1;
105
			do {
106
				$clone_exists = false;
107
				$clone['cloneif'] = "{$_POST['if']}_wlan{$clone_id}";
108
				foreach ($a_clones as $existing) {
109
					if ($clone['cloneif'] == $existing['cloneif']) {
110
						$clone_exists = true;
111
						$clone_id++;
112
						break;
113
					}
114
				}
115
			} while ($clone_exists);
116
		}
117

    
118
		if (isset($id) && $a_clones[$id]) {
119
			if (clone_inuse($id)) {
120
				if ($clone['if'] != $a_clones[$id]['if'])
121
					$input_errors[] = gettext("This wireless clone cannot be modified because it is still assigned as an interface.");
122
				else if ($clone['mode'] != $a_clones[$id]['mode'])
123
					$input_errors[] = gettext("Use the configuration page for the assigned interface to change the mode.");
124
			}
125
		}
126
		if (!$input_errors) {
127
			if (!interface_wireless_clone($clone['cloneif'], $clone)) {
128
				$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']);
129
			} else {
130
				if (isset($id) && $a_clones[$id]) {
131
					if ($clone['if'] != $a_clones[$id]['if'])
132
						mwexec("/sbin/ifconfig " . $a_clones[$id]['cloneif'] . " destroy");
133
					$input_errors[] = sprintf(gettext("Created with id %s"), $id);
134
					$a_clones[$id] = $clone;
135
				} else {
136
					$input_errors[] = gettext("Created without id");
137
					$a_clones[] = $clone;
138
				}
139

    
140
				usort($a_clones, "clone_compare");
141
				write_config();
142

    
143
				header("Location: interfaces_wireless.php");
144
				exit;
145
			}
146
		}
147
	}
148
}
149

    
150
$pgtitle = array(gettext("Interfaces"),gettext("Wireless"),gettext("Edit"));
151
include("head.inc");
152

    
153
?>
154

    
155
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
156
<?php include("fbegin.inc"); ?>
157
<?php if ($input_errors) print_input_errors($input_errors); ?>
158
            <form action="interfaces_wireless_edit.php" method="post" name="iform" id="iform">
159
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces wireless edit">
160
                <tr>
161
                  <td colspan="2" valign="top" class="listtopic"><?=gettext("Wireless clone configuration");?></td>
162
                </tr>
163
                <tr>
164
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("Parent interface");?></td>
165
                  <td width="78%" class="vtable">
166
                    <select name="if" class="formselect">
167
                      <?php
168
                      foreach ($portlist as $ifn => $ifinfo)
169
                        if (preg_match($g['wireless_regex'], $ifn)) {
170
                            echo "<option value=\"{$ifn}\"";
171
                            if ($ifn == $pconfig['if'])
172
                                echo " selected=\"selected\"";
173
                            echo ">";
174
                            echo htmlspecialchars($ifn . " (" . $ifinfo['mac'] . ")");
175
                            echo "</option>";
176
                        }
177
                      ?>
178
                    </select></td>
179
                </tr>
180
                <tr>
181
                  <td valign="top" class="vncellreq"><?=gettext("Mode");?></td>
182
                  <td class="vtable">
183
                    <select name="mode" class="formselect">
184
                      <option <?php if ($pconfig['mode'] == 'bss') echo "selected=\"selected\"";?> value="bss"><?=gettext("Infrastructure (BSS)");?></option>
185
                      <option <?php if ($pconfig['mode'] == 'adhoc') echo "selected=\"selected\"";?> value="adhoc"><?=gettext("Ad-hoc (IBSS)");?></option>
186
                      <option <?php if ($pconfig['mode'] == 'hostap') echo "selected=\"selected\"";?> value="hostap"><?=gettext("Access Point");?></option>
187
                    </select></td>
188
                </tr>
189
                <tr>
190
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
191
                  <td width="78%" class="vtable">
192
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
193
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
194
                    "for your reference (not parsed).");?></span></td>
195
                </tr>
196
                <tr>
197
                  <td width="22%" valign="top">&nbsp;</td>
198
                  <td width="78%">
199
                    <input type="hidden" name="cloneif" value="<?=htmlspecialchars($pconfig['cloneif']); ?>" />
200
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
201
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
202
                    <?php if (isset($id) && $a_clones[$id]): ?>
203
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
204
                    <?php endif; ?>
205
                  </td>
206
                </tr>
207
              </table>
208
</form>
209
<?php include("fend.inc"); ?>
210
</body>
211
</html>
(114-114/256)