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
		$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ?  $config['system']['webgui']['session_timeout'] : 240;
41
		csrf_conf('expires', $timeout_minutes * 60);
42
	}
43
	require_once("csrf/csrf-magic.php");
44
}
45

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

    
55
Header("X-Frame-Options: SAMEORIGIN");
56
require_once("authgui.inc");
57

    
58
/* parse the configuration and include all configuration functions */
59
require_once("functions.inc");
60

    
61
/* Pull in all the gui related display classes) */
62
foreach (scandir("/usr/local/www/classes/") as $file) {
63
	if (stristr($file, ".inc") !== false) {
64
		require_once("classes/{$file}");
65
	}
66
}
67

    
68
$g['theme'] = get_current_theme();
69

    
70
/* Set the default interface language */
71
if($config['system']['language'] <> "") {
72
	$g['language'] = $config['system']['language'];
73
} elseif ($g['language'] == "") {
74
	$g['language'] = 'en_US';
75
}
76

    
77
set_language($g['language']);
78

    
79
/* used by progress bar */
80
$lastseen = "-1";
81

    
82
$navlevelsep = ": ";	/* navigation level separator string */
83
$mandfldhtml = "";		/* display this before mandatory input fields */
84
$mandfldhtmlspc = "";	/* same as above, but with spacing */
85

    
86
/* Some ajax scripts still need access to GUI */
87
if(!$ignorefirmwarelock) {
88
	if (is_subsystem_dirty('firmwarelock')) {
89
		if (!$d_isfwfile) {
90
			header("Location: system_firmware.php");
91
			exit;
92
		} else {
93
			return;
94
		}
95
	}
96
}
97

    
98
$firewall_rules_dscp_types = array("af11", 
99
				"af12", 
100
				"af13", 
101
				"af21", 
102
				"af22", 
103
				"af23", 
104
				"af31", 
105
				"af32", 
106
				"af33", 
107
				"af41", 
108
				"af42", 
109
				"af43", 
110
				"EF", 
111
				"1-64", 
112
				"0x10",
113
				"0x04-0xfc");
114

    
115
$auth_server_types = array(
116
	'ldap' => "LDAP",
117
	'radius' => "Radius");
118

    
119
$ldap_urltypes = array(
120
	'TCP - Standard' => 389,
121
	'SSL - Encrypted' => 636);
122

    
123
$ldap_scopes = array(
124
	'one' => "One Level",
125
	'subtree' => "Entire Subtree");
126

    
127
$ldap_protvers = array(
128
	2,
129
	3);
130

    
131
$ldap_templates = array(
132

    
133
	'open' => array(
134
				'desc' => "OpenLDAP",
135
				'attr_user' => "cn",
136
				'attr_group' => "cn",
137
				'attr_member' => "member"),
138

    
139
	'msad' => array(
140
				'desc' => "Microsoft AD",
141
				'attr_user' => "samAccountName",
142
				'attr_group' => "cn",
143
				'attr_member' => "memberOf"),
144

    
145
	'edir' => array(
146
				'desc' => "Novell eDirectory",
147
				'attr_user' => "cn",
148
				'attr_group' => "cn",
149
				'attr_member' => "uniqueMember"));
150

    
151
$radius_srvcs = array(
152
	'both' => "Authentication and Accounting",
153
	'auth' => "Authentication",
154
	'acct' => "Accounting");
155

    
156
$netbios_nodetypes = array(
157
	'0' => "none",
158
	'1' => "b-node",
159
	'2' => "p-node",
160
	'4' => "m-node",
161
	'5' => "h-node");
162

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

    
210
/* TCP flags */
211
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
212

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

    
215
$spiflist = get_configured_interface_with_descr(false, true);
216
foreach ($spiflist as $ifgui => $ifdesc) {
217
	$specialnets[$ifgui] = $ifdesc . " net";
218
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
219
}
220

    
221
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
222
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
223
	"10half" => "10BASE-T half-duplex");
224

    
225
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
226
	"hostap" => "Access Point");
227

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

    
231
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
232

    
233
	/* check for bad control characters */
234
	foreach ($postdata as $pn => $pd) {
235
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
236
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
237
		}
238
	}
239

    
240
	for ($i = 0; $i < count($reqdfields); $i++) {
241
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
242
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
243
		}
244
	}
