Project

General

Profile

Download (33.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	guiconfig.inc
4
	by Scott Ullrich, Copyright 2004, All rights reserved.
5
	originally based on of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE:	base
33
*/
34

    
35
/* Include authentication routines */
36
/* THIS MUST BE ABOVE ALL OTHER CODE */
37
if(!$nocsrf) {
38
	function csrf_startup() {
39
		csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
40
	}
41
	require_once("csrf/csrf-magic.php");
42
}
43
require_once("authgui.inc");
44

    
45
/* make sure nothing is cached */
46
if (!$omit_nocacheheaders) {
47
	header("Expires: 0");
48
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
49
	header("Cache-Control: no-store, no-cache, must-revalidate");
50
	header("Cache-Control: post-check=0, pre-check=0", false);
51
	header("Pragma: no-cache");
52
}
53

    
54
/* parse the configuration and include all configuration functions */
55
require_once("functions.inc");
56

    
57
/* Pull in all the gui related display classes) */
58
foreach (scandir("/usr/local/www/classes/") as $file) {
59
	if (stristr($file, ".inc") !== false) {
60
		require_once("classes/{$file}");
61
	}
62
}
63
/*
64
 *   if user has selected a custom template, use it.
65
 *   otherwise default to pfsense template
66
 */
67
if($config['theme'] <> "")
68
        $g['theme'] = $config['theme'];
69
else
70
        $g['theme'] = "pfsense";
71

    
72
/*
73
 *  If this device is an apple ipod/iphone
74
 *  switch the theme to one that works with it.
75
 */
76
$apple_ua = array("iPhone","iPod", "iPad");
77
foreach($apple_ua as $useragent)
78
	if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent))
79
		$g['theme'] = "pfsense";
80

    
81
/* Set the default interface language */
82
if($config['system']['language'] <> "") {
83
	$g['language'] = $config['system']['language'];
84
} elseif ($g['language'] == "") {
85
	$g['language'] = 'en_US';
86
}
87

    
88
set_language($g['language']);
89

    
90
/* used by progress bar */
91
$lastseen = "-1";
92

    
93
$navlevelsep = ": ";	/* navigation level separator string */
94
$mandfldhtml = "";		/* display this before mandatory input fields */
95
$mandfldhtmlspc = "";	/* same as above, but with spacing */
96

    
97
/* Some ajax scripts still need access to GUI */
98
if(!$ignorefirmwarelock) {
99
	if (is_subsystem_dirty('firmwarelock')) {
100
		if (!$d_isfwfile) {
101
			header("Location: system_firmware.php");
102
			exit;
103
		} else {
104
			return;
105
		}
106
	}
107
}
108

    
109
$firewall_rules_dscp_types = array("af11", 
110
				"af12", 
111
				"af13", 
112
				"af21", 
113
				"af22", 
114
				"af23", 
115
				"af31", 
116
				"af32", 
117
				"af33", 
118
				"af41", 
119
				"af42", 
120
				"af43", 
121
				"EF", 
122
				"1-64", 
123
				"0x10",
124
				"0x04-0xfc");
125

    
126
$auth_server_types = array(
127
	'ldap' => "LDAP",
128
	'radius' => "Radius");
129

    
130
$ldap_urltypes = array(
131
	'TCP - Standard' => 389,
132
	'SSL - Encrypted' => 636);
133

    
134
$ldap_scopes = array(
135
	'one' => "One Level",
136
	'subtree' => "Entire Subtree");
137

    
138
$ldap_protvers = array(
139
	2,
140
	3);
141

    
142
$ldap_templates = array(
143

    
144
	'open' => array(
145
				'desc' => "OpenLDAP",
146
				'attr_user' => "cn",
147
				'attr_group' => "cn",
148
				'attr_member' => "member"),
149

    
150
	'msad' => array(
151
				'desc' => "Microsoft AD",
152
				'attr_user' => "samAccountName",
153
				'attr_group' => "cn",
154
				'attr_member' => "memberOf"),
155

    
156
	'edir' => array(
157
				'desc' => "Novell eDirectory",
158
				'attr_user' => "cn",
159
				'attr_group' => "cn",
160
				'attr_member' => "uniqueMember"));
161

    
162
$radius_srvcs = array(
163
	'both' => "Authentication and Accounting",
164
	'auth' => "Authentication",
165
	'acct' => "Accounting");
