Project

General

Profile

Download (19 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	guiconfig.inc
5
	by Scott Ullrich, Copyright 2004, All rights reserved.
6
	originally based on of m0n0wall (http://m0n0.ch/wall)
7

    
8
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
9
	All rights reserved.
10

    
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13

    
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16

    
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20

    
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
/* make sure nothing is cached */
34
if (!$omit_nocacheheaders) {
35
	header("Expires: 0");
36
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
37
	header("Cache-Control: no-store, no-cache, must-revalidate");
38
	header("Cache-Control: post-check=0, pre-check=0", false);
39
	header("Pragma: no-cache");
40
}
41

    
42
/* Include authentication routines */
43
/* THIS MUST BE ABOVE ALL OTHER CODE */
44
require_once("auth.inc");
45

    
46
/* parse the configuration and include all configuration functions */
47
require_once("config.inc");
48
require_once("functions.inc");
49

    
50
/*
51
 *   if user has selected a custom template, use it.
52
 *   otherwise default to pfsense tempalte
53
 */
54
if($config['theme'] <> "")
55
        $g['theme'] = $config['theme'];
56
else
57
        $g['theme'] = "pfsense";
58

    
59
$d_landirty_path = $g['varrun_path'] . "/lan.conf.dirty";
60
$d_pppoeuserdirty_path = $g['varrun_path'] . "/vpn-pppoe-users-edit.dirty";
61
$d_hostsdirty_path = $g['varrun_path'] . "/hosts.dirty";
62
$d_natconfdirty_path = $g['varrun_path'] . "/nat.conf.dirty";
63
$d_filterconfdirty_path = $g['varrun_path'] . "/filter.conf.dirty";
64
$d_ipsecconfdirty_path = $g['varrun_path'] . "/ipsec.conf.dirty";
65
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
66
$d_pptpuserdirty_path = $g['varrun_path'] . "/pptpd.user.dirty";
67
$d_dnsmasqdirty_path = $g['varrun_path'] . "/dnsmasq.dirty";
68
$d_staticmapsdirty_path = $g['varrun_path'] . "/staticmaps.dirty";
69
$d_staticroutesdirty_path = $g['varrun_path'] . "/staticroutes.dirty";
70
$d_aliasesdirty_path = $g['varrun_path'] . "/aliases.dirty";
71
$d_proxyarpdirty_path = $g['varrun_path'] . "/proxyarp.dirty";
72
$d_fwupenabled_path = $g['varrun_path'] . "/fwup.enabled";
73
$d_firmwarelock_path = $g['varrun_path'] . "/firmware.lock";
74
$d_sysrebootreqd_path = $g['varrun_path'] . "/sysreboot.reqd";
75
$d_passthrumacsdirty_path = $g['varrun_path'] . "/passthrumacs.dirty";
76
$d_allowedipsdirty_path = $g['varrun_path'] . "/allowedips.dirty";
77
$d_ovpnclidirty_path = $g['varrun_path'] . "/ovpnclient.dirty";
78
$d_vipconfdirty_path = $g['varrun_path'] . "/vip.conf.dirty";
79
$d_poolconfdirty_path = $g['varrun_path'] . "/pool.conf.dirty";
80
$d_vsconfdirty_path = $g['varrun_path'] . "/vs.conf.dirty";
81
/* used by progress bar */
82
$lastseen = "-1";
83

    
84
if (file_exists($d_firmwarelock_path)) {
85
	if (!$d_isfwfile) {
86
		header("Location: system_firmware.php");
87
		exit;
88
	} else {
89
		return;
90
	}
91
}
92

    
93
/* some well knows ports */
94
$wkports = array(3389 => "MS RDP",
95
	21 => "FTP",
96
	22 => "SSH",
97
	23 => "Telnet",
98
	25 => "SMTP",
99
	53 => "DNS",
100
	80 => "HTTP",
101
	110 => "POP3",
102
	113 => "IDENT/AUTH",
103
	123 => "NTP",
104
	143 => "IMAP",
105
	443 => "HTTPS",
106
	993 => "IMAP/S");
107

    
108
$specialnets = array("wanip" => "WAN address","lan" => "LAN net", "pptp" => "PPTP clients");
109

    
110
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
111
	$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
112
}
113

    
114
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
115
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
116
	"10half" => "10BASE-T half-duplex");