245
}
246

    
247
function print_input_errors($input_errors) {
248
	global $g;
249

    
250
	print <<<EOF
251
	<div id='inputerrorsdiv' name='inputerrorsdiv'>
252
	<p>
253
	<table border="0" cellspacing="0" cellpadding="4" width="100%">
254
	<tr>
255
		<td class="inputerrorsleft">
256
			<img src="/themes/{$g['theme']}/images/icons/icon_error.gif">
257
		</td>
258
		<td class="inputerrorsright">
259
			<span class="errmsg"><p>
260
				The following input errors were detected:
261
				<ul>
262
EOF;
263
		foreach ($input_errors as $ierr) {
264
			echo "<li>" . htmlspecialchars($ierr) . "</li>";
265
		}
266

    
267
	print <<<EOF2
268
				</ul>
269
			</span>
270
		</td></tr>
271
	</table>
272
	</div>
273
	</p>&nbsp;<br>
274
EOF2;
275
	
276
}
277

    
278
function verify_gzip_file($fname) {
279

    
280
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
281
	if ($returnvar != 0)
282
		return 0;
283
	else
284
		return 1;
285
}
286

    
287
function print_info_box_np($msg, $name="apply",$value="", $showapply=false) {
288
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
289

    
290
	if(empty($value)) {
291
		$value = gettext("Apply changes");
292
	}
293

    
294
	// Set the Nifty background color if one is not set already (defaults to white)
295
	if($nifty_background == "")
296
		$nifty_background = "#FFF";
297

    
298
	if(stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
299
		$savebutton = "<td class='infoboxsave'>";
300
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
301
		if($_POST['if'])
302
			$savebutton .= "<input type='hidden' name='if' value='" . htmlspecialchars($_POST['if']) . "'>";
303
		$savebutton.="</td>";
304
	}
305
	$nifty_redbox = "#990000";
306
	$nifty_blackbox = "#000000";
307
	
308
	$themename = $g['theme'];
309
	
310
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
311
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
312
		eval($toeval);
313
	}
314
	
315
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
316
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
317
		eval($toeval);
318
	}	
319
		
320
	if(!$savebutton) {
321
		$savebutton = '<td class="infoboxsave"><input value="Close" type="button" onClick="jQuery(\'#redboxtable\').hide();"></td>';
322
	}
323

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

    
354
}
355

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

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

    
418
}
419

    
420
function print_info_box($msg) {
421
	print_info_box_np($msg);
422
}
423

    
424
function get_std_save_message($ok) {
425
	global $d_sysrebootreqd_path;
426
	$filter_related = false;
427
	$filter_pages = array("nat", "filter");
428
	$to_return = "The changes have been applied successfully.";
429
	foreach($filter_pages as $fp) 
430
		if(stristr($_SERVER['SCRIPT_FILENAME'], $fp))
431
			$filter_related = true;	
432
	if($filter_related)
433
		$to_return .= "<br/>You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
434
	return $to_return;
435
}
436

    
437
function pprint_address($adr) {
438
	global $specialnets;
439

    
440
	if (isset($adr['any'])) {
441
		$padr = "*";
442
	} else if ($adr['network']) {
443
		$padr = $specialnets[$adr['network']];
444
	} else {
445
		$padr = $adr['address'];
446
	}
447

    
448
	if (isset($adr['not']))
449
		$padr = "! " . $padr;
450

    
451
	return $padr;
452
}
453

    
454
function pprint_port($port) {
455
	global $wkports;
456

    
457
	$pport = "";
458

    
459
	if (!$port)
460
		return "*";
461
	else {
462
		$srcport = explode("-", $port);
463
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
464
			$pport = $srcport[0];
465
			if ($wkports[$srcport[0]]) {
466
				$pport .= " (" . $wkports[$srcport[0]] . ")";
467
			}
468
		} else
469
			$pport .= $srcport[0] . " - " . $srcport[1];
470
	}
471

    
472
	return $pport;
473
}
474

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

    
514
        return $item_set;
515
}
516

    
517
function gentitle($title) {
518
	global $navlevelsep;
519
	if(!is_array($title))
520
		return $title;
521
	else
522
		return join($navlevelsep, $title);
523
}
524

    
525
function genhtmltitle($title) {
526
        global $config;
527
        return gentitle($title);
528
}
529

    
530
/* update the changedesc and changecount(er) variables */
531
function update_changedesc($update) {
532
	global $changedesc;
533
	global $changecount;
534

    
535
	$changedesc .= " {$update}";
536
	$changecount++;
537
}
538

    
539
function clear_log_file($logfile = "/var/log/system.log") {
540
	global $config, $g;
541
	exec("/usr/bin/killall syslogd");
542
	if(isset($config['system']['disablesyslogclog'])) {
543
		unlink($logfile);
544
		touch($logfile);
545
	} else {
546
		if(isset($config['system']['usefifolog'])) 
547
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
548
		else
549
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
550
	}
551
	system_syslogd_start();	
552
}
553

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

    
592
			} else {
593
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
594
			}
