Project

General

Profile

Download (23.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("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
$navlevelsep = ": ";	/* navigation level separator string */
91
$mandfldhtml = "";		/* display this before mandatory input fields */
92
$mandfldhtmlspc = "";	/* same as above, but with spacing */
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
$auth_server_types = array(
104
	'ldap' => "LDAP",
105
	'radius' => "Radius");
106

    
107
$ldap_urltypes = array(
108
	'TCP - Standard' => 389,
109
	'SSL - Encrypted' => 636);
110

    
111
$ldap_scopes = array(
112
	'one' => "One Level",
113
	'subtree' => "Entire Subtree");
114

    
115
$ldap_protvers = array(
116
	2,
117
	3);
118

    
119
$ldap_templates = array(
120

    
121
	'open' => array(
122
				'desc' => "OpenLDAP",
123
				'attr_user' => "cn",
124
				'attr_group' => "cn",
125
				'attr_member' => "member"),
126

    
127
	'msad' => array(
128
				'desc' => "Microsoft AD",
129
				'attr_user' => "samAccountNAme",
130
				'attr_group' => "cn",
131
				'attr_member' => "member"),
132

    
133
	'edir' => array(
134
				'desc' => "Novell eDirectory",
135
				'attr_user' => "cn",
136
				'attr_group' => "cn",
137
				'attr_member' => "uniqueMember"));
138

    
139
$radius_srvcs = array(
140
	'both' => "Authentication and Accounting",
141
	'auth' => "Authentication",
142
	'acct' => "Accounting");
143

    
144
/* some well knows ports */
145
$wkports = array(
146
	3389 => "MS RDP",
147
	21 => "FTP",
148
	22 => "SSH",
149
	23 => "Telnet",
150
	25 => "SMTP",
151
	53 => "DNS",
152
	69 => "TFTP",
153
	80 => "HTTP",
154
	110 => "POP3",
155
	113 => "IDENT/AUTH",
156
	119 => "NNTP",
157
	123 => "NTP",
158
	137 => "NetBIOS-NS",
159
	138 => "NetBIOS-DGM",
160
	139 => "NetBIOS-SSN",
161
	143 => "IMAP",
162
	161 => "SNMP",
163
	162 => "SNMP-Trap",
164
	389 => "LDAP",
165
	443 => "HTTPS",
166
	445 => "MS DS",
167
	465 => "SMTP/S",
168
	500 => "isakmp",
169
	993 => "IMAP/S",
170
	995 => "POP3/S",
171
	1194 => "OpenVPN",
172
	1512 => "MS WINS",
173
	1701 => "L2TP",
174
	1723 => "PPTP",
175
	1755 => "MMS/TCP",
176
	1812 => "Radius",
177
	1813 => "Radius-accounting",
178
	3000 => "HBCI",
179
	3478 => "STUN",
180
	4500 => "IPsec NAT-T",
181
	5004 => "RTP",
182
	5060 => "SIP",
183
	5190 => "ICQ",
184
	5900 => "VNC",
185
	5999 => "CVSup",
186
	7000 => "MMS/UDP");
187

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

    
190
$spiflist = get_configured_interface_with_descr(true, true);
191
foreach ($spiflist as $if => $ifdesc) {
192
	$specialnets[$if] = $ifdesc . " net";
193
}
194

    
195
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
196
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
197
	"10half" => "10BASE-T half-duplex");
198

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

    
202
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
203

    
204
	/* check for bad control characters */
205
	foreach ($postdata as $pn => $pd) {
206
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
207
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
208
		}
209
	}
210

    
211
	for ($i = 0; $i < count($reqdfields); $i++) {
212
		if ($_POST[$reqdfields[$i]] == "") {
213
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
214
		}
215
	}
