1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_aliases_edit.php
|
5
|
Copyright (C) 2004 Scott Ullrich
|
6
|
Copyright (C) 2009 Ermal Lu?i
|
7
|
All rights reserved.
|
8
|
|
9
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
10
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
/*
|
35
|
pfSense_BUILDER_BINARIES: /bin/rm /bin/mkdir /usr/bin/fetch
|
36
|
pfSense_MODULE: aliases
|
37
|
*/
|
38
|
|
39
|
##|+PRIV
|
40
|
##|*IDENT=page-firewall-alias-edit
|
41
|
##|*NAME=Firewall: Alias: Edit page
|
42
|
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
|
43
|
##|*MATCH=firewall_aliases_edit.php*
|
44
|
##|-PRIV
|
45
|
|
46
|
$pgtitle = array("Firewall","Aliases","Edit");
|
47
|
|
48
|
// Keywords not allowed in names
|
49
|
$reserved_keywords = array("pass", "out", "queue", "max", "min", "pptp", "pppoe", "l2tp", "openvpn");
|
50
|
|
51
|
require("guiconfig.inc");
|
52
|
require_once("functions.inc");
|
53
|
require_once("filter.inc");
|
54
|
require_once("shaper.inc");
|
55
|
|
56
|
$reserved_ifs = get_configured_interface_list(false, true);
|
57
|
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs);
|
58
|
|
59
|
if (!is_array($config['aliases']['alias']))
|
60
|
$config['aliases']['alias'] = array();
|
61
|
$a_aliases = &$config['aliases']['alias'];
|
62
|
|
63
|
if($_POST)
|
64
|
$origname = $_POST['origname'];
|
65
|
|
66
|
// Debugging
|
67
|
if($debug)
|
68
|
exec("rm -f {$g['tmp_path']}/alias_rename_log.txt");
|
69
|
|
70
|
function alias_same_type($name, $type) {
|
71
|
global $config;
|
72
|
|
73
|
foreach ($config['aliases']['alias'] as $alias) {
|
74
|
if ($name == $alias['name']) {
|
75
|
if (in_array($type, array("host", "network")) &&
|
76
|
in_array($alias['type'], array("host", "network")))
|
77
|
return true;
|
78
|
if ($type == $alias['type'])
|
79
|
return true;
|
80
|
else
|
81
|
return false;
|
82
|
}
|
83
|
}
|
84
|
return true;
|
85
|
}
|
86
|
|
87
|
$id = $_GET['id'];
|
88
|
if (isset($_POST['id']))
|
89
|
$id = $_POST['id'];
|
90
|
|
91
|
if (isset($id) && $a_aliases[$id]) {
|
92
|
$original_alias_name = $a_aliases[$id]['name'];
|
93
|
$pconfig['name'] = $a_aliases[$id]['name'];
|
94
|
$pconfig['detail'] = $a_aliases[$id]['detail'];
|
95
|
$pconfig['address'] = $a_aliases[$id]['address'];
|
96
|
$pconfig['type'] = $a_aliases[$id]['type'];
|
97
|
$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
|
98
|
|
99
|
/* optional if list */
|
100
|
$iflist = get_configured_interface_with_descr(true, true);
|
101
|
foreach ($iflist as $if => $ifdesc)
|
102
|
if($ifdesc == $pconfig['descr'])
|
103
|
$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
|
104
|
|
105
|
|
106
|
if($a_aliases[$id]['aliasurl'] <> "") {
|
107
|
$pconfig['type'] = "url";
|
108
|
if(is_array($a_aliases[$id]['aliasurl'])) {
|
109
|
$isfirst = 0;
|
110
|
$pconfig['address'] = "";
|
111
|
foreach($a_aliases[$id]['aliasurl'] as $aa) {
|
112
|
if($isfirst == 1)
|
113
|
$pconfig['address'] .= " ";
|
114
|
$isfirst = 1;
|
115
|
$pconfig['address'] .= $aa;
|
116
|
}
|
117
|
} else {
|
118
|
$pconfig['address'] = $a_aliases[$id]['aliasurl'];
|
119
|
}
|
120
|
}
|
121
|
}
|
122
|
|
123
|
if ($_POST) {
|
124
|
|
125
|
unset($input_errors);
|
126
|
$pconfig = $_POST;
|
127
|
|
128
|
/* input validation */
|
129
|
|
130
|
$x = is_validaliasname($_POST['name']);
|
131
|
if (!isset($x)) {
|
132
|
$input_errors[] = "Reserved word used for alias name.";
|
133
|
} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
|
134
|
$input_errors[] = "Reserved word used for alias name.";
|
135
|
} else {
|
136
|
if (is_validaliasname($_POST['name']) == false)
|
137
|
$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
|
138
|
}
|
139
|
/* check for name conflicts */
|
140
|
foreach ($a_aliases as $alias) {
|
141
|
if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
|
142
|
continue;
|
143
|
|
144
|
if ($alias['name'] == $_POST['name']) {
|
145
|
$input_errors[] = "An alias with this name already exists.";
|
146
|
break;
|
147
|
}
|
148
|
}
|
149
|
|
150
|
/* Check for reserved keyword names */
|
151
|
foreach($reserved_keywords as $rk)
|
152
|
if($rk == $_POST['name'])
|
153
|
$input_errors[] = "Cannot use a reserved keyword as alias name $rk";
|
154
|
|
155
|
/* check for name interface description conflicts */
|
156
|
foreach($config['interfaces'] as $interface) {
|
157
|
if($interface['descr'] == $_POST['name']) {
|
158
|
$input_errors[] = "An interface description with this name already exists.";
|
159
|
break;
|
160
|
}
|
161
|
}
|
162
|
|
163
|
$alias = array();
|
164
|
$alias['name'] = $_POST['name'];
|
165
|
if($_POST['type'] == "url") {
|
166
|
$address = "";
|
167
|
$isfirst = 0;
|
168
|
$address_count = 2;
|
169
|
|
170
|
/* item is a url type */
|
171
|
for($x=0; isset($_POST['address'. $x]); $x++) {
|
172
|
if($_POST['address' . $x]) {
|
173
|
/* fetch down and add in */
|
174
|
$isfirst = 0;
|
175
|
$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
|
176
|
unlink($temp_filename);
|
177
|
$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
|
178
|
fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
|
179
|
fclose($fda);
|
180
|
mwexec("/bin/mkdir -p {$temp_filename}");
|
181
|
mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
|
182
|
/* if the item is tar gzipped then extract */
|
183
|
if(stristr($_POST['address' . $x], ".tgz"))
|
184
|
process_alias_tgz($temp_filename);
|
185
|
if(file_exists("{$temp_filename}/aliases")) {
|
186
|
$file_contents = file_get_contents("{$temp_filename}/aliases");
|
187
|
$file_contents = str_replace("#", "\n#", $file_contents);
|
188
|
$file_contents_split = split("\n", $file_contents);
|
189
|
foreach($file_contents_split as $fc) {
|
190
|
$tmp = trim($fc);
|
191
|
if(stristr($fc, "#")) {
|
192
|
$tmp_split = split("#", $tmp);
|
193
|
$tmp = trim($tmp_split[0]);
|
194
|
}
|
195
|
if(trim($tmp) <> "") {
|
196
|
if($isfirst == 1)
|
197
|
$address .= " ";
|
198
|
$address .= $tmp;
|
199
|
$isfirst = 1;
|
200
|
}
|
201
|
}
|
202
|
if($isfirst == 0) {
|
203
|
/* nothing was found */
|
204
|
$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
|
205
|
$dont_update = true;
|
206
|
break;
|
207
|
}
|
208
|
$alias['aliasurl'][] = $_POST['address' . $x];
|
209
|
mwexec("/bin/rm -rf {$temp_filename}");
|
210
|
} else {
|
211
|
$input_errors[] = "You must provide a valid URL.";
|
212
|
$dont_update = true;
|
213
|
break;
|
214
|
}
|
215
|
}
|
216
|
}
|
217
|
} else {
|
218
|
$address = "";
|
219
|
$isfirst = 0;
|
220
|
/* item is a normal alias type */
|
221
|
$wrongaliases = "";
|
222
|
for($x=0; $x<4999; $x++) {
|
223
|
if($_POST["address{$x}"] <> "") {
|
224
|
$count = 1;
|
225
|
if ($isfirst > 0)
|
226
|
$address .= " ";
|
227
|
if (is_iprange($_POST["address{$x}"])) {
|
228
|
list($startip, $endip) = explode('-', $_POST["address{$x}"]);
|
229
|
$rangesubnets = ip_range_to_subnet_array($startip, $endip);
|
230
|
$count = count($rangesubnets);
|
231
|
$address .= implode($rangesubnets, ' ');
|
232
|
} else {
|
233
|
$address .= $_POST["address{$x}"];
|
234
|
if(($_POST['type'] == "network" || is_ipaddr($_POST["address{$x}"])) && $_POST["address_subnet{$x}"] <> "")
|
235
|
$address .= "/" . $_POST["address_subnet{$x}"];
|
236
|
}
|
237
|
if($_POST["detail{$x}"] <> "") {
|
238
|
$final_address_details .= str_repeat($_POST["detail{$x}"] . "||", $count);
|
239
|
} else {
|
240
|
$final_address_details .= str_repeat("Entry added " . date('r') . "||", $count);
|
241
|
}
|
242
|
$isfirst += $count;
|
243
|
|
244
|
if (is_alias($_POST["address{$x}"])) {
|
245
|
if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
|
246
|
$wrongaliases .= " " . $_POST["address{$x}"];
|
247
|
} else if ($_POST['type'] == "port") {
|
248
|
if (!is_port($_POST["address{$x}"]))
|
249
|
$input_errors[] = $_POST["address{$x}"] . " is not a valid port or alias.";
|
250
|
} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
|
251
|
if (!is_ipaddr($_POST["address{$x}"])
|
252
|
&& !is_hostname($_POST["address{$x}"])
|
253
|
&& !is_iprange($_POST["address{$x}"]))
|
254
|
$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
|
255
|
}
|
256
|
}
|
257
|
}
|
258
|
if ($wrongaliases <> "")
|
259
|
$input_errors[] = "The alias(es): {$wrongaliases} \ncannot be nested cause they are not of the same type.";
|
260
|
}
|
261
|
|
262
|
if (!$input_errors) {
|
263
|
$alias['address'] = $address;
|
264
|
$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
|
265
|
$alias['type'] = $_POST['type'];
|
266
|
$alias['detail'] = $final_address_details;
|
267
|
|
268
|
/* Check to see if alias name needs to be
|
269
|
* renamed on referenced rules and such
|
270
|
*/
|
271
|
if ($_POST['name'] <> $_POST['origname']) {
|
272
|
// Firewall rules
|
273
|
update_alias_names_upon_change('filter', 'rule', 'source', 'address', $_POST['name'], $origname);
|
274
|
update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $_POST['name'], $origname);
|
275
|
// NAT Rules
|
276
|
update_alias_names_upon_change('nat', 'rule', 'target', '', $_POST['name'], $origname);
|
277
|
update_alias_names_upon_change('nat', 'rule', 'external-port', '', $_POST['name'], $origname);
|
278
|
update_alias_names_upon_change('nat', 'rule', 'local-port', '' , $_POST['name'], $origname);
|
279
|
// Alias in an alias
|
280
|
update_alias_names_upon_change('aliases', 'alias', 'address', '' , $_POST['name'], $origname);
|
281
|
}
|
282
|
|
283
|
if (isset($id) && $a_aliases[$id]) {
|
284
|
if ($a_aliases[$id]['name'] <> $alias['name']) {
|
285
|
foreach ($a_aliases as $aliasid => $aliasd) {
|
286
|
if ($aliasd['address'] <> "") {
|
287
|
$tmpdirty = false;
|
288
|
$tmpaddr = explode(" ", $aliasd['address']);
|
289
|
foreach ($tmpaddr as $tmpidx => $tmpalias) {
|
290
|
if ($tmpalias == $a_aliases[$id]['name']) {
|
291
|
$tmpaddr[$tmpidx] = $alias['name'];
|
292
|
$tmpdirty = true;
|
293
|
}
|
294
|
}
|
295
|
if ($tmpdirty == true)
|
296
|
$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
|
297
|
}
|
298
|
}
|
299
|
}
|
300
|
$a_aliases[$id] = $alias;
|
301
|
} else
|
302
|
$a_aliases[] = $alias;
|
303
|
|
304
|
mark_subsystem_dirty('aliases');
|
305
|
|
306
|
// Sort list
|
307
|
$a_aliases = msort($a_aliases, "name");
|
308
|
|
309
|
write_config();
|
310
|
filter_configure();
|
311
|
|
312
|
header("Location: firewall_aliases.php");
|
313
|
exit;
|
314
|
}
|
315
|
//we received input errors, copy data to prevent retype
|
316
|
else
|
317
|
{
|
318
|
$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
|
319
|
$pconfig['address'] = $address;
|
320
|
$pconfig['type'] = $_POST['type'];
|
321
|
$pconfig['detail'] = $final_address_details;
|
322
|
}
|
323
|
}
|
324
|
|
325
|
include("head.inc");
|
326
|
|
327
|
$jscriptstr = <<<EOD
|
328
|
|
329
|
<script type="text/javascript">
|
330
|
|
331
|
var objAlias = new Array(4999);
|
332
|
function typesel_change() {
|
333
|
switch (document.iform.type.selectedIndex) {
|
334
|
case 0: /* host */
|
335
|
var cmd;
|
336
|
|
337
|
newrows = totalrows;
|
338
|
for(i=0; i<newrows; i++) {
|
339
|
comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
|
340
|
eval(comd);
|
341
|
comd = 'document.iform.address_subnet' + i + '.value = "";';
|
342
|
eval(comd);
|
343
|
}
|
344
|
break;
|
345
|
case 1: /* network */
|
346
|
var cmd;
|
347
|
|
348
|
newrows = totalrows;
|
349
|
for(i=0; i<newrows; i++) {
|
350
|
comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
|
351
|
eval(comd);
|
352
|
}
|
353
|
break;
|
354
|
case 2: /* port */
|
355
|
var cmd;
|
356
|
|
357
|
newrows = totalrows;
|
358
|
for(i=0; i<newrows; i++) {
|
359
|
comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
|
360
|
eval(comd);
|
361
|
comd = 'document.iform.address_subnet' + i + '.value = "32";';
|
362
|
eval(comd);
|
363
|
}
|
364
|
break;
|
365
|
case 3: /* OpenVPN Users */
|
366
|
var cmd;
|
367
|
|
368
|
newrows = totalrows;
|
369
|
for(i=0; i<newrows; i++) {
|
370
|
comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
|
371
|
eval(comd);
|
372
|
comd = 'document.iform.address_subnet' + i + '.value = "";';
|
373
|
eval(comd);
|
374
|
}
|
375
|
break;
|
376
|
|
377
|
case 4: /* url */
|
378
|
var cmd;
|
379
|
newrows = totalrows;
|
380
|
for(i=0; i<newrows; i++) {
|
381
|
comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
|
382
|
eval(comd);
|
383
|
}
|
384
|
break;
|
385
|
}
|
386
|
}
|
387
|
|
388
|
function add_alias_control() {
|
389
|
var name = "address" + (totalrows - 1);
|
390
|
obj = document.getElementById(name);
|
391
|
obj.setAttribute('class', 'formfldalias');
|
392
|
obj.setAttribute('autocomplete', 'off');
|
393
|
objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
|
394
|
}
|
395
|
EOD;
|
396
|
|
397
|
$network_str = gettext("Network");
|
398
|
$networks_str = gettext("Network(s)");
|
399
|
$cidr_str = gettext("CIDR");
|
400
|
$description_str = gettext("Description");
|
401
|
$hosts_str = gettext("Host(s)");
|
402
|
$ip_str = gettext("IP");
|
403
|
$ports_str = gettext("Port(s)");
|
404
|
$port_str = gettext("Port");
|
405
|
$url_str = gettext("URL");
|
406
|
$update_freq_str = gettext("Update Freq.");
|
407
|
|
408
|
$networks_help = gettext("Networks are specified in CIDR format. Select the CIDR mask that pertains to each entry. /32 specifies a single host, /24 specifies 255.255.255.0, etc. Hostnames (FQDNs) may also be specified, using a /32 mask.");
|
409
|
$hosts_help = gettext("Enter as many hosts as you would like. Hosts must be specified by their IP address.");
|
410
|
$ports_help = gettext("Enter as many ports as you wish. Port ranges can be expressed by seperating with a colon.");
|
411
|
$url_help = gettext("Enter as many urls as you wish. Also set the time that you would like the url refreshed in days. After saving {$g['product_name']} will download the URL and import the items into the alias.");
|
412
|
|
413
|
$openvpn_str = gettext("Username");
|
414
|
$openvpn_user_str = gettext("OpenVPN Users");
|
415
|
$openvpn_help = gettext("Enter as many usernames as you wish.");
|
416
|
$openvpn_freq = gettext("");
|
417
|
|
418
|
$jscriptstr .= <<<EOD
|
419
|
|
420
|
function update_box_type() {
|
421
|
var indexNum = document.forms[0].type.selectedIndex;
|
422
|
var selected = document.forms[0].type.options[indexNum].text;
|
423
|
if(selected == '{$networks_str}') {
|
424
|
document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
|
425
|
document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
|
426
|
document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
|
427
|
document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
|
428
|
document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
|
429
|
} else if(selected == '{$hosts_str}') {
|
430
|
document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
|
431
|
document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
|
432
|
document.getElementById ("twocolumn").firstChild.data = "";
|
433
|
document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
|
434
|
document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
|
435
|
} else if(selected == '{$ports_str}') {
|
436
|
document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
|
437
|
document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
|
438
|
document.getElementById ("twocolumn").firstChild.data = "";
|
439
|
document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
|
440
|
document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
|
441
|
} else if(selected == '{$url_str}') {
|
442
|
document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
|
443
|
document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
|
444
|
document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
|
445
|
document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
|
446
|
document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
|
447
|
} else if(selected == '{$openvpn_user_str}') {
|
448
|
document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
|
449
|
document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
|
450
|
document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
|
451
|
document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
|
452
|
document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
|
453
|
}
|
454
|
}
|
455
|
</script>
|
456
|
|
457
|
EOD;
|
458
|
|
459
|
?>
|
460
|
|
461
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
|
462
|
<?php
|
463
|
include("fbegin.inc");
|
464
|
echo $jscriptstr;
|
465
|
?>
|
466
|
|
467
|
<script type="text/javascript" src="/javascript/row_helper.js">
|
468
|
</script>
|
469
|
<script type="text/javascript" src="/javascript/autosuggest.js">
|
470
|
</script>
|
471
|
<script type="text/javascript" src="/javascript/suggestions.js">
|
472
|
</script>
|
473
|
|
474
|
<input type='hidden' name='address_type' value='textbox' />
|
475
|
<input type='hidden' name='address_subnet_type' value='select' />
|
476
|
|
477
|
<script type="text/javascript">
|
478
|
rowname[0] = "address";
|
479
|
rowtype[0] = "textbox";
|
480
|
rowsize[0] = "30";
|
481
|
|
482
|
rowname[1] = "address_subnet";
|
483
|
rowtype[1] = "select";
|
484
|
rowsize[1] = "1";
|
485
|
|
486
|
rowname[2] = "detail";
|
487
|
rowtype[2] = "textbox";
|
488
|
rowsize[2] = "50";
|
489
|
</script>
|
490
|
|
491
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
492
|
<div id="inputerrors"></div>
|
493
|
|
494
|
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
|
495
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
496
|
<tr>
|
497
|
<td colspan="2" valign="top" class="listtopic">Alias Edit</td>
|
498
|
</tr>
|
499
|
<tr>
|
500
|
<td valign="top" class="vncellreq">Name</td>
|
501
|
<td class="vtable">
|
502
|
<input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
|
503
|
<input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
|
504
|
<br />
|
505
|
<span class="vexpl">
|
506
|
The name of the alias may only consist of the characters a-z, A-Z and 0-9.
|
507
|
</span>
|
508
|
</td>
|
509
|
</tr>
|
510
|
<tr>
|
511
|
<td width="22%" valign="top" class="vncell">Description</td>
|
512
|
<td width="78%" class="vtable">
|
513
|
<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
|
514
|
<br />
|
515
|
<span class="vexpl">
|
516
|
You may enter a description here for your reference (not parsed).
|
517
|
</span>
|
518
|
</td>
|
519
|
</tr>
|
520
|
<tr>
|
521
|
<td valign="top" class="vncellreq">Type</td>
|
522
|
<td class="vtable">
|
523
|
<select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
|
524
|
<option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
|
525
|
<option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
|
526
|
<option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
|
527
|
<option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected"; ?>>OpenVPN Users</option>
|
528
|
</select>
|
529
|
</td>
|
530
|
</tr>
|
531
|
<tr>
|
532
|
<td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
|
533
|
<td width="78%" class="vtable">
|
534
|
<table id="maintable">
|
535
|
<tbody>
|
536
|
<tr>
|
537
|
<td colspan="4">
|
538
|
<div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">Item information</div>
|
539
|
</td>
|
540
|
</tr>
|
541
|
<tr>
|
542
|
<td><div id="onecolumn">Network</div></td>
|
543
|
<td><div id="twocolumn">CIDR</div></td>
|
544
|
<td><div id="threecolumn">Description</div></td>
|
545
|
</tr>
|
546
|
|
547
|
<?php
|
548
|
$counter = 0;
|
549
|
$address = $pconfig['address'];
|
550
|
if ($address <> "") {
|
551
|
$item = explode(" ", $address);
|
552
|
$item3 = explode("||", $pconfig['detail']);
|
553
|
foreach($item as $ww) {
|
554
|
$address = $item[$counter];
|
555
|
$address_subnet = "";
|
556
|
$item2 = explode("/", $address);
|
557
|
foreach($item2 as $current) {
|
558
|
if($item2[1] <> "") {
|
559
|
$address = $item2[0];
|
560
|
$address_subnet = $item2[1];
|
561
|
}
|
562
|
}
|
563
|
$item4 = $item3[$counter];
|
564
|
$tracker = $counter;
|
565
|
?>
|
566
|
<tr>
|
567
|
<td>
|
568
|
<input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
|
569
|
</td>
|
570
|
<td>
|
571
|
<select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
|
572
|
<option></option>
|
573
|
<?php for ($i = 32; $i >= 1; $i--): ?>
|
574
|
<option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
|
575
|
<?php endfor; ?>
|
576
|
</select>
|
577
|
</td>
|
578
|
<td>
|
579
|
<input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
|
580
|
</td>
|
581
|
<td>
|
582
|
<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
|
583
|
</td>
|
584
|
</tr>
|
585
|
<?php
|
586
|
$counter++;
|
587
|
|
588
|
} // end foreach
|
589
|
} // end if
|
590
|
?>
|
591
|
</tbody>
|
592
|
<tfoot>
|
593
|
|
594
|
</tfoot>
|
595
|
</table>
|
596
|
<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
|
597
|
<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
|
598
|
</a>
|
599
|
</td>
|
600
|
</tr>
|
601
|
<tr>
|
602
|
<td width="22%" valign="top"> </td>
|
603
|
<td width="78%">
|
604
|
<input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
|
605
|
<a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
|
606
|
<?php if (isset($id) && $a_aliases[$id]): ?>
|
607
|
<input name="id" type="hidden" value="<?=$id;?>" />
|
608
|
<?php endif; ?>
|
609
|
</td>
|
610
|
</tr>
|
611
|
</table>
|
612
|
</form>
|
613
|
|
614
|
<script type="text/javascript">
|
615
|
field_counter_js = 3;
|
616
|
rows = 1;
|
617
|
totalrows = <?php echo $counter; ?>;
|
618
|
loaded = <?php echo $counter; ?>;
|
619
|
typesel_change();
|
620
|
update_box_type();
|
621
|
|
622
|
<?php
|
623
|
$isfirst = 0;
|
624
|
$aliases = "";
|
625
|
$addrisfirst = 0;
|
626
|
$aliasesaddr = "";
|
627
|
if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
|
628
|
foreach($config['aliases']['alias'] as $alias_name) {
|
629
|
if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
|
630
|
continue;
|
631
|
if($addrisfirst == 1) $aliasesaddr .= ",";
|
632
|
$aliasesaddr .= "'" . $alias_name['name'] . "'";
|
633
|
$addrisfirst = 1;
|
634
|
}
|
635
|
?>
|
636
|
|
637
|
var addressarray=new Array(<?php echo $aliasesaddr; ?>);
|
638
|
|
639
|
<?php
|
640
|
for ($jv = 0; $jv < $counter; $jv++)
|
641
|
echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
|
642
|
?>
|
643
|
|
644
|
|
645
|
</script>
|
646
|
|
647
|
<?php include("fend.inc"); ?>
|
648
|
</body>
|
649
|
</html>
|
650
|
|
651
|
<?php
|
652
|
function process_alias_tgz($temp_filename) {
|
653
|
mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
|
654
|
mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
|
655
|
unlink("{$temp_filename}/aliases.tgz");
|
656
|
$files_to_process = return_dir_as_array("{$temp_filename}/");
|
657
|
/* foreach through all extracted files and build up aliases file */
|
658
|
$fd = fopen("{$temp_filename}/aliases", "a");
|
659
|
foreach($files_to_process as $f2p) {
|
660
|
$file_contents = file_get_contents($f2p);
|
661
|
fwrite($fd, $file_contents);
|
662
|
unlink($f2p);
|
663
|
}
|
664
|
fclose($fd);
|
665
|
}
|
666
|
|
667
|
?>
|