Project

General

Profile

Download (11.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	interfaces_groups_edit.php
4

    
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6
	Copyright (C) 2009 Ermal Luçi
7
	Copyright (C) 2004 Scott Ullrich
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
33
	pfSense_MODULE:	interfaces
34
*/
35

    
36
##|+PRIV
37
##|*IDENT=page-interfaces-groups-edit
38
##|*NAME=Interfaces: Groups: Edit page
39
##|*DESCR=Allow access to the 'Interfaces: Groups: Edit' page.
40
##|*MATCH=interfaces_groups_edit.php*
41
##|-PRIV
42

    
43

    
44
require("guiconfig.inc");
45
require_once("functions.inc");
46

    
47
$pgtitle = array(gettext("Interfaces"), gettext("Groups"), gettext("Edit"));
48
$shortcut_section = "interfaces";
49

    
50
if (!is_array($config['ifgroups']['ifgroupentry'])) {
51
	$config['ifgroups']['ifgroupentry'] = array();
52
}
53

    
54
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
55

    
56
if (is_numericint($_GET['id'])) {
57
	$id = $_GET['id'];
58
}
59
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
60
	$id = $_POST['id'];
61
}
62

    
63
if (isset($id) && $a_ifgroups[$id]) {
64
	$pconfig['ifname'] = $a_ifgroups[$id]['ifname'];
65
	$pconfig['members'] = $a_ifgroups[$id]['members'];
66
	$pconfig['descr'] = html_entity_decode($a_ifgroups[$id]['descr']);
67
}
68

    
69
$iflist = get_configured_interface_with_descr();
70
$iflist_disabled = get_configured_interface_with_descr(false, true);
71

    
72
if ($_POST) {
73

    
74
	unset($input_errors);
75
	$pconfig = $_POST;
76

    
77
	if (!isset($id)) {
78
		foreach ($a_ifgroups as $groupentry) {
79
			if ($groupentry['ifname'] == $_POST['ifname']) {
80
				$input_errors[] = gettext("Group name already exists!");
81
			}
82
		}
83
	}
84
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match)) {
85
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
86
	}
87

    
88
	foreach ($iflist as $gif => $gdescr) {
89
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname']) {
90
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
91
		}
92
	}
93
	$members = "";
94
	$isfirst = 0;
95
	/* item is a normal ifgroupentry type */
96
	for ($x = 0; $x < 9999; $x++) {
97
		if ($_POST["members{$x}"] <> "") {
98
			if ($isfirst > 0) {
99
				$members .= " ";
100
			}
101
			$members .= $_POST["members{$x}"];
102
			$isfirst++;
103
		}
104
	}
105

    
106
	if (!$input_errors) {
107
		$ifgroupentry = array();
108
		$ifgroupentry['members'] = $members;
109
		$ifgroupentry['descr'] = $_POST['descr'];
110

    
111
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
112
			if (!empty($config['filter']) && is_array($config['filter']['rule'])) {
113
				foreach ($config['filter']['rule'] as $ridx => $rule) {
114
					if (isset($rule['floating'])) {
115
						$rule_ifs = explode(",", $rule['interface']);
116
						$rule_changed = false;
117
						foreach ($rule_ifs as $rule_if_id => $rule_if) {
118
							if ($rule_if == $a_ifgroups[$id]['ifname']) {
119
								$rule_ifs[$rule_if_id] = $_POST['ifname'];
120
								$rule_changed = true;
121
							}
122
						}
123
						if ($rule_changed) {
124
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
125
						}
126
					} else {
127
						if ($rule['interface'] == $a_ifgroups[$id]['ifname']) {
128
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
129
						}
130
					}
131
				}
132
			}
133
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
134
				foreach ($config['nat']['rule'] as $ridx => $rule) {
135
					if ($rule['interface'] == $a_ifgroups[$id]['ifname']) {
136
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
137
					}
138
				}
139
			}
140
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
141
			if (count($omembers) > 0) {
142
				foreach ($omembers as $ifs) {
143
					$realif = get_real_interface($ifs);
144
					if ($realif) {
145
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
146
					}
147
				}
148
			}