216
}
217

    
218
function print_input_errors($input_errors) {
219
	global $g;
220
	echo "<p><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">\n";
221
	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";
222
	echo "<td bgcolor=\"#FFD9D1\" style=\"padding-left: 8px; padding-top: 6px\">";
223

    
224
	echo "<span class=\"errmsg\"><p>The following input errors were detected:<ul>\n";
225
	foreach ($input_errors as $ierr) {
226
		echo "<li>" . htmlspecialchars($ierr) . "</li>\n";
227
	}
228
	echo "</ul></span>";
229

    
230
	echo "</td></tr></table></p>&nbsp;<br>";
231
}
232

    
233
function exec_rc_script($scriptname) {
234

    
235
	global $d_sysrebootreqd_path;
236

    
237
	$execoutput = "";
238
	$retval = "";
239
	exec($scriptname . " >/dev/null 2>&1", $execoutput, $retval);
240
	return $retval;
241
}
242

    
243
function exec_rc_script_async($scriptname) {
244

    
245
	global $d_sysrebootreqd_path;
246
	$execoutput = "";
247
	$retval = "";
248

    
249
	exec("nohup " . $scriptname . " >/dev/null 2>&1 &", $execoutput, $retval);
250
	return $retval;
251
}
252

    
253
function verify_gzip_file($fname) {
254

    
255
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
256
	if ($returnvar != 0)
257
		return 0;
258
	else
259
		return 1;
260
}
261

    
262
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
263
	global $g;
264
	echo "<table height=\"32\" width=\"100%\">\n";
265
	echo "  <tr>\n";
266
	echo "   <td>\n";
267
	echo "      <div style='background-color:#990000' id='redbox'>\n";
268
	echo "       <table width='100%'><tr><td width='8%'>\n";
269
	echo "        &nbsp;&nbsp;&nbsp;<img style='vertical-align:middle' src=\"/themes/".$g['theme']."/images/icons/icon_exclam.gif\" width=\"28\" height=\"32\">\n";
270
	echo "        </td>\n";
271
	echo "        <td width='70%'><font color='white'><b>{$msg}</b></font>\n";
272
	echo "        </td>";
273
	if(stristr($msg, "apply") == true || stristr($msg, "save") || stristr($msg, "create")) {
274
		echo "         <td>";
275
		echo "           <input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">\n";
276
		echo "         </td>";
277
	}
278
	echo "        </tr></table>\n";
279
	echo "       </div>\n";
280
	echo "    </td>\n";
281
	echo "</table>\n";
282
	echo "<script type=\"text/javascript\">\n";
283
	echo "NiftyCheck();\n";
284
	echo "Rounded(\"div#redbox\",\"all\",\"#FFF\",\"#990000\",\"smooth\");\n";
285
	echo "Rounded(\"td#blackbox\",\"all\",\"#FFF\",\"#000000\",\"smooth\");\n";
286
	echo "</script>\n";
287
	echo "\n<br>\n";
288
}
289

    
290
function print_info_box($msg) {
291
	echo "<p>";
292
	print_info_box_np($msg);
293
	echo "</p>";
294
}
295

    
296
function format_bytes($bytes) {
297
	if ($bytes >= 1073741824) {
298
		return sprintf("%.2f GB", $bytes/1073741824);
299
	} else if ($bytes >= 1048576) {
300
		return sprintf("%.2f MB", $bytes/1048576);
301
	} else if ($bytes >= 1024) {
302
		return sprintf("%.0f KB", $bytes/1024);
303
	} else {
304
		return sprintf("%d bytes", $bytes);
305
	}
306
}
307

    
308
function get_std_save_message($ok) {
309
	global $d_sysrebootreqd_path;
310

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

    
314
function pprint_address($adr) {
315
	global $specialnets;
316

    
317
	if (isset($adr['any'])) {
318
		$padr = "*";
319
	} else if ($adr['network']) {
320
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
321
			$padr = "Interface IP address";
322
		} else {
323
			$padr = $specialnets[$adr['network']];
324
		}
325
	} else {
326
		$padr = $adr['address'];
327
	}
328

    
329
	if (isset($adr['not']))
330
		$padr = "! " . $padr;
331

    
332
	return $padr;
333
}
334

    
335
function pprint_port($port) {
336
	global $wkports;
337

    
338
	$pport = "";
339

    
340
	if (!$port)
341
		return "*";
342
	else {
343
		$srcport = explode("-", $port);
344
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
345
			$pport = $srcport[0];
346
			if ($wkports[$srcport[0]]) {
347
				$pport .= " (" . $wkports[$srcport[0]] . ")";
348
			}
349
		} else
350
			$pport .= $srcport[0] . " - " . $srcport[1];
351
	}
