Projet

Général

Profil

Télécharger (11,1 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / interfaces_groups_edit.php @ 36b9bb28

1 0ec2fdf0 Ermal Lu?i
<?php
2
/*
3 1d7ba683 ayvis
	Copyright (C) 2009 Ermal Luçi
4 0ec2fdf0 Ermal Lu?i
	Copyright (C) 2004 Scott Ullrich
5
	All rights reserved.
6
7
	Redistribution and use in source and binary forms, with or without
8
	modification, are permitted provided that the following conditions are met:
9
10
	1. Redistributions of source code must retain the above copyright notice,
11
	   this list of conditions and the following disclaimer.
12
13
	2. Redistributions in binary form must reproduce the above copyright
14
	   notice, this list of conditions and the following disclaimer in the
15
	   documentation and/or other materials provided with the distribution.
16
17
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
	POSSIBILITY OF SUCH DAMAGE.
27
*/
28 7ac5a4cb Scott Ullrich
/*
29
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
30
	pfSense_MODULE:	interfaces
31
*/
32 0ec2fdf0 Ermal Lu?i
33
##|+PRIV
34 7997ed44 Renato Botelho
##|*IDENT=page-interfaces-groups-edit
35 0ec2fdf0 Ermal Lu?i
##|*NAME=Interfaces: Groups: Edit page
36 7997ed44 Renato Botelho
##|*DESCR=Allow access to the 'Interfaces: Groups: Edit' page.
37 0ec2fdf0 Ermal Lu?i
##|*MATCH=interfaces_groups_edit.php*
38
##|-PRIV
39
40
41
require("guiconfig.inc");
42 6730eae1 Carlos Eduardo Ramos
require_once("functions.inc");
43
44
$pgtitle = array(gettext("Interfaces"),gettext("Groups"),gettext("Edit"));
45 b32dd0a6 jim-p
$shortcut_section = "interfaces";
46 0ec2fdf0 Ermal Lu?i
47
if (!is_array($config['ifgroups']['ifgroupentry']))
48
	$config['ifgroups']['ifgroupentry'] = array();
49
50
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
51
52 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
53 45316b1c Ermal Lu?i
	$id = $_GET['id'];
54 e41ec584 Renato Botelho
if (isset($_POST['id']) && is_numericint($_POST['id']))
55 0ec2fdf0 Ermal Lu?i
	$id = $_POST['id'];
56
57
if (isset($id) && $a_ifgroups[$id]) {
58
	$pconfig['ifname'] = $a_ifgroups[$id]['ifname'];
59
	$pconfig['members'] = $a_ifgroups[$id]['members'];
60
	$pconfig['descr'] = html_entity_decode($a_ifgroups[$id]['descr']);
61
}
62
63 6e73977b Renato Botelho
$iflist = get_configured_interface_with_descr();
64
$iflist_disabled = get_configured_interface_with_descr(false, true);
65
66 0ec2fdf0 Ermal Lu?i
if ($_POST) {
67
68
	unset($input_errors);
69
	$pconfig = $_POST;
70
71 45316b1c Ermal Lu?i
	if (!isset($id)) {
72 42753d25 Ermal Lu?i
		foreach ($a_ifgroups as $groupentry)
73
			if ($groupentry['ifname'] == $_POST['ifname'])
74 6730eae1 Carlos Eduardo Ramos
				$input_errors[] = gettext("Group name already exists!");
75 42753d25 Ermal Lu?i
	}
76
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match))
77 a9a7a131 Rafael Lucas
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
78 0ec2fdf0 Ermal Lu?i
79 6e73977b Renato Botelho
	foreach ($iflist as $gif => $gdescr) {
80 4a71c087 Ermal
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname'])
81
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
82
	}
83 0ec2fdf0 Ermal Lu?i
	$members = "";
84
	$isfirst = 0;
85
	/* item is a normal ifgroupentry type */
86
	for($x=0; $x<9999; $x++) {
87
		if($_POST["members{$x}"] <> "") {
88
			if ($isfirst > 0)
89
				$members .= " ";
90
			$members .= $_POST["members{$x}"];
91
			$isfirst++;
92
		}
93
	}
94
95
	if (!$input_errors) {
96 62663b54 Ermal
		$ifgroupentry = array();
97 0ec2fdf0 Ermal Lu?i
		$ifgroupentry['members'] = $members;
98 d865241e jim-p
		$ifgroupentry['descr'] = $_POST['descr'];
99 0ec2fdf0 Ermal Lu?i
100 62663b54 Ermal
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
101 4d3c8697 Ermal
			if (!empty($config['filter']) && is_array($config['filter']['rule'])) {
102
				foreach ($config['filter']['rule'] as $ridx => $rule) {
103
					if (isset($rule['floating'])) {
104
						$rule_ifs = explode(",", $rule['interface']);
105
						$rule_changed = false;
106
						foreach ($rule_ifs as $rule_if_id => $rule_if) {
107
							if ($rule_if == $a_ifgroups[$id]['ifname']) {
108
								$rule_ifs[$rule_if_id] = $_POST['ifname'];
109
								$rule_changed = true;
110
							}
111 22d0d529 Erik Fonnesbeck
						}
112 4d3c8697 Ermal
						if ($rule_changed)
113
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
114
					} else {
115
						if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
116
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
117 22d0d529 Erik Fonnesbeck
					}
118
				}
119 62663b54 Ermal
			}
120 4d3c8697 Ermal
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
121
				foreach ($config['nat']['rule'] as $ridx => $rule) {
122
					if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
123
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
124
				}
125 62663b54 Ermal
			}