166

    
167
$netbios_nodetypes = array(
168
	'0' => "none",
169
	'1' => "b-node",
170
	'2' => "p-node",
171
	'4' => "m-node",
172
	'5' => "h-node");
173

    
174
/* some well knows ports */
175
$wkports = array(
176
	5999 => "CVSup",	
177
	53 => "DNS",
178
	21 => "FTP",
179
	3000 => "HBCI",
180
	80 => "HTTP",
181
	443 => "HTTPS",
182
	5190 => "ICQ",
183
	113 => "IDENT/AUTH",
184
	143 => "IMAP",
185
	993 => "IMAP/S",
186
	4500 => "IPsec NAT-T",
187
	500 => "ISAKMP",
188
	1701 => "L2TP",
189
	389 => "LDAP",
190
	1755 => "MMS/TCP",
191
	7000 => "MMS/UDP",
192
	445 => "MS DS",
193
	3389 => "MS RDP",
194
	1512 => "MS WINS",
195
	1863 => "MSN",
196
	119 => "NNTP",
197
	123 => "NTP",
198
	138 => "NetBIOS-DGM",
199
	137 => "NetBIOS-NS",
200
	139 => "NetBIOS-SSN",
201
	1194 => "OpenVPN",
202
	110 => "POP3",
203
	995 => "POP3/S",
204
	1723 => "PPTP",	
205
	1812 => "RADIUS",
206
	1813 => "RADIUS accounting",
207
	5004 => "RTP",
208
	5060 => "SIP",
209
	25 => "SMTP",
210
	465 => "SMTP/S",
211
	161 => "SNMP",
212
	162 => "SNMP-Trap",
213
	22 => "SSH",
214
	3478 => "STUN",
215
	3544 => "Teredo",
216
	23 => "Telnet",
217
	69 => "TFTP",
218
	5900 => "VNC");
219

    
220
/* TCP flags */
221
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg");
222

    
223
$specialnets = array("pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
224

    
225
$spiflist = get_configured_interface_with_descr(false, true);
226
foreach ($spiflist as $ifgui => $ifdesc) {
227
	$specialnets[$ifgui] = $ifdesc . " net";
228
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
229
}
230

    
231
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
232
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
233
	"10half" => "10BASE-T half-duplex");
234

    
235
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
236
	"hostap" => "Access Point");
237

    
238
/* platforms that support firmware updating */
239
$fwupplatforms = array('pfSense', 'net45xx', 'net48xx', 'generic-pc', 'embedded', 'wrap', 'nanobsd');
240

    
241
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
242

    
243
	/* check for bad control characters */
244
	foreach ($postdata as $pn => $pd) {
245
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
246
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
247
		}
248
	}
249

    
250
	for ($i = 0; $i < count($reqdfields); $i++) {
251
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
252
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
253
		}
254
	}
255
}
256

    
257
function print_input_errors($input_errors) {
258
	global $g;
259

    
260
	print <<<EOF
261
	<div id='inputerrorsdiv' name='inputerrorsdiv'>
262
	<p>
263
	<table border="0" cellspacing="0" cellpadding="4" width="100%">
264
	<tr>
265
		<td class="inputerrorsleft">
266
			<img src="/themes/{$g['theme']}/images/icons/icon_error.gif">
267
		</td>
268
		<td class="inputerrorsright">
269
			<span class="errmsg"><p>
270
				The following input errors were detected:
271
				<ul>
272
EOF;
273
		foreach ($input_errors as $ierr) {
274
			echo "<li>" . htmlspecialchars($ierr) . "</li>";
275
		}
276

    
277
	print <<<EOF2
278
				</ul>
279
			</span>
280
		</td></tr>
281
	</table>
282
	</div>
283
	</p>&nbsp;<br>
284
EOF2;
285
	
286
}
287

    
288
function verify_gzip_file($fname) {
289

    
290
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
291
	if ($returnvar != 0)
292
		return 0;
293
	else
294
		return 1;
295
}
296

    
297
function print_info_box_np($msg, $name="apply",$value="", $showapply=false) {
298
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
299

    
300
	if(empty($value)) {
301
		$value = gettext("Apply changes");
302
	}
303

    
304
	// Set the Nifty background color if one is not set already (defaults to white)
305
	if($nifty_background == "")
306
		$nifty_background = "#FFF";
307

    
308
	if(stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
309
		$savebutton = "<td class='infoboxsave'>";
310
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
311
		if($_POST['if']) 
312
			$savebutton .= "<input type='hidden' name='if' value='{$_POST['if']}'>";
313
		$savebutton.="</td>";
314
	}
315
	$nifty_redbox = "#990000";
316
	$nifty_blackbox = "#000000";
317
	
318
	$themename = $g['theme'];
319
	
320
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
321
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
322
		eval($toeval);
323
	}
