Project

General

Profile

Download (20.8 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
$apple_ua = array("iPhone","iPod");
60
foreach($apple_ua as $useragent)
61
	if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent))
62
		$g['theme'] = "pfsense";
63

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

    
87
/* OpenVPN Directories */
88
$d_ovpnsrvdirty_path = "/tmp/ovpn-srv.dirty";
89
$d_ovpncrldirty_path = "/tmp/ovpn-crl.dirty";
90
$d_ovpnclidirty_path = "/tmp/ovpn-cli.dirty";
91
/* used by progress bar */
92
$lastseen = "-1";
93

    
94
if (file_exists($d_firmwarelock_path)) {
95
	if (!$d_isfwfile) {
96
		header("Location: system_firmware.php");
97
		exit;
98
	} else {
99
		return;
100
	}
101
}
102

    
103
/* some well knows ports */
104
$wkports = array(3389 => "MS RDP",
105
	21 => "FTP",
106
	22 => "SSH",
107
	23 => "Telnet",
108
	25 => "SMTP",
109
	53 => "DNS",
110
	69 => "TFTP",
111
	80 => "HTTP",
112
	110 => "POP3",
113
	113 => "IDENT/AUTH",
114
	119 => "NNTP",
115
	123 => "NTP",
116
	137 => "NetBIOS-NS",
117
	138 => "NetBIOS-DGM",
118
	139 => "NetBIOS-SSN",
119
	143 => "IMAP",
120
	161 => "SNMP",
121
	162 => "SNMP-Trap",
122
	389 => "LDAP",
123
	443 => "HTTPS",
124
	445 => "MS DS",
125
	465 => "SMTP/S",
126
	500 => "isakmp",
127
	993 => "IMAP/S",
128
	995 => "POP3/S",
129
	1194 => "OpenVPN",
130
	1512 => "MS WINS",
131
	1701 => "L2TP",
132
	1723 => "PPTP",
133
	1812 => "Radius",
134
	1813 => "Radius-accounting",
135
	3000 => "HBCI",
136
	4500 => "IPSec NAT-T",
137
	5190 => "ICQ",
138
	5900 => "VNC",
139
	5999 => "CVSup");
140

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

    
143
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
144
	$specialnets['opt' . $i] = $config['interfaces']['opt' . $i]['descr'] . " net";
145
}
146

    
147
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
148
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
149
	"10half" => "10BASE-T half-duplex");
150

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

    
154
/* IPsec defines */
155
$my_identifier_list = array('myaddress' => 'My IP address',
156
				'address' => 'IP address',
157
				'fqdn' => 'Domain name',
158
				'user_fqdn' => 'User FQDN',
159
				'dyn_dns' => 'Dynamic DNS');
160

    
161
$p1_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
162
		'cast128' => 'CAST128','rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
163
$p2_ealgos = array('des' => 'DES', '3des' => '3DES', 'blowfish' => 'Blowfish',
164
		'cast128' => 'CAST128', 'rijndael' => 'Rijndael (AES)', 'rijndael 256' => 'Rijndael 256');
165

    
166
$p1_halgos = array('sha1' => 'SHA1', 'md5' => 'MD5');
167
$p1_authentication_methods = array('pre_shared_key' => 'Pre-shared key', 'rsasig' => 'RSA signature');
168
$p2_halgos = array('hmac_sha1' => 'SHA1', 'hmac_md5' => 'MD5');
169
$p2_protos = array('esp' => 'ESP', 'ah' => 'AH');
170
$p2_pfskeygroups = array('0' => 'off', '1' => '1', '2' => '2', '5' => '5');
171

    
172
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
173

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

    
181
	for ($i = 0; $i < count($reqdfields); $i++) {
182
		if ($_POST[$reqdfields[$i]] == "") {
183
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
184
		}
185
	}
186
}
187

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

    
194
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
195
	foreach ($input_errors as $ierr) {
196
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
197
	}
198
	echo "</ul></span>";
199

    
200
	echo "</td></tr></table></p>&nbsp;<br>";