352

    
353
	return $pport;
354
}
355

    
356
function captiveportal_users_sort() {
357
	global $g, $config;
358

    
359
	function cpusercmp($a, $b) {
360
		return strcasecmp($a['name'], $b['name']);
361
	}
362

    
363
	usort($config['captiveportal']['user'], "cpusercmp");
364
}
365

    
366
function admin_groups_sort() {
367
	global $g, $config;
368

    
369
	function cpusercmp($a, $b) {
370
		return strcasecmp($a['name'], $b['name']);
371
	}
372

    
373
	usort($config['system']['group'], "cpusercmp");
374
}
375

    
376
function admin_users_sort() {
377
	global $g, $config;
378

    
379
	function cpusercmp($a, $b) {
380
		return strcasecmp($a['name'], $b['name']);
381
	}
382

    
383
	usort($config['system']['user'], "cpusercmp");
384
}
385

    
386
/* sort by interface only, retain the original order of rules that apply to
387
   the same interface */
388
function filter_rules_sort() {
389
	global $config;
390

    
391
	/* mark each rule with the sequence number (to retain the order while sorting) */
392
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
393
		$config['filter']['rule'][$i]['seq'] = $i;
394

    
395
	function filtercmp($a, $b) {
396
		if ($a['interface'] == $b['interface'])
397
			return $a['seq'] - $b['seq'];
398
		else
399
			return -strcmp($a['interface'], $b['interface']);
400
	}
401

    
402
	usort($config['filter']['rule'], "filtercmp");
403

    
404
	/* strip the sequence numbers again */
405
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
406
		unset($config['filter']['rule'][$i]['seq']);
407
}
408

    
409
function nat_rules_sort() {
410
	global $config;
411

    
412
	function natcmp($a, $b) {
413
		if ($a['external-address'] == $b['external-address']) {
414
			if ($a['protocol'] == $b['protocol']) {
415
				if ($a['external-port'] == $b['external-port']) {
416
					return 0;
417
				} else {
418
					return ($a['external-port'] - $b['external-port']);
419
				}
420
			} else {
421
				return strcmp($a['protocol'], $b['protocol']);
422
			}
423
		} else if (!$a['external-address'])
424
			return 1;
425
		else if (!$b['external-address'])
426
			return -1;
427
		else
428
			return ipcmp($a['external-address'], $b['external-address']);
429
	}
430

    
431
	usort($config['nat']['rule'], "natcmp");
432
}
433

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

    
437
	function nat1to1cmp($a, $b) {
438
		return ipcmp($a['external'], $b['external']);
439
	}
440

    
441
	usort($config['nat']['onetoone'], "nat1to1cmp");
442
}
443

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

    
447
	function natservercmp($a, $b) {
448
		return ipcmp($a['ipaddr'], $b['ipaddr']);
449
	}
450

    
451
	usort($config['nat']['servernat'], "natservercmp");
452
}
453

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

    
457
	function natoutcmp($a, $b) {
458
		return strcmp($a['source']['network'], $b['source']['network']);
459
	}
460

    
461
	usort($config['nat']['advancedoutbound']['rule'], "natoutcmp");
462
}
463

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

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

    
471
	usort($config['pptpd']['user'], "usercmp");
472
}
473

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

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

    
481
	usort($config['openvpn']['user'], "usercmp");
