Project

General

Profile

Download (6.55 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * services_igmpproxy_edit.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-services-igmpproxy-edit
30
##|*NAME=Services: IGMP Proxy: Edit
31
##|*DESCR=Allow access to the 'Services: IGMP Proxy: Edit' page.
32
##|*MATCH=services_igmpproxy_edit.php*
33
##|-PRIV
34

    
35
$pgtitle = array(gettext("Services"), gettext("IGMP Proxy"), gettext("Edit"));
36
$pglinks = array("", "services_igmpproxy.php", "@self");
37

    
38
require_once("guiconfig.inc");
39

    
40
//igmpproxy_sort();
41

    
42
init_config_arr(array('igmpproxy', 'igmpentry'));
43
$a_igmpproxy = &$config['igmpproxy']['igmpentry'];
44

    
45
if (is_numericint($_REQUEST['id'])) {
46
	$id = $_REQUEST['id'];
47
}
48

    
49
if (isset($id) && $a_igmpproxy[$id]) {
50
	$pconfig['ifname'] = $a_igmpproxy[$id]['ifname'];
51
	$pconfig['threshold'] = $a_igmpproxy[$id]['threshold'];
52
	$pconfig['type'] = $a_igmpproxy[$id]['type'];
53
	$pconfig['address'] = $a_igmpproxy[$id]['address'];
54
	$pconfig['descr'] = html_entity_decode($a_igmpproxy[$id]['descr']);
55
}
56

    
57
if ($_POST['save']) {
58
	unset($input_errors);
59
	$pconfig = $_POST;
60

    
61
	if ($_POST['type'] == "upstream") {
62
		foreach ($a_igmpproxy as $pid => $proxyentry) {
63
			if (isset($id) && $id == $pid) {
64
				continue;
65
			}
66

    
67
			if ($proxyentry['type'] == "upstream" && $proxyentry['ifname'] != $_POST['interface']) {
68
				$input_errors[] = gettext("Only one 'upstream' interface can be configured.");
69
			}
70
		}
71
	}
72

    
73
	if (!empty($_POST['threshold']) && (!is_numeric($_POST['threshold']) ||
74
	    ($_POST['threshold'] < -1) || ($_POST['threshold'] > 256))) {
75
		$input_errors[] = gettext("Threshold value should be between -1 and 256.");
76
	} 
77

    
78
	$igmpentry = array();
79
	$igmpentry['ifname'] = $_POST['ifname'];
80
	$igmpentry['threshold'] = $_POST['threshold'];
81
	$igmpentry['type'] = $_POST['type'];
82
	$address = "";
83
	$isfirst = 0;
84

    
85
	/* item is a normal igmpentry type */
86
	$x = 0;
87
	while ($_POST["address{$x}"]) {
88

    
89
		if ($isfirst > 0) {
90
			$address .= " ";
91
		}
92

    
93
		$this_addr =  $_POST["address{$x}"] . "/" . $_POST["address_subnet{$x}"];
94
		if (is_subnetv4($this_addr)) {
95
			$address .= $this_addr;
96
			$isfirst++;
97
		} else {
98
			$input_errors[] = sprintf(gettext("The following submitted address is invalid: %s"), $this_addr);
99
		}
100

    
101
		$x++;
102
	}
103

    
104
	if (!$input_errors) {
105
		$igmpentry['address'] = $address;
106
		$igmpentry['descr'] = $_POST['descr'];
107

    
108
		if (isset($id) && $a_igmpproxy[$id]) {
109
			$a_igmpproxy[$id] = $igmpentry;
110
		} else {
111
			$a_igmpproxy[] = $igmpentry;
112
		}
113

    
114
		write_config("IGMP Proxy item saved");
115

    
116
		mark_subsystem_dirty('igmpproxy');
117
		header("Location: services_igmpproxy.php");
118
		exit;
119
	} else {
120
		//we received input errors, copy data to prevent retype
121
		$pconfig['descr'] = $_POST['descr'];
122
		$pconfig['address'] = $address;
123
		$pconfig['type'] = $_POST['type'];
124
	}
125
}
126

    
127
include("head.inc");
128

    
129
if ($input_errors) {
130
	print_input_errors($input_errors);
131
}
132

    
133
// These two inputs appear in the original file. Don't know what they are for
134
// but they are here just in case.
135

    
136
$h1 = new Form_Input(
137
	'address_type',
138
	null,
139
	'textbox',
140
	'hidden'
141
	);
142

    
143
$h2 = new Form_Input(
144
	'address_subnet_type',
145
	null,
146
	'select',
147
	'hidden'
148
	);
149

    
150
$form = new Form;
151

    
152
$section = new Form_Section('IGMP Proxy Edit');
153

    
154
$optionlist = array();
155
$iflist = get_configured_interface_with_descr();
156

    
157
foreach ($iflist as $ifnam => $ifdescr) {
158
	if (!empty($config['interfaces'][$ifnam]['ipaddr'])) {
159
		$optionlist[$ifnam] = $ifdescr;
160
	}
161
}
162

    
163
$section->addInput(new Form_Select(
164
	'ifname',
165
	'*Interface',
166
	$pconfig['ifname'],
167
	$optionlist
168
));
169

    
170
$section->addInput(new Form_Input(
171
	'descr',
172
	'Description',
173
	'text',
174
	$pconfig['descr']
175
))->setHelp('A description may be entered here for administrative reference (not parsed).');
176

    
177
$section->addInput(new Form_Select(
178
	'type',
179
	'*Type',
180
	$pconfig['type'],
181
	['upstream' => gettext('Upstream Interface'), 'downstream' => gettext('Downstream Interface')]
182
))->setHelp('The upstream network interface is the outgoing interface which is responsible for communicating to available multicast data sources. ' .
183
			'There can only be one upstream interface.%1$s' .
184
			'Downstream network interfaces are the distribution	interfaces to the destination networks, where multicast clients can join groups and '.
185
			'receive multicast data. One or more downstream interfaces must be configured.', '<br />');
186

    
187
$section->addInput(new Form_Input(
188
	'threshold',
189
	'Threshold',
190
	'text',
191
	$pconfig['threshold']
192
))->setHelp('Defines the TTL threshold for the network interface. Packets with a lower TTL than the threshold value will be ignored. ' .
193
			'This setting is optional, and by default the threshold is 1.');
194

    
195
if (isset($id) && $a_igmpproxy[$id]) {
196
		$form->addGlobal(new Form_Input(
197
		'id',
198
		null,
199
		'hidden',
200
		$id
201
	));
202
}
203

    
204
$counter = 0;
205
$address = $pconfig['address'];
206

    
207
//if ($address == "") {
208
//	$address = "/";
209
//}
210

    
211
$item = explode(" ", $address);
212
$rows = count($item) -1;
213

    
214
foreach ($item as $ww) {
215
	$address = $item[$counter];
216
	$address_subnet = "";
217
	$item2 = explode("/", $address);
218

    
219
	foreach ($item2 as $current) {
220
		if ($item2[1] != "") {
221
			$address = $item2[0];
222
			$address_subnet = $item2[1];
223
		}
224
	}
225

    
226
	$item4 = $item3[$counter];
227
	$tracker = $counter;
228

    
229
	$group = new Form_group($tracker == 0? 'Networks':null);
230
	$group->addClass("repeatable");
231

    
232
	$group->add(new Form_IpAddress(
233
		'address' . $tracker,
234
		null,
235
		$address,
236
		['placeholder' => 'Address']
237
	))->sethelp($tracker == $rows ? 'Network/CIDR':null)->addMask('address_subnet' . $tracker, $address_subnet, 32, 0)->setWidth(4);
238

    
239
	$group->add(new Form_Button(
240
		'deleterow' . $counter,
241
		'Delete',
242
		null,
243
		'fa-trash'
244
	))->removeClass('btn-primary')->addClass('btn-warning');
245

    
246
	$counter++;
247
	$section->add($group);
248
} // end foreach
249

    
250
$section->addInput(new Form_Button(
251
	'addrow',
252
	'Add network',
253
	null,
254
	'fa-plus'
255
))->removeClass('btn-primary')->addClass('btn-success addbtn');
256

    
257
$form->add($section);
258

    
259
print($form);
260

    
261
include("foot.inc");
(130-130/228)