Project

General

Profile

Download (20.6 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
	69 => "TFTP",
106
	80 => "HTTP",
107
	110 => "POP3",
108
	113 => "IDENT/AUTH",
109
	119 => "NNTP",
110
	123 => "NTP",
111
	137 => "NetBIOS-NS",
112
	138 => "NetBIOS-DGM",
113
	139 => "NetBIOS-SSN",
114
	143 => "IMAP",
115
	161 => "SNMP",
116
	162 => "SNMP-Trap",
117
	389 => "LDAP",
118
	443 => "HTTPS",
119
	445 => "MS DS",
120
	465 => "SMTP/S",
121
	500 => "isakmp",
122
	993 => "IMAP/S",
123
	995 => "POP3/S",
124
	1194 => "OpenVPN",
125
	1512 => "MS WINS",
126
	1701 => "L2TP",
127
	1723 => "PPTP",
128
	1812 => "Radius",
129
	1813 => "Radius-accounting",
130
	3000 => "HBCI",
131
	4500 => "IPSec NAT-T",
132
	5190 => "ICQ",
133
	5900 => "VNC",
134
	5999 => "CVSup");
135

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

    
138
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
139
	$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
140
}
141

    
142
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
143
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
144
	"10half" => "10BASE-T half-duplex");
145

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

    
149
/* IPsec defines */
150
$my_identifier_list = array('myaddress' => 'My IP address',
151
				'address' => 'IP address',
152
				'fqdn' => 'Domain name',
153
				'user_fqdn' => 'User FQDN',
154
				'dyn_dns' => 'Dynamic DNS');
155

    
156
$p1_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
157
		'cast128' => 'CAST128','rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
158
$p2_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
159
		'cast128' => 'CAST128', 'rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
160

    
161
$p1_halgos = array('sha1' => 'SHA1', 'md5' => 'MD5');
162
$p1_authentication_methods = array('pre_shared_key' => 'Pre-shared key', 'rsasig' => 'RSA signature');
163
$p2_halgos = array('hmac_sha1' => 'SHA1', 'hmac_md5' => 'MD5');
164
$p2_protos = array('esp' => 'ESP', 'ah' => 'AH');
165
$p2_pfskeygroups = array('0' => 'off', '1' => '1', '2' => '2', '5' => '5');
166

    
167
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
168

    
169
	/* check for bad control characters */
170
	foreach ($postdata as $pn => $pd) {
171
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
172
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
173
		}
174
	}
175

    
176
	for ($i = 0; $i < count($reqdfields); $i++) {
177
		if ($_POST[$reqdfields[$i]] == "") {
178
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
179
		}
180
	}
181
}
182

    
183
function print_input_errors($input_errors) {
184
	global $g;
185
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
186
	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";
187
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
188

    
189
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
190
	foreach ($input_errors as $ierr) {
191
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
192
	}
193
	echo "</ul></span>";
194

    
195
	echo "</td></tr></table></p>&nbsp;<br>";
196
}
197

    
198
function exec_rc_script($scriptname) {
199

    
200
	global $d_sysrebootreqd_path;
201

    
202
	$execoutput = "";
203
	$retval = "";
204
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
205
	return $retval;
206
}
207

    
208
function exec_rc_script_async($scriptname) {
209

    
210
	global $d_sysrebootreqd_path;
211
	$execoutput = "";
212
	$retval = "";
213

    
214
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
215
	return $retval;
216
}
217

    
218
function verify_gzip_file($fname) {
219

    
220
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
221
	if ($returnvar != 0)
222
		return 0;
223
	else
224
		return 1;
225
}
226

    
227
function print_info_box_np($msg) {
228
	global $g;
229
	echo "<table height=\"32\" width=\"100%\">\n";
230
	echo "  <tr>\n";
231
	echo "   <td>\n";
232
	echo "      <div style='background-color:#990000' id='redbox'>\n";
233
	echo "       <table width='100%'><tr><td width='8%'>\n";
234
	echo "        &nbsp;&nbsp;&nbsp;<img style='vertical-align:middle' src=\"/themes/".$g['theme']."/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\">\n";
235
	echo "        </td>\n";
236
	echo "        <td width='70%'><font color='white'><b>{$msg}</b></font>\n";
237
	echo "        </td>";
238
	if(stristr($msg, "apply") == true) {
239
		echo "         <td>";
240
		echo "           <input name=\"apply\" type=\"submit\" class=\"formbtn\" id=\"apply\" value=\"Apply changes\">\n";
241
		echo "         </td>";
242
	}
243
	echo "        </tr></table>\n";
244
	echo "       </div>\n";
245
	echo "    </td>\n";
246
	echo "</table>\n";
247
	echo "<script type=\"text/javascript\">\n";
248
	echo "NiftyCheck();\n";
249
	echo "Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");\n";
