Project

General

Profile

Download (21 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("authgui.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_sysctldirty_path = $g['varrun_path'] . "/sysctl.conf.dirty";
80
$d_vsconfdirty_path = $g['varrun_path'] . "/vs.conf.dirty";
81
$d_shaperconfdirty_path = $g['varrun_path'] . "/shaper.conf.dirty";
82

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

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

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

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

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

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

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

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

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

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

    
169
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
170

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

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

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

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

    
197
	echo "</td></tr></table></p>&nbsp;<br>";
198
}
199

    
200
function exec_rc_script($scriptname) {
201

    
202
	global $d_sysrebootreqd_path;
203

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

    
210
function exec_rc_script_async($scriptname) {
211

    
212
	global $d_sysrebootreqd_path;
213
	$execoutput = "";
214
	$retval = "";
215

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

    
220
function verify_gzip_file($fname) {
221

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

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

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

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

    
275
function get_std_save_message($ok) {
276
	global $d_sysrebootreqd_path;
277

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

    
281
function pprint_address($adr) {
282
	global $specialnets;
283

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

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

    
299
	return $padr;
300
}
301

    
302
function pprint_port($port) {
303
	global $wkports;
304

    
305
	$pport = "";
306

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

    
320
	return $pport;
321
}
322

    
323
function captiveportal_users_sort() {
324
	global $g, $config;
325

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

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

    
333
function admin_groups_sort() {
334
	global $g, $config;
335

    
336
	function cpusercmp($a, $b) {
337
		return strcasecmp($a['name'], $b['name']);
338
	}
339

    
340
	usort($config['system']['group'], "cpusercmp");
341
}
342

    
343
function admin_users_sort() {
344
	global $g, $config;
345

    
346
	function cpusercmp($a, $b) {
347
		return strcasecmp($a['name'], $b['name']);
348
	}
349

    
350
	usort($config['system']['user'], "cpusercmp");
351
}
352

    
353
/* sort by interface only, retain the original order of rules that apply to
354
   the same interface */
355
function filter_rules_sort() {
356
	global $config;
357

    
358
	/* mark each rule with the sequence number (to retain the order while sorting) */
359
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
360
		$config['filter']['rule'][$i]['seq'] = $i;
361

    
362
	function filtercmp($a, $b) {
363
		if ($a['interface'] == $b['interface'])
364
			return $a['seq'] - $b['seq'];
365
		else
366
			return -strcmp($a['interface'], $b['interface']);
367
	}
368

    
369
	usort($config['filter']['rule'], "filtercmp");
370

    
371
	/* strip the sequence numbers again */
372
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
373
		unset($config['filter']['rule'][$i]['seq']);
374
}
375

    
376
function nat_rules_sort() {
377
	global $config;
378

    
379
	function natcmp($a, $b) {
380
		if ($a['external-address'] == $b['external-address']) {
381
			if ($a['protocol'] == $b['protocol']) {
382
				if ($a['external-port'] == $b['external-port']) {
383
					return 0;
384
				} else {
385
					return ($a['external-port'] - $b['external-port']);
386
				}
387
			} else {
388
				return strcmp($a['protocol'], $b['protocol']);
389
			}
390
		} else if (!$a['external-address'])
391
			return 1;
392
		else if (!$b['external-address'])
393
			return -1;
394
		else
395
			return ipcmp($a['external-address'], $b['external-address']);
396
	}
397

    
398
	usort($config['nat']['rule'], "natcmp");
399
}
400

    
401
function nat_1to1_rules_sort() {
402
	global $g, $config;
403

    
404
	function nat1to1cmp($a, $b) {
405
		return ipcmp($a['external'], $b['external']);
406
	}
407

    
408
	usort($config['nat']['onetoone'], "nat1to1cmp");
409
}
410

    
411
function nat_server_rules_sort() {
412
	global $g, $config;
413

    
414
	function natservercmp($a, $b) {
415
		return ipcmp($a['ipaddr'], $b['ipaddr']);
416
	}
417

    
418
	usort($config['nat']['servernat'], "natservercmp");
419
}
420

    
421
function nat_out_rules_sort() {
422
	global $g, $config;
423

    
424
	function natoutcmp($a, $b) {
425
		return strcmp($a['source']['network'], $b['source']['network']);
426
	}
427

    
428
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
429
}
430

    
431
function pptpd_users_sort() {
432
	global $g, $config;
433

    
434
	function usercmp($a, $b) {
435
		return strcasecmp($a['name'], $b['name']);
436
	}
437

    
438
	usort($config['pptpd']['user'], "usercmp");
439
}
440

    
441
function pppoe_users_sort() {
442
	global $g, $config;
443

    
444
	function usercmp($a, $b) {
445
		return strcasecmp($a['name'], $b['name']);
446
	}
447

    
448
	usort($config['pppoe']['user'], "usercmp");
449
}
450

    
451
function staticroutes_sort() {
452
	global $g, $config;
453

    
454
	function staticroutecmp($a, $b) {
455
		return strcmp($a['network'], $b['network']);
456
	}
457

    
458
	usort($config['staticroutes']['route'], "staticroutecmp");
459
}
460

    
461
function hosts_sort() {
462
	global $g, $config;
463

    
464
	function hostcmp($a, $b) {
465
		return strcasecmp($a['host'], $b['host']);
466
	}
467

    
468
	usort($config['dnsmasq']['hosts'], "hostcmp");
469
}
470

    
471
function staticmaps_sort($if) {
472
	global $g, $config;
473

    
474
	function staticmapcmp($a, $b) {
475
		return ipcmp($a['ipaddr'], $b['ipaddr']);
476
	}
477

    
478
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
479
}
480

    
481
function aliases_sort() {
482
	global $g, $config;
483

    
484
	function aliascmp($a, $b) {
485
		return strcmp($a['name'], $b['name']);
486
	}
487

    
488
	usort($config['aliases']['alias'], "aliascmp");
489
}
490

    
491
function schedule_sort(){
492
	global $g, $config;
493

    
494
	function schedulecmp($a, $b) {
495
		return strcmp($a['name'], $b['name']);
496
	}
497

    
498
	usort($config['schedules']['schedule'], "schedulecmp");
499

    
500
}
501

    
502
function ipsec_mobilekey_sort() {
503
	global $g, $config;
504

    
505
	function mobilekeycmp($a, $b) {
506
		return strcmp($a['ident'][0], $b['ident'][0]);
507
	}
508

    
509
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
510
}
511

    
512
function proxyarp_sort() {
513
	global $g, $config;
514

    
515
	function proxyarpcmp($a, $b) {
516
		if (isset($a['network']))
517
			list($ast,$asn) = explode("/", $a['network']);
518
		else if (isset($a['range'])) {
519
			$ast = $a['range']['from'];
520
			$asn = 32;
521
		}
522
		if (isset($b['network']))
523
			list($bst,$bsn) = explode("/", $b['network']);
524
		else if (isset($b['range'])) {
525
			$bst = $b['range']['from'];
526
			$bsn = 32;
527
		}
528
		if (ipcmp($ast, $bst) == 0)
529
			return ($asn - $bsn);
530
		else
531
			return ipcmp($ast, $bst);
532
	}
533

    
534
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
535
}
536

    
537
function passthrumacs_sort() {
538
	global $g, $config;
539

    
540
	function passthrumacscmp($a, $b) {
541
		return strcmp($a['mac'], $b['mac']);
542
	}
543

    
544
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
545
}
546

    
547
function cpelements_sort() {
548
	global $g, $config;
549

    
550
	function cpelementscmp($a, $b) {
551
		return strcasecmp($a['name'], $b['name']);
552
	}
553

    
554
	usort($config['captiveportal']['element'],"cpelementscmp");
555
}
556

    
557
function allowedips_sort() {
558
	global $g, $config;
559

    
560
	function allowedipscmp($a, $b) {
561
		return strcmp($a['ip'], $b['ip']);
562
	}
563

    
564
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
565
}
566

    
567
function wol_sort() {
568
	global $g, $config;
569

    
570
	function wolcmp($a, $b) {
571
		return strcmp($a['descr'], $b['descr']);
572
	}
573

    
574
	usort($config['wol']['wolentry'], "wolcmp");
575
}
576

    
577
function sort_rule_by_queue_priority() {
578
	global $g, $config;
579
	global $queues;
580

    
581
	function rqpcmp($a, $b) {
582
		global $queues;
583

    
584
		$ra = $queues[$a['outqueue']];
585
		$rb = $queues[$b['outqueue']];
586

    
587
		if ($ra == $rb)
588
			return 0;
589
		/* reverse sort - we want higher priority first */
590
		return ($ra < $rb) ? 1 : -1;
591
	}
592

    
593
	foreach($config['shaper']['queue'] as $q) {
594
		$queues[$q['name']] = $q['priority'];
595
	}
596

    
597
	usort($config['shaper']['rule'], "rqpcmp");
598
}
599
function gentitle($pgname) {
600
	global $config;
601
	return $config['system']['hostname'] . "." . $config['system']['domain'] . " - " . $pgname;
602
}
603

    
604
/* update the changedesc and changecount(er) variables */
605
function update_changedesc($update) {
606
	global $changedesc;
607
	global $changecount;
608

    
609
	$changedesc .= " {$update}";
610
	$changecount++;
611
}
612

    
613
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
614
	global $g, $config;
615
    $sor = isset($config['syslog']['reverse']) ? "-r" : "";
616
    $logarr = "";
617
	$grepline = "  ";
618
	if(is_array($grepfor))
619
		foreach($grepfor as $agrep)
620
			$grepline .= " | grep \"$agrep\"";
621
	if(is_array($grepinvert))
622
		foreach($grepinvert as $agrep)
623
			$grepline .= " | grep -v \"$agrep\"";
624
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
625
    echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
626
    foreach ($logarr as $logent) {
627
            $logent = preg_split("/\s+/", $logent, 6);
628
            echo "<tr valign=\"top\">\n";
629
            if ($withorig) {
630
            		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
631
                    echo "<td class=\"listlr\" nowrap>" . $entry_date_time  . "</td>\n";
632
                    echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
633
            } else {
634
                    echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
635
            }
636
            echo "</tr>\n";
637
    }
638
}
639

    
640
function return_clog($logfile, $tail, $grepfor = "", $grepinvert = "", $grepreverse = false) {
641
	global $g, $config;
642
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
643
	$sor = isset($grepreverse) ? "-r" : "";
644
	$logarr = "";
645
	$grepline = "  ";
646
	if(is_array($grepfor))
647
		foreach($grepfor as $agrep)
648
			$grepline .= " | grep \"$agrep\"";
649
	if(is_array($grepinvert))
650
		foreach($grepinvert as $agrep)
651
			$grepline .= " | grep -v \"$agrep\"";
652
	echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
653
	exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
654
	return($logarr);
655
}
656

    
657
/* Check if variable has changed, update and log if it has
658
 * returns true if var changed
659
 * varname = variable name in plain text
660
 * orig = original value
661
 * new = new value
662
 */
663
function update_if_changed($varname, & $orig, $new) {
664
	if (is_array($orig) && is_array($new)) {
665
		$a_diff = array_diff($orig, $new);
666
		foreach ($a_diff as $diff) {
667
			update_changedesc("removed {$varname}: \"{$diff}\"");
668
		}
669
		$a_diff = array_diff($new, $orig);
670
		foreach ($a_diff as $diff) {
671
			update_changedesc("added {$varname}: \"{$diff}\"");
672
		}
673
		$orig = $new;
674
		return true;
675

    
676
	} else {
677
		if ($orig != $new) {
678
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
679
			$orig = $new;
680
			return true;
681
		}
682
	}
683
	return false;
684
}
685

    
686
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
687

    
688
        if (isset($adr['any']))
689
                $padr = "any";
690
        else if ($adr['network'])
691
                $padr = $adr['network'];
692
        else if ($adr['address']) {
693
                list($padr, $pmask) = explode("/", $adr['address']);
694
                if (!$pmask)
695
                        $pmask = 32;
696
        }
697

    
698
        if (isset($adr['not']))
699
                $pnot = 1;
700
        else
701
                $pnot = 0;
702

    
703
        if ($adr['port']) {
704
                list($pbeginport, $pendport) = explode("-", $adr['port']);
705
                if (!$pendport)
706
                        $pendport = $pbeginport;
707
        } else {
708
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
709
                        /* Item is a port alias */
710
                } else {
711
                        $pbeginport = "any";
712
                        $pendport = "any";
713
                }
714
        }
715
}
716

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

    
719
        $adr = array();
720

    
721
        if ($padr == "any")
722
                $adr['any'] = true;
723
        else if (is_specialnet($padr))
724
                $adr['network'] = $padr;
725
        else {
726
                $adr['address'] = $padr;
727
                if ($pmask != 32)
728
                        $adr['address'] .= "/" . $pmask;
729
        }
730

    
731
        if ($pnot)
732
                $adr['not'] = true;
733
        else
734
                unset($adr['not']);
735

    
736
        if (($pbeginport != 0) && ($pbeginport != "any")) {
737
                if ($pbeginport != $pendport)
738
                        $adr['port'] = $pbeginport . "-" . $pendport;
739
                else
740
                        $adr['port'] = $pbeginport;
741
        }
742

    
743
        if(alias_expand($pbeginport)) {
744
                $adr['port'] = $pbeginport;
745
        }
746
}
747

    
748
function is_specialnet($net) {
749
        global $specialsrcdst;
750

    
751
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
752
                return true;
753
        else
754
                return false;
755
}
756

    
757
function ipsec_ca_sort() {
758
        global $g, $config;
759

    
760
        function ipseccacmp($a, $b) {
761
                return strcmp($a['ident'], $b['ident']);
762
        }
763

    
764
        usort($config['ipsec']['cacert'], "ipseccacmp");
765
}
766

    
767

    
768
?>
(66-66/181)