117

    
118
/* platforms that support firmware updating */
119
$fwupplatforms = array('pfSense', 'net45xx', 'net48xx', 'generic-pc', 'embedded', 'wrap');
120

    
121
/* IPsec defines */
122
$my_identifier_list = array('myaddress' => 'My IP address',
123
				'address' => 'IP address',
124
				'fqdn' => 'Domain name',
125
				'user_fqdn' => 'User FQDN',
126
				'dyn_dns' => 'Dynamic DNS');
127

    
128
$p1_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
129
                                        'cast128' => 'CAST128');
130
$p2_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
131
                                        'cast128' => 'CAST128', 'rijndael' => 'Rijndael (AES)');
132
$p1_halgos = array('sha1' => 'SHA1', 'md5' => 'MD5');
133
$p1_authentication_methods = array('pre_shared_key' => 'Pre-shared key', 'rsasig' => 'RSA signature');
134
$p2_halgos = array('hmac_sha1' => 'SHA1', 'hmac_md5' => 'MD5');
135
$p2_protos = array('esp' => 'ESP', 'ah' => 'AH');
136
$p2_pfskeygroups = array('0' => 'off', '1' => '1', '2' => '2', '5' => '5');
137

    
138
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
139

    
140
	/* check for bad control characters */
141
	foreach ($postdata as $pn => $pd) {
142
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
143
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
144
		}
145
	}
146

    
147
	for ($i = 0; $i < count($reqdfields); $i++) {
148
		if ($_POST[$reqdfields[$i]] == "") { 
149
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
150
		}
151
	}
152
}
153

    
154
function print_input_errors($input_errors) {
155
	global $g;
156
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
157
	echo "<tr><td bgcolor=\"#990000\" width=\"36\" align=\"center\" valign=\"top\"><img src=\"./themes/".$g['theme']."/images/icons/icon_error.gif\" width=\"28\" height=\"32\"></td>\n";
158
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
159

    
160
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
161
	foreach ($input_errors as $ierr) {
162
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
163
	}
164
	echo "</ul></span>";
165

    
166
	echo "</td></tr></table></p>&nbsp;<br>";
167
}
168

    
169
function exec_rc_script($scriptname) {
170

    
171
	global $d_sysrebootreqd_path;
172

    
173
	if (file_exists($d_sysrebootreqd_path))
174
		return 0;
175

    
176
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
177
	return $retval;
178
}
179

    
180
function exec_rc_script_async($scriptname) {
181

    
182
	global $d_sysrebootreqd_path;
183

    
184
	if (file_exists($d_sysrebootreqd_path))
185
		return 0;
186

    
187
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
188
	return $retval;
189
}
190

    
191
function verify_gzip_file($fname) {
192

    
193
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
194
	if ($returnvar != 0)
195
		return 0;
196
	else
197
		return 1;
198
}
199

    
200
function print_info_box_np($msg) {
201
	global $g;
202
	echo "<table height=\"32\" width=\"100%\">\n";
203
	echo "  <tr>\n";
204
	echo "   <td>\n";
205
	echo "      <div style='background-color:#990000' id='redbox'>\n";
206
	echo "       <table width='100%'><tr><td width='8%'>\n";
207
	echo "        &nbsp;&nbsp;&nbsp;<img style='vertical-align:middle' src=\"/themes/".$g['theme']."/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\">\n";
208
	echo "        </td>\n";
209
	echo "        <td width='70%'><font color='white'><b>{$msg}</b></font>\n";
210
	echo "        </td>";
211
	if(stristr($msg, "apply") == true) {
212
		echo "         <td>";
213
		echo "           <input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"Apply changes\">\n";
214
		echo "         </td>";
215
	}
216
	echo "        </tr></table>\n";
217
	echo "       </div>\n";
218
	echo "    </td>\n";
219
	echo "</table>\n";
220
	echo "<script type=\"text/javascript\">\n";
221
	echo "NiftyCheck();\n";
222
	echo "Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");\n";
223
	echo "Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");\n";
224
	echo "</script>\n";
225
	echo "\n<br>\n";
