Project

General

Profile

Download (19.5 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_vsconfdirty_path = $g['varrun_path'] . "/vs.conf.dirty";
80
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
81

    
82
/* OpenVPN Directories */
83
$d_ovpnsrvdirty_path = "/tmp/ovpn-srv.dirty";
84
$d_ovpncrldirty_path = "/tmp/ovpn-crl.dirty";
85
$d_ovpnclidirty_path = "/tmp/ovpn-cli.dirty";
86
/* used by progress bar */
87
$lastseen = "-1";
88

    
89
if (file_exists($d_firmwarelock_path)) {
90
	if (!$d_isfwfile) {
91
		header("Location: system_firmware.php");
92
		exit;
93
	} else {
94
		return;
95
	}
96
}
97

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

    
113
$specialnets = array("wanip" => "WAN address", "lanip" => "LAN address", "lan" => "LAN net", "pptp" => "PPTP clients");
114

    
115
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
116
	$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
117
}
118

    
119
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
120
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
121
	"10half" => "10BASE-T half-duplex");
122

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

    
126
/* IPsec defines */
127
$my_identifier_list = array('myaddress' => 'My IP address',
128
				'address' => 'IP address',
129
				'fqdn' => 'Domain name',
130
				'user_fqdn' => 'User FQDN',
131
				'dyn_dns' => 'Dynamic DNS');
132

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

    
143
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
144

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

    
152
	for ($i = 0; $i < count($reqdfields); $i++) {
153
		if ($_POST[$reqdfields[$i]] == "") { 
154
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
155
		}
156
	}
157
}
158

    
159
function print_input_errors($input_errors) {
160
	global $g;
161
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
162
	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";
163
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
164

    
165
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
166
	foreach ($input_errors as $ierr) {
167
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
168
	}
169
	echo "</ul></span>";
170

    
171
	echo "</td></tr></table></p>&nbsp;<br>";
172
}
173

    
174
function exec_rc_script($scriptname) {
175

    
176
	global $d_sysrebootreqd_path;
177

    
178
	if (file_exists($d_sysrebootreqd_path))
179
		return 0;
180
	$execoutput = "";
181
	$retval = "";
182
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
183
	return $retval;
184
}
185

    
186
function exec_rc_script_async($scriptname) {
187

    
188
	global $d_sysrebootreqd_path;
189
	$execoutput = "";
190
	$retval = "";
191
	if (file_exists($d_sysrebootreqd_path))
192
		return 0;
193

    
194
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
195
	return $retval;
196
}
197

    
198
function verify_gzip_file($fname) {
199

    
200
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
201
	if ($returnvar != 0)
202
		return 0;
203
	else
204
		return 1;
205
}
206

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

    
235
function print_info_box($msg) {
236
	echo "<p>";
237
	print_info_box_np($msg);
238
	echo "</p>";
239
}
240

    
241
function format_bytes($bytes) {
242
	if ($bytes >= 1073741824) {
243
		return sprintf("%.2f GB", $bytes/1073741824);
244
	} else if ($bytes >= 1048576) {
245
		return sprintf("%.2f MB", $bytes/1048576);
246
	} else if ($bytes >= 1024) {
247
		return sprintf("%.0f KB", $bytes/1024);
248
	} else {
249
		return sprintf("%d bytes", $bytes);
250
	}
251
}
252

    
253
function get_std_save_message($ok) {
254
	global $d_sysrebootreqd_path;
255

    
256
	return "The changes have been applied successfully.  You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
257
}
258

    
259
function pprint_address($adr) {
260
	global $specialnets;
261

    
262
	if (isset($adr['any'])) {
263
		$padr = "*";
264
	} else if ($adr['network']) {
265
		$padr = $specialnets[$adr['network']];
266
	} else {
267
		$padr = $adr['address'];
268
	}
269

    
270
	if (isset($adr['not']))
271
		$padr = "! " . $padr;
272

    
273
	return $padr;
274
}
275

    
276
function pprint_port($port) {
277
	global $wkports;
278

    
279
	$pport = "";
280

    
281
	if (!$port)
282
		echo "*";
283
	else {
284
		$srcport = explode("-", $port);
285
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
286
			$pport = $srcport[0];
287
			if ($wkports[$srcport[0]]) {
288
				$pport .= " (" . $wkports[$srcport[0]] . ")";
289
			}
290
		} else
291
			$pport .= $srcport[0] . " - " . $srcport[1];
292
	}