250
	echo "Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");\n";
251
	echo "</script>\n";
252
	echo "\n<br>\n";
253
}
254

    
255
function print_info_box($msg) {
256
	echo "<p>";
257
	print_info_box_np($msg);
258
	echo "</p>";
259
}
260

    
261
function format_bytes($bytes) {
262
	if ($bytes >= 1073741824) {
263
		return sprintf("%.2f GB", $bytes/1073741824);
264
	} else if ($bytes >= 1048576) {
265
		return sprintf("%.2f MB", $bytes/1048576);
266
	} else if ($bytes >= 1024) {
267
		return sprintf("%.0f KB", $bytes/1024);
268
	} else {
269
		return sprintf("%d bytes", $bytes);
270
	}
271
}
272

    
273
function get_std_save_message($ok) {
274
	global $d_sysrebootreqd_path;
275

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

    
279
function pprint_address($adr) {
280
	global $specialnets;
281

    
282
	if (isset($adr['any'])) {
283
		$padr = "*";
284
	} else if ($adr['network']) {
285
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
286
			$padr = "Interface IP address";
287
		} else {
288
			$padr = $specialnets[$adr['network']];
289
		}
290
	} else {
291
		$padr = $adr['address'];
292
	}
293

    
294
	if (isset($adr['not']))
295
		$padr = "! " . $padr;
296

    
297
	return $padr;
298
}
299

    
300
function pprint_port($port) {
301
	global $wkports;
302

    
303
	$pport = "";
304

    
305
	if (!$port)
306
		return "*";
307
	else {
308
		$srcport = explode("-", $port);
309
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
310
			$pport = $srcport[0];
311
			if ($wkports[$srcport[0]]) {
312
				$pport .= " (" . $wkports[$srcport[0]] . ")";
313
			}
314
		} else
315
			$pport .= $srcport[0] . " - " . $srcport[1];
316
	}
317

    
318
	return $pport;
319
}
320

    
321
function captiveportal_users_sort() {
322
	global $g, $config;
323

    
324
	function cpusercmp($a, $b) {
325
		return strcasecmp($a['name'], $b['name']);
326
	}
327

    
328
	usort($config['captiveportal']['user'], "cpusercmp");
329
}
330

    
331
/* sort by interface only, retain the original order of rules that apply to
332
   the same interface */
333
function filter_rules_sort() {
334
	global $config;
335

    
336
	/* mark each rule with the sequence number (to retain the order while sorting) */
337
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
338
		$config['filter']['rule'][$i]['seq'] = $i;
339

    
340
	function filtercmp($a, $b) {
341
		if ($a['interface'] == $b['interface'])
342
			return $a['seq'] - $b['seq'];
343
		else
344
			return -strcmp($a['interface'], $b['interface']);
345
	}
346

    
347
	usort($config['filter']['rule'], "filtercmp");
348

    
349
	/* strip the sequence numbers again */
350
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
351
		unset($config['filter']['rule'][$i]['seq']);
352
}
353

    
354
function nat_rules_sort() {
355
	global $config;
356

    
357
	function natcmp($a, $b) {
358
		if ($a['external-address'] == $b['external-address']) {
359
			if ($a['protocol'] == $b['protocol']) {
360
				if ($a['external-port'] == $b['external-port']) {
361
					return 0;
362
				} else {
363
					return ($a['external-port'] - $b['external-port']);
364
				}
365
			} else {
366
				return strcmp($a['protocol'], $b['protocol']);
367
			}
368
		} else if (!$a['external-address'])
369
			return 1;
370
		else if (!$b['external-address'])
371
			return -1;
372
		else
373
			return ipcmp($a['external-address'], $b['external-address']);
374
	}
375

    
376
	usort($config['nat']['rule'], "natcmp");
377
}
378

    
379
function nat_1to1_rules_sort() {
380
	global $g, $config;
381

    
382
	function nat1to1cmp($a, $b) {
383
		return ipcmp($a['external'], $b['external']);
384
	}
385

    
386
	usort($config['nat']['onetoone'], "nat1to1cmp");
387
}
388

    
389
function nat_server_rules_sort() {
390
	global $g, $config;
391

    
392
	function natservercmp($a, $b) {
393
		return ipcmp($a['ipaddr'], $b['ipaddr']);
394
	}
395

    
396
	usort($config['nat']['servernat'], "natservercmp");
397
}
398

    
399
function nat_out_rules_sort() {
400
	global $g, $config;
401

    
402
	function natoutcmp($a, $b) {
403
		return strcmp($a['source']['network'], $b['source']['network']);
404
	}
405

    
406
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
407
}
408

    
409
function pptpd_users_sort() {
410
	global $g, $config;
411

    
412
	function usercmp($a, $b) {
413
		return strcasecmp($a['name'], $b['name']);
414
	}
415

    
416
	usort($config['pptpd']['user'], "usercmp");
417
}
418

    
419
function pppoe_users_sort() {
420
	global $g, $config;
421

    
422
	function usercmp($a, $b) {
423
		return strcasecmp($a['name'], $b['name']);
424
	}
425

    
426
	usort($config['pppoe']['user'], "usercmp");
427
}
428

    
429
function staticroutes_sort() {
430
	global $g, $config;
431

    
432
	function staticroutecmp($a, $b) {
433
		return strcmp($a['network'], $b['network']);
434
	}
435

    
436
	usort($config['staticroutes']['route'], "staticroutecmp");
437
}
438

    
439
function hosts_sort() {
440
	global $g, $config;
441

    
442
	function hostcmp($a, $b) {
443
		return strcasecmp($a['host'], $b['host']);
444
	}
445

    
446
	usort($config['dnsmasq']['hosts'], "hostcmp");
447
}
448

    
449
function staticmaps_sort($if) {
450
	global $g, $config;
451

    
452
	function staticmapcmp($a, $b) {
453
		return ipcmp($a['ipaddr'], $b['ipaddr']);
454
	}
455

    
456
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
457
}
458

    
459
function aliases_sort() {
460
	global $g, $config;
461

    
462
	function aliascmp($a, $b) {
463
		return strcmp($a['name'], $b['name']);
464
	}
465

    
466
	usort($config['aliases']['alias'], "aliascmp");
467
}
468

    
469
function schedule_sort(){
470
	global $g, $config;
471

    
472
	function schedulecmp($a, $b) {
473
		return strcmp($a['name'], $b['name']);
474
	}
475

    
476
	usort($config['schedules']['schedule'], "schedulecmp");
477

    
478
}
479

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

    
483
	function mobilekeycmp($a, $b) {
484
		return strcmp($a['ident'][0], $b['ident'][0]);
485
	}