226
}
227

    
228
function print_info_box($msg) {
229
	echo "<p>";
230
	print_info_box_np($msg);
231
	echo "</p>";
232
}
233

    
234
function format_bytes($bytes) {
235
	if ($bytes >= 1073741824) {
236
		return sprintf("%.2f GB", $bytes/1073741824);
237
	} else if ($bytes >= 1048576) {
238
		return sprintf("%.2f MB", $bytes/1048576);
239
	} else if ($bytes >= 1024) {
240
		return sprintf("%.0f KB", $bytes/1024);
241
	} else {
242
		return sprintf("%d bytes", $bytes);
243
	}
244
}
245

    
246
function get_std_save_message($ok) {
247
	global $d_sysrebootreqd_path;
248

    
249
	return "The changes have been applied successfully.";
250
}
251

    
252
function pprint_address($adr) {
253
	global $specialnets;
254

    
255
	if (isset($adr['any'])) {
256
		$padr = "*";
257
	} else if ($adr['network']) {
258
		$padr = $specialnets[$adr['network']];
259
	} else {
260
		$padr = $adr['address'];
261
	}
262

    
263
	if (isset($adr['not']))
264
		$padr = "! " . $padr;
265

    
266
	return $padr;
267
}
268

    
269
function pprint_port($port) {
270
	global $wkports;
271

    
272
	$pport = "";
273

    
274
	if (!$port)
275
		echo "*";
276
	else {
277
		$srcport = explode("-", $port);
278
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
279
			$pport = $srcport[0];
280
			if ($wkports[$srcport[0]]) {
281
				$pport .= " (" . $wkports[$srcport[0]] . ")";
282
			}
283
		} else
284
			$pport .= $srcport[0] . " - " . $srcport[1];
285
	}
286

    
287
	return $pport;
288
}
289

    
290
function captiveportal_users_sort() {
291
	global $g, $config;
292
	
293
	function cpusercmp($a, $b) {
294
		return strcasecmp($a['name'], $b['name']);
295
	}
296
	
297
	usort($config['captiveportal']['user'], "cpusercmp");
298
}
299

    
300
/* sort by interface only, retain the original order of rules that apply to
301
   the same interface */