324
	
325
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
326
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
327
		eval($toeval);
328
	}	
329
		
330
	if(!$savebutton) {
331
		$savebutton = '<td class="infoboxsave"><input value="Close" type="button" onClick="jQuery(\'#redboxtable\').hide();"></td>';
332
	}
333

    
334
	echo <<<EOFnp
335
	<table class='infobox' id='redboxtable'>
336
		<tr>
337
			<td>
338
				<div class='infoboxnp' id='redbox'>
339
					<table class='infoboxnptable2'>
340
						<tr>
341
							<td class='infoboxnptd'>
342
								&nbsp;&nbsp;&nbsp;<img class='infoboxnpimg' src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" >
343
							</td>
344
							<td class='infoboxnptd2'>
345
								<b>{$msg}</b>
346
							</td>
347
							{$savebutton}
348
						</tr>
349
					</table>
350
				</div>
351
				<div>
352
					<p/>
353
				</div>
354
			</td>
355
		</tr>
356
	</table>
357
	<script type="text/javascript">
358
		NiftyCheck();
359
		Rounded("div#redbox","all","{$nifty_background}","{$nifty_redbox}","smooth");
360
		Rounded("td#blackbox","all","{$nifty_background}","{$nifty_blackbox}","smooth");
361
	</script>
362
EOFnp;
363

    
364
}
365

    
366
function print_info_box_np_undo($msg, $name="apply",$value="Apply changes", $undo) {
367
	global $g;
368
	
369
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
370
		$savebutton = "<td class='infoboxsave'><nobr>";
371
		$savebutton .= " <input type=\"button\" value=\"Undo\" onClick=\"document.location='{$undo}'\">";
372
		$savebutton .= " <input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
373
		$savebutton.="</nobr></td>";
374
		if($_POST['if']) 
375
			$savebutton .= "<input type='hidden' name='if' value='{$_POST['if']}'>";
376
	}
377
	$nifty_redbox = "#990000";
378
	$nifty_blackbox = "#000000";
379
	
380
	$themename = $g['theme'];
381
	
382
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
383
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
384
		eval($toeval);
385
	}
386
	
387
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
388
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
389
		eval($toeval);
390
	}	
391
	
392
		
393
	if(!$savebutton) {
394
		$savebutton = '<td class="infoboxsave"><input value="Close" type="button" onClick="jQuery(\'#redboxtable\').hide();"></td>';
395
	}
396

    
397
	echo <<<EOFnp
398
	<table class='infobox' id='redboxtable'>
399
		<tr>
400
			<td>
401
				<div class='infoboxnp' id='redbox'>
402
					<table class='infoboxnptable2'>
403
						<tr>
404
							<td class='infoboxnptd'>
405
								&nbsp;&nbsp;&nbsp;<img class='infoboxnpimg' src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" >
406
							</td>
407
							<td class='infoboxnptd2'>
408
								<b>{$msg}</b>
409
							</td>
410
							{$savebutton} 
411
							{$undobutton}
412
						</tr>
413
					</table>
414
				</div>
415
				<div>
416
					<p/>
417
				</div>
418
			</td>
419
		</tr>
420
	</table>
421
	<script type="text/javascript">
422
		NiftyCheck();
423
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
424
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
425
	</script>
426
EOFnp;
427

    
428
}
429

    
430
function print_info_box($msg) {
431
	print_info_box_np($msg);
432
}
433

    
434
function get_std_save_message($ok) {
435
	global $d_sysrebootreqd_path;
436
	$filter_related = false;
437
	$filter_pages = array("nat", "filter");
438
	$to_return = "The changes have been applied successfully.";
439
	foreach($filter_pages as $fp) 
440
		if(stristr($_SERVER['SCRIPT_FILENAME'], $fp))
441
			$filter_related = true;	
442
	if($filter_related)
443
		$to_return .= "<br/>You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
444
	return $to_return;
445
}
446

    
447
function pprint_address($adr) {
448
	global $specialnets;
449

    
450
	if (isset($adr['any'])) {
451
		$padr = "*";
452
	} else if ($adr['network']) {
453
		$padr = $specialnets[$adr['network']];
454
	} else {
455
		$padr = $adr['address'];
456
	}
457

    
458
	if (isset($adr['not']))
459
		$padr = "! " . $padr;
460

    
461
	return $padr;
462
}
463

    
464
function pprint_port($port) {
465
	global $wkports;
466

    
467
	$pport = "";
468

    
469
	if (!$port)
470
		return "*";
471
	else {
472
		$srcport = explode("-", $port);
473
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
474
			$pport = $srcport[0];
475
			if ($wkports[$srcport[0]]) {
476
				$pport .= " (" . $wkports[$srcport[0]] . ")";
477
			}
478
		} else
479
			$pport .= $srcport[0] . " - " . $srcport[1];
480
	}
