Project

General

Profile

Download (33.2 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
require_once("authgui.inc");
38

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

    
48
/* parse the configuration and include all configuration functions */
49
require_once("functions.inc");
50

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

    
66
/*
67
 *  If this device is an apple ipod/iphone
68
 *  switch the theme to one that works with it.
69
 */
70
$apple_ua = array("iPhone","iPod", "iPad");
71
foreach($apple_ua as $useragent)
72
	if(strstr($_SERVER['HTTP_USER_AGENT'], $useragent))
73
		$g['theme'] = "pfsense";
74

    
75
/* used by progress bar */
76
$lastseen = "-1";
77

    
78
$navlevelsep = ": ";	/* navigation level separator string */
79
$mandfldhtml = "";		/* display this before mandatory input fields */
80
$mandfldhtmlspc = "";	/* same as above, but with spacing */
81

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

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

    
111
$auth_server_types = array(
112
	'ldap' => "LDAP",
113
	'radius' => "Radius");
114

    
115
$ldap_urltypes = array(
116
	'TCP - Standard' => 389,
117
	'SSL - Encrypted' => 636);
118

    
119
$ldap_scopes = array(
120
	'one' => "One Level",
121
	'subtree' => "Entire Subtree");
122

    
123
$ldap_protvers = array(
124
	2,
125
	3);
126

    
127
$ldap_templates = array(
128

    
129
	'open' => array(
130
				'desc' => "OpenLDAP",
131
				'attr_user' => "cn",
132
				'attr_group' => "cn",
133
				'attr_member' => "member"),
134

    
135
	'msad' => array(
136
				'desc' => "Microsoft AD",
137
				'attr_user' => "samAccountName",
138
				'attr_group' => "cn",
139
				'attr_member' => "memberOf"),
140

    
141
	'edir' => array(
142
				'desc' => "Novell eDirectory",
143
				'attr_user' => "cn",
144
				'attr_group' => "cn",
145
				'attr_member' => "uniqueMember"));
146

    
147
$radius_srvcs = array(
148
	'both' => "Authentication and Accounting",
149
	'auth' => "Authentication",
150
	'acct' => "Accounting");
151

    
152
$netbios_nodetypes = array(
153
	'0' => "none",
154
	'1' => "b-node",
155
	'2' => "p-node",
156
	'4' => "m-node",
157
	'5' => "h-node");
158

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

    
205
/* TCP flags */
206
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg");
207

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

    
210
$spiflist = get_configured_interface_with_descr(false, true);
211
foreach ($spiflist as $ifgui => $ifdesc) {
212
	$specialnets[$ifgui] = $ifdesc . " net";
213
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
214
}
215

    
216
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
217
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
218
	"10half" => "10BASE-T half-duplex");
219

    
220
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
221
	"hostap" => "Access Point");
222

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

    
226
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
227

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

    
235
	for ($i = 0; $i < count($reqdfields); $i++) {
236
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
237
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
238
		}
239
	}
240
}
241

    
242
function print_input_errors($input_errors) {
243
	global $g;
244

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

    
261
	print <<<EOF2
262
				</ul>
263
			</span>
264
		</td></tr>
265
	</table>
266
	</p>&nbsp;<br>
267
EOF2;
268
	
269
}
270

    
271
function verify_gzip_file($fname) {
272

    
273
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
274
	if ($returnvar != 0)
275
		return 0;
276
	else
277
		return 1;
278
}
279

    
280
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
281
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
282

    
283
	// Set the Nifty background color if one is not set already (defaults to white)
284
	if($nifty_background == "")
285
		$nifty_background = "#FFF";
286

    
287
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
288
		$savebutton = "<td class='infoboxsave'>";
289
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
290
		if($_POST['if']) 
291
			$savebutton .= "<input type='hidden' name='if' value='{$_POST['if']}'>";
292
		$savebutton.="</td>";
293
	}
294
	$nifty_redbox = "#990000";
295
	$nifty_blackbox = "#000000";
296
	
297
	$themename = $g['theme'];
298
	
299
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
300
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
301
		eval($toeval);
302
	}
303
	
304
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
305
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
306
		eval($toeval);
307
	}	
308
		
309
	if(!$savebutton) {
310
		$savebutton = '<td class="infoboxsave"><input value="Close" type="button" onClick="$(\'redboxtable\').hide();"></td>';
311
	}
312

    
313
	echo <<<EOFnp
314
	<table class='infobox' id='redboxtable'>
315
		<tr>
316
			<td>