482
}
483

    
484
function pppoe_users_sort() {
485
	global $g, $config;
486

    
487
	function usercmp($a, $b) {
488
		return strcasecmp($a['name'], $b['name']);
489
	}
490

    
491
	usort($config['pppoe']['user'], "usercmp");
492
}
493

    
494
function staticroutes_sort() {
495
	global $g, $config;
496

    
497
	function staticroutecmp($a, $b) {
498
		return strcmp($a['network'], $b['network']);
499
	}
500

    
501
	usort($config['staticroutes']['route'], "staticroutecmp");
502
}
503

    
504
function hosts_sort() {
505
	global $g, $config;
506

    
507
	function hostcmp($a, $b) {
508
		return strcasecmp($a['host'], $b['host']);
509
	}
510

    
511
	usort($config['dnsmasq']['hosts'], "hostcmp");
512
}
513

    
514
function staticmaps_sort($if) {
515
	global $g, $config;
516

    
517
	function staticmapcmp($a, $b) {
518
		return ipcmp($a['ipaddr'], $b['ipaddr']);
519
	}
520

    
521
	usort($config['dhcpd'][$if]['staticmap'], "staticmapcmp");
522
}
523

    
524
function aliases_sort() {
525
	global $g, $config;
526

    
527
	function aliascmp($a, $b) {
528
		return strcmp($a['name'], $b['name']);
529
	}
530

    
531
	usort($config['aliases']['alias'], "aliascmp");
532
}
533

    
534
function schedule_sort(){
535
	global $g, $config;
536

    
537
	function schedulecmp($a, $b) {
538
		return strcmp($a['name'], $b['name']);
539
	}
540

    
541
	usort($config['schedules']['schedule'], "schedulecmp");
542

    
543
}
544

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

    
548
	function mobilekeycmp($a, $b) {
549
		return strcmp($a['ident'][0], $b['ident'][0]);
550
	}
551

    
552
	usort($config['ipsec']['mobilekey'], "mobilekeycmp");
553
}
554

    
555
function proxyarp_sort() {
556
	global $g, $config;
557

    
558
	function proxyarpcmp($a, $b) {
559
		if (isset($a['network']))
560
			list($ast,$asn) = explode("/", $a['network']);
561
		else if (isset($a['range'])) {
562
			$ast = $a['range']['from'];
563
			$asn = 32;
564
		}
565
		if (isset($b['network']))
566
			list($bst,$bsn) = explode("/", $b['network']);
567
		else if (isset($b['range'])) {
568
			$bst = $b['range']['from'];
569
			$bsn = 32;
570
		}
571
		if (ipcmp($ast, $bst) == 0)
572
			return ($asn - $bsn);
573
		else
574
			return ipcmp($ast, $bst);
575
	}
576

    
577
	usort($config['proxyarp']['proxyarpnet'], "proxyarpcmp");
578
}
579

    
580
function passthrumacs_sort() {
581
	global $g, $config;
582

    
583
	function passthrumacscmp($a, $b) {
584
		return strcmp($a['mac'], $b['mac']);
585
	}
586

    
587
	usort($config['captiveportal']['passthrumac'],"passthrumacscmp");
588
}
589

    
590
function cpelements_sort() {
591
	global $g, $config;
592

    
593
	function cpelementscmp($a, $b) {
594
		return strcasecmp($a['name'], $b['name']);
595
	}
596

    
597
	usort($config['captiveportal']['element'],"cpelementscmp");
598
}
599

    
600
function allowedips_sort() {
601
	global $g, $config;
602

    
603
	function allowedipscmp($a, $b) {
604
		return strcmp($a['ip'], $b['ip']);
605
	}
606

    
607
	usort($config['captiveportal']['allowedip'],"allowedipscmp");
608
}
609

    
610
function wol_sort() {
611
	global $g, $config;
612

    
613
	function wolcmp($a, $b) {
614
		return strcmp($a['descr'], $b['descr']);
615
	}
616

    
617
	usort($config['wol']['wolentry'], "wolcmp");
618
}
619

    
620
function gentitle($title) {
621
	global $navlevelsep;
622
	if(!is_array($title))
623
		return $title;
624
	else
625
		return join($navlevelsep, $title); 
626
}
627

    
628
function genhtmltitle($title) {
629
        global $config;
630
        return gentitle($title);
631
}
632

    
633
/* update the changedesc and changecount(er) variables */
634
function update_changedesc($update) {
635
	global $changedesc;
636
	global $changecount;
637

    
638
	$changedesc .= " {$update}";
639
	$changecount++;
640
}
641

    
642
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
643
	global $g, $config;
