Project

General

Profile

Download (32.1 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 (substr($file, -4) == ".inc") {
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">
252
	<p>
253
	<table border="0" cellspacing="0" cellpadding="4" width="100%" summary="input errors">
254
	<tr>
255
		<td class="inputerrorsleft">
256
			<img src="/themes/{$g['theme']}/images/icons/icon_error.gif" alt="errors" />
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
			</p></span>
270
		</td></tr>
271
	</table>
272
	</div>
273
	</p>&nbsp;<br />
274
EOF2;
275

    
276
}
277

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

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

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

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

    
297
	if(stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
298
		$savebutton = "<td class=\"infoboxsave\">";
299
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
300
		if($_POST['if'])
301
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
302
		$savebutton.="</td>";
303
	}
304
	$nifty_redbox = "#990000";
305
	$nifty_blackbox = "#000000";
306

    
307
	$themename = $g['theme'];
308

    
309
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
310
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
311
		eval($toeval);
312
	}
313

    
314
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
315
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
316
		eval($toeval);
317
	}
318

    
319
	if(!$savebutton) {
320
		$savebutton = "<td class=\"infoboxsave\"><input value=\"Close\" type=\"button\" onclick=\"jQuery('#redboxtable').hide();\" /></td>";
321
	}
322

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

    
355
}
356

    
357
function print_info_box_np_undo($msg, $name="apply",$value="Apply changes", $undo) {
358
	global $g;
359

    
360
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
361
		$savebutton = "<td class=\"infoboxsave nowrap\">";
362
		$savebutton .= "<input type=\"button\" value=\"Undo\" onclick=\"document.location='{$undo}'\" />";
363
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
364
		$savebutton .= "</td>";
365
		if($_POST['if'])
366
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
367
	}
368
	$nifty_redbox = "#990000";
369
	$nifty_blackbox = "#000000";
370

    
371
	$themename = $g['theme'];
372

    
373
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
374
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
375
		eval($toeval);
376
	}
377

    
378
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
379
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
380
		eval($toeval);
381
	}
382

    
383

    
384
	if(!$savebutton) {
385
		$savebutton = "<td class=\"infoboxsave\"><input value=\"Close\" type=\"button\" onclick=\"jQuery('#redboxtable').hide();\" /></td>";
386
	}
387

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

    
421
}
422

    
423
function print_info_box($msg) {
424
	print_info_box_np($msg);
425
}
426

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

    
440
function pprint_address($adr) {
441
	global $specialnets;
442

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

    
451
	if (isset($adr['not']))
452
		$padr = "! " . $padr;
453

    
454
	return $padr;
455
}
456

    
457
function pprint_port($port) {
458
	global $wkports;
459

    
460
	$pport = "";
461

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

    
475
	return $pport;
476
}
477

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

    
517
	return $item_set;
518
}
519

    
520
function gentitle($title) {
521
	global $navlevelsep;
522
	if(!is_array($title))
523
		return $title;
524
	else
525
		return join($navlevelsep, $title);
526
}
527

    
528
function genhtmltitle($title) {
529
	global $config;
530
	return gentitle($title);
531
}
532

    
533
/* update the changedesc and changecount(er) variables */
534
function update_changedesc($update) {
535
	global $changedesc;
536
	global $changecount;
537

    
538
	$changedesc .= " {$update}";
539
	$changecount++;
540
}
541

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

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

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

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

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

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

    
654
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
655
	if (isset($adr['any']))
656
		$padr = "any";
657
	else if ($adr['network'])
658
		$padr = $adr['network'];
659
	else if ($adr['address']) {
660
		list($padr, $pmask) = explode("/", $adr['address']);
661
		if (!$pmask) {
662
			if (is_ipaddrv6($padr))
663
				$pmask = 128;
664
			else
665
				$pmask = 32;
666
		}
667
	}
668

    
669
	if (isset($adr['not']))
670
		$pnot = 1;
671
	else
672
		$pnot = 0;
