Projet

Général

Profil

Télécharger (7,82 ko) Statistiques
| Branche: | Tag: | Révision:

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

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

    
89
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
90

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