Project

General

Profile

Download (10.7 KB) Statistics
| Branch: | Tag: | Revision:
1 0ec2fdf0 Ermal Lu?i
<?php
2
/*
3
	Copyright (C) 2009 Ermal Lu?i
4
	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
##|*IDENT=page-interfacess-groups
35
##|*NAME=Interfaces: Groups: Edit page
36
##|*DESCR=Edit Interface groups
37
##|*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 45316b1c Ermal Lu?i
if (isset($_GET['id']))
53
	$id = $_GET['id'];
54 0ec2fdf0 Ermal Lu?i
if (isset($_POST['id']))
55
	$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
<?php
171
	include("fbegin.inc");
172
?>
173
174
<script type="text/javascript">
175
// 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
                        $innerHTML="\"<INPUT type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"'></input><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
203
204
			$iflist = get_configured_interface_with_descr();
205
                        foreach ($iflist as $ifnam => $ifdescr)
206
                                $innerHTML .= "<option value={$ifnam}>{$ifdescr}</option>";
207
			$innerHTML .= "</select>\";";
208
                ?>
209
			td.innerHTML=<?=$innerHTML;?>
210
                tr.appendChild(td);
211
        }
212
        td = d.createElement("td");
213
        td.rowSpan = "1";
214
215 bddc8818 Erik Fonnesbeck
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" /></a>';
216 0ec2fdf0 Ermal Lu?i
        tr.appendChild(td);
217
        tbody.appendChild(tr);
218
        totalrows++;
219
    });
220
})();
221
222
function removeRow(el) {
223
    var cel;
224
    while (el && el.nodeName.toLowerCase() != "tr")
225
            el = el.parentNode;
226
227
    if (el && el.parentNode) {
228
        cel = el.getElementsByTagName("td").item(0);
229
        el.parentNode.removeChild(el);
230
    }
231
}
232
233
	rowname[0] = "members";
234
	rowtype[0] = "textbox";
235
	rowsize[0] = "30";
236
237
	rowname[2] = "detail";
238
	rowtype[2] = "textbox";
239
	rowsize[2] = "50";
240
</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
<table width="100%" border="0" cellpadding="6" cellspacing="0">
248
  <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
      <table id="maintable">
273
        <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
					echo "<option value={$ifnam}";
293
					if ($ifnam == $members)
294
						echo " selected";
295
					echo ">{$ifdescr}</option>";
296
				}
297
			?>
298
                        </select>
299
	</td>
300
        <td>
301 bddc8818 Erik Fonnesbeck
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" /></a>
302 0ec2fdf0 Ermal Lu?i
	      </td>
303
          </tr>
304
<?php
305
		$counter++;
306
307
		} // end foreach
308
	} // end if
309
?>
310
        </tbody>
311
        <tfoot>
312
313
        </tfoot>
314
		  </table>
315
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
316 a9a7a131 Rafael Lucas
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
317 0ec2fdf0 Ermal Lu?i
      </a>
318
		</td>
319
  </tr>
320
  <tr>
321
    <td width="22%" valign="top">&nbsp;</td>
322
    <td width="78%">
323 a9a7a131 Rafael Lucas
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
324
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
325 0ec2fdf0 Ermal Lu?i
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
326 225a2f0b Scott Ullrich
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
327 0ec2fdf0 Ermal Lu?i
      <?php endif; ?>
328
    </td>
329
  </tr>
330
</table>
331
</form>
332
333
<script type="text/javascript">
334
	field_counter_js = 1;
335
	rows = 1;
336
	totalrows = <?php echo $counter; ?>;
337
	loaded = <?php echo $counter; ?>;
338
</script>
339
340
<?php include("fend.inc"); ?>
341
</body>
342
</html>