595
			echo "</tr>\n";
596
	}
597
}
598

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

    
622
/* Check if variable has changed, update and log if it has
623
 * returns true if var changed
624
 * varname = variable name in plain text
625
 * orig = original value
626
 * new = new value
627
 */
628
function update_if_changed($varname, & $orig, $new) {
629
	if (is_array($orig) && is_array($new)) {
630
		$a_diff = array_diff($orig, $new);
631
		foreach ($a_diff as $diff) {
632
			update_changedesc("removed {$varname}: \"{$diff}\"");
633
		}
634
		$a_diff = array_diff($new, $orig);
635
		foreach ($a_diff as $diff) {
636
			update_changedesc("added {$varname}: \"{$diff}\"");
637
		}
638
		$orig = $new;
639
		return true;
640

    
641
	} else {
642
		if ($orig != $new) {
643
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
644
			$orig = $new;
645
			return true;
646
		}
647
	}
648
	return false;
649
}
650

    
651
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
652

    
653
        if (isset($adr['any']))
654
                $padr = "any";
655
        else if ($adr['network'])
656
                $padr = $adr['network'];
657
        else if ($adr['address']) {
658
                list($padr, $pmask) = explode("/", $adr['address']);
659
                if (!$pmask)
660
                        $pmask = 32;
661
        }
662

    
663
        if (isset($adr['not']))
664
                $pnot = 1;
665
        else
666
                $pnot = 0;
667

    
668
        if ($adr['port']) {
669
                list($pbeginport, $pendport) = explode("-", $adr['port']);
670
                if (!$pendport)
671
                        $pendport = $pbeginport;
672
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
673
		$pbeginport = "any";
674
		$pendport = "any";
675
        }
676
}
677

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

    
680
        $adr = array();
681

    
682
        if ($padr == "any")
683
                $adr['any'] = true;
684
        else if (is_specialnet($padr))
685
                $adr['network'] = $padr;
686
        else {
687
                $adr['address'] = $padr;
688
                if ($pmask != 32)
689
                        $adr['address'] .= "/" . $pmask;
690
        }
691

    
692
        if ($pnot)
693
                $adr['not'] = true;
694
        else
695
                unset($adr['not']);
696

    
697
        if (($pbeginport != 0) && ($pbeginport != "any")) {
698
                if ($pbeginport != $pendport)
699
                        $adr['port'] = $pbeginport . "-" . $pendport;
700
                else
701
                        $adr['port'] = $pbeginport;
702
        }
703

    
704
        if(is_alias($pbeginport)) {
705
                $adr['port'] = $pbeginport;
706
        }
707
}
708

    
709
function is_specialnet($net) {
710
        global $specialsrcdst;
711

    
712
	if(!$net) 
713
		return false;
714
        if (in_array($net, $specialsrcdst))
715
                return true;
716
        else
717
                return false;
718
}
719

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

    
756

    
757
// Return inline javascript file or CSS to minimizie 
758
// request count going back to server.
759
function outputJavaScriptFileInline($javascript) {
760
	if(file_exists($javascript)) {
761
		echo "\n<script type=\"text/javascript\">\n";
762
		include($javascript);
763
		echo "\n</script>\n";
764
	} else {
765
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
766
	}
767
}
768

    
769

    
770

    
771
function outputCSSPrintFileInline($css) {
772
	if(file_exists($css)) {
773
		echo "\n<style media=\"print\" type=\"text/css\">\n";
774
		include($css);
775
		echo "\n</style>\n";
776
	} else {
777
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
778
	}
779
}
780

    
781

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

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

    
836
function is_rfc2616_code($code) {
837
	global $rfc2616;
838
	if (isset($rfc2616[$code]))
839
		return true;
840
	else
841
		return false;
842
}
843

    
844
function print_rfc2616_select($tag, $current){
845
	global $rfc2616;
846

    
847
	/* Default to 200 OK if not set */
848
	if ($current == "")
849
		$current = 200;
850

    
851
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
852
	foreach($rfc2616 as $code => $message) {
853
		if ($code == $current) {
854
			$sel = " selected";
855
		} else {
856
			$sel = "";
857
		}
858
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
859
	}
860
}
861

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

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

    
916
		if ($tab_array_space == '') {
917
			$tab_array_space = 1;
918
		}