486

    
487
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
488
}
489

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

    
493
	function proxyarpcmp($a, $b) {
494
		if (isset($a['network']))
495
			list($ast,$asn) = explode("/", $a['network']);
496
		else if (isset($a['range'])) {
497
			$ast = $a['range']['from'];
498
			$asn = 32;
499
		}
500
		if (isset($b['network']))
501
			list($bst,$bsn) = explode("/", $b['network']);
502
		else if (isset($b['range'])) {
503
			$bst = $b['range']['from'];
504
			$bsn = 32;
505
		}
506
		if (ipcmp($ast, $bst) == 0)
507
			return ($asn - $bsn);
508
		else
509
			return ipcmp($ast, $bst);
510
	}
511

    
512
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
513
}
514

    
515
function passthrumacs_sort() {
516
	global $g, $config;
517

    
518
	function passthrumacscmp($a, $b) {
519
		return strcmp($a['mac'], $b['mac']);
520
	}
521

    
522
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
523
}
524

    
525
function cpelements_sort() {
526
	global $g, $config;
527

    
528
	function cpelementscmp($a, $b) {
529
		return strcasecmp($a['name'], $b['name']);
530
	}
531

    
532
	usort($config['captiveportal']['element'],"cpelementscmp");
533
}
534

    
535
function allowedips_sort() {
536
	global $g, $config;
537

    
538
	function allowedipscmp($a, $b) {
539
		return strcmp($a['ip'], $b['ip']);
540
	}
541

    
542
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
543
}
544

    
545
function wol_sort() {
546
	global $g, $config;
547

    
548
	function wolcmp($a, $b) {
549
		return strcmp($a['descr'], $b['descr']);
550
	}
551

    
552
	usort($config['wol']['wolentry'], "wolcmp");
553
}
554

    
555
function sort_rule_by_queue_priority() {
556
	global $g, $config;
557
	global $queues;
558

    
559
	function rqpcmp($a, $b) {
560
		global $queues;
561

    
562
		$ra = $queues[$a['outqueue']];
563
		$rb = $queues[$b['outqueue']];
564

    
565
		if ($ra == $rb)
566
			return 0;
567
		/* reverse sort - we want higher priority first */
568
		return ($ra < $rb) ? 1 : -1;
569
	}
570

    
571
	foreach($config['shaper']['queue'] as $q) {
572
		$queues[$q['name']] = $q['priority'];
573
	}
574

    
575
	usort($config['shaper']['rule'], "rqpcmp");
576
}
577
function gentitle($pgname) {
578
	global $config;
579
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
580
}
581

    
582
/* update the changedesc and changecount(er) variables */
583
function update_changedesc($update) {
584
	global $changedesc;
585
	global $changecount;
586

    
587
	$changedesc .= " {$update}";
588
	$changecount++;
589
}
590

    
591
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
592
	global $g, $config;