317
				<div class='infoboxnp' id='redbox'>
318
					<table class='infoboxnptable2'>
319
						<tr>
320
							<td class='infoboxnptd'>
321
								&nbsp;&nbsp;&nbsp;<img class='infoboxnpimg' src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" >
322
							</td>
323
							<td class='infoboxnptd2'>
324
								<b>{$msg}</b>
325
							</td>
326
							{$savebutton}
327
						</tr>
328
					</table>
329
				</div>
330
				<div>
331
					<p/>
332
				</div>
333
			</td>
334
		</tr>
335
	</table>
336
	<script type="text/javascript">
337
		NiftyCheck();
338
		Rounded("div#redbox","all","{$nifty_background}","{$nifty_redbox}","smooth");
339
		Rounded("td#blackbox","all","{$nifty_background}","{$nifty_blackbox}","smooth");
340
	</script>
341
EOFnp;
342

    
343
}
344

    
345
function print_info_box_np_undo($msg, $name="apply",$value="Apply changes", $undo) {
346
	global $g;
347
	
348
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
349
		$savebutton = "<td class='infoboxsave'><nobr>";
350
		$savebutton .= " <input type=\"button\" value=\"Undo\" onClick=\"document.location='{$undo}'\">";
351
		$savebutton .= " <input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
352
		$savebutton.="</nobr></td>";
353
		if($_POST['if']) 
354
			$savebutton .= "<input type='hidden' name='if' value='{$_POST['if']}'>";
355
	}
356
	$nifty_redbox = "#990000";
357
	$nifty_blackbox = "#000000";
358
	
359
	$themename = $g['theme'];
360
	
361
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
362
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
363
		eval($toeval);
364
	}
365
	
366
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
367
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
368
		eval($toeval);
369
	}	
370
	
371
		
372
	if(!$savebutton) {
373
		$savebutton = '<td class="infoboxsave"><input value="Close" type="button" onClick="$(\'redboxtable\').hide();"></td>';
374
	}
375

    
376
	echo <<<EOFnp
377
	<table class='infobox' id='redboxtable'>
378
		<tr>
379
			<td>
380
				<div class='infoboxnp' id='redbox'>
381
					<table class='infoboxnptable2'>
382
						<tr>
383
							<td class='infoboxnptd'>
384
								&nbsp;&nbsp;&nbsp;<img class='infoboxnpimg' src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" >
385
							</td>
386
							<td class='infoboxnptd2'>
387
								<b>{$msg}</b>
388
							</td>
389
							{$savebutton} 
390
							{$undobutton}
391
						</tr>
392
					</table>
393
				</div>
394
				<div>
395
					<p/>
396
				</div>
397
			</td>
398
		</tr>
399
	</table>
400
	<script type="text/javascript">
401
		NiftyCheck();
402
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
403
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
404
	</script>
405
EOFnp;
406

    
407
}
408

    
409
function print_info_box($msg) {
410
	print_info_box_np($msg);
411
}
412

    
413
function get_std_save_message($ok) {
414
	global $d_sysrebootreqd_path;
415

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

    
419
function pprint_address($adr) {
420
	global $specialnets;
421

    
422
	if (isset($adr['any'])) {
423
		$padr = "*";
424
	} else if ($adr['network']) {
425
		$padr = $specialnets[$adr['network']];
426
	} else {
427
		$padr = $adr['address'];
428
	}
429

    
430
	if (isset($adr['not']))
431
		$padr = "! " . $padr;
432

    
433
	return $padr;
434
}
435

    
436
function pprint_port($port) {
437
	global $wkports;
438

    
439
	$pport = "";
440

    
441
	if (!$port)
442
		return "*";
443
	else {
444
		$srcport = explode("-", $port);
445
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
446
			$pport = $srcport[0];
447
			if ($wkports[$srcport[0]]) {
448
				$pport .= " (" . $wkports[$srcport[0]] . ")";
449
			}
450
		} else
451
			$pport .= $srcport[0] . " - " . $srcport[1];
452
	}
453

    
454
	return $pport;
455
}
456

    
457
/* sort by interface only, retain the original order of rules that apply to
458
   the same interface */
459
function filter_rules_sort() {
460
	global $config;
461

    
462
	/* mark each rule with the sequence number (to retain the order while sorting) */
463
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
464
		$config['filter']['rule'][$i]['seq'] = $i;
465

    
466
	function filtercmp($a, $b) {
467
		if ($a['interface'] == $b['interface'])
468
			return $a['seq'] - $b['seq'];
469
		else
470
			return -strcmp($a['interface'], $b['interface']);
471
	}
472

    
473
	usort($config['filter']['rule'], "filtercmp");
474

    
475
	/* strip the sequence numbers again */
476
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
477
		unset($config['filter']['rule'][$i]['seq']);
478
}
479

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

    
519
        return $item_set;
