Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
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
64
if ($_POST) {
65
66
	unset($input_errors);
67
	$pconfig = $_POST;
68
69 45316b1c Ermal Lu?i
	if (!isset($id)) {
70 42753d25 Ermal Lu?i
		foreach ($a_ifgroups as $groupentry)
71
			if ($groupentry['ifname'] == $_POST['ifname'])
72 6730eae1 Carlos Eduardo Ramos
				$input_errors[] = gettext("Group name already exists!");
73 42753d25 Ermal Lu?i
	}
74
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match))
75 a9a7a131 Rafael Lucas
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
76 0ec2fdf0 Ermal Lu?i
77 4a71c087 Ermal
	$ifaces = get_configured_interface_with_descr();
78
	foreach ($ifaces as $gif => $gdescr) {
79
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname'])
80
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
81
	}
82 0ec2fdf0 Ermal Lu?i
	$members = "";
83
	$isfirst = 0;
84
	/* item is a normal ifgroupentry type */
85
	for($x=0; $x<9999; $x++) {
86
		if($_POST["members{$x}"] <> "") {
87
			if ($isfirst > 0)
88
				$members .= " ";
89
			$members .= $_POST["members{$x}"];
90
			$isfirst++;
91
		}
92
	}
93
94
	if (!$input_errors) {
95 62663b54 Ermal
		$ifgroupentry = array();
96 0ec2fdf0 Ermal Lu?i
		$ifgroupentry['members'] = $members;
97 d865241e jim-p
		$ifgroupentry['descr'] = $_POST['descr'];
98 0ec2fdf0 Ermal Lu?i
99 62663b54 Ermal
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
100 4d3c8697 Ermal
			if (!empty($config['filter']) && is_array($config['filter']['rule'])) {
101
				foreach ($config['filter']['rule'] as $ridx => $rule) {
102
					if (isset($rule['floating'])) {
103
						$rule_ifs = explode(",", $rule['interface']);
104
						$rule_changed = false;
105
						foreach ($rule_ifs as $rule_if_id => $rule_if) {
106
							if ($rule_if == $a_ifgroups[$id]['ifname']) {
107
								$rule_ifs[$rule_if_id] = $_POST['ifname'];
108
								$rule_changed = true;
109
							}
110 22d0d529 Erik Fonnesbeck
						}
111 4d3c8697 Ermal
						if ($rule_changed)
112
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
113
					} else {
114
						if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
115
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
116 22d0d529 Erik Fonnesbeck
					}
117
				}
118 62663b54 Ermal
			}
119 4d3c8697 Ermal
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
120
				foreach ($config['nat']['rule'] as $ridx => $rule) {
121
					if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
122
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
123
				}
124 62663b54 Ermal
			}
125
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
126
			if (count($omembers) > 0) {
127
				foreach ($omembers as $ifs) {
128
					$realif = get_real_interface($ifs);
129
					if ($realif)
130
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
131
				}
132
			}
133
			$ifgroupentry['ifname'] = $_POST['ifname'];
134
			$a_ifgroups[$id] = $ifgroupentry;
135
		} else if (isset($id) && $a_ifgroups[$id]) {
136 42753d25 Ermal Lu?i
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
137
			$nmembers = explode(" ", $members);
138
			$delmembers = array_diff($omembers, $nmembers);
139
			if (count($delmembers) > 0) {
140
				foreach ($delmembers as $ifs) {
141
					$realif = get_real_interface($ifs);
142
					if ($realif)
143
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
144
				}
145
			}
146 62663b54 Ermal
			$ifgroupentry['ifname'] = $_POST['ifname'];
147 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[$id] = $ifgroupentry;
148 62663b54 Ermal
		} else {
149
			$ifgroupentry['ifname'] = $_POST['ifname'];
150 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[] = $ifgroupentry;
151 62663b54 Ermal
		}
152 0ec2fdf0 Ermal Lu?i
153
		write_config();
154
155 42753d25 Ermal Lu?i
		interface_group_setup($ifgroupentry);
156
157 0ec2fdf0 Ermal Lu?i
		header("Location: interfaces_groups.php");
158
		exit;
159
	} else {
160 d865241e jim-p
		$pconfig['descr'] = $_POST['descr'];
161 0ec2fdf0 Ermal Lu?i
		$pconfig['members'] = $members;
162
	}
163
}
164
165
include("head.inc");
166
167
?>
168
169
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
170 5e3a7e82 Colin Fleming
<?php include("fbegin.inc"); ?>
171 0ec2fdf0 Ermal Lu?i
172
<script type="text/javascript">
173 5e3a7e82 Colin Fleming
//<![CDATA[
174 0ec2fdf0 Ermal Lu?i
// Global Variables
175
var rowname = new Array(9999);
176
var rowtype = new Array(9999);
177
var newrow  = new Array(9999);
178
var rowsize = new Array(9999);
179
180
for (i = 0; i < 9999; i++) {
181
        rowname[i] = '';
182
        rowtype[i] = 'select';
183
        newrow[i] = '';
184
        rowsize[i] = '30';
185
}
186
187
var field_counter_js = 0;
188
var loaded = 0;
189
var is_streaming_progress_bar = 0;
190
var temp_streaming_text = "";
191
192
var addRowTo = (function() {
193
    return (function (tableId) {
194
        var d, tbody, tr, td, bgc, i, ii, j;
195
        d = document;
196
        tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
197
        tr = d.createElement("tr");
198
        for (i = 0; i < field_counter_js; i++) {
199
                td = d.createElement("td");
200
		<?php
201 5e3a7e82 Colin Fleming
                        $innerHTML="\"<input type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"' /><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
202 0ec2fdf0 Ermal Lu?i
203
			$iflist = get_configured_interface_with_descr();
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
				foreach ($iflist as $ifnam => $ifdescr) {
292 5e3a7e82 Colin Fleming
					echo "<option value=\"{$ifnam}\"";
293 0ec2fdf0 Ermal Lu?i
					if ($ifnam == $members)
294 5e3a7e82 Colin Fleming
						echo " selected=\"selected\"";
295 0ec2fdf0 Ermal Lu?i
					echo ">{$ifdescr}</option>";
296
				}
297
			?>
298
                        </select>
299
	</td>
300
        <td>
301 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>
302 0ec2fdf0 Ermal Lu?i
	      </td>
303
          </tr>
304
<?php
305
		$counter++;
306
307
		} // end foreach
308
	} // end if
309
?>
310
        </tbody>
311
		  </table>
312
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
313 a9a7a131 Rafael Lucas
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
314 0ec2fdf0 Ermal Lu?i
      </a>
315
		</td>
316
  </tr>
317
  <tr>
318
    <td width="22%" valign="top">&nbsp;</td>
319
    <td width="78%">
320 a9a7a131 Rafael Lucas
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
321
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
322 0ec2fdf0 Ermal Lu?i
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
323 225a2f0b Scott Ullrich
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
324 0ec2fdf0 Ermal Lu?i
      <?php endif; ?>
325
    </td>
326
  </tr>
327
</table>
328
</form>
329
330
<script type="text/javascript">
331 5e3a7e82 Colin Fleming
//<![CDATA[
332 0ec2fdf0 Ermal Lu?i
	field_counter_js = 1;
333
	rows = 1;
334
	totalrows = <?php echo $counter; ?>;
335
	loaded = <?php echo $counter; ?>;
336 5e3a7e82 Colin Fleming
//]]>
337 0ec2fdf0 Ermal Lu?i
</script>
338
339
<?php include("fend.inc"); ?>
340
</body>
341
</html>