293

    
294
	return $pport;
295
}
296

    
297
function captiveportal_users_sort() {
298
	global $g, $config;
299
	
300
	function cpusercmp($a, $b) {
301
		return strcasecmp($a['name'], $b['name']);
302
	}
303
	
304
	usort($config['captiveportal']['user'], "cpusercmp");
305
}
306

    
307
/* sort by interface only, retain the original order of rules that apply to
308
   the same interface */
309
function filter_rules_sort() {
310
	global $config;
311

    
312
	/* mark each rule with the sequence number (to retain the order while sorting) */
313
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
314
		$config['filter']['rule'][$i]['seq'] = $i;
315

    
316
	function filtercmp($a, $b) {
317
		if ($a['interface'] == $b['interface'])
318
			return $a['seq'] - $b['seq'];
319
		else
320
			return -strcmp($a['interface'], $b['interface']);
321
	}
322

    
323
	usort($config['filter']['rule'], "filtercmp");
324

    
325
	/* strip the sequence numbers again */
326
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
327
		unset($config['filter']['rule'][$i]['seq']);
328
}
329

    
330
function nat_rules_sort() {
331
	global $config;
332

    
333
	function natcmp($a, $b) {
334
		if ($a['external-address'] == $b['external-address']) {
335
			if ($a['protocol'] == $b['protocol']) {
336
				if ($a['external-port'] == $b['external-port']) {
337
					return 0;
338
				} else {
339
					return ($a['external-port'] - $b['external-port']);
340
				}
341
			} else {
342
				return strcmp($a['protocol'], $b['protocol']);
343
			}
344
		} else if (!$a['external-address'])
345
			return 1;
346
		else if (!$b['external-address'])
347
			return -1;
348
		else
349
			return ipcmp($a['external-address'], $b['external-address']);
350
	}
351

    
352
	usort($config['nat']['rule'], "natcmp");
353
}
354

    
355
function nat_1to1_rules_sort() {
356
	global $g, $config;
357

    
358
	function nat1to1cmp($a, $b) {
359
		return ipcmp($a['external'], $b['external']);
360
	}
361

    
362
	usort($config['nat']['onetoone'], "nat1to1cmp");
363
}
364

    
365
function nat_server_rules_sort() {
366
	global $g, $config;
367

    
368
	function natservercmp($a, $b) {
369
		return ipcmp($a['ipaddr'], $b['ipaddr']);
370
	}
371

    
372
	usort($config['nat']['servernat'], "natservercmp");
373
}
374

    
375
function nat_out_rules_sort() {
376
	global $g, $config;
377

    
378
	function natoutcmp($a, $b) {
379
		return strcmp($a['source']['network'], $b['source']['network']);
380
	}
381

    
382
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
383
}
384

    
385
function pptpd_users_sort() {
386
	global $g, $config;
387

    
388
	function usercmp($a, $b) {
389
		return strcasecmp($a['name'], $b['name']);
390
	}
391

    
392
	usort($config['pptpd']['user'], "usercmp");
393
}
394

    
395
function pppoe_users_sort() {
396
	global $g, $config;
397

    
398
	function usercmp($a, $b) {
399
		return strcasecmp($a['name'], $b['name']);
400
	}
401

    
402
	usort($config['pppoe']['user'], "usercmp");
403
}
404

    
405
function staticroutes_sort() {
406
	global $g, $config;
407

    
408
	function staticroutecmp($a, $b) {
409
		return strcmp($a['network'], $b['network']);
410
	}
411

    
412
	usort($config['staticroutes']['route'], "staticroutecmp");
413
}
414

    
415
function hosts_sort() {
416
	global $g, $config;
417

    
418
	function hostcmp($a, $b) {
419
		return strcasecmp($a['host'], $b['host']);
420
	}
421

    
422
	usort($config['dnsmasq']['hosts'], "hostcmp");
423
}
424

    
425
function staticmaps_sort($if) {
426
	global $g, $config;
427

    
428
	function staticmapcmp($a, $b) {
429
		return ipcmp($a['ipaddr'], $b['ipaddr']);
430
	}
431

    
432
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
433
}
434

    
435
function aliases_sort() {
436
	global $g, $config;
437

    
438
	function aliascmp($a, $b) {
439
		return strcmp($a['name'], $b['name']);
440
	}
441

    
442
	usort($config['aliases']['alias'], "aliascmp");
443
}
444

    
445
function ipsec_mobilekey_sort() {
446
	global $g, $config;
447

    
448
	function mobilekeycmp($a, $b) {
449
		return strcmp($a['ident'][0], $b['ident'][0]);
450
	}
451

    
452
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
453
}
454

    
455
function proxyarp_sort() {
456
	global $g, $config;
457

    
458
	function proxyarpcmp($a, $b) {
459
		if (isset($a['network']))
460
			list($ast,$asn) = explode("/", $a['network']);
461
		else if (isset($a['range'])) {
462
			$ast = $a['range']['from'];
463
			$asn = 32;
464
		}
465
		if (isset($b['network']))
466
			list($bst,$bsn) = explode("/", $b['network']);
467
		else if (isset($b['range'])) {
468
			$bst = $b['range']['from'];
469
			$bsn = 32;
470
		}
471
		if (ipcmp($ast, $bst) == 0)
472
			return ($asn - $bsn);
473
		else
474
			return ipcmp($ast, $bst);
475
	}
476

    
477
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
478
}
479

    
480
function passthrumacs_sort() {
481
	global $g, $config;
482

    
483
	function passthrumacscmp($a, $b) {
484
		return strcmp($a['mac'], $b['mac']);
485
	}
486

    
487
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
488
}
489

    
490
function cpelements_sort() {
491
	global $g, $config;
492

    
493
	function cpelementscmp($a, $b) {
494
		return strcasecmp($a['name'], $b['name']);
495
	}
496
	
497
	usort($config['captiveportal']['element'],"cpelementscmp");
498
}
499

    
500
function allowedips_sort() {
501
	global $g, $config;
502

    
503
	function allowedipscmp($a, $b) {
504
		return strcmp($a['ip'], $b['ip']);
505
	}
506

    
507
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
508
}
509

    
510
function wol_sort() {
511
	global $g, $config;
512

    
513
	function wolcmp($a, $b) {
514
		return strcmp($a['descr'], $b['descr']);
515
	}
516

    
517
	usort($config['wol']['wolentry'], "wolcmp");
518
}
519

    
520
function sort_rule_by_queue_priority() {
521
	global $g, $config;
522
	global $queues;
523

    
524
	function rqpcmp($a, $b) {
525
		global $queues;
526

    
527
		$ra = $queues[$a['outqueue']];
528
		$rb = $queues[$b['outqueue']];
529

    
530
		if ($ra == $rb)
531
			return 0;
532
		/* reverse sort - we want higher priority first */	
533
		return ($ra < $rb) ? 1 : -1;
534
	}
535

    
536
	foreach($config['shaper']['queue'] as $q) {
537
		$queues[$q['name']] = $q['priority'];
538
	}
539

    
540
	usort($config['shaper']['rule'], "rqpcmp");
541
}
542
function gentitle($pgname) {
543
	global $config;
544
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
545
}
546

    
547
/* update the changedesc and changecount(er) variables */
548
function update_changedesc($update) {
549
	global $changedesc;
550
	global $changecount;
551

    
552
	$changedesc .= " {$update}";
553
	$changecount++;
554
}
555

    
556
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
557
	global $g, $config;
