Project

General

Profile

Download (7.61 KB) Statistics
| Branch: | Tag: | Revision:
1 0ec2fdf0 Ermal Lu?i
<?php
2
/*
3 ce77a9c4 Phil Davis
	interfaces_groups_edit.php
4
5
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
6 1d7ba683 ayvis
	Copyright (C) 2009 Ermal Luçi
7 0ec2fdf0 Ermal Lu?i
	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 7ac5a4cb Scott Ullrich
/*
32
	pfSense_BUILDER_BINARIES:	/sbin/ifconfig
33
	pfSense_MODULE:	interfaces
34
*/
35 0ec2fdf0 Ermal Lu?i
36
##|+PRIV
37 7997ed44 Renato Botelho
##|*IDENT=page-interfaces-groups-edit
38 0ec2fdf0 Ermal Lu?i
##|*NAME=Interfaces: Groups: Edit page
39 7997ed44 Renato Botelho
##|*DESCR=Allow access to the 'Interfaces: Groups: Edit' page.
40 0ec2fdf0 Ermal Lu?i
##|*MATCH=interfaces_groups_edit.php*
41
##|-PRIV
42
43
44
require("guiconfig.inc");
45 6730eae1 Carlos Eduardo Ramos
require_once("functions.inc");
46
47 19013d43 Thane Gill
$pgtitle = array(gettext("Interfaces"),gettext("Groups"),gettext("Interface Group Edit"));
48 b32dd0a6 jim-p
$shortcut_section = "interfaces";
49 0ec2fdf0 Ermal Lu?i
50 19013d43 Thane Gill
if (!is_array($config['ifgroups']['ifgroupentry'])) {
51 0ec2fdf0 Ermal Lu?i
	$config['ifgroups']['ifgroupentry'] = array();
52 19013d43 Thane Gill
}
53 0ec2fdf0 Ermal Lu?i
54
$a_ifgroups = &$config['ifgroups']['ifgroupentry'];
55
56 19013d43 Thane Gill
if (is_numericint($_GET['id'])){
57 45316b1c Ermal Lu?i
	$id = $_GET['id'];
58 19013d43 Thane Gill
}
59
if (isset($_POST['id']) && is_numericint($_POST['id'])) {
60 0ec2fdf0 Ermal Lu?i
	$id = $_POST['id'];
61 19013d43 Thane Gill
}
62 0ec2fdf0 Ermal Lu?i
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 19013d43 Thane Gill
$interface_list = get_configured_interface_with_descr();
70
$interface_list_disabled = get_configured_interface_with_descr(false, true);
71 6e73977b Renato Botelho
72 0ec2fdf0 Ermal Lu?i
if ($_POST) {
73
	unset($input_errors);
74
	$pconfig = $_POST;
75
76 45316b1c Ermal Lu?i
	if (!isset($id)) {
77 19013d43 Thane Gill
		foreach ($a_ifgroups as $group_entry)
78
			if ($group_entry['ifname'] == $_POST['ifname'])
79 6730eae1 Carlos Eduardo Ramos
				$input_errors[] = gettext("Group name already exists!");
80 42753d25 Ermal Lu?i
	}
81 19013d43 Thane Gill
	if (preg_match("/([^a-zA-Z])+/", $_POST['ifname'], $match)) {
82 a9a7a131 Rafael Lucas
		$input_errors[] = gettext("Only letters A-Z are allowed as the group name.");
83 19013d43 Thane Gill
	}
84 0ec2fdf0 Ermal Lu?i
85 19013d43 Thane Gill
	/* chech if ifname is the same as an interface name */
86
	foreach ($interface_list as $gif => $gdescr) {
87 4a71c087 Ermal
		if ($gdescr == $_POST['ifname'] || $gif == $_POST['ifname'])
88
			$input_errors[] = "The specified group name is already used by an interface. Please choose another name.";
89
	}
90 19013d43 Thane Gill
91
	$members = isset($_POST['members']) ? join(' ', $_POST['members']) : "";
92 0ec2fdf0 Ermal Lu?i
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 19013d43 Thane Gill
		// Edit group name
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 19013d43 Thane Gill
						if ($rule_changed) {
112 4d3c8697 Ermal
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
113 19013d43 Thane Gill
						}
114 4d3c8697 Ermal
					} else {
115 19013d43 Thane Gill
						if ($rule['interface'] == $a_ifgroups[$id]['ifname']) {
116 4d3c8697 Ermal
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
117 19013d43 Thane Gill
						}
118 22d0d529 Erik Fonnesbeck
					}
119
				}
120 62663b54 Ermal
			}
121 4d3c8697 Ermal
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
122
				foreach ($config['nat']['rule'] as $ridx => $rule) {
123 19013d43 Thane Gill
					if ($rule['interface'] == $a_ifgroups[$id]['ifname']) {
124 4d3c8697 Ermal
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
125 19013d43 Thane Gill
					}
126 4d3c8697 Ermal
				}
127 62663b54 Ermal
			}