302
function filter_rules_sort() {
303
	global $config;
304

    
305
	/* mark each rule with the sequence number (to retain the order while sorting) */
306
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
307
		$config['filter']['rule'][$i]['seq'] = $i;
308

    
309
	function filtercmp($a, $b) {
310
		if ($a['interface'] == $b['interface'])
311
			return $a['seq'] - $b['seq'];
312
		else
313
			return -strcmp($a['interface'], $b['interface']);
314
	}
315

    
316
	usort($config['filter']['rule'], "filtercmp");
317

    
318
	/* strip the sequence numbers again */
319
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
320
		unset($config['filter']['rule'][$i]['seq']);
321
}
322

    
323
function nat_rules_sort() {
324
	global $config;
325

    
326
	function natcmp($a, $b) {
327
		if ($a['external-address'] == $b['external-address']) {
328
			if ($a['protocol'] == $b['protocol']) {
329
				if ($a['external-port'] == $b['external-port']) {
330
					return 0;
331
				} else {
332
					return ($a['external-port'] - $b['external-port']);
333
				}
334
			} else {
335
				return strcmp($a['protocol'], $b['protocol']);
336
			}
337
		} else if (!$a['external-address'])
338
			return 1;
339
		else if (!$b['external-address'])
340
			return -1;
341
		else
342
			return ipcmp($a['external-address'], $b['external-address']);
343
	}
344

    
345
	usort($config['nat']['rule'], "natcmp");
346
}
347

    
348
function nat_1to1_rules_sort() {
349
	global $g, $config;
350

    
351
	function nat1to1cmp($a, $b) {
352
		return ipcmp($a['external'], $b['external']);
353
	}
354

    
355
	usort($config['nat']['onetoone'], "nat1to1cmp");
356
}
357

    
358
function nat_server_rules_sort() {
359
	global $g, $config;
360

    
361
	function natservercmp($a, $b) {
362
		return ipcmp($a['ipaddr'], $b['ipaddr']);
363
	}
364

    
365
	usort($config['nat']['servernat'], "natservercmp");
366
}
367

    
368
function nat_out_rules_sort() {
369
	global $g, $config;
370

    
371
	function natoutcmp($a, $b) {
372
		return strcmp($a['source']['network'], $b['source']['network']);
373
	}
374

    
375
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
376
}
377

    
378
function pptpd_users_sort() {
379
	global $g, $config;
380

    
381
	function usercmp($a, $b) {
382
		return strcasecmp($a['name'], $b['name']);
383
	}
384

    
385
	usort($config['pptpd']['user'], "usercmp");
386
}
387

    
388
function pppoe_users_sort() {
389
	global $g, $config;
390

    
391
	function usercmp($a, $b) {
392
		return strcasecmp($a['name'], $b['name']);
393
	}
394

    
395
	usort($config['pppoe']['user'], "usercmp");
396
}
397

    
398
function staticroutes_sort() {
399
	global $g, $config;
400

    
401
	function staticroutecmp($a, $b) {
402
		return strcmp($a['network'], $b['network']);
403
	}
404

    
405
	usort($config['staticroutes']['route'], "staticroutecmp");
406
}
407

    
408
function hosts_sort() {
409
	global $g, $config;
410

    
411
	function hostcmp($a, $b) {
412
		return strcasecmp($a['host'], $b['host']);
413
	}
414

    
415
	usort($config['dnsmasq']['hosts'], "hostcmp");
416
}
417

    
418
function staticmaps_sort($if) {
419
	global $g, $config;
420

    
421
	function staticmapcmp($a, $b) {
422
		return ipcmp($a['ipaddr'], $b['ipaddr']);
423
	}
424

    
425
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
426
}
427

    
428
function aliases_sort() {
429
	global $g, $config;
430

    
431
	function aliascmp($a, $b) {
432
		return strcmp($a['name'], $b['name']);
433
	}
434

    
435
	usort($config['aliases']['alias'], "aliascmp");
436
}
437

    
438
function ipsec_mobilekey_sort() {
439
	global $g, $config;
440

    
441
	function mobilekeycmp($a, $b) {
442
		return strcmp($a['ident'][0], $b['ident'][0]);
443
	}
444

    
445
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
446
}
447

    
448
function proxyarp_sort() {
449
	global $g, $config;
450

    
451
	function proxyarpcmp($a, $b) {
452
		if (isset($a['network']))
453
			list($ast,$asn) = explode("/", $a['network']);
454
		else if (isset($a['range'])) {
455
			$ast = $a['range']['from'];
456
			$asn = 32;
457
		}
458
		if (isset($b['network']))
459
			list($bst,$bsn) = explode("/", $b['network']);
460
		else if (isset($b['range'])) {
461
			$bst = $b['range']['from'];
462
			$bsn = 32;
463
		}
464
		if (ipcmp($ast, $bst) == 0)
465
			return ($asn - $bsn);
466
		else
467
			return ipcmp($ast, $bst);
468
	}
469

    
470
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
471
}
472

    
473
function passthrumacs_sort() {
474
	global $g, $config;
475

    
476
	function passthrumacscmp($a, $b) {
477
		return strcmp($a['mac'], $b['mac']);
478
	}
479

    
480
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
481
}
482

    
483
function cpelements_sort() {
484
	global $g, $config;
485

    
486
	function cpelementscmp($a, $b) {
487
		return strcasecmp($a['name'], $b['name']);
488
	}
489
	
490
	usort($config['captiveportal']['element'],"cpelementscmp");
491
}
492

    
493
function allowedips_sort() {
494
	global $g, $config;
495

    
496
	function allowedipscmp($a, $b) {
497
		return strcmp($a['ip'], $b['ip']);
498
	}
499

    
500
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
501
}
502

    
503
function wol_sort() {
504
	global $g, $config;
505

    
506
	function wolcmp($a, $b) {
507
		return strcmp($a['descr'], $b['descr']);
508
	}
509

    
510
	usort($config['wol']['wolentry'], "wolcmp");
511
}
512

    
513
function sort_rule_by_queue_priority() {
514
	global $g, $config;
515
	global $queues;
516

    
517
	function rqpcmp($a, $b) {
518
		global $queues;
519

    
520
		$ra = $queues[$a['outqueue']];
521
		$rb = $queues[$b['outqueue']];
522

    
523
		if ($ra == $rb)
524
			return 0;
525
		/* reverse sort - we want higher priority first */	
526
		return ($ra < $rb) ? 1 : -1;
527
	}
528

    
529
	foreach($config['shaper']['queue'] as $q) {
530
		$queues[$q['name']] = $q['priority'];
531
	}
532

    
533
	usort($config['shaper']['rule'], "rqpcmp");
534
}
535
function gentitle($pgname) {
536
	global $config;
537
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
538
}
539

    
540
/* update the changedesc and changecount(er) variables */
541
function update_changedesc($update) {
542
	global $changedesc;
543
	global $changecount;
544

    
545
	$changedesc .= " {$update}";
546
	$changecount++;
547
}
548

    
549
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
550
	global $g, $config;
