Project

General

Profile

Download (10.6 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 0ec2fdf0 Ermal Lu?i
46
if (!is_array($config['ifgroups']['ifgroupentry']))
47
	$config['ifgroups']['ifgroupentry'] = array();
48
49
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
50
51 45316b1c Ermal Lu?i
if (isset($_GET['id']))
52
	$id = $_GET['id'];
53 0ec2fdf0 Ermal Lu?i
if (isset($_POST['id']))
54
	$id = $_POST['id'];
55
56
if (isset($id) && $a_ifgroups[$id]) {
57
	$pconfig['ifname'] = $a_ifgroups[$id]['ifname'];
58
	$pconfig['members'] = $a_ifgroups[$id]['members'];
59
	$pconfig['descr'] = html_entity_decode($a_ifgroups[$id]['descr']);
60
61
}
62
63
if ($_POST) {
64
65
	unset($input_errors);
66
	$pconfig = $_POST;
67
68 45316b1c Ermal Lu?i
	if (!isset($id)) {
69 42753d25 Ermal Lu?i
		foreach ($a_ifgroups as $groupentry)
70
			if ($groupentry['ifname'] == $_POST['ifname'])
71 6730eae1 Carlos Eduardo Ramos
				$input_errors[] = gettext("Group name already exists!");
72 42753d25 Ermal Lu?i
	}
73
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match))
74 a9a7a131 Rafael Lucas
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
75 0ec2fdf0 Ermal Lu?i
76 4a71c087 Ermal
	$ifaces = get_configured_interface_with_descr();
77
	foreach ($ifaces as $gif => $gdescr) {
78
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname'])
79
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
80
	}
81 0ec2fdf0 Ermal Lu?i
	$members = "";
82
	$isfirst = 0;
83
	/* item is a normal ifgroupentry type */
84
	for($x=0; $x<9999; $x++) {
85
		if($_POST["members{$x}"] <> "") {
86
			if ($isfirst > 0)
87
				$members .= " ";
88
			$members .= $_POST["members{$x}"];
89
			$isfirst++;
90
		}
91
	}
92
93
	if (!$input_errors) {
94 62663b54 Ermal
		$ifgroupentry = array();
95 0ec2fdf0 Ermal Lu?i
		$ifgroupentry['members'] = $members;
96 d865241e jim-p
		$ifgroupentry['descr'] = $_POST['descr'];
97 0ec2fdf0 Ermal Lu?i
98 62663b54 Ermal
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
99 4d3c8697 Ermal
			if (!empty($config['filter']) && is_array($config['filter']['rule'])) {
100
				foreach ($config['filter']['rule'] as $ridx => $rule) {
101
					if (isset($rule['floating'])) {
102
						$rule_ifs = explode(",", $rule['interface']);
103
						$rule_changed = false;
104
						foreach ($rule_ifs as $rule_if_id => $rule_if) {
105
							if ($rule_if == $a_ifgroups[$id]['ifname']) {
106
								$rule_ifs[$rule_if_id] = $_POST['ifname'];
107
								$rule_changed = true;
108
							}
109 22d0d529 Erik Fonnesbeck
						}
110 4d3c8697 Ermal
						if ($rule_changed)
111
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
112
					} else {
113
						if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
114
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
115 22d0d529 Erik Fonnesbeck
					}
116
				}
117 62663b54 Ermal
			}
118 4d3c8697 Ermal
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
119
				foreach ($config['nat']['rule'] as $ridx => $rule) {
120
					if ($rule['interface'] == $a_ifgroups[$id]['ifname'])
121
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
122
				}
123 62663b54 Ermal
			}
124
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
125
			if (count($omembers) > 0) {
126
				foreach ($omembers as $ifs) {
127
					$realif = get_real_interface($ifs);
128
					if ($realif)
129
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
130
				}
131
			}
132
			$ifgroupentry['ifname'] = $_POST['ifname'];
133
			$a_ifgroups[$id] = $ifgroupentry;
134
		} else if (isset($id) && $a_ifgroups[$id]) {
135 42753d25 Ermal Lu?i
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
136
			$nmembers = explode(" ", $members);
137
			$delmembers = array_diff($omembers, $nmembers);
138
			if (count($delmembers) > 0) {
139
				foreach ($delmembers as $ifs) {
140
					$realif = get_real_interface($ifs);
141
					if ($realif)
142
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
143
				}
144
			}
145 62663b54 Ermal
			$ifgroupentry['ifname'] = $_POST['ifname'];
146 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[$id] = $ifgroupentry;
147 62663b54 Ermal
		} else {
148
			$ifgroupentry['ifname'] = $_POST['ifname'];
149 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[] = $ifgroupentry;
150 62663b54 Ermal
		}
151 0ec2fdf0 Ermal Lu?i
152
		write_config();
153
154 42753d25 Ermal Lu?i
		interface_group_setup($ifgroupentry);
155
156 0ec2fdf0 Ermal Lu?i
		header("Location: interfaces_groups.php");
157
		exit;