644
    $sor = isset($config['syslog']['reverse']) ? "-r" : "";
645
    $logarr = "";
646
	$grepline = "  ";
647
	if(is_array($grepfor))
648
		foreach($grepfor as $agrep)
649
			$grepline .= " | grep \"$agrep\"";
650
	if(is_array($grepinvert))
651
		foreach($grepinvert as $agrep)
652
			$grepline .= " | grep -v \"$agrep\"";
653
	if($config['system']['disablesyslogclog']) 
654
		exec("cat {$logfile}{$grepline} | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
655
	else 
656
		exec("/usr/sbin/clog {$logfile}{$grepline} | grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
657
    /* comment out debug code
658
    echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
659
    */
660
    foreach ($logarr as $logent) {
661
            $logent = preg_split("/\s+/", $logent, 6);
662
            echo "<tr valign=\"top\">\n";
663
            if ($withorig) {
664
            		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
665
                    echo "<td class=\"listlr\" nowrap>" . $entry_date_time  . "</td>\n";
666
                    echo "<td class=\"listr\">" . htmlspecialchars($logent[4] . " " . $logent[5]) . "</td>\n";
667
            } else {
668
                    echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
669
            }
670
            echo "</tr>\n";
671
    }
672
}
673

    
674
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
675
	global $g, $config;
676
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
677
	$logarr = "";
678
	$grepline = "  ";
679
	if(is_array($grepfor))
680
		foreach($grepfor as $agrep)
681
			$grepline .= " | grep \"$agrep\"";
682
	if(is_array($grepinvert))
683
		foreach($grepinvert as $agrep)
684
			$grepline .= " | grep -v \"$agrep\"";
685
	/* comment out debug code
686
	echo "<!-- /usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail} -->";
687
	*/
688
	if($config['system']['disablesyslogclog']) 
689
		exec("cat {$logfile}{$grepline} | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
690
	else 
691
		exec("/usr/sbin/clog {$logfile}{$grepline} | grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
692
	return($logarr);
693
}
694

    
695
/* Check if variable has changed, update and log if it has
696
 * returns true if var changed
697
 * varname = variable name in plain text
698
 * orig = original value
699
 * new = new value
700
 */
701
function update_if_changed($varname, & $orig, $new) {
702
	if (is_array($orig) && is_array($new)) {
703
		$a_diff = array_diff($orig, $new);
704
		foreach ($a_diff as $diff) {
705
			update_changedesc("removed {$varname}: \"{$diff}\"");
706
		}
707
		$a_diff = array_diff($new, $orig);
708
		foreach ($a_diff as $diff) {
709
			update_changedesc("added {$varname}: \"{$diff}\"");
710
		}
711
		$orig = $new;
712
		return true;
713

    
714
	} else {
715
		if ($orig != $new) {
716
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
717
			$orig = $new;
718
			return true;
719
		}
720
	}
721
	return false;
722
}
723

    
724
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
725

    
726
        if (isset($adr['any']))
727
                $padr = "any";
728
        else if ($adr['network'])
729
                $padr = $adr['network'];
730
        else if ($adr['address']) {
731
                list($padr, $pmask) = explode("/", $adr['address']);
732
                if (!$pmask)
733
                        $pmask = 32;
734
        }
735

    
736
        if (isset($adr['not']))
737
                $pnot = 1;
738
        else
739
                $pnot = 0;
740

    
741
        if ($adr['port']) {
742
                list($pbeginport, $pendport) = explode("-", $adr['port']);
743
                if (!$pendport)
744
                        $pendport = $pbeginport;
745
        } else {
746
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
747
                        /* Item is a port alias */
748
                } else {
749
                        $pbeginport = "any";
750
                        $pendport = "any";
751
                }
752
        }
753
}
754

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

    
757
        $adr = array();