919

    
920
		if ($tab_array_char_limit == '') {
921
			$tab_array_char_limit = 92;
922
		}
923

    
924
		foreach ($tab_array as $tab_id => $ta){
925
			if(!isAllowedPage($ta[2]))
926
				unset ($tab_array[$tab_id]);
927
			}
928

    
929
        $tab_active_bg   = "#EEEEEE";
930
        $tab_inactive_bg = "#777777";
931
        $nifty_tabs_corners = "#FFF";
932
        $font_color = "white";
933

    
934
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
935
        $themename = $config['theme'];
936
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
937
        if(file_exists($filename)) {
938
                $eval_code = file_get_contents($filename);
939
                eval($eval_code);
940
        }
941

    
942
        $tabcharcount = 0;
943
        foreach ($tab_array as $ta)
944
                $tabcharcount = $tabcharcount + strlen($ta[0]);
945

    
946
		if($no_drop_down == true) {
947
			$tabcharcount = 0;
948
			unset($tab_array_char_limit);
949
		}
950

    
951
        // If the character count of the tab names is > 670
952
        // then show a select item dropdown menubox.
953
         if($tabcharcount > $tab_array_char_limit) {
954
                echo "Currently viewing: ";
955
                echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
956
                foreach ($tab_array as $ta) {
957
                        if($ta[1]=="true")
958
                                $selected = " SELECTED";
959
                        else
960
                                $selected = "";
961
                        // Onclick in option will not work in some browser
962
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
963
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
964
                }
965
                echo "</select>\n<p/>";
966
                echo "<script type=\"text/javascript\">";
967
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
968
                echo "</script>";
969
        }  else {
970
                echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
971
                echo "<!-- Tabbed bar code-->\n";
972
				echo "<ul class=\"newtabmenu\">\n";
973
                $tabscounter = 0;
974
                foreach ($tab_array as $ta) {
975
                        if ($ta[1] == true) {
976
								echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
977
                        } else {
978
								echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
979
                        }
980
                        $tabscounter++;
981
                }
982
                echo "</ul>\n</div>\n";
983
        }