201
}
202

    
203
function exec_rc_script($scriptname) {
204

    
205
	global $d_sysrebootreqd_path;
206

    
207
	$execoutput = "";
208
	$retval = "";
209
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
210
	return $retval;
211
}
212

    
213
function exec_rc_script_async($scriptname) {
214

    
215
	global $d_sysrebootreqd_path;
216
	$execoutput = "";
217
	$retval = "";
218

    
219
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
220
	return $retval;
221
}
222

    
223
function verify_gzip_file($fname) {
224

    
225
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
226
	if ($returnvar != 0)
227
		return 0;
228
	else
229
		return 1;
230
}
231

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

    
260
function print_info_box($msg) {
261
	echo "<p>";
262
	print_info_box_np($msg);
263
	echo "</p>";
264
}
265

    
266
function format_bytes($bytes) {
267
	if ($bytes >= 1073741824) {
268
		return sprintf("%.2f GB", $bytes/1073741824);
269
	} else if ($bytes >= 1048576) {
270
		return sprintf("%.2f MB", $bytes/1048576);
271
	} else if ($bytes >= 1024) {
272
		return sprintf("%.0f KB", $bytes/1024);
273
	} else {
274
		return sprintf("%d bytes", $bytes);
275
	}
276
}
277

    
278
function get_std_save_message($ok) {
279
	global $d_sysrebootreqd_path;
280

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

    
284
function pprint_address($adr) {
285
	global $specialnets;
286

    
287
	if (isset($adr['any'])) {
288
		$padr = "*";
289
	} else if ($adr['network']) {
290
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
291
			$padr = "Interface IP address";
292
		} else {
293
			$padr = $specialnets[$adr['network']];
294
		}
295
	} else {
296
		$padr = $adr['address'];
297
	}
298

    
299
	if (isset($adr['not']))
300
		$padr = "! " . $padr;
301

    
302
	return $padr;
303
}
304

    
305
function pprint_port($port) {
306
	global $wkports;
307

    
308
	$pport = "";
309

    
310
	if (!$port)
311
		return "*";
312
	else {
313
		$srcport = explode("-", $port);
314
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
315
			$pport = $srcport[0];
316
			if ($wkports[$srcport[0]]) {
317
				$pport .= " (" . $wkports[$srcport[0]] . ")";
318
			}
319
		} else
320
			$pport .= $srcport[0] . " - " . $srcport[1];
321
	}
322

    
323
	return $pport;
324
}
325

    
326
function captiveportal_users_sort() {
327
	global $g, $config;
328

    
329
	function cpusercmp($a, $b) {
330
		return strcasecmp($a['name'], $b['name']);
331
	}
332

    
333
	usort($config['captiveportal']['user'], "cpusercmp");
334
}
335

    
336
/* sort by interface only, retain the original order of rules that apply to
337
   the same interface */
338
function filter_rules_sort() {
339
	global $config;
340

    
341
	/* mark each rule with the sequence number (to retain the order while sorting) */
342
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
343
		$config['filter']['rule'][$i]['seq'] = $i;
344

    
345
	function filtercmp($a, $b) {
346
		if ($a['interface'] == $b['interface'])
347
			return $a['seq'] - $b['seq'];
348
		else
349
			return -strcmp($a['interface'], $b['interface']);
350
	}
351

    
352
	usort($config['filter']['rule'], "filtercmp");
353

    
354
	/* strip the sequence numbers again */
355
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
356
		unset($config['filter']['rule'][$i]['seq']);
357
}
358

    
359
function nat_rules_sort() {
360
	global $config;
361

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

    
381
	usort($config['nat']['rule'], "natcmp");
382
}
383

    
384
function nat_1to1_rules_sort() {
385
	global $g, $config;
386

    
387
	function nat1to1cmp($a, $b) {
388
		return ipcmp($a['external'], $b['external']);
389
	}
390

    
391
	usort($config['nat']['onetoone'], "nat1to1cmp");
392
}
393

    
394
function nat_server_rules_sort() {
395
	global $g, $config;
396

    
397
	function natservercmp($a, $b) {
398
		return ipcmp($a['ipaddr'], $b['ipaddr']);
399
	}
400

    
401
	usort($config['nat']['servernat'], "natservercmp");
402
}
403

    
404
function nat_out_rules_sort() {
405
	global $g, $config;
406

    
407
	function natoutcmp($a, $b) {
408
		return strcmp($a['source']['network'], $b['source']['network']);
409
	}
410

    
411
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
412
}
413

    
414
function pptpd_users_sort() {
415
	global $g, $config;
416

    
417
	function usercmp($a, $b) {
418
		return strcasecmp($a['name'], $b['name']);
419
	}
420

    
421
	usort($config['pptpd']['user'], "usercmp");
422
}
423

    
424
function pppoe_users_sort() {
425
	global $g, $config;
426

    
427
	function usercmp($a, $b) {
428
		return strcasecmp($a['name'], $b['name']);
429
	}
430

    
431
	usort($config['pppoe']['user'], "usercmp");
432
}
433

    
434
function staticroutes_sort() {
435
	global $g, $config;
436

    
437
	function staticroutecmp($a, $b) {
438
		return strcmp($a['network'], $b['network']);
439
	}
440

    
441
	usort($config['staticroutes']['route'], "staticroutecmp");
442
}
443

    
444
function hosts_sort() {
445
	global $g, $config;
446

    
447
	function hostcmp($a, $b) {
448
		return strcasecmp($a['host'], $b['host']);
449
	}
450

    
451
	usort($config['dnsmasq']['hosts'], "hostcmp");
452
}
453

    
454
function staticmaps_sort($if) {
455
	global $g, $config;
456

    
457
	function staticmapcmp($a, $b) {
458
		return ipcmp($a['ipaddr'], $b['ipaddr']);
459
	}
460

    
461
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
462
}
463

    
464
function aliases_sort() {
465
	global $g, $config;
466

    
467
	function aliascmp($a, $b) {
468
		return strcmp($a['name'], $b['name']);
469
	}
470

    
471
	usort($config['aliases']['alias'], "aliascmp");
472
}
473

    
474
function schedule_sort(){
475
	global $g, $config;
476

    
477
	function schedulecmp($a, $b) {
478
		return strcmp($a['name'], $b['name']);
479
	}
480

    
481
	usort($config['schedules']['schedule'], "schedulecmp");
482

    
483
}
484

    
485
function ipsec_mobilekey_sort() {
486
	global $g, $config;
487

    
488
	function mobilekeycmp($a, $b) {
489
		return strcmp($a['ident'][0], $b['ident'][0]);
490
	}
491

    
492
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
493
}
494

    
495
function proxyarp_sort() {
496
	global $g, $config;
497

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

    
517
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
518
}
519

    
520
function passthrumacs_sort() {
521
	global $g, $config;
522

    
523
	function passthrumacscmp($a, $b) {
524
		return strcmp($a['mac'], $b['mac']);
525
	}
526

    
527
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
528
}
529

    
530
function cpelements_sort() {
531
	global $g, $config;
532

    
533
	function cpelementscmp($a, $b) {
534
		return strcasecmp($a['name'], $b['name']);
535
	}
536

    
537
	usort($config['captiveportal']['element'],"cpelementscmp");
538
}
539

    
540
function allowedips_sort() {
541
	global $g, $config;
542

    
543
	function allowedipscmp($a, $b) {
544
		return strcmp($a['ip'], $b['ip']);
545
	}
546

    
547
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
548
}
549

    
550
function wol_sort() {
551
	global $g, $config;
552

    
553
	function wolcmp($a, $b) {
554
		return strcmp($a['descr'], $b['descr']);
555
	}
556

    
557
	usort($config['wol']['wolentry'], "wolcmp");
558
}
559

    
560
function sort_rule_by_queue_priority() {
561
	global $g, $config;
562
	global $queues;
563

    
564
	function rqpcmp($a, $b) {
565
		global $queues;
566

    
567
		$ra = $queues[$a['outqueue']];
568
		$rb = $queues[$b['outqueue']];
569

    
570
		if ($ra == $rb)
571
			return 0;
572
		/* reverse sort - we want higher priority first */
573
		return ($ra < $rb) ? 1 : -1;
574
	}
575

    
576
	foreach($config['shaper']['queue'] as $q) {
577
		$queues[$q['name']] = $q['priority'];
578
	}
579

    
580
	usort($config['shaper']['rule'], "rqpcmp");
581
}
582
function gentitle($pgname) {
583
	global $config;
584
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
585
}
586

    
587
/* update the changedesc and changecount(er) variables */
588
function update_changedesc($update) {
589
	global $changedesc;
590
	global $changecount;
591

    
592
	$changedesc .= " {$update}";
593
	$changecount++;
594
}
595

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

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

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

    
663
	} else {
664
		if ($orig != $new) {
665
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
666
			$orig = $new;
667
			return true;
668
		}
669
	}