481

    
482
	return $pport;
483
}
484

    
485
function firewall_check_for_advanced_options(&$item) {
486
        $item_set = "";
487
        if($item['max'])
488
                $item_set .= "max {$item['max']} ";
489
        if($item['max-src-nodes'])
490
                $item_set .= "max-src-nodes {$item['max-src-nodes']} ";
491
        if($item['max-src-conn'])
492
                $item_set .= "max-src-conn {$item['max-src-conn']} ";
493
        if($item['max-src-states'])
494
                $item_set .= "max-src-states {$item['max-src-states']} ";
495
        if($item['statetype'] != "keep state" && $item['statetype'] != "")
496
                $item_set .= "statetype {$item['statetype']} ";
497
        if($item['statetimeout'])
498
                $item_set .= "statetimeout {$item['statetimeout']} ";
499
        if($item['nosync'])
500
                $item_set .= "nosync ";
501
        if($item['max-src-conn-rate'])
502
                $item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
503
        if($item['max-src-conn-rates'])
504
                $item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
505
        if($item['gateway'])
506
                $item_set .= "gateway {$item['gateway']} ";
507
        if($item['dnpipe'])
508
                $item_set .= "limiter {$item['dnpipe']} ";
509
        if($item['pdnpipe'])
510
                $item_set .= "limiter {$item['pdnpipe']} ";
511
        if($item['l7container'])
512
                $item_set .= "layer7 {$item['l7container']} ";
513
        if($item['tag'])
514
                $item_set .= "tag {$item['tag']} ";
515
        if($item['tagged'])
516
                $item_set .= "tagged {$item['tagged']} ";
517
        if(isset($item['allowopts']))
518
                $item_set .= "allowopts ";
519
        if(isset($item['disablereplyto']))
520
                $item_set .= "disable reply-to ";
521
        if($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2'])
522
                $item_set .= "tcpflags set";
523

    
524
        return $item_set;
525
}
526

    
527
function gentitle($title) {
528
	global $navlevelsep;
529
	if(!is_array($title))
530
		return $title;
531
	else
532
		return join($navlevelsep, $title);
533
}
534

    
535
function genhtmltitle($title) {
536
        global $config;
537
        return gentitle($title);
538
}
539

    
540
/* update the changedesc and changecount(er) variables */
541
function update_changedesc($update) {
542
	global $changedesc;
543
	global $changecount;
544

    
545
	$changedesc .= " {$update}";
546
	$changecount++;
547
}
548

    
549
function clear_log_file($logfile = "/var/log/system.log") {
550
	global $config, $g;
551
	exec("/usr/bin/killall syslogd");
552
	if(isset($config['system']['disablesyslogclog'])) {
553
		unlink($logfile);
554
		touch($logfile);
555
	} else {
556
		if(isset($config['system']['usefifolog'])) 
557
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
558
		else
559
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
560
	}
561
	system_syslogd_start();	
562
}
563

    
564
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
565
	global $g, $config;
566
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
567
	$logarr = "";
568
	$grepline = "  ";
569
	if(is_array($grepfor))
570
		foreach($grepfor as $agrep)
571
			$grepline .= " | grep \"$agrep\"";
572
	if(is_array($grepinvert))
573
		foreach($grepinvert as $agrep)
574
			$grepline .= " | grep -v \"$agrep\"";
575
	if(file_exists($logfile) && filesize($logfile) == 0) {
576
		$logarr = array("Log file started.");
577
	} else {
578
		if($config['system']['disablesyslogclog']) {
579
			exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
580
		} else {
581
			if(isset($config['system']['usefifolog']))
582
				exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
583
			else
584
				exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
585
		}
586
	}
587
	foreach ($logarr as $logent) {
588
			$logent = preg_split("/\s+/", $logent, 6);
589
			echo "<tr valign=\"top\">\n";
590
			if ($withorig) {
591
					if(isset($config['system']['usefifolog'])) {
592
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
593
						$entry_text = htmlspecialchars($logent[5]);
594
					} else {
595
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
596
						$entry_text = htmlspecialchars($logent[4] . " " . $logent[5]);
597
					}
598
					echo "<td class=\"listlr\" nowrap>{$entry_date_time}</td>\n";
599
					echo "<td class=\"listr\">{$entry_text}</td>\n";
600

    
601
			} else {
602
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
603
			}
604
			echo "</tr>\n";
605
	}
606
}
607

    
608
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
609
	global $g, $config;