558
    $sor = isset($config['syslog']['reverse']) ? "-r" : "";
559
    $logarr = "";
560
	exec("/usr/sbin/clog {$logfile} | grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
561

    
562
	if(is_array($grepfor)) {
563
		 $i = 0;
564
                 foreach($grepfor as $agrep) { 	 
565
                         $regexp = "/" . $agrep . "/i"; 	 
566
                         if($grepinvert[$i]) { 	 
567
                                 $logarr = preg_grep($regexp, $logarr, PREG_GREP_INVERT); 	 
568
                         } else { 	 
569
                                 $logarr = preg_grep($regexp, $logarr); 	 
570
                         }
571
			 $i++;
572
                 } 	 
573
        }
574
        foreach ($logarr as $logent) {
575
                $logent = preg_split("/\s+/", $logent, 6);
576
                echo "<tr valign=\"top\">\n";
577
                if ($withorig) {
578
                		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
579
                		if(strlen($entry_date_time) > 17) 
580
                			continue;
581
                        echo "<td class=\"listlr\" nowrap>" . $entry_date_time  . "</td>\n";
582
                        echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
583
                } else {
584
                        echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
585
                }
586
                echo "</tr>\n";
587
        }
588
}
589

    
590
/* Check if variable has changed, update and log if it has
591
 * returns true if var changed
592
 * varname = variable name in plain text
593
 * orig = original value
594
 * new = new value
595
 */