126
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
127
			if (count($omembers) > 0) {
128
				foreach ($omembers as $ifs) {
129
					$realif = get_real_interface($ifs);
130
					if ($realif)
131
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
132
				}
133
			}
134
			$ifgroupentry['ifname'] = $_POST['ifname'];
135
			$a_ifgroups[$id] = $ifgroupentry;
136
		} else if (isset($id) && $a_ifgroups[$id]) {
137 42753d25 Ermal Lu?i
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
138
			$nmembers = explode(" ", $members);
139
			$delmembers = array_diff($omembers, $nmembers);
140
			if (count($delmembers) > 0) {
141
				foreach ($delmembers as $ifs) {
142
					$realif = get_real_interface($ifs);
143
					if ($realif)
144
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
145
				}
146
			}
147 62663b54 Ermal
			$ifgroupentry['ifname'] = $_POST['ifname'];
148 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[$id] = $ifgroupentry;
149 62663b54 Ermal
		} else {
150
			$ifgroupentry['ifname'] = $_POST['ifname'];
151 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[] = $ifgroupentry;
152 62663b54 Ermal
		}
153 0ec2fdf0 Ermal Lu?i
154
		write_config();
155
156 42753d25 Ermal Lu?i
		interface_group_setup($ifgroupentry);
157
158 0ec2fdf0 Ermal Lu?i
		header("Location: interfaces_groups.php");
159
		exit;
160
	} else {
161 d865241e jim-p
		$pconfig['descr'] = $_POST['descr'];
162 0ec2fdf0 Ermal Lu?i
		$pconfig['members'] = $members;
163
	}
164
}
165
166
include("head.inc");
167
168
?>
169
170
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
171 5e3a7e82 Colin Fleming
<?php include("fbegin.inc"); ?>
172 0ec2fdf0 Ermal Lu?i
173
<script type="text/javascript">
174 5e3a7e82 Colin Fleming
//<![CDATA[
175 0ec2fdf0 Ermal Lu?i
// Global Variables
176
var rowname = new Array(9999);
177
var rowtype = new Array(9999);
178
var newrow  = new Array(9999);
179
var rowsize = new Array(9999);
180
181
for (i = 0; i < 9999; i++) {
182
        rowname[i] = '';
183
        rowtype[i] = 'select';
184
        newrow[i] = '';
185
        rowsize[i] = '30';
186
}
187
188
var field_counter_js = 0;
189
var loaded = 0;
190
var is_streaming_progress_bar = 0;
191
var temp_streaming_text = "";
192
193
var addRowTo = (function() {
194
    return (function (tableId) {
195
        var d, tbody, tr, td, bgc, i, ii, j;
196
        d = document;
197
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
198
        tr = d.createElement("tr");
199
        for (i = 0; i < field_counter_js; i++) {
200
                td = d.createElement("td");
201
		<?php
202 5e3a7e82 Colin Fleming
                        $innerHTML="\"<input type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"' /><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
203 0ec2fdf0 Ermal Lu?i
204
                        foreach ($iflist as $ifnam => $ifdescr)
205 329bb072 Colin Fleming
                                $innerHTML .= "<option value='{$ifnam}'>{$ifdescr}<\/option>";
206
			$innerHTML .= "<\/select>\";";
207 0ec2fdf0 Ermal Lu?i
                ?>
208
			td.innerHTML=<?=$innerHTML;?>
209
                tr.appendChild(td);
210
        }
211
        td = d.createElement("td");
212
        td.rowSpan = "1";
213
214 329bb072 Colin Fleming
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" alt="remove" /><\/a>';
215 0ec2fdf0 Ermal Lu?i
        tr.appendChild(td);
216
        tbody.appendChild(tr);
217
        totalrows++;
218
    });
219
})();
220
221
function removeRow(el) {
222
    var cel;
223
    while (el && el.nodeName.toLowerCase() != "tr")
224
            el = el.parentNode;
225
226
    if (el && el.parentNode) {
227
        cel = el.getElementsByTagName("td").item(0);
228
        el.parentNode.removeChild(el);
229
    }
230
}
231
232
	rowname[0] = "members";
233
	rowtype[0] = "textbox";
234
	rowsize[0] = "30";
235
236
	rowname[2] = "detail";
237
	rowtype[2] = "textbox";
238
	rowsize[2] = "50";
239 5e3a7e82 Colin Fleming
//]]>
240 0ec2fdf0 Ermal Lu?i
</script>
241
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
242
243
<?php if ($input_errors) print_input_errors($input_errors); ?>
244
<div id="inputerrors"></div>
245
246
<form action="interfaces_groups_edit.php" method="post" name="iform" id="iform">
247 5e3a7e82 Colin Fleming
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces groups edit">
248 0ec2fdf0 Ermal Lu?i
  <tr>