610
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
611
	$logarr = "";
612
	$grepline = "  ";
613
	if(is_array($grepfor))
614
		foreach($grepfor as $agrep)
615
			$grepline .= " | grep \"$agrep\"";
616
	if(is_array($grepinvert))
617
		foreach($grepinvert as $agrep)
618
			$grepline .= " | grep -v \"$agrep\"";
619
	if($config['system']['disablesyslogclog']) {
620
		exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
621
	} else {
622
		if(isset($config['system']['usefifolog'])) {
623
			exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);			
624
		} else {
625
			exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
626
		}
627
	}
628
	return($logarr);
629
}
630

    
631
/* Check if variable has changed, update and log if it has
632
 * returns true if var changed
633
 * varname = variable name in plain text
634
 * orig = original value
635
 * new = new value
636
 */
637
function update_if_changed($varname, & $orig, $new) {
638
	if (is_array($orig) && is_array($new)) {
639
		$a_diff = array_diff($orig, $new);
640
		foreach ($a_diff as $diff) {
641
			update_changedesc("removed {$varname}: \"{$diff}\"");
642
		}
643
		$a_diff = array_diff($new, $orig);
644
		foreach ($a_diff as $diff) {
645
			update_changedesc("added {$varname}: \"{$diff}\"");
646
		}
647
		$orig = $new;
648
		return true;
649

    
650
	} else {
651
		if ($orig != $new) {
652
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
653
			$orig = $new;
654
			return true;
655
		}
656
	}
657
	return false;
658
}
659

    
660
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
661

    
662
        if (isset($adr['any']))
663
                $padr = "any";
664
        else if ($adr['network'])
665
                $padr = $adr['network'];
666
        else if ($adr['address']) {
667
                list($padr, $pmask) = explode("/", $adr['address']);
668
                if (!$pmask)
669
                        $pmask = 32;
670
        }
671

    
672
        if (isset($adr['not']))
673
                $pnot = 1;
674
        else
675
                $pnot = 0;
676

    
677
        if ($adr['port']) {
678
                list($pbeginport, $pendport) = explode("-", $adr['port']);
679
                if (!$pendport)
680
                        $pendport = $pbeginport;
681
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
682
		$pbeginport = "any";
683
		$pendport = "any";
684
        }
685
}
686

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

    
689
        $adr = array();
690

    
691
        if ($padr == "any")
692
                $adr['any'] = true;
693
        else if (is_specialnet($padr))
694
                $adr['network'] = $padr;
695
        else {
696
                $adr['address'] = $padr;
697
                if ($pmask != 32)
698
                        $adr['address'] .= "/" . $pmask;
699
        }
700

    
701
        if ($pnot)
702
                $adr['not'] = true;
703
        else
704
                unset($adr['not']);
705

    
706
        if (($pbeginport != 0) && ($pbeginport != "any")) {
707
                if ($pbeginport != $pendport)
708
                        $adr['port'] = $pbeginport . "-" . $pendport;
709
                else
710
                        $adr['port'] = $pbeginport;
711
        }
712

    
713
        if(is_alias($pbeginport)) {
714
                $adr['port'] = $pbeginport;
715
        }