670
	return false;
671
}
672

    
673
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
674

    
675
        if (isset($adr['any']))
676
                $padr = "any";
677
        else if ($adr['network'])
678
                $padr = $adr['network'];
679
        else if ($adr['address']) {
680
                list($padr, $pmask) = explode("/", $adr['address']);
681
                if (!$pmask)
682
                        $pmask = 32;
683
        }
684

    
685
        if (isset($adr['not']))
686
                $pnot = 1;
687
        else
688
                $pnot = 0;
689

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

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

    
706
        $adr = array();
707

    
708
        if ($padr == "any")
709
                $adr['any'] = true;
710
        else if (is_specialnet($padr))
711
                $adr['network'] = $padr;
712
        else {
713
                $adr['address'] = $padr;
714
                if ($pmask != 32)
715
                        $adr['address'] .= "/" . $pmask;
716
        }
717

    
718
        if ($pnot)
719
                $adr['not'] = true;
720
        else
721
                unset($adr['not']);
722

    
723
        if (($pbeginport != 0) && ($pbeginport != "any")) {
724
                if ($pbeginport != $pendport)
725
                        $adr['port'] = $pbeginport . "-" . $pendport;
726
                else
727
                        $adr['port'] = $pbeginport;
728
        }
729

    
730
        if(alias_expand($pbeginport)) {
731
                $adr['port'] = $pbeginport;
732
        }
733
}
734

    
735
function is_specialnet($net) {
736
        global $specialsrcdst;
737

    
738
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
739
                return true;
740
        else
741
                return false;
742
}
743

    
744
function ipsec_ca_sort() {
745
        global $g, $config;
746

    
747
        function ipseccacmp($a, $b) {
748
                return strcmp($a['ident'], $b['ident']);
749
        }
750

    
751
        usort($config['ipsec']['cacert'], "ipseccacmp");
752
}
753

    
754

    
755
?>
(63-63/173)