249 a9a7a131 Rafael Lucas
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface Groups Edit");?></td>
250 0ec2fdf0 Ermal Lu?i
  </tr>
251
  <tr>
252 a9a7a131 Rafael Lucas
    <td valign="top" class="vncellreq"><?=gettext("Group Name");?></td>
253 0ec2fdf0 Ermal Lu?i
    <td class="vtable">
254 dd5bf424 Scott Ullrich
	<input class="formfld unknown" name="ifname" id="ifname" value="<?=htmlspecialchars($pconfig['ifname']);?>" />
255 42753d25 Ermal Lu?i
	<br />
256 a9a7a131 Rafael Lucas
	<?=gettext("No numbers or spaces are allowed. Only characters in a-zA-Z");?>
257 0ec2fdf0 Ermal Lu?i
    </td>
258
  </tr>
259
  <tr>
260 a9a7a131 Rafael Lucas
    <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
261 0ec2fdf0 Ermal Lu?i
    <td width="78%" class="vtable">
262 dd5bf424 Scott Ullrich
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
263 0ec2fdf0 Ermal Lu?i
      <br />
264
      <span class="vexpl">
265 a9a7a131 Rafael Lucas
        <?=gettext("You may enter a description here for your reference (not parsed).");?>
266 0ec2fdf0 Ermal Lu?i
      </span>
267
    </td>
268
  </tr>
269
  <tr>
270 a9a7a131 Rafael Lucas
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
271 0ec2fdf0 Ermal Lu?i
    <td width="78%" class="vtable">
272 5e3a7e82 Colin Fleming
      <table id="maintable" summary="main table">
273 0ec2fdf0 Ermal Lu?i
        <tbody>
274
          <tr>
275 a9a7a131 Rafael Lucas
            <td><div id="onecolumn"><?=gettext("Interface");?></div></td>
276 0ec2fdf0 Ermal Lu?i
          </tr>
277
278
	<?php
279
	$counter = 0;
280
	$members = $pconfig['members'];
281
	if ($members <> "") {
282
		$item = explode(" ", $members);
283
		foreach($item as $ww) {
284
			$members = $item[$counter];
285
			$tracker = $counter;
286
	?>
287
        <tr>
288
	<td class="vtable">
289
	        <select name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>">
290
			<?php
291 6e73977b Renato Botelho
				$found = false;
292 0ec2fdf0 Ermal Lu?i
				foreach ($iflist as $ifnam => $ifdescr) {
293 5e3a7e82 Colin Fleming
					echo "<option value=\"{$ifnam}\"";
294 6e73977b Renato Botelho
					if ($ifnam == $members) {
295
						$found = true;
296 5e3a7e82 Colin Fleming
						echo " selected=\"selected\"";
297 6e73977b Renato Botelho
					}
298 0ec2fdf0 Ermal Lu?i
					echo ">{$ifdescr}</option>";
299
				}
300 6e73977b Renato Botelho
301
				if ($found === false)
302
					foreach ($iflist_disabled as $ifnam => $ifdescr)
303
						if ($ifnam == $members)
304
							echo "<option value=\"{$ifnam}\" selected=\"selected\">{$ifdescr}</option>";
305 0ec2fdf0 Ermal Lu?i
			?>
306
                        </select>
307
	</td>
308
        <td>
309 5e3a7e82 Colin Fleming
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="remove" /></a>
310 0ec2fdf0 Ermal Lu?i
	      </td>
311
          </tr>
312
<?php
313
		$counter++;
314
315
		} // end foreach
316
	} // end if
317
?>
318
        </tbody>
319
		  </table>
320
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
321 a9a7a131 Rafael Lucas
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
322 0ec2fdf0 Ermal Lu?i
      </a>
323
		</td>
324
  </tr>
325
  <tr>
326
    <td width="22%" valign="top">&nbsp;</td>
327
    <td width="78%">
328 a9a7a131 Rafael Lucas
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
329
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
330 0ec2fdf0 Ermal Lu?i
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
331 225a2f0b Scott Ullrich
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
332 0ec2fdf0 Ermal Lu?i
      <?php endif; ?>
333
    </td>
334
  </tr>
335
</table>
336
</form>
337
338
<script type="text/javascript">
339 5e3a7e82 Colin Fleming
//<![CDATA[
340 0ec2fdf0 Ermal Lu?i
	field_counter_js = 1;
341
	rows = 1;
342
	totalrows = <?php echo $counter; ?>;
343
	loaded = <?php echo $counter; ?>;
344 5e3a7e82 Colin Fleming
//]]>
345 0ec2fdf0 Ermal Lu?i
</script>
346
347 36b9bb28 Renato Botelho
<?php
348
	unset($iflist);
349
	unset($iflist_disabled);
350
	include("fend.inc");
351
?>
352 0ec2fdf0 Ermal Lu?i
</body>
353
</html>