716
}
717

    
718
function is_specialnet($net) {
719
        global $specialsrcdst;
720

    
721
	if(!$net) 
722
		return false;
723
        if (in_array($net, $specialsrcdst))
724
                return true;
725
        else
726
                return false;
727
}
728

    
729
//function to create widget tabs when called
730
function display_widget_tabs(& $tab_array) {	
731
	echo "<div id='tabs'>";
732
	$tabscounter = 0;
733
	foreach ($tab_array as $ta) {
734
	$dashpos = strpos($ta[2],'-');
735
	$tabname = $ta[2] . "-tab";
736
	$tabclass = substr($ta[2],0,$dashpos);
737
	$tabclass = $tabclass . "-class";
738
		if ($ta[1] == true) {
739
			$tabActive = "table-cell";
740
			$tabNonActive = "none";
741
		} 
742
		else {
743
			$tabActive = "none";
744
			$tabNonActive = "table-cell";
745
		}
746
		echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
747
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
748
		echo "&nbsp;&nbsp;&nbsp;</B>";
749
		echo "</div>";
750
		
751
		echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
752
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
753
		echo "&nbsp;&nbsp;&nbsp;</B>";
754
		echo "</div>";
755
	}
756
	
757
	echo "<script type=\"text/javascript\">";
758
	echo "NiftyCheck();\n";
759
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
760
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
761
	echo "</script>";
762
	echo "</div>";
763
}
764

    
765

    
766
// Return inline javascript file or CSS to minimizie 
767
// request count going back to server.
768
function outputJavaScriptFileInline($javascript) {
769
	if(file_exists($javascript)) {
770
		echo "\n<script type=\"text/javascript\">\n";
771
		include($javascript);
772
		echo "\n</script>\n";
773
	} else {
774
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
775
	}
776
}
777

    
778

    
779

    
780
function outputCSSPrintFileInline($css) {
781
	if(file_exists($css)) {
782
		echo "\n<style media=\"print\" type=\"text/css\">\n";
783
		include($css);
784
		echo "\n</style>\n";
785
	} else {
786
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
787
	}
788
}
789

    
790

    
791
function outputCSSFileInline($css) {
792
	if(file_exists($css)) {
793
		echo "\n<style type=\"text/css\">\n";
794
		include($css);
795
		echo "\n</style>\n";
796
	} else {
797
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
798
	}
799
}
800

    
801
$rfc2616 = array(
802
	100 => "100 Continue",
803
	101 => "101 Switching Protocols",
804
	200 => "200 OK",
805
	201 => "201 Created",
806
	202 => "202 Accepted",
807
	203 => "203 Non-Authoritative Information",
808
	204 => "204 No Content",
809
	205 => "205 Reset Content",
810
	206 => "206 Partial Content",
811
	300 => "300 Multiple Choices",
812
	301 => "301 Moved Permanently",
813
	302 => "302 Found",
814
	303 => "303 See Other",
815
	304 => "304 Not Modified",
816
	305 => "305 Use Proxy",
817
	306 => "306 (Unused)",
818
	307 => "307 Temporary Redirect",
819
	400 => "400 Bad Request",
820
	401 => "401 Unauthorized",
821
	402 => "402 Payment Required",
822
	403 => "403 Forbidden",
823
	404 => "404 Not Found",
824
	405 => "405 Method Not Allowed",
825
	406 => "406 Not Acceptable",
826
	407 => "407 Proxy Authentication Required",
827
	408 => "408 Request Timeout",
828
	409 => "409 Conflict",
829
	410 => "410 Gone",
830
	411 => "411 Length Required",
831
	412 => "412 Precondition Failed",
832
	413 => "413 Request Entity Too Large",
833
	414 => "414 Request-URI Too Long",
834
	415 => "415 Unsupported Media Type",
835
	416 => "416 Requested Range Not Satisfiable",
836
	417 => "417 Expectation Failed",
837
	500 => "500 Internal Server Error",
838
	501 => "501 Not Implemented",
839
	502 => "502 Bad Gateway",
840
	503 => "503 Service Unavailable",
841
	504 => "504 Gateway Timeout",
842
	505 => "505 HTTP Version Not Supported"
843
);
844

    
845
function is_rfc2616_code($code) {
846
	global $rfc2616;
847
	if (isset($rfc2616[$code]))
848
		return true;
849
	else
850
		return false;
851
}
852

    
853
function print_rfc2616_select($tag, $current){
854
	global $rfc2616;
855

    
856
	/* Default to 200 OK if not set */
857
	if ($current == "")
858
		$current = 200;
859

    
860
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
861
	foreach($rfc2616 as $code => $message) {
862
		if ($code == $current) {
863
			$sel = " selected";
864
		} else {
865
			$sel = "";
866
		}
867
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
868
	}
869
}
870

    
871
// Useful debugging function, much cleaner than print_r
872
function echo_array($array,$return_me=false){
873
    if(is_array($array) == false){
874
        $return = "The provided variable is not an array.";
875
    }else{
876
        foreach($array as $name=>$value){
877
            if(is_array($value)){
878
                $return .= "";
879
                $return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
880
                $return .= echo_array($value,true);
881
                $return .= "</div>}";
882
                $return .= "\n\n";
883
            }else{
884
                if(is_string($value)){
885
                    $value = "\"$value\"";
886
                }
887
                $return .= "['<b>$name</b>'] = $value\n\n";
888
            }
889
        }
890
    }
891
    if($return_me == true){
892
        return $return;
893
    }else{
894
        echo "<pre>".$return."</pre>";
895
    }
896
}
897

    
898
/****f* pfsense-utils/display_top_tabs
899
 * NAME
900
 *   display_top_tabs - display tabs with rounded edges
901
 * INPUTS
902
 *   $text      - array of tabs
903
 * RESULT
904
 *   null
905
 ******/