520
}
521

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

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

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

    
540
	$changedesc .= " {$update}";
541
	$changecount++;
542
}
543

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

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

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

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

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

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

    
655
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
656

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

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

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

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

    
684
        $adr = array();
685

    
686
        if ($padr == "any")
687
                $adr['any'] = true;
688
        else if (is_specialnet($padr))
689
                $adr['network'] = $padr;
690
        else {
691
                $adr['address'] = $padr;
692
                if ($pmask != 32)
693
                        $adr['address'] .= "/" . $pmask;
694
        }
695

    
696
        if ($pnot)
697
                $adr['not'] = true;
698
        else
699
                unset($adr['not']);
700

    
701
        if (($pbeginport != 0) && ($pbeginport != "any")) {
702
                if ($pbeginport != $pendport)
703
                        $adr['port'] = $pbeginport . "-" . $pendport;
704
                else
705
                        $adr['port'] = $pbeginport;
706
        }
707

    
708
        if(is_alias($pbeginport)) {
709
                $adr['port'] = $pbeginport;
710
        }
711
}
712

    
713
function is_specialnet($net) {
714
        global $specialsrcdst;
715

    
716
	if(!$net) 
717
		return false;
718
        if (in_array($net, $specialsrcdst))
719
                return true;
720
        else
721
                return false;
722
}
723

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

    
760

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

    
773

    
774

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

    
785

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

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

    
840
function is_rfc2616_code($code) {
841
	global $rfc2616;
842
	if (isset($rfc2616[$code]))
843
		return true;
844
	else
845
		return false;
846
}
847

    
848
function print_rfc2616_select($tag, $current){
849
	global $rfc2616;
850

    
851
	/* Default to 200 OK if not set */
852
	if ($current == "")
853
		$current = 200;
854

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

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

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

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

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

    
956
        unset ($tab_array);
957
        $tab_array = & $tab_temp;
958

    
959
        $tab_active_bg   = "#EEEEEE";
960
        $tab_inactive_bg = "#777777";
961
        $nifty_tabs_corners = "#FFF";
962
        $font_color = "white";
963

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

    
972
        $tabcharcount = 0;
973
        foreach ($tab_array as $ta)
974
                $tabcharcount = $tabcharcount + strlen($ta[0]);
975

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

    
1013
function add_package_tabs($tabgroup, & $tab_array) {
1014
        global $config, $g;
1015

    
1016
        if(!is_array($config['installedpackages']))
1017
                return;
1018
        if(!is_array($config['installedpackages']['tab']))
1019
                return;
1020

    
1021
        foreach($config['installedpackages']['tab'] as $tab) {
1022
                if ($tab['group'] !== $group)
1023
                        continue;
1024
                $tab_entry = array();
1025
                if($tab['name']) {
1026
                        $tab_entry[] = $tab['name'];
1027
                        $tab_entry[] = false;
1028
                        $tab_entry[] = $tab['url'];
1029
                        $tab_array[] = $tab_entry;
1030
                }
1031
        }
1032
}
1033

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

    
1071
                	$alias_descr_substr = $alias_name['descr'];
1072
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
1073
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
1074
                	$strlength = strlen ($alias_caption);
1075
                	if ($strlength >= $maxlength)
1076
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
1077

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

    
1081
                	if ($alias_name['name'] == $src)
1082
                        	$alias_src_span_begin = $span_begin;
1083
                	if ($alias_name['name'] == $srcport)
1084
                        	$alias_src_port_span_begin = $span_begin;
1085
                	if ($alias_name['name'] == $dst)
1086
                        	$alias_dst_span_begin = $span_begin;
1087
                	if ($alias_name['name'] == $dstport)
1088
                        	$alias_dst_port_span_begin = $span_begin;
1089
        	}
1090
        	$descriptions = array ();
1091
        	$descriptions['src'] = $alias_src_span_begin;
1092
        	$descriptions['srcport'] = $alias_src_port_span_begin;
1093
        	$descriptions['dst'] = $alias_dst_span_begin;
1094
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
1095

    
1096
        	return $descriptions;
1097
  	}
1098
}
1099

    
1100
?>
(73-73/219)