673

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

    
684
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
685
	$adr = array();
686

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

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

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

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

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

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

    
730
//function to create widget tabs when called
731
function display_widget_tabs(& $tab_array) {
732
	echo "<div id=\"tabs\">";
733
	$tabscounter = 0;
734
	foreach ($tab_array as $ta) {
735
	$dashpos = strpos($ta[2],'-');
736
	$tabname = $ta[2] . "-tab";
737
	$tabclass = substr($ta[2],0,$dashpos);
738
	$tabclass = $tabclass . "-class";
739
		if ($ta[1] == true) {
740
			$tabActive = "table-cell";
741
			$tabNonActive = "none";
742
		}
743
		else {
744
			$tabActive = "none";
745
			$tabNonActive = "table-cell";
746
		}
747
		echo "<div id=\"{$ta[2]}-active\" class=\"{$tabclass}-tabactive\" style=\"display:{$tabActive}; background-color:#EEEEEE; color:black;\">";
748
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
749
		echo "&nbsp;&nbsp;&nbsp;</b>";
750
		echo "</div>";
751

    
752
		echo "<div id=\"{$ta[2]}-deactive\" class=\"{$tabclass}-tabdeactive\" style=\"display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;\" onclick=\"return changeTabDIV('{$ta[2]}')\">";
753
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
754
		echo "&nbsp;&nbsp;&nbsp;</b>";
755
		echo "</div>";
756
	}
757

    
758
	echo "<script type=\"text/javascript\">";
759
	echo "\n//<![CDATA[\n";
760
	echo "NiftyCheck();\n";
761
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
762
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
763
	echo "//]]>\n";
764
	echo "</script>";
765
	echo "</div>";
766
}
767

    
768

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

    
781

    
782

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

    
793

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

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

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

    
856
function print_rfc2616_select($tag, $current){
857
	global $rfc2616;
858

    
859
	/* Default to 200 OK if not set */
860
	if ($current == "")
861
		$current = 200;
862

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

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

    
901
/****f* pfsense-utils/display_top_tabs
902
 * NAME
903
 *   display_top_tabs - display tabs with rounded edges
904
 * INPUTS
905
 *   $text      - array of tabs
906
 * RESULT
907
 *   null
908
 ******/
909
function display_top_tabs(& $tab_array, $no_drop_down = false) {
910
	global $HTTP_SERVER_VARS;
911
	global $config;
912
	global $g;
913
	global $tab_array_indent;
914
	global $tab_array_space;
915
	global $tab_array_char_limit;
916

    
917
	/*  does the user have access to this tab?
918
	 *  master user has access to everything.
919
	 *  if the user does not have access, simply
920
	 *  unset the tab item.
921
	 */
922

    
923
	/* empty string code */
924
	if ($tab_array_indent == '') {
925
		$tab_array_indent = 0;
926
	}
927

    
928
	if ($tab_array_space == '') {
929
		$tab_array_space = 1;
930
	}
931

    
932
	if ($tab_array_char_limit == '') {
933
		$tab_array_char_limit = 92;
934
	}
935

    
936
	foreach ($tab_array as $tab_id => $ta){
937
		if(!isAllowedPage($ta[2]))
938
			unset ($tab_array[$tab_id]);
939
	}
940

    
941
	$tab_active_bg   = "#EEEEEE";
942
	$tab_inactive_bg = "#777777";
943
	$nifty_tabs_corners = "#FFF";
944
	$font_color = "white";
945

    
946
	/* if tabcontrols.php exist for a theme, allow it to be overriden */
947
	$themename = $config['theme'];
948
	$filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
949
	if(file_exists($filename)) {
950
		$eval_code = file_get_contents($filename);
951
		eval($eval_code);
952
	}
953

    
954
	$tabcharcount = 0;
955
	foreach ($tab_array as $ta)
956
		$tabcharcount = $tabcharcount + strlen($ta[0]);
957

    
958
	if($no_drop_down == true) {
959
		$tabcharcount = 0;
960
		unset($tab_array_char_limit);
961
	}
962

    
963
	// If the character count of the tab names is > 670
964
	// then show a select item dropdown menubox.
965
	if($tabcharcount > $tab_array_char_limit) {
966
		echo "Currently viewing: ";
967
		echo "<select name=\"TabSelect\" onchange=\"tabs_will_go(this)\">\n";
968
		foreach ($tab_array as $ta) {
969
			if($ta[1]=="true")
970
				$selected = " selected=\"selected\"";
971
			else
972
				$selected = "";
973
			// Onclick in option will not work in some browser
974
			// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
975
			echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
976
		}
977
		echo "</select>\n<p>&nbsp;</p>";
978
		echo "<script type=\"text/javascript\">";
979
		echo "\n//<![CDATA[\n";
980
		echo " function tabs_will_go(obj){ document.location = obj.value; }\n";
981
		echo "//]]>\n";
982
		echo "</script>";
983
	}  else {
984
		echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
985
		echo "<!-- Tabbed bar code-->\n";
986
		echo "<ul class=\"newtabmenu\">\n";
987
		$tabscounter = 0;
988
		foreach ($tab_array as $ta) {
989
			if ($ta[1] == true) {
990
				echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
991
			} else {
992
				echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
993
			}
994
			$tabscounter++;
995
		}
996
		echo "</ul>\n</div>\n";
997
	}
998
}
999

    
1000
function add_package_tabs($tabgroup, & $tab_array) {
1001
	global $config, $g;
1002

    
1003
	if(!is_array($config['installedpackages']))
1004
		return;
1005
	if(!is_array($config['installedpackages']['tab']))
1006
		return;
1007

    
1008
	foreach($config['installedpackages']['tab'] as $tab) {
1009
		if ($tab['group'] !== $group)
1010
			continue;
1011
		$tab_entry = array();
1012
		if($tab['name']) {
1013
			$tab_entry[] = $tab['name'];
1014
			$tab_entry[] = false;
1015
			$tab_entry[] = $tab['url'];
1016
			$tab_array[] = $tab_entry;
1017
		}
1018
	}
1019
}
1020

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

    
1086
function rule_popup($src,$srcport,$dst,$dstport){
1087
	global $config,$g;
1088
	$aliases_array = array();
1089
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
1090
		$descriptions = array ();
1091
		foreach ($config['aliases']['alias'] as $alias_id=>$alias_name){
1092
			$loading_image="<a><img src=\'/themes/{$g['theme']}/images/misc/loader.gif\' alt=\'loader\' /> " .gettext("loading...")."</a>";
1093
			switch ($alias_name['type']){
1094
			case "port":
1095
				$width="250";
1096
				break;
1097
			case "urltable":
1098
				$width="500";
1099
				break;
1100
			default:
1101
				$width="350";
1102
				break;
1103
			}
1104
			$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>";
1105
			$span_end = "</u></span>";
1106
			if ($alias_name['name'] == $src) {
1107
				$descriptions['src'] = $span_begin;
1108
				$descriptions['src_end'] = $span_end;
1109
			}
1110
			if ($alias_name['name'] == $srcport) {
1111
				$descriptions['srcport'] = $span_begin;
1112
				$descriptions['srcport_end'] = $span_end;
1113
			}
1114
			if ($alias_name['name'] == $dst ) {
1115
				$descriptions['dst'] = $span_begin;
1116
				$descriptions['dst_end'] = $span_end;
1117
			}
1118
			if ($alias_name['name'] == $dstport) {
1119
				$descriptions['dstport'] = $span_begin;
1120
				$descriptions['dstport_end'] = $span_end;
1121
			}
1122
		}
1123
		return $descriptions;
1124
	}
1125
}
1126

    
1127
$timezone = $config['system']['timezone'];
1128
if (!$timezone)
1129
	$timezone = "Etc/UTC";
1130

    
1131
date_default_timezone_set($timezone);
1132

    
1133
?>
(86-86/246)