906
function display_top_tabs(& $tab_array, $no_drop_down = false) {
907
        global $HTTP_SERVER_VARS;
908
        global $config;
909
        global $g;
910
		global $tab_array_indent;
911
		global $tab_array_space;
912
		global $tab_array_char_limit;
913
		
914
        /*  does the user have access to this tab?
915
         *  master user has access to everything.
916
         *  if the user does not have access, simply
917
         *  unset the tab item.
918
         */
919
		 
920
		/* empty string code */ 
921
		if ($tab_array_indent == '') {
922
			$tab_array_indent = 0;
923
		}
924

    
925
		if ($tab_array_space == '') {
926
			$tab_array_space = 1;
927
		}
928

    
929
		if ($tab_array_char_limit == '') {
930
			$tab_array_char_limit = 92;
931
		}
932

    
933
        $tab_temp = array ();
934
        foreach ($tab_array as $ta)
935
                if(isAllowedPage($ta[2]))
936
                        $tab_temp[] = $ta;
937
        /*
938
                // FIXME :      if the checks are not good enough
939
                //                      in isAllowedPage, it needs to be
940
                //                      fixed instead of kludging here
941

    
942
                // TODO: humm what shall we do with pkg_edit.php and pkg.php?
943
                if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) {
944
                        $pos_equal = strpos($link, "=");
945
                        $pos_xmlsuffix = strpos($link, ".xml");
946
                        // do we match an absolute url including ?xml= foo
947
                        if(!isAllowedPage($link, $allowed))
948
                                $link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3));
949
                }
950
                // next check - what if the basename contains a query string?
951
                if ((strpos($link, "?")) !== false) {
952
                        $pos_qmark = strpos($link, "?");
953
                        $link = substr($link, 0, $pos_qmark);
954
                }
955
                $authorized_text = print_r($allowed, true);
956
                if(is_array($authorized))
957
                        if (in_array(basename($link), $authorized))
958
        */
959

    
960
        unset ($tab_array);
961
        $tab_array = & $tab_temp;
962

    
963
        $tab_active_bg   = "#EEEEEE";
964
        $tab_inactive_bg = "#777777";
965
        $nifty_tabs_corners = "#FFF";
966
        $font_color = "white";
967

    
968
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
969
        $themename = $config['theme'];
970
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
971
        if(file_exists($filename)) {
972
                $eval_code = file_get_contents($filename);
973
                eval($eval_code);
974
        }
975

    
976
        $tabcharcount = 0;
977
        foreach ($tab_array as $ta)
978
                $tabcharcount = $tabcharcount + strlen($ta[0]);
979

    
980
		if($no_drop_down == true) {
981
			$tabcharcount = 0;
982
			unset($tab_array_char_limit);
983
		}
984

    
985
        // If the character count of the tab names is > 670
986
        // then show a select item dropdown menubox.
987
         if($tabcharcount > $tab_array_char_limit) {
988
                echo "Currently viewing: ";
989
                echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
990
                foreach ($tab_array as $ta) {
991
                        if($ta[1]=="true")
992
                                $selected = " SELECTED";
993
                        else
994
                                $selected = "";
995
                        // Onclick in option will not work in some browser
996
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
997
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
998
                }
999
                echo "</select>\n<p/>";
1000
                echo "<script type=\"text/javascript\">";
1001
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
1002
                echo "</script>";
1003
        }  else {
1004
                echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
1005
                echo "<!-- Tabbed bar code-->\n";
1006
				echo "<ul class=\"newtabmenu\">\n";
1007
                $tabscounter = 0;
1008
                foreach ($tab_array as $ta) {
1009
                        if ($ta[1] == true) {
1010
								echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1011
                        } else {
1012
								echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1013
                        }
1014
                        $tabscounter++;
1015
                }
1016
                echo "</ul>\n</div>\n";
1017
        }
1018
}
1019

    
1020
function add_package_tabs($tabgroup, & $tab_array) {
1021
        global $config, $g;
1022

    
1023
        if(!is_array($config['installedpackages']))
1024
                return;
1025
        if(!is_array($config['installedpackages']['tab']))
1026
                return;
1027

    
1028
        foreach($config['installedpackages']['tab'] as $tab) {
1029
                if ($tab['group'] !== $group)
1030
                        continue;
1031
                $tab_entry = array();
1032
                if($tab['name']) {
1033
                        $tab_entry[] = $tab['name'];
1034
                        $tab_entry[] = false;
1035
                        $tab_entry[] = $tab['url'];
1036
                        $tab_array[] = $tab_entry;
1037
                }
1038
        }
1039
}
1040

    
1041
function rule_popup($src,$srcport,$dst,$dstport){
1042
	global $config;
1043
	$aliases_array = array();
1044
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1045
	{
1046
		$span_begin = "";
1047
                $alias_src_span_begin = "";
1048
                $alias_src_span_end = "";
1049
                $alias_src_port_span_begin = "";
1050
                $alias_src_port_span_end = "";
1051
                $alias_dst_span_begin = "";
1052
                $alias_dst_span_end = "";
1053
                $alias_dst_port_span_begin = "";
1054
                $alias_dst_port_span_end = "";
1055
                $alias_content_text = "";
1056
        	foreach($config['aliases']['alias'] as $alias_name)
1057
        	{
1058
                	$alias_addresses = explode (" ", $alias_name['address']);
1059
                	$alias_details = explode ("||", $alias_name['detail']);
1060
                	$alias_objects_with_details = "";
1061
                	$counter = 0;
1062
			if ($alias_name['url']) {
1063
				$alias_objects_with_details .= $alias_name['url'] . "<br/>";
1064
			}
1065
                	foreach($alias_addresses as $alias_ports_address)
1066
                	{
1067
                        	$alias_objects_with_details .= $alias_addresses[$counter];
1068
                        	$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
1069
                        	if ($alias_details[$counter] != "" && $alias_detail_default === False){
1070
                                	$alias_objects_with_details .=" - " . $alias_details[$counter];
1071
                        	}
1072
                        	$alias_objects_with_details .= "<br>";
1073
                        	$counter++;
1074
                	}
1075
                	//max character length for caption field
1076
                	$maxlength = 60;
1077

    
1078
                	$alias_descr_substr = $alias_name['descr'];
1079
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
1080
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
1081
                	$strlength = strlen ($alias_caption);
1082
                	if ($strlength >= $maxlength)
1083
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
1084

    
1085
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
1086
			$alias_content_escaped = str_replace("'", "\'", $alias_content_text);
1087
			$span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>$alias_caption_escaped</h1><p>$alias_content_escaped</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><U>";
1088

    
1089
                	if ($alias_name['name'] == $src)
1090
                        	$alias_src_span_begin = $span_begin;
1091
                	if ($alias_name['name'] == $srcport)
1092
                        	$alias_src_port_span_begin = $span_begin;
1093
                	if ($alias_name['name'] == $dst)
1094
                        	$alias_dst_span_begin = $span_begin;
1095
                	if ($alias_name['name'] == $dstport)
1096
                        	$alias_dst_port_span_begin = $span_begin;
1097
        	}
1098
        	$descriptions = array ();
1099
        	$descriptions['src'] = $alias_src_span_begin;
1100
        	$descriptions['srcport'] = $alias_src_port_span_begin;
1101
        	$descriptions['dst'] = $alias_dst_span_begin;
1102
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
1103

    
1104
        	return $descriptions;
1105
  	}
1106
}
1107

    
1108
$timezone = $syscfg['timezone'];
1109
if (!$timezone)
1110
	$timezone = "Etc/UTC";
1111

    
1112
date_default_timezone_set($timezone);
1113

    
1114
?>
(84-84/245)