596
function update_if_changed($varname, & $orig, $new) {
597
	if (is_array($orig) && is_array($new)) {
598
		$a_diff = array_diff($orig, $new);
599
		foreach ($a_diff as $diff) {
600
			update_changedesc("removed {$varname}: \"{$diff}\"");
601
		}
602
		$a_diff = array_diff($new, $orig);
603
		foreach ($a_diff as $diff) {
604
			update_changedesc("added {$varname}: \"{$diff}\"");
605
		}
606
		$orig = $new;
607
		return true;
608
			
609
	} else { 
610
		if ($orig != $new) {
611
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
612
			$orig = $new;
613
			return true;
614
		}
615
	}
616
	return false;
617
}
618

    
619
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
620

    
621
        if (isset($adr['any']))
622
                $padr = "any";
623
        else if ($adr['network'])
624
                $padr = $adr['network'];
625
        else if ($adr['address']) {
626
                list($padr, $pmask) = explode("/", $adr['address']);
627
                if (!$pmask)
628
                        $pmask = 32;
629
        }
630

    
631
        if (isset($adr['not']))
632
                $pnot = 1;
633
        else
634
                $pnot = 0;
635

    
636
        if ($adr['port']) {
637
                list($pbeginport, $pendport) = explode("-", $adr['port']);
638
                if (!$pendport)
639
                        $pendport = $pbeginport;
640
        } else {
641
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
642
                        /* Item is a port alias */
643
                } else {
644
                        $pbeginport = "any";
645
                        $pendport = "any";
646
                }
647
        }
648
}
649

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

    
652
        $adr = array();
653

    
654
        if ($padr == "any")
655
                $adr['any'] = true;
656
        else if (is_specialnet($padr))
657
                $adr['network'] = $padr;
658
        else {
659
                $adr['address'] = $padr;
660
                if ($pmask != 32)
661
                        $adr['address'] .= "/" . $pmask;
662
        }
663

    
664
        if ($pnot)
665
                $adr['not'] = true;
666
        else
667
                unset($adr['not']);
668

    
669
        if (($pbeginport != 0) && ($pbeginport != "any")) {
670
                if ($pbeginport != $pendport)
671
                        $adr['port'] = $pbeginport . "-" . $pendport;
672
                else
673
                        $adr['port'] = $pbeginport;
674
        }
675

    
676
        if(alias_expand($pbeginport)) {
677
                $adr['port'] = $pbeginport;
678
        }
679
}
680

    
681
function is_specialnet($net) {
682
        global $specialsrcdst;
683

    
684
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
685
                return true;
686
        else
687
                return false;
688
}
689

    
690
function ipsec_ca_sort() {
691
        global $g, $config;
692

    
693
        function ipseccacmp($a, $b) {
694
                return strcmp($a['ident'], $b['ident']);
695
        }
696

    
697
        usort($config['ipsec']['cacert'], "ipseccacmp");
698
}
699

    
700

    
701
?>
(57-57/163)