593
    $sor = isset($config['syslog']['reverse']) ? "-r" : "";
594
    $logarr = "";
595
	$grepline = "  ";
596
	if(is_array($grepfor))
597
		foreach($grepfor as $agrep)
598
			$grepline .= " | grep \"$agrep\"";
599
	if(is_array($grepinvert))
600
		foreach($grepinvert as $agrep)
601
			$grepline .= " | grep -v \"$agrep\"";
602
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
603
    /* comment out debug code
604
    echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
605
    */
606
    foreach ($logarr as $logent) {
607
            $logent = preg_split("/\s+/", $logent, 6);
608
            echo "<tr valign=\"top\">\n";
609
            if ($withorig) {
610
            		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
611
                    echo "<td class=\"listlr\" nowrap>" . $entry_date_time  . "</td>\n";
612
                    echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
613
            } else {
614
                    echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
615
            }
616
            echo "</tr>\n";
617
    }
618
}
619

    
620
function return_clog($logfile, $tail, $grepfor = "", $grepinvert = "", $grepreverse = false) {
621
	global $g, $config;
622
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
623
	$sor = isset($grepreverse) ? "-r" : "";
624
	$logarr = "";
625
	$grepline = "  ";
626
	if(is_array($grepfor))
627
		foreach($grepfor as $agrep)
628
			$grepline .= " | grep \"$agrep\"";
629
	if(is_array($grepinvert))
630
		foreach($grepinvert as $agrep)
631
			$grepline .= " | grep -v \"$agrep\"";
632
	/* comment out debug code
633
	echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
634
	*/
635
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
636
	return($logarr);
637
}
638

    
639
/* Check if variable has changed, update and log if it has
640
 * returns true if var changed
641
 * varname = variable name in plain text
642
 * orig = original value
643
 * new = new value
644
 */
645
function update_if_changed($varname, & $orig, $new) {
646
	if (is_array($orig) && is_array($new)) {
647
		$a_diff = array_diff($orig, $new);
648
		foreach ($a_diff as $diff) {
649
			update_changedesc("removed {$varname}: \"{$diff}\"");
650
		}
651
		$a_diff = array_diff($new, $orig);
652
		foreach ($a_diff as $diff) {
653
			update_changedesc("added {$varname}: \"{$diff}\"");
654
		}
655
		$orig = $new;
656
		return true;
657

    
658
	} else {
659
		if ($orig != $new) {
660
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
661
			$orig = $new;
662
			return true;
663
		}
664
	}
665
	return false;
666
}
667

    
668
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
669

    
670
        if (isset($adr['any']))
671
                $padr = "any";
672
        else if ($adr['network'])
673
                $padr = $adr['network'];
674
        else if ($adr['address']) {
675
                list($padr, $pmask) = explode("/", $adr['address']);
676
                if (!$pmask)
677
                        $pmask = 32;
678
        }
679

    
680
        if (isset($adr['not']))
681
                $pnot = 1;
682
        else
683
                $pnot = 0;
684

    
685
        if ($adr['port']) {
686
                list($pbeginport, $pendport) = explode("-", $adr['port']);
687
                if (!$pendport)
688
                        $pendport = $pbeginport;
689
        } else {
690
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
691
                        /* Item is a port alias */
692
                } else {
693
                        $pbeginport = "any";
694
                        $pendport = "any";
695
                }
696
        }
697
}
698

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

    
701
        $adr = array();
702

    
703
        if ($padr == "any")
704
                $adr['any'] = true;
705
        else if (is_specialnet($padr))
706
                $adr['network'] = $padr;
707
        else {
708
                $adr['address'] = $padr;
709
                if ($pmask != 32)
710
                        $adr['address'] .= "/" . $pmask;
711
        }
712

    
713
        if ($pnot)
714
                $adr['not'] = true;
715
        else
716
                unset($adr['not']);
717

    
718
        if (($pbeginport != 0) && ($pbeginport != "any")) {
719
                if ($pbeginport != $pendport)
720
                        $adr['port'] = $pbeginport . "-" . $pendport;
721
                else
722
                        $adr['port'] = $pbeginport;
723
        }
724

    
725
        if(alias_expand($pbeginport)) {
726
                $adr['port'] = $pbeginport;
727
        }
728
}
729

    
730
function is_specialnet($net) {
731
        global $specialsrcdst;
732

    
733
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
734
                return true;
735
        else
736
                return false;
737
}
738

    
739
function ipsec_ca_sort() {
740
        global $g, $config;
741

    
742
        function ipseccacmp($a, $b) {
743
                return strcmp($a['ident'], $b['ident']);
744
        }
745

    
746
        usort($config['ipsec']['cacert'], "ipseccacmp");
747
}
748

    
749

    
750
?>
(63-63/173)