758

    
759
        if ($padr == "any")
760
                $adr['any'] = true;
761
        else if (is_specialnet($padr))
762
                $adr['network'] = $padr;
763
        else {
764
                $adr['address'] = $padr;
765
                if ($pmask != 32)
766
                        $adr['address'] .= "/" . $pmask;
767
        }
768

    
769
        if ($pnot)
770
                $adr['not'] = true;
771
        else
772
                unset($adr['not']);
773

    
774
        if (($pbeginport != 0) && ($pbeginport != "any")) {
775
                if ($pbeginport != $pendport)
776
                        $adr['port'] = $pbeginport . "-" . $pendport;
777
                else
778
                        $adr['port'] = $pbeginport;
779
        }
780

    
781
        if(alias_expand($pbeginport)) {
782
                $adr['port'] = $pbeginport;
783
        }
784
}
785

    
786
function is_specialnet($net) {
787
        global $specialsrcdst;
788
		if(!$net) 
789
			return false;
790
        if (in_array($net, $specialsrcdst) || strstr($net, "opt"))
791
                return true;
792
        else
793
                return false;
794
}
795

    
796
function ipsec_ca_sort() {
797
        global $g, $config;
798

    
799
        function ipseccacmp($a, $b) {
800
                return strcmp($a['ident'], $b['ident']);
801
        }
802

    
803
        usort($config['ipsec']['cacert'], "ipseccacmp");
804
}
805

    
806
//function to create widget tabs when called
807
function display_widget_tabs(& $tab_array) {	
808
	echo "<div id='tabs'>";
809
	$tabscounter = 0;
810
	foreach ($tab_array as $ta) {
811
	$dashpos = strpos($ta[2],'-');
812
	$tabname = $ta[2] . "-tab";
813
	$tabclass = substr($ta[2],0,$dashpos);
814
	$tabclass = $tabclass . "-class";
815
		if ($ta[1] == true) {
816
			$tabActive = "table-cell";
817
			$tabNonActive = "none";
818
		} 
819
		else {
820
			$tabActive = "none";
821
			$tabNonActive = "table-cell";
822
		}
823
		echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
824
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
825
		echo "&nbsp;&nbsp;&nbsp;</B>";
826
		echo "</div>";
827
		
828
		echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
829
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
830
		echo "&nbsp;&nbsp;&nbsp;</B>";
831
		echo "</div>";
832
	}
833
	
834
	echo "<script type=\"text/javascript\">";
835
	echo "NiftyCheck();\n";
836
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
837
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
838
	echo "</script>";
839
	echo "</div>";
840
}
841

    
842

    
843
// Return inline javascript file or CSS to minimizie 
844
// request count going back to server.
845
function outputJavaScriptFileInline($javascript) {
846
	if(file_exists($javascript)) {
847
		echo "\n<script type=\"text/javascript\">\n";
848
		include($javascript);
849
		echo "\n</script>\n";
850
	} else {
851
		echo "<p/>ERROR!  COULD NOT LOCATE $javascript";
852
		echo "<p/>Please contact webmaster.";
853
		exit;
854
	}
855
}
856

    
857

    
858

    
859
function outputCSSPrintFileInline($css) {
860
	if(file_exists($css)) {
861
		echo "\n<style media=\"print\" type=\"text/css\">\n";
862
		include($css);
863
		echo "\n</style>\n";
864
	} else {
865
		echo "<p/>ERROR!  COULD NOT LOCATE $css";
866
		echo "<p/>Please contact webmaster.";
867
		exit;
868
	}
869
}
870

    
871

    
872
function outputCSSFileInline($css) {
873
	if(file_exists($css)) {
874
		echo "\n<style type=\"text/css\">\n";
875
		include($css);
876
		echo "\n</style>\n";
877
	} else {
878
		echo "<p/>ERROR!  COULD NOT LOCATE $css";
879
		echo "<p/>Please contact webmaster.";
880
		exit;
881
	}
882
}
883

    
884
?>
885

    
(68-68/210)