Project

General

Profile

Download (7.61 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("Interface Group 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
$interface_list = get_configured_interface_with_descr();
70
$interface_list_disabled = get_configured_interface_with_descr(false, true);
71

    
72
if ($_POST) {
73
	unset($input_errors);
74
	$pconfig = $_POST;
75

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

    
85
	/* chech if ifname is the same as an interface name */
86
	foreach ($interface_list as $gif => $gdescr) {
87
		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

    
91
	$members = isset($_POST['members']) ? join(' ', $_POST['members']) : "";
92

    
93
	if (!$input_errors) {
94
		$ifgroupentry = array();
95
		$ifgroupentry['members'] = $members;
96
		$ifgroupentry['descr'] = $_POST['descr'];
97

    
98
		// Edit group name
99
		if (isset($id) && $a_ifgroups[$id] && $_POST['ifname'] != $a_ifgroups[$id]['ifname']) {
100
			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
						}
111
						if ($rule_changed) {
112
							$config['filter']['rule'][$ridx]['interface'] = implode(",", $rule_ifs);
113
						}
114
					} else {
115
						if ($rule['interface'] == $a_ifgroups[$id]['ifname']) {
116
							$config['filter']['rule'][$ridx]['interface'] = $_POST['ifname'];
117
						}
118
					}
119
				}
120
			}
121
			if (!empty($config['nat']) && is_array($config['nat']['rule'])) {
122
				foreach ($config['nat']['rule'] as $ridx => $rule) {
123
					if ($rule['interface'] == $a_ifgroups[$id]['ifname']) {
124
						$config['nat']['rule'][$ridx]['interface'] = $_POST['ifname'];
125
					}
126
				}
127
			}
128
			$omembers = explode(" ", $a_ifgroups[$id]['members']);
129
			if (count($omembers) > 0) {
130
				foreach ($omembers as $ifs) {
131
					$realif = get_real_interface($ifs);
132
					if ($realif) {
133
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
134
					}
135
				}
136
			}
137
			$ifgroupentry['ifname'] = $_POST['ifname'];
138
			$a_ifgroups[$id] = $ifgroupentry;
139

    
140
		// Edit old group
141
		} else if (isset($id) && $a_ifgroups[$id]) {
142
			$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
					if ($realif) {
149
						mwexec("/sbin/ifconfig {$realif} -group " . $a_ifgroups[$id]['ifname']);
150
					}
151
				}
152
			}
153
			$ifgroupentry['ifname'] = $_POST['ifname'];
154
			$a_ifgroups[$id] = $ifgroupentry;
155

    
156
		// Create new group
157
		} else {
158
			$ifgroupentry['ifname'] = $_POST['ifname'];
159
			$a_ifgroups[] = $ifgroupentry;
160
		}
161

    
162
		write_config();
163
		interface_group_setup($ifgroupentry);
164

    
165
		header("Location: interfaces_groups.php");
166
		exit;
167
	} else {
168
		$pconfig['descr'] = $_POST['descr'];
169
		$pconfig['members'] = $members;
170
	}
171
}
172

    
173
include("head.inc");
174

    
175
if ($input_errors) {
176
	print_input_errors($input_errors);
177
}
178

    
179
?>
180
<div id="inputerrors"></div>
181
<?php
182
$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

    
228
if (isset($id) && $a_ifgroups[$id]) {
229
	$form->addGlobal(new Form_Input(
230
		'id',
231
		'id',
232
		'hidden',
233
		$id
234
	));
235
}
236

    
237
$form->add($section);
238
print $form;
239

    
240
unset($interface_list);
241
unset($interface_list_disabled);
242
include("fend.inc");
243
?>
(91-91/241)