149
			$ifgroupentry['ifname'] = $_POST['ifname'];
150
			$a_ifgroups[$id] = $ifgroupentry;
151
		} else if (isset($id) && $a_ifgroups[$id]) {
152
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
153
			$nmembers = explode(" ", $members);
154
			$delmembers = array_diff($omembers, $nmembers);
155
			if (count($delmembers) > 0) {
156
				foreach ($delmembers as $ifs) {
157
					$realif = get_real_interface($ifs);
158
					if ($realif) {
159
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
160
					}
161
				}
162
			}
163
			$ifgroupentry['ifname'] = $_POST['ifname'];
164
			$a_ifgroups[$id] = $ifgroupentry;
165
		} else {
166
			$ifgroupentry['ifname'] = $_POST['ifname'];
167
			$a_ifgroups[] = $ifgroupentry;
168
		}
169

    
170
		write_config();
171

    
172
		interface_group_setup($ifgroupentry);
173

    
174
		header("Location: interfaces_groups.php");
175
		exit;
176
	} else {
177
		$pconfig['descr'] = $_POST['descr'];
178
		$pconfig['members'] = $members;
179
	}
180
}
181

    
182
include("head.inc");
183

    
184
?>
185

    
186
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
187
<?php include("fbegin.inc"); ?>
188

    
189
<script type="text/javascript">
190
//<![CDATA[
191
// Global Variables
192
var rowname = new Array(9999);
193
var rowtype = new Array(9999);
194
var newrow  = new Array(9999);
195
var rowsize = new Array(9999);
196

    
197
for (i = 0; i < 9999; i++) {
198
	rowname[i] = '';
199
	rowtype[i] = 'select';
200
	newrow[i] = '';
201
	rowsize[i] = '30';
202
}
203

    
204
var field_counter_js = 0;
205
var loaded = 0;
206
var is_streaming_progress_bar = 0;
207
var temp_streaming_text = "";
208

    
209
var addRowTo = (function() {
210
	return (function (tableId) {
211
		var d, tbody, tr, td, bgc, i, ii, j;
212
		d = document;
213
		tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
214
		tr = d.createElement("tr");
215
		for (i = 0; i < field_counter_js; i++) {
216
				td = d.createElement("td");
217
		<?php
218
			$innerHTML="\"<input type='hidden' value='\" + totalrows +\"' name='\" + rowname[i] + \"_row-\" + totalrows + \"' /><select size='1' name='\" + rowname[i] + totalrows + \"'>\" +\"";
219

    
220
			foreach ($iflist as $ifnam => $ifdescr) {
221
				$innerHTML .= "<option value='{$ifnam}'>{$ifdescr}<\/option>";
222
			}
223
			$innerHTML .= "<\/select>\";";
224
		?>
225
			td.innerHTML=<?=$innerHTML;?>
226
				tr.appendChild(td);
227
		}
228
		td = d.createElement("td");
229
		td.rowSpan = "1";
230

    
231
		td.innerHTML = '<a onclick="removeRow(this);return false;" href="#"><img border="0" src="/themes/' + theme + '/images/icons/icon_x.gif" alt="remove" /><\/a>';
232
		tr.appendChild(td);
233
		tbody.appendChild(tr);
234
		totalrows++;
235
	});
236
})();
237

    
238
function removeRow(el) {
239
	var cel;
240
	while (el && el.nodeName.toLowerCase() != "tr") {
241
		el = el.parentNode;
242
	}
243

    
244
	if (el && el.parentNode) {
245
		cel = el.getElementsByTagName("td").item(0);
246
		el.parentNode.removeChild(el);
247
	}
248
}
249

    
250
	rowname[0] = "members";
251
	rowtype[0] = "textbox";
252
	rowsize[0] = "30";
253

    
254
	rowname[2] = "detail";
255
	rowtype[2] = "textbox";
256
	rowsize[2] = "50";
257
//]]>
258
</script>
259
<input type='hidden' name='members_type' value='textbox' class="formfld unknown" />
260

    
261
<?php if ($input_errors) print_input_errors($input_errors); ?>
262
<div id="inputerrors"></div>
263

    
264
<form action="interfaces_groups_edit.php" method="post" name="iform" id="iform">
265
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="interfaces groups edit">
266
	<tr>