158
	} else {
159 d865241e jim-p
		$pconfig['descr'] = $_POST['descr'];
160 0ec2fdf0 Ermal Lu?i
		$pconfig['members'] = $members;
161
	}
162
}
163
164
include("head.inc");
165
166
?>
167
168
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
169
<?php
170
	include("fbegin.inc");
171
?>
172
173
<script type="text/javascript">
174
// 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
                        $innerHTML="\"<INPUT type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"'></input><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
202
203
			$iflist = get_configured_interface_with_descr();
204
                        foreach ($iflist as $ifnam => $ifdescr)
205
                                $innerHTML .= "<option value={$ifnam}>{$ifdescr}</option>";
206
			$innerHTML .= "</select>\";";
207
                ?>
208
			td.innerHTML=<?=$innerHTML;?>
209
                tr.appendChild(td);
210
        }
211
        td = d.createElement("td");
212
        td.rowSpan = "1";
213
214 bddc8818 Erik Fonnesbeck
        td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" /></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
</script>
240
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
241
242
<?php if ($input_errors) print_input_errors($input_errors); ?>
243
<div id="inputerrors"></div>
244
245
<form action="interfaces_groups_edit.php" method="post" name="iform" id="iform">
246
<table width="100%" border="0" cellpadding="6" cellspacing="0">
247
  <tr>
248 a9a7a131 Rafael Lucas
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface Groups Edit");?></td>
249 0ec2fdf0 Ermal Lu?i
  </tr>
250
  <tr>
251 a9a7a131 Rafael Lucas
    <td valign="top" class="vncellreq"><?=gettext("Group Name");?></td>
252 0ec2fdf0 Ermal Lu?i
    <td class="vtable">
253 dd5bf424 Scott Ullrich
	<input class="formfld unknown" name="ifname" id="ifname" value="<?=htmlspecialchars($pconfig['ifname']);?>" />
254 42753d25 Ermal Lu?i
	<br />
255 a9a7a131 Rafael Lucas
	<?=gettext("No numbers or spaces are allowed. Only characters in a-zA-Z");?>
256 0ec2fdf0 Ermal Lu?i
    </td>
257
  </tr>
258
  <tr>
259 a9a7a131 Rafael Lucas
    <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
260 0ec2fdf0 Ermal Lu?i
    <td width="78%" class="vtable">
261 dd5bf424 Scott Ullrich
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
262 0ec2fdf0 Ermal Lu?i
      <br />
263
      <span class="vexpl">
264 a9a7a131 Rafael Lucas
        <?=gettext("You may enter a description here for your reference (not parsed).");?>
265 0ec2fdf0 Ermal Lu?i
      </span>
266
    </td>
267
  </tr>
268
  <tr>
269 a9a7a131 Rafael Lucas
    <td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
270 0ec2fdf0 Ermal Lu?i
    <td width="78%" class="vtable">
271
      <table id="maintable">
272
        <tbody>
273
          <tr>
274 a9a7a131 Rafael Lucas
            <td><div id="onecolumn"><?=gettext("Interface");?></div></td>
275 0ec2fdf0 Ermal Lu?i
          </tr>
276
277
	<?php
278
	$counter = 0;
279
	$members = $pconfig['members'];
280
	if ($members <> "") {
281
		$item = explode(" ", $members);
282
		foreach($item as $ww) {
283
			$members = $item[$counter];
284
			$tracker = $counter;
285
	?>
286
        <tr>
287
	<td class="vtable">
288
	        <select name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>">
289
			<?php
290
				foreach ($iflist as $ifnam => $ifdescr) {
291
					echo "<option value={$ifnam}";
292
					if ($ifnam == $members)
293
						echo " selected";
294
					echo ">{$ifdescr}</option>";
295
				}
296
			?>
297
                        </select>
298
	</td>
299
        <td>
300 bddc8818 Erik Fonnesbeck
	<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" /></a>
301 0ec2fdf0 Ermal Lu?i
	      </td>
302
          </tr>
303
<?php
304
		$counter++;
305
306
		} // end foreach
307
	} // end if
308
?>
309
        </tbody>
310
        <tfoot>
311
312
        </tfoot>
313
		  </table>
314
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
315 a9a7a131 Rafael Lucas
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
316 0ec2fdf0 Ermal Lu?i
      </a>
317
		</td>
318
  </tr>
319
  <tr>
320
    <td width="22%" valign="top">&nbsp;</td>
321
    <td width="78%">
322 a9a7a131 Rafael Lucas
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
323
      <a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
324 0ec2fdf0 Ermal Lu?i
      <?php if (isset($id) && $a_ifgroups[$id]): ?>
325 225a2f0b Scott Ullrich
      <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
326 0ec2fdf0 Ermal Lu?i
      <?php endif; ?>
327
    </td>
328
  </tr>
329
</table>
330
</form>
331
332
<script type="text/javascript">
333
	field_counter_js = 1;
334
	rows = 1;
335
	totalrows = <?php echo $counter; ?>;
336
	loaded = <?php echo $counter; ?>;
337
</script>
338
339
<?php include("fend.inc"); ?>
340
</body>
341
</html>