551
        $sor = isset($config['syslog']['reverse']) ? "-r" : "";
552
	exec("/usr/sbin/clog {$logfile} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
553
	if(is_array($grepfor)) {
554
		 $i = 0;
555
                 foreach($grepfor as $agrep) { 	 
556
                         $regexp = "/" . $agrep . "/i"; 	 
557
                         if($grepinvert[$i]) { 	 
558
                                 $logarr = preg_grep($regexp, $logarr, PREG_GREP_INVERT); 	 
559
                         } else { 	 
560
                                 $logarr = preg_grep($regexp, $logarr); 	 
561
                         }
562
			 $i++;
563
                 } 	 
564
        }
565
        foreach ($logarr as $logent) {
566
                $logent = preg_split("/\s+/", $logent, 6);
567
                echo "<tr valign=\"top\">\n";
568
                if ($withorig) {
569
                        echo "<td class=\"listlr\" nowrap>" . htmlspecialchars(join(" ", array_slice($logent, 0, 3))) . "</td>\n";
570
                        echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
571
                } else {
572
                        echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
573
                }
574
                echo "</tr>\n";
575
        }
576
}
577

    
578
/* Check if variable has changed, update and log if it has
579
 * returns true if var changed
580
 * varname = variable name in plain text
581
 * orig = original value
582
 * new = new value
583
 */
584
function update_if_changed($varname, & $orig, $new) {
585
	if (is_array($orig) && is_array($new)) {
586
		$a_diff = array_diff($orig, $new);
587
		foreach ($a_diff as $diff) {
588
			update_changedesc("removed {$varname}: \"{$diff}\"");
589
		}
590
		$a_diff = array_diff($new, $orig);
591
		foreach ($a_diff as $diff) {
592
			update_changedesc("added {$varname}: \"{$diff}\"");
593
		}
594
		$orig = $new;
595
		return true;
596
			
597
	} else { 
598
		if ($orig != $new) {
599
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
600
			$orig = $new;
601
			return true;
602
		}
603
	}
604
	return false;
605
}
606

    
607
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
608

    
609
        if (isset($adr['any']))
610
                $padr = "any";
611
        else if ($adr['network'])
612
                $padr = $adr['network'];
613
        else if ($adr['address']) {
614
                list($padr, $pmask) = explode("/", $adr['address']);
615
                if (!$pmask)
616
                        $pmask = 32;
617
        }
618

    
619
        if (isset($adr['not']))
620
                $pnot = 1;
621
        else
622
                $pnot = 0;
623

    
624
        if ($adr['port']) {
625
                list($pbeginport, $pendport) = explode("-", $adr['port']);
626
                if (!$pendport)
627
                        $pendport = $pbeginport;
628
        } else {
629
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
630
                        /* Item is a port alias */
631
                } else {
632
                        $pbeginport = "any";
633
                        $pendport = "any";
634
                }
635
        }
636
}
637

    
638
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
639

    
640
        $adr = array();
641

    
642
        if ($padr == "any")
643
                $adr['any'] = true;
644
        else if (is_specialnet($padr))
645
                $adr['network'] = $padr;
646
        else {
647
                $adr['address'] = $padr;
648
                if ($pmask != 32)
649
                        $adr['address'] .= "/" . $pmask;
650
        }
651

    
652
        if ($pnot)
653
                $adr['not'] = true;
654
        else
655
                unset($adr['not']);
656

    
657
        if (($pbeginport != 0) && ($pbeginport != "any")) {
658
                if ($pbeginport != $pendport)
659
                        $adr['port'] = $pbeginport . "-" . $pendport;
660
                else
661
                        $adr['port'] = $pbeginport;
662
        }
663

    
664
        if(alias_expand($pbeginport)) {
665
                $adr['port'] = $pbeginport;
666
        }
667
}
668

    
669
function is_specialnet($net) {
670
        global $specialsrcdst;
671

    
672
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
673
                return true;
674
        else
675
                return false;
676
}
677

    
678
function ipsec_ca_sort() {
679
        global $g, $config;
680

    
681
        function ipseccacmp($a, $b) {
682
                return strcmp($a['ident'], $b['ident']);
683
        }
684

    
685
        usort($config['ipsec']['cacert'], "ipseccacmp");
686
}
687

    
688

    
689
?>
(54-54/154)