267
		<td colspan="2" valign="top" class="listtopic"><?=gettext("Interface Groups Edit");?></td>
268
	</tr>
269
	<tr>
270
		<td valign="top" class="vncellreq"><?=gettext("Group Name");?></td>
271
		<td class="vtable">
272
			<input class="formfld unknown" name="ifname" id="ifname" maxlength="15" value="<?=htmlspecialchars($pconfig['ifname']);?>" />
273
			<br />
274
			<?=gettext("No numbers or spaces are allowed. Only characters in a-zA-Z");?>
275
		</td>
276
	</tr>
277
	<tr>
278
		<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
279
		<td width="78%" class="vtable">
280
			<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
281
			<br />
282
			<span class="vexpl">
283
				<?=gettext("You may enter a description here for your reference (not parsed).");?>
284
			</span>
285
		</td>
286
	</tr>
287
	<tr>
288
		<td width="22%" valign="top" class="vncellreq"><div id="membersnetworkport"><?=gettext("Member (s)");?></div></td>
289
		<td width="78%" class="vtable">
290
			<table id="maintable" summary="main table">
291
			<tbody>
292
				<tr>
293
					<td>
294
						<div id="onecolumn"><?=gettext("Interface");?></div>
295
					</td>
296
				</tr>
297
<?php
298
	$counter = 0;
299
	$members = $pconfig['members'];
300
	if ($members <> "") {
301
		$item = explode(" ", $members);
302
		foreach ($item as $ww) {
303
			$members = $item[$counter];
304
			$tracker = $counter;
305
?>
306
				<tr>
307
					<td class="vtable">
308
						<select name="members<?php echo $tracker; ?>" class="formselect" id="members<?php echo $tracker; ?>">
309
<?php
310
			$found = false;
311
			foreach ($iflist as $ifnam => $ifdescr) {
312
				echo "<option value=\"{$ifnam}\"";
313
				if ($ifnam == $members) {
314
					$found = true;
315
					echo " selected=\"selected\"";
316
				}
317
				echo ">{$ifdescr}</option>";
318
			}
319

    
320
			if ($found === false) {
321
				foreach ($iflist_disabled as $ifnam => $ifdescr) {
322
					if ($ifnam == $members) {
323
						echo "<option value=\"{$ifnam}\" selected=\"selected\">{$ifdescr}</option>";
324
					}
325
				}
326
			}
327
?>
328
						</select>
329
					</td>
330
					<td>
331
						<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="remove" /></a>
332
					</td>
333
				</tr>
334
<?php
335
			$counter++;
336
		} // end foreach
337
	} // end if
338
?>
339
			</tbody>
340
			</table>
341
			<a onclick="javascript:addRowTo('maintable'); return false;" href="#">
342
				<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry");?>" />
343
			</a>
344
			<br /><br />
345
			<strong><?php echo gettext("NOTE:");?></strong>
346
			<?php echo gettext("Rules for WAN type interfaces in groups do not contain the reply-to mechanism upon which Multi-WAN typically relies.");?>
347
			<a href="https://doc.pfsense.org/index.php/Interface_Groups"><?PHP echo gettext("More Information");?></a>
348
		</td>
349
	</tr>
350
	<tr>
351
		<td width="22%" valign="top">&nbsp;</td>
352
		<td width="78%">
353
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
354
			<a href="interfaces_groups.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel");?>" /></a>
355
		<?php if (isset($id) && $a_ifgroups[$id]): ?>
356
			<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
357
		<?php endif; ?>
358
		</td>
359
	</tr>
360
</table>
361
</form>
362

    
363
<script type="text/javascript">
364
//<![CDATA[
365
	field_counter_js = 1;
366
	rows = 1;
367
	totalrows = <?php echo $counter; ?>;
368
	loaded = <?php echo $counter; ?>;
369
//]]>
370
</script>
371

    
372
<?php
373
	unset($iflist);
374
	unset($iflist_disabled);
375
	include("fend.inc");
376
?>
377
</body>
378
</html>
(104-104/252)