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 = htmlspecialchars($logent[4] . " " . $logent[5]);
587
					}
588
					echo "<td class=\"listlr\" nowrap>{$entry_date_time}</td>\n";
589
					echo "<td class=\"listr\">{$entry_text}</td>\n";
590

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

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

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

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

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

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

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

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

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

    
679
        $adr = array();
680

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

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

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

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

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

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

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

    
755

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

    
768

    
769

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

    
780

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1071
function rule_popup($src,$srcport,$dst,$dstport){
1072
	global $config,$g;
1073
	$aliases_array = array();
1074
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
1075
		$descriptions = array ();
1076
		foreach ($config['aliases']['alias'] as $alias_id=>$alias_name){
1077
			$loading_image="<a><img src=\'/themes/{$g['theme']}/images/misc/loader.gif\'> " .gettext("loading...")."</a>";
1078
			switch ($alias_name['type']){
1079
			case "port":
1080
				$width="250";
1081
				break;
1082
			case "urltable":
1083
				$width="500";
1084
				break;
1085
			default:
1086
				$width="350";
1087
				break;
1088
			}
1089
			$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>";
1090
			$span_end = "</u></span>";
1091
			if ($alias_name['name'] == $src) {
1092
				$descriptions['src'] = $span_begin;
1093
				$descriptions['src_end'] = $span_end;
1094
			}
1095
			if ($alias_name['name'] == $srcport) {
1096
				$descriptions['srcport'] = $span_begin;
1097
				$descriptions['srcport_end'] = $span_end;
1098
			}
1099
			if ($alias_name['name'] == $dst ) {
1100
				$descriptions['dst'] = $span_begin;
1101
				$descriptions['dst_end'] = $span_end;
1102
			}
1103
			if ($alias_name['name'] == $dstport) {
1104
				$descriptions['dstport'] = $span_begin;
1105
				$descriptions['dstport_end'] = $span_end;
1106
			}
1107
		}
1108
		return $descriptions;
1109
  	}
1110
}
1111

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

    
1116
date_default_timezone_set($timezone);
1117

    
1118
?>
(85-85/249)