984
}
985

    
986
function add_package_tabs($tabgroup, & $tab_array) {
987
        global $config, $g;
988

    
989
        if(!is_array($config['installedpackages']))
990
                return;
991
        if(!is_array($config['installedpackages']['tab']))
992
                return;
993

    
994
        foreach($config['installedpackages']['tab'] as $tab) {
995
                if ($tab['group'] !== $group)
996
                        continue;
997
                $tab_entry = array();
998
                if($tab['name']) {
999
                        $tab_entry[] = $tab['name'];
1000
                        $tab_entry[] = false;
1001
                        $tab_entry[] = $tab['url'];
1002
                        $tab_array[] = $tab_entry;
1003
                }
1004
        }
1005
}
1006

    
1007
function alias_info_popup($alias_id){
1008
	global $config;
1009
	$maxlength = 60;
1010
	$close_title="title='".gettext('move mouse out this alias to hide')."'";
1011
	if (is_array($config['aliases']['alias'][$alias_id])){
1012
		$alias_name=$config['aliases']['alias'][$alias_id];
1013
		$alias_objects_with_details = "<table width='100%' border='0' cellpadding='2' cellspacing='0'>";
1014
		if ($alias_name['url']) {
1015
			exec("/sbin/pfctl -t {$alias_name['name']} -T show | wc -l", $total_entries);
1016
			$counter=preg_replace("/\D/","",$total_entries[0]);
1017
			exec("/sbin/pfctl -t {$alias_name['name']} -T show | head -10002", $alias_addresses);
1018
			$alias_objects_with_details .= "<tr><td colspan='3' $close_title class='vncell'>{$alias_name['url']}</td></tr>";
1019
			$x=0;
1020
			foreach ($alias_addresses as $alias_ports_address ) {
1021
				switch ($x) {
1022
				case 0:
1023
					$x++;
1024
					$alias_objects_with_details .= "<tr><td $close_title class='vncell' width='33%' style='background: #FFFFFF;color: #000000;'>{$alias_ports_address}</td>";
1025
					break;
1026
				case 1:
1027
					$x++;
1028
					$alias_objects_with_details .= "<td $close_title class='vncell' width='33%' style='background: #FFFFFF;color: #000000;'>{$alias_ports_address}</td>";
1029
					break;
1030
				default:
1031
					$x=0;
1032
					$alias_objects_with_details .= "<td  $close_title class='vncell' width='33%' style='background: #FFFFFF;color: #000000;'>{$alias_ports_address}</td><tr>";
1033
					break;
1034
				}
1035
			}
1036
			for ($y = $x; $y <= $x; $y++) {
1037
				$alias_objects_with_details .= "<td $close_title class='vncell' width='33%'>&nbsp;</td>";
1038
			}
1039
			if ($x > 0) {
1040
				$alias_objects_with_details .= "</tr>";
1041
			}
1042
			if ($counter > 10002) {
1043
				$alias_objects_with_details .= "<tr><td colspan='3'> listing only first 10k items</td><tr>";
1044
			}
1045
		}
1046
		else{
1047
			$alias_addresses = explode (" ", $alias_name['address']);
1048
			$alias_details = explode ("||", $alias_name['detail']);
1049
			$counter = 0;
1050
			foreach ($alias_addresses as $alias_ports_address) {
1051
				$alias_objects_with_details .= "<tr><td $close_title width='5%' class='vncell' style='background: #FFFFFF;color: #000000;'>{$alias_addresses[$counter]}</td>";
1052
				$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
1053
				if ($alias_details[$counter] != "" && $alias_detail_default === False)
1054
					$alias_objects_with_details .="<td $close_title width='95%' class='vncell' style='background: #FFFFFF;color: #000000;'>{$alias_details[$counter]}</td>";
1055
				else
1056
					$alias_objects_with_details .="<td $close_title width='95%' class='vncell' style='background: #FFFFFF;color: #000000;'>&nbsp;</td>";
1057
				$alias_objects_with_details .= "</tr>";
1058
				$counter++;
1059
			}
1060
		}
1061
		$alias_objects_with_details .= "</table>";
1062
	}
1063
	$alias_descr_substr = $alias_name['descr'];
1064
	if ($strlength >= $maxlength)
1065
		$alias_descr_substr = substr($alias_descr_substr, 0, $maxlength) . "...";
1066
	$item_text = ($counter > 1 ? "items" : "item");
1067
	$alias_caption = "{$alias_descr_substr} - {$counter} {$item_text}<a href='/firewall_aliases_edit.php?id={$alias_id}' title='".gettext('edit this alias')."'>&nbsp;&nbsp;edit </a>";
1068
	$strlength = strlen ($alias_caption);
1069
	print "<h1>{$alias_caption}</h1>" . $alias_objects_with_details;
1070
}
1071

    
1072
function rule_popup($src,$srcport,$dst,$dstport){
1073
	global $config,$g;
1074
	$aliases_array = array();
1075
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
1076
		$descriptions = array ();
1077
		foreach ($config['aliases']['alias'] as $alias_id=>$alias_name){
1078
			$loading_image="<a><img src=\'/themes/{$g['theme']}/images/misc/loader.gif\'> " .gettext("loading...")."</a>";
1079
			switch ($alias_name['type']){
1080
			case "port":
1081
				$width="250";
1082
				break;
1083
			case "urltable":
1084
				$width="500";
1085
				break;
1086
			default:
1087
				$width="350";
1088
				break;
1089
			}
1090
			$span_begin = "<span style=\"cursor: help;\" onmouseover=\"var response_html=domTT_activate(this, event, 'id','ttalias_{$alias_id}','content','{$loading_image}', 'trail', true, 'delay', 300, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle','type','velcro','width',{$width});alias_popup('{$alias_id}','{$g["theme"]}','".gettext('loading...')."');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><u>";
1091
			$span_end = "</u></span>";
1092
			if ($alias_name['name'] == $src) {
1093
				$descriptions['src'] = $span_begin;
1094
				$descriptions['src_end'] = $span_end;
1095
			}
1096
			if ($alias_name['name'] == $srcport) {
1097
				$descriptions['srcport'] = $span_begin;
1098
				$descriptions['srcport_end'] = $span_end;
1099
			}
1100
			if ($alias_name['name'] == $dst ) {
1101
				$descriptions['dst'] = $span_begin;
1102
				$descriptions['dst_end'] = $span_end;
1103
			}
1104
			if ($alias_name['name'] == $dstport) {
1105
				$descriptions['dstport'] = $span_begin;
1106
				$descriptions['dstport_end'] = $span_end;
1107
			}
1108
		}
1109
		return $descriptions;
1110
  	}
1111
}
1112

    
1113
$timezone = $config['system']['timezone'];
1114
if (!$timezone)
1115
	$timezone = "Etc/UTC";
1116

    
1117
date_default_timezone_set($timezone);
1118

    
1119
?>
(86-86/249)