1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
services_igmpproxy_edit.php
|
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
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
11
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
12
|
All rights reserved.
|
13
|
|
14
|
Redistribution and use in source and binary forms, with or without
|
15
|
modification, are permitted provided that the following conditions are met:
|
16
|
|
17
|
1. Redistributions of source code must retain the above copyright notice,
|
18
|
this list of conditions and the following disclaimer.
|
19
|
|
20
|
2. Redistributions in binary form must reproduce the above copyright
|
21
|
notice, this list of conditions and the following disclaimer in the
|
22
|
documentation and/or other materials provided with the distribution.
|
23
|
|
24
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
25
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
26
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
27
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
28
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
POSSIBILITY OF SUCH DAMAGE.
|
34
|
*/
|
35
|
/*
|
36
|
pfSense_MODULE: igmpproxy
|
37
|
*/
|
38
|
|
39
|
##|+PRIV
|
40
|
##|*IDENT=page-services-igmpproxy-edit
|
41
|
##|*NAME=Firewall: Igmpproxy: Edit page
|
42
|
##|*DESCR=Allow access to the 'Services: Igmpproxy: Edit' page.
|
43
|
##|*MATCH=services_igmpproxy_edit.php*
|
44
|
##|-PRIV
|
45
|
|
46
|
$pgtitle = array(gettext("Firewall"),gettext("IGMP Proxy"), gettext("Edit"));
|
47
|
|
48
|
require("guiconfig.inc");
|
49
|
|
50
|
if (!is_array($config['igmpproxy']['igmpentry']))
|
51
|
$config['igmpproxy']['igmpentry'] = array();
|
52
|
|
53
|
//igmpproxy_sort();
|
54
|
$a_igmpproxy = &$config['igmpproxy']['igmpentry'];
|
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
|
if (isset($id) && $a_igmpproxy[$id]) {
|
63
|
$pconfig['ifname'] = $a_igmpproxy[$id]['ifname'];
|
64
|
$pconfig['threshold'] = $a_igmpproxy[$id]['threshold'];
|
65
|
$pconfig['type'] = $a_igmpproxy[$id]['type'];
|
66
|
$pconfig['address'] = $a_igmpproxy[$id]['address'];
|
67
|
$pconfig['descr'] = html_entity_decode($a_igmpproxy[$id]['descr']);
|
68
|
}
|
69
|
|
70
|
// Add a row to the network table
|
71
|
if($_GET['act'] && $_GET['act'] == 'addrow')
|
72
|
$pconfig['address'] .= '/32';
|
73
|
|
74
|
// Remove a row from the network table
|
75
|
if($_GET['act'] && $_GET['act'] == 'delrow') {
|
76
|
$row = $_GET['row'];
|
77
|
|
78
|
$addresses = explode(" ", $pconfig['address']);
|
79
|
|
80
|
$pconfig['address'] = "";
|
81
|
|
82
|
$idx = 0;
|
83
|
foreach($addresses as $address) {
|
84
|
if($idx != $row)
|
85
|
$pconfig['address'] .= ($idx > 0 ? ' ':null) . $address;
|
86
|
|
87
|
$idx++;
|
88
|
}
|
89
|
}
|
90
|
|
91
|
if ($_POST) {
|
92
|
unset($input_errors);
|
93
|
$pconfig = $_POST;
|
94
|
|
95
|
if ($_POST['type'] == "upstream") {
|
96
|
foreach ($a_igmpproxy as $pid => $proxyentry) {
|
97
|
if (isset($id) && $id == $pid)
|
98
|
continue;
|
99
|
if ($proxyentry['type'] == "upstream" && $proxyentry['ifname'] != $_POST['interface'])
|
100
|
$input_errors[] = gettext("Only one 'upstream' interface can be configured.");
|
101
|
}
|
102
|
}
|
103
|
|
104
|
$igmpentry = array();
|
105
|
$igmpentry['ifname'] = $_POST['ifname'];
|
106
|
$igmpentry['threshold'] = $_POST['threshold'];
|
107
|
$igmpentry['type'] = $_POST['type'];
|
108
|
$address = "";
|
109
|
$isfirst = 0;
|
110
|
/* item is a normal igmpentry type */
|
111
|
for($x=0; $x<4999; $x++) {
|
112
|
if($_POST["address{$x}"] != "") {
|
113
|
if ($isfirst > 0)
|
114
|
$address .= " ";
|
115
|
$address .= $_POST["address{$x}"];
|
116
|
$address .= "/" . $_POST["address_subnet{$x}"];
|
117
|
$isfirst++;
|
118
|
}
|
119
|
}
|
120
|
|
121
|
if (!$input_errors) {
|
122
|
$igmpentry['address'] = $address;
|
123
|
$igmpentry['descr'] = $_POST['descr'];
|
124
|
|
125
|
if (isset($id) && $a_igmpproxy[$id])
|
126
|
$a_igmpproxy[$id] = $igmpentry;
|
127
|
else
|
128
|
$a_igmpproxy[] = $igmpentry;
|
129
|
|
130
|
write_config();
|
131
|
|
132
|
mark_subsystem_dirty('igmpproxy');
|
133
|
header("Location: services_igmpproxy.php");
|
134
|
exit;
|
135
|
}
|
136
|
//we received input errors, copy data to prevent retype
|
137
|
else
|
138
|
{
|
139
|
$pconfig['descr'] = $_POST['descr'];
|
140
|
$pconfig['address'] = $address;
|
141
|
$pconfig['type'] = $_POST['type'];
|
142
|
}
|
143
|
}
|
144
|
|
145
|
include("head.inc");
|
146
|
|
147
|
if ($input_errors)
|
148
|
print_input_errors($input_errors);
|
149
|
|
150
|
require('classes/Form.class.php');
|
151
|
|
152
|
// These two inputs appear inthe original file. Don't know what they are for
|
153
|
// but they are here just in case.
|
154
|
|
155
|
$h1 = new Form_Input(
|
156
|
'address_type',
|
157
|
null,
|
158
|
'textbox',
|
159
|
'hidden'
|
160
|
);
|
161
|
|
162
|
$h2 = new Form_Input(
|
163
|
'address_subnet_type',
|
164
|
null,
|
165
|
'select',
|
166
|
'hidden'
|
167
|
);
|
168
|
|
169
|
$form = new Form;
|
170
|
|
171
|
$section = new Form_Section('IGMP Proxy Edit');
|
172
|
|
173
|
$optionlist = array();
|
174
|
$iflist = get_configured_interface_with_descr();
|
175
|
|
176
|
foreach ($iflist as $ifnam => $ifdescr)
|
177
|
$optionlist[$ifnam] = $ifdescr;
|
178
|
|
179
|
$section->addInput(new Form_Select(
|
180
|
'ifname',
|
181
|
'Interface',
|
182
|
$pconfig['ifname'],
|
183
|
$optionlist
|
184
|
));
|
185
|
|
186
|
$section->addInput(new Form_Input(
|
187
|
'descr',
|
188
|
'Description',
|
189
|
'text',
|
190
|
$pconfig['descr']
|
191
|
))->setHelp('You may enter a description here for your reference (not parsed).');
|
192
|
|
193
|
$section->addInput(new Form_Select(
|
194
|
'type',
|
195
|
'Type',
|
196
|
$pconfig['type'],
|
197
|
['upstream' => gettext('Upstream Interface'), 'downstream' => gettext('Downstream Interface')]
|
198
|
))->setHelp('The upstream network interface is the outgoing interface which is responsible for communicating to available multicast data sources .' .
|
199
|
'There can only be one upstream interface.' . '<br />' .
|
200
|
'Downstream network interfaces are the distribution interfaces to the destination networks, where multicast clients can join groups and '.
|
201
|
'receive multicast data. One or more downstream interfaces must be configured.');
|
202
|
|
203
|
$section->addInput(new Form_Input(
|
204
|
'threshold',
|
205
|
'Threshold',
|
206
|
'text',
|
207
|
$pconfig['threshold']
|
208
|
))->setHelp('Defines the TTL threshold for the network interface. Packets with a lower TTL than the threshold value will be ignored. ' .
|
209
|
'This setting is optional, and by default the threshold is 1.');
|
210
|
|
211
|
if (isset($id) && $a_igmpproxy[$id]){
|
212
|
$section->addInput(new Form_Input(
|
213
|
'id',
|
214
|
null,
|
215
|
'hidden',
|
216
|
$id
|
217
|
));
|
218
|
}
|
219
|
|
220
|
$counter = 0;
|
221
|
$address = $pconfig['address'];
|
222
|
|
223
|
if ($address != "") {
|
224
|
$item = explode(" ", $address);
|
225
|
$rows = count($item) -1;
|
226
|
foreach($item as $ww) {
|
227
|
$address = $item[$counter];
|
228
|
$address_subnet = "";
|
229
|
$item2 = explode("/", $address);
|
230
|
foreach($item2 as $current) {
|
231
|
if($item2[1] != "") {
|
232
|
$address = $item2[0];
|
233
|
$address_subnet = $item2[1];
|
234
|
}
|
235
|
}
|
236
|
$item4 = $item3[$counter];
|
237
|
$tracker = $counter;
|
238
|
|
239
|
$group = new Form_group($tracker == 0? 'Network':null);
|
240
|
|
241
|
$group->add(new Form_Input(
|
242
|
'address' . $tracker,
|
243
|
null,
|
244
|
'text',
|
245
|
$address,
|
246
|
['placeholder' => 'Address']
|
247
|
))->sethelp($tracker == $rows ? 'Network':null);
|
248
|
|
249
|
$group->add(new Form_Select(
|
250
|
'ifname',
|
251
|
'Interface',
|
252
|
$address_subnet,
|
253
|
array_combine(range(32, 1, -1), range(32, 1, -1))
|
254
|
))->sethelp($tracker == $rows ? 'CIDR':null);;
|
255
|
|
256
|
$btndel = new Form_Button (
|
257
|
'removerow',
|
258
|
'Remove',
|
259
|
'services_igmpproxy_edit.php?act=delrow&row=' . $tracker
|
260
|
);
|
261
|
|
262
|
$btndel->removeClass('btn-primary')->addClass('btn-danger btn-sm');
|
263
|
$group->add($btndel);
|
264
|
|
265
|
$counter++;
|
266
|
$section->add($group);
|
267
|
} // end foreach
|
268
|
} // end if
|
269
|
|
270
|
$btnadd = new Form_Button (
|
271
|
'addrow',
|
272
|
'Add Network',
|
273
|
'services_igmpproxy_edit.php?act=addrow'
|
274
|
);
|
275
|
|
276
|
$btnadd->removeClass('btn-primary')->addClass('btn-success btn-sm');
|
277
|
|
278
|
$section->addInput(new Form_StaticText(
|
279
|
null,
|
280
|
$btnadd . ' (Save after each Add or Delete)'
|
281
|
));
|
282
|
|
283
|
$form->add($section);
|
284
|
|
285
|
print($form);
|
286
|
|
287
|
include("foot.inc");
|