128
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
129
			if (count($omembers) > 0) {
130
				foreach ($omembers as $ifs) {
131
					$realif = get_real_interface($ifs);
132 19013d43 Thane Gill
					if ($realif) {
133 62663b54 Ermal
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
134 19013d43 Thane Gill
					}
135 62663b54 Ermal
				}
136
			}
137
			$ifgroupentry['ifname'] = $_POST['ifname'];
138
			$a_ifgroups[$id] = $ifgroupentry;
139 19013d43 Thane Gill
140
		// Edit old group
141 62663b54 Ermal
		} else if (isset($id) && $a_ifgroups[$id]) {
142 42753d25 Ermal Lu?i
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
143
			$nmembers = explode(" ", $members);
144
			$delmembers = array_diff($omembers, $nmembers);
145
			if (count($delmembers) > 0) {
146
				foreach ($delmembers as $ifs) {
147
					$realif = get_real_interface($ifs);
148 19013d43 Thane Gill
					if ($realif) {
149 42753d25 Ermal Lu?i
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
150 19013d43 Thane Gill
					}
151 42753d25 Ermal Lu?i
				}
152
			}
153 62663b54 Ermal
			$ifgroupentry['ifname'] = $_POST['ifname'];
154 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[$id] = $ifgroupentry;
155 19013d43 Thane Gill
156
		// Create new group
157 62663b54 Ermal
		} else {
158
			$ifgroupentry['ifname'] = $_POST['ifname'];
159 0ec2fdf0 Ermal Lu?i
			$a_ifgroups[] = $ifgroupentry;
160 62663b54 Ermal
		}
161 0ec2fdf0 Ermal Lu?i
162
		write_config();
163 42753d25 Ermal Lu?i
		interface_group_setup($ifgroupentry);
164
165 0ec2fdf0 Ermal Lu?i
		header("Location: interfaces_groups.php");
166
		exit;
167
	} else {
168 d865241e jim-p
		$pconfig['descr'] = $_POST['descr'];
169 0ec2fdf0 Ermal Lu?i
		$pconfig['members'] = $members;
170
	}
171
}
172
173
include("head.inc");
174
175 19013d43 Thane Gill
if ($input_errors) {
176
	print_input_errors($input_errors);
177 0ec2fdf0 Ermal Lu?i
}
178
179 19013d43 Thane Gill
?>
180 0ec2fdf0 Ermal Lu?i
<div id="inputerrors"></div>
181
<?php
182 19013d43 Thane Gill
$tab_array = array();
183
$tab_array[0]  = array(gettext("Interface assignments"), false, "interfaces_assign.php");
184
$tab_array[1]  = array(gettext("Interface Groups"), true, "interfaces_groups.php");
185
$tab_array[2]  = array(gettext("Wireless"), false, "interfaces_wireless.php");
186
$tab_array[3]  = array(gettext("VLANs"), false, "interfaces_vlan.php");
187
$tab_array[4]  = array(gettext("QinQs"), false, "interfaces_qinq.php");
188
$tab_array[5]  = array(gettext("PPPs"), false, "interfaces_ppps.php");
189
$tab_array[7]  = array(gettext("GRE"), false, "interfaces_gre.php");
190
$tab_array[8]  = array(gettext("GIF"), false, "interfaces_gif.php");
191
$tab_array[9]  = array(gettext("Bridges"), false, "interfaces_bridge.php");
192
$tab_array[10] = array(gettext("LAGG"), false, "interfaces_lagg.php");
193
display_top_tabs($tab_array);
194
195
require('classes/Form.class.php');
196
$form = new Form;
197
$section = new Form_Section('Interface Group Edit');
198
199
$section->addInput(new Form_Input(
200
	'ifname',
201
	'Group Name',
202
	'text',
203
	$pconfig['ifname'],
204
	['placeholder' => 'Group Name']
205
))->setWidth(6)->setHelp('No numbers or spaces are allowed. '.
206
	'Only characters in a-zA-Z');
207
208
$section->addInput(new Form_Input(
209
	'descr',
210
	'Group Description',
211
	'text',
212
	$pconfig['descr'],
213
	['placeholder' => 'Group Description']
214
))->setWidth(6)->setHelp('You may enter a group decsription '.
215
	'here for your reference (not parsed)');
216
217
$section->addInput(new Form_Select(
218
	'members[]',
219
	'Group Members',
220
	explode(' ', $pconfig['members']),
221
	$interface_list,
222
	true
223
))->setWidth(6)->setHelp('NOTE: Rules for WAN type '.
224
	'interfaces in groups do not contain the reply-to mechanism upon which '.
225
	'Multi-WAN typically relies. '.
226
	'<a href="https://doc.pfsense.org/index.php/ifgroups">More Information</a>');
227 0ec2fdf0 Ermal Lu?i
228 19013d43 Thane Gill
if (isset($id) && $a_ifgroups[$id]) {
229
	$form->addGlobal(new Form_Input(
230
		'id',
231
		'id',
232
		'hidden',
233
		$id
234
	));
235
}
236 0ec2fdf0 Ermal Lu?i
237 19013d43 Thane Gill
$form->add($section);
238
print $form;
239
240
unset($interface_list);
241
unset($interface_list_disabled);
242
include("fend.inc");
243 36b9bb28 Renato Botelho
?>