Project

General

Profile

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

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

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

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

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

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

    
36
/* Include authentication routines */
37
/* THIS MUST BE ABOVE ALL OTHER CODE */
38
require_once("authgui.inc");
39

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

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

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

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

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

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

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

    
95
$firewall_rules_dscp_types = array("af11", 
96
								"af12", 
97
								"af13", 
98
								"af21", 
99
								"af22", 
100
								"af23", 
101
								"af31", 
102
								"af32", 
103
								"af33", 
104
								"af41", 
105
								"af42", 
106
								"af43", 
107
								"EF", 
108
								"1-64", 
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
$specialnets = array("wanip" => "WAN address", "lanip" => "LAN address", "lan" => "LAN net", "pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
206

    
207
$spiflist = get_configured_interface_with_descr(true, true);
208
foreach ($spiflist as $ifgui => $ifdesc) {
209
	$specialnets[$ifgui] = $ifdesc . " net";
210
}
211

    
212
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
213
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
214
	"10half" => "10BASE-T half-duplex");
215

    
216
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
217
	"hostap" => "Access Point");
218

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

    
222
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
223

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

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

    
238
function print_input_errors($input_errors) {
239
	global $g;
240

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

    
257
	print <<<EOF2
258
				</ul>
259
			</span>
260
		</td></tr>
261
	</table>
262
	</p>&nbsp;<br>
263
EOF2;
264
	
265
}
266

    
267
function verify_gzip_file($fname) {
268

    
269
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
270
	if ($returnvar != 0)
271
		return 0;
272
	else
273
		return 1;
274
}
275

    
276
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
277
	global $g;
278
	
279
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
280
		$savebutton = "<td class='infoboxsave'>";
281
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
282
		if($_POST['if']) 
283
			$savebutton .= "<input type='hidden' name='if' value='{$_POST['if']}'>";
284
		$savebutton.="</td>";
285
	}
286
	$nifty_redbox = "#990000";
287
	$nifty_blackbox = "#000000";
288
	
289
	$themename = $g['theme'];
290
	
291
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
292
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
293
		eval($toeval);
294
	}
295
	
296
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
297
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
298
		eval($toeval);
299
	}	
300
		
301
	echo <<<EOFnp
302
	<table class='infobox'>
303
		<tr>
304
			<td>
305
				<div class='infoboxnp' id='redbox'>
306
					<table class='infoboxnptable2'>
307
						<tr>
308
							<td class='infoboxnptd'>
309
								&nbsp;&nbsp;&nbsp;<img class='infoboxnpimg' src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" >
310
							</td>
311
							<td class='infoboxnptd2'>
312
								<b>{$msg}</b>
313
							</td>
314
							{$savebutton}
315
						</tr>
316
					</table>
317
				</div>
318
			</td>
319
		</tr>
320
	</table>
321
	<script type="text/javascript">
322
		NiftyCheck();
323
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
324
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
325
	</script>
326
	<br/>
327
EOFnp;
328

    
329
}
330

    
331
function print_info_box($msg) {
332
	echo "<p>";
333
	print_info_box_np($msg);
334
	echo "</p>";
335
}
336

    
337
function get_std_save_message($ok) {
338
	global $d_sysrebootreqd_path;
339

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

    
343
function pprint_address($adr) {
344
	global $specialnets;
345

    
346
	if (isset($adr['any'])) {
347
		$padr = "*";
348
	} else if ($adr['network']) {
349
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
350
			$padr = "Interface IP address";
351
		} else {
352
			$padr = $specialnets[$adr['network']];
353
		}
354
	} else {
355
		$padr = $adr['address'];
356
	}
357

    
358
	if (isset($adr['not']))
359
		$padr = "! " . $padr;
360

    
361
	return $padr;
362
}
363

    
364
function pprint_port($port) {
365
	global $wkports;
366

    
367
	$pport = "";
368

    
369
	if (!$port)
370
		return "*";
371
	else {
372
		$srcport = explode("-", $port);
373
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
374
			$pport = $srcport[0];
375
			if ($wkports[$srcport[0]]) {
376
				$pport .= " (" . $wkports[$srcport[0]] . ")";
377
			}
378
		} else
379
			$pport .= $srcport[0] . " - " . $srcport[1];
380
	}
381

    
382
	return $pport;
383
}
384

    
385
/* sort by interface only, retain the original order of rules that apply to
386
   the same interface */
387
function filter_rules_sort() {
388
	global $config;
389

    
390
	/* mark each rule with the sequence number (to retain the order while sorting) */
391
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
392
		$config['filter']['rule'][$i]['seq'] = $i;
393

    
394
	function filtercmp($a, $b) {
395
		if ($a['interface'] == $b['interface'])
396
			return $a['seq'] - $b['seq'];
397
		else
398
			return -strcmp($a['interface'], $b['interface']);
399
	}
400

    
401
	usort($config['filter']['rule'], "filtercmp");
402

    
403
	/* strip the sequence numbers again */
404
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
405
		unset($config['filter']['rule'][$i]['seq']);
406
}
407

    
408
function gentitle($title) {
409
	global $navlevelsep;
410
	if(!is_array($title))
411
		return $title;
412
	else
413
		return join($navlevelsep, $title);
414
}
415

    
416
function genhtmltitle($title) {
417
        global $config;
418
        return gentitle($title);
419
}
420

    
421
/* update the changedesc and changecount(er) variables */
422
function update_changedesc($update) {
423
	global $changedesc;
424
	global $changecount;
425

    
426
	$changedesc .= " {$update}";
427
	$changecount++;
428
}
429

    
430
function clear_log_file($logfile = "/var/log/system.log") {
431
	global $config, $g;
432
	exec("/usr/bin/killall syslogd");
433
	if(isset($config['system']['disablesyslogclog'])) {
434
		unlink($logfile);
435
		touch($logfile);
436
	} else {
437
		if(isset($config['system']['usefifolog'])) 
438
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
439
		else
440
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
441
	}
442
	system_syslogd_start();	
443
}
444

    
445
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
446
	global $g, $config;
447
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
448
	$logarr = "";
449
	$grepline = "  ";
450
	if(is_array($grepfor))
451
		foreach($grepfor as $agrep)
452
			$grepline .= " | grep \"$agrep\"";
453
	if(is_array($grepinvert))
454
		foreach($grepinvert as $agrep)
455
			$grepline .= " | grep -v \"$agrep\"";
456
	if(file_exists($logfile) && filesize($logfile) == 0) {
457
		$logarr = array("Log file started.");
458
	} else {
459
		if($config['system']['disablesyslogclog']) {
460
			exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
461
		} else {
462
			if(isset($config['system']['usefifolog']))
463
				exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
464
			else
465
				exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
466
		}
467
	}
468
	foreach ($logarr as $logent) {
469
			$logent = preg_split("/\s+/", $logent, 6);
470
			echo "<tr valign=\"top\">\n";
471
			if ($withorig) {
472
					if(isset($config['system']['usefifolog'])) {
473
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
474
						$entry_text = htmlspecialchars($logent[5]);
475
					} else {
476
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
477
						$entry_text = htmlspecialchars($logent[4] . " " . $logent[5]);
478
					}
479
					echo "<td class=\"listlr\" nowrap>{$entry_date_time}</td>\n";
480
					echo "<td class=\"listr\">{$entry_text}</td>\n";
481

    
482
			} else {
483
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
484
			}
485
			echo "</tr>\n";
486
	}
487
}
488

    
489
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
490
	global $g, $config;
491
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
492
	$logarr = "";
493
	$grepline = "  ";
494
	if(is_array($grepfor))
495
		foreach($grepfor as $agrep)
496
			$grepline .= " | grep \"$agrep\"";
497
	if(is_array($grepinvert))
498
		foreach($grepinvert as $agrep)
499
			$grepline .= " | grep -v \"$agrep\"";
500
	if($config['system']['disablesyslogclog']) {
501
		exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
502
	} else {
503
		if(isset($config['system']['usefifolog'])) {
504
			exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);			
505
		} else {
506
			exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
507
		}
508
	}
509
	return($logarr);
510
}
511

    
512
/* Check if variable has changed, update and log if it has
513
 * returns true if var changed
514
 * varname = variable name in plain text
515
 * orig = original value
516
 * new = new value
517
 */
518
function update_if_changed($varname, & $orig, $new) {
519
	if (is_array($orig) && is_array($new)) {
520
		$a_diff = array_diff($orig, $new);
521
		foreach ($a_diff as $diff) {
522
			update_changedesc("removed {$varname}: \"{$diff}\"");
523
		}
524
		$a_diff = array_diff($new, $orig);
525
		foreach ($a_diff as $diff) {
526
			update_changedesc("added {$varname}: \"{$diff}\"");
527
		}
528
		$orig = $new;
529
		return true;
530

    
531
	} else {
532
		if ($orig != $new) {
533
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
534
			$orig = $new;
535
			return true;
536
		}
537
	}
538
	return false;
539
}
540

    
541
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
542

    
543
        if (isset($adr['any']))
544
                $padr = "any";
545
        else if ($adr['network'])
546
                $padr = $adr['network'];
547
        else if ($adr['address']) {
548
                list($padr, $pmask) = explode("/", $adr['address']);
549
                if (!$pmask)
550
                        $pmask = 32;
551
        }
552

    
553
        if (isset($adr['not']))
554
                $pnot = 1;
555
        else
556
                $pnot = 0;
557

    
558
        if ($adr['port']) {
559
                list($pbeginport, $pendport) = explode("-", $adr['port']);
560
                if (!$pendport)
561
                        $pendport = $pbeginport;
562
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
563
		$pbeginport = "any";
564
		$pendport = "any";
565
        }
566
}
567

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

    
570
        $adr = array();
571

    
572
        if ($padr == "any")
573
                $adr['any'] = true;
574
        else if (is_specialnet($padr))
575
                $adr['network'] = $padr;
576
        else {
577
                $adr['address'] = $padr;
578
                if ($pmask != 32)
579
                        $adr['address'] .= "/" . $pmask;
580
        }
581

    
582
        if ($pnot)
583
                $adr['not'] = true;
584
        else
585
                unset($adr['not']);
586

    
587
        if (($pbeginport != 0) && ($pbeginport != "any")) {
588
                if ($pbeginport != $pendport)
589
                        $adr['port'] = $pbeginport . "-" . $pendport;
590
                else
591
                        $adr['port'] = $pbeginport;
592
        }
593

    
594
        if(is_alias($pbeginport)) {
595
                $adr['port'] = $pbeginport;
596
        }
597
}
598

    
599
function is_specialnet($net) {
600
        global $specialsrcdst;
601

    
602
	if(!$net) 
603
		return false;
604
        if (in_array($net, $specialsrcdst))
605
                return true;
606
        else
607
                return false;
608
}
609

    
610
//function to create widget tabs when called
611
function display_widget_tabs(& $tab_array) {	
612
	echo "<div id='tabs'>";
613
	$tabscounter = 0;
614
	foreach ($tab_array as $ta) {
615
	$dashpos = strpos($ta[2],'-');
616
	$tabname = $ta[2] . "-tab";
617
	$tabclass = substr($ta[2],0,$dashpos);
618
	$tabclass = $tabclass . "-class";
619
		if ($ta[1] == true) {
620
			$tabActive = "table-cell";
621
			$tabNonActive = "none";
622
		} 
623
		else {
624
			$tabActive = "none";
625
			$tabNonActive = "table-cell";
626
		}
627
		echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
628
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
629
		echo "&nbsp;&nbsp;&nbsp;</B>";
630
		echo "</div>";
631
		
632
		echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
633
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
634
		echo "&nbsp;&nbsp;&nbsp;</B>";
635
		echo "</div>";
636
	}
637
	
638
	echo "<script type=\"text/javascript\">";
639
	echo "NiftyCheck();\n";
640
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
641
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
642
	echo "</script>";
643
	echo "</div>";
644
}
645

    
646

    
647
// Return inline javascript file or CSS to minimizie 
648
// request count going back to server.
649
function outputJavaScriptFileInline($javascript) {
650
	if(file_exists($javascript)) {
651
		echo "\n<script type=\"text/javascript\">\n";
652
		include($javascript);
653
		echo "\n</script>\n";
654
	} else {
655
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
656
	}
657
}
658

    
659

    
660

    
661
function outputCSSPrintFileInline($css) {
662
	if(file_exists($css)) {
663
		echo "\n<style media=\"print\" type=\"text/css\">\n";
664
		include($css);
665
		echo "\n</style>\n";
666
	} else {
667
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
668
	}
669
}
670

    
671

    
672
function outputCSSFileInline($css) {
673
	if(file_exists($css)) {
674
		echo "\n<style type=\"text/css\">\n";
675
		include($css);
676
		echo "\n</style>\n";
677
	} else {
678
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
679
	}
680
}
681

    
682
$rfc2616 = array(
683
	100 => "100 Continue",
684
	101 => "101 Switching Protocols",
685
	200 => "200 OK",
686
	201 => "201 Created",
687
	202 => "202 Accepted",
688
	203 => "203 Non-Authoritative Information",
689
	204 => "204 No Content",
690
	205 => "205 Reset Content",
691
	206 => "206 Partial Content",
692
	300 => "300 Multiple Choices",
693
	301 => "301 Moved Permanently",
694
	302 => "302 Found",
695
	303 => "303 See Other",
696
	304 => "304 Not Modified",
697
	305 => "305 Use Proxy",
698
	306 => "306 (Unused)",
699
	307 => "307 Temporary Redirect",
700
	400 => "400 Bad Request",
701
	401 => "401 Unauthorized",
702
	402 => "402 Payment Required",
703
	403 => "403 Forbidden",
704
	404 => "404 Not Found",
705
	405 => "405 Method Not Allowed",
706
	406 => "406 Not Acceptable",
707
	407 => "407 Proxy Authentication Required",
708
	408 => "408 Request Timeout",
709
	409 => "409 Conflict",
710
	410 => "410 Gone",
711
	411 => "411 Length Required",
712
	412 => "412 Precondition Failed",
713
	413 => "413 Request Entity Too Large",
714
	414 => "414 Request-URI Too Long",
715
	415 => "415 Unsupported Media Type",
716
	416 => "416 Requested Range Not Satisfiable",
717
	417 => "417 Expectation Failed",
718
	500 => "500 Internal Server Error",
719
	501 => "501 Not Implemented",
720
	502 => "502 Bad Gateway",
721
	503 => "503 Service Unavailable",
722
	504 => "504 Gateway Timeout",
723
	505 => "505 HTTP Version Not Supported"
724
);
725

    
726
function is_rfc2616_code($code) {
727
	global $rfc2616;
728
	if (isset($rfc2616[$code]))
729
		return true;
730
	else
731
		return false;
732
}
733

    
734
function print_rfc2616_select($tag, $current){
735
	global $rfc2616;
736

    
737
	/* Default to 200 OK if not set */
738
	if ($current == "")
739
		$current = 200;
740

    
741
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
742
	foreach($rfc2616 as $code => $message) {
743
		if ($code == $current) {
744
			$sel = " selected";
745
		} else {
746
			$sel = "";
747
		}
748
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
749
	}
750
}
751

    
752
// Useful debugging function, much cleaner than print_r
753
function echo_array($array,$return_me=false){
754
    if(is_array($array) == false){
755
        $return = "The provided variable is not an array.";
756
    }else{
757
        foreach($array as $name=>$value){
758
            if(is_array($value)){
759
                $return .= "";
760
                $return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
761
                $return .= echo_array($value,true);
762
                $return .= "</div>}";
763
                $return .= "\n\n";
764
            }else{
765
                if(is_string($value)){
766
                    $value = "\"$value\"";
767
                }
768
                $return .= "['<b>$name</b>'] = $value\n\n";
769
            }
770
        }
771
    }
772
    if($return_me == true){
773
        return $return;
774
    }else{
775
        echo "<pre>".$return."</pre>";
776
    }
777
}
778

    
779
/****f* pfsense-utils/display_top_tabs
780
 * NAME
781
 *   display_top_tabs - display tabs with rounded edges
782
 * INPUTS
783
 *   $text      - array of tabs
784
 * RESULT
785
 *   null
786
 ******/
787
function display_top_tabs(& $tab_array) {
788
        global $HTTP_SERVER_VARS;
789
        global $config;
790
        global $g;
791

    
792
        /*  does the user have access to this tab?
793
         *  master user has access to everything.
794
         *  if the user does not have access, simply
795
         *  unset the tab item.
796
         */
797

    
798
        $tab_temp = array ();
799
        foreach ($tab_array as $ta)
800
                if(isAllowedPage($ta[2]))
801
                        $tab_temp[] = $ta;
802
        /*
803
                // FIXME :      if the checks are not good enough
804
                //                      in isAllowedPage, it needs to be
805
                //                      fixed instead of kludging here
806

    
807
                // TODO: humm what shall we do with pkg_edit.php and pkg.php?
808
                if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) {
809
                        $pos_equal = strpos($link, "=");
810
                        $pos_xmlsuffix = strpos($link, ".xml");
811
                        // do we match an absolute url including ?xml= foo
812
                        if(!isAllowedPage($link, $allowed))
813
                                $link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3));
814
                }
815
                // next check - what if the basename contains a query string?
816
                if ((strpos($link, "?")) !== false) {
817
                        $pos_qmark = strpos($link, "?");
818
                        $link = substr($link, 0, $pos_qmark);
819
                }
820
                $authorized_text = print_r($allowed, true);
821
                if(is_array($authorized))
822
                        if (in_array(basename($link), $authorized))
823
        */
824

    
825
        unset ($tab_array);
826
        $tab_array = & $tab_temp;
827

    
828
        $tab_active_bg   = "#EEEEEE";
829
        $tab_inactive_bg = "#777777";
830
        $nifty_tabs_corners = "#FFF";
831
        $font_color = "white";
832

    
833
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
834
        $themename = $config['theme'];
835
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
836
        if(file_exists($filename)) {
837
                $eval_code = file_get_contents($filename);
838
                eval($eval_code);
839
        }
840

    
841
        $tabcharcount = 0;
842
        foreach ($tab_array as $ta)
843
                $tabcharcount = $tabcharcount + strlen($ta[0]);
844

    
845
        // If the character count of the tab names is > 670
846
        // then show a select item dropdown menubox.
847
        if($tabcharcount > 82) {
848
                echo "Currently viewing: ";
849
                echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
850
                foreach ($tab_array as $ta) {
851
                        if($ta[1]=="true")
852
                                $selected = " SELECTED";
853
                        else
854
                                $selected = "";
855
                        // Onclick in option will not work in some browser
856
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
857
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
858
                }
859
                echo "</select>\n<p/>";
860
                echo "<script type=\"text/javascript\">";
861
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
862
                echo "</script>";
863
        }  else {
864
                echo "<table cellpadding='0' cellspacing='0'>\n";
865
                echo " <tr>\n";
866
                $tabscounter = 0;
867
                foreach ($tab_array as $ta) {
868
                        if ($ta[1] == true) {
869
                                echo "  <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabactive'></div></td>\n";
870
                        } else {
871
                                echo "  <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabdeactive{$tabscounter}'></div></td>\n";
872
                        }
873
                        $tabscounter++;
874
                }
875
                echo "</tr>\n<tr>\n";
876
                foreach ($tab_array as $ta) {
877
                        if ($ta[1] == true) {
878
                                echo "  <td height=\"15\" valign=\"middle\" bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
879
                                echo "&nbsp;&nbsp;&nbsp;";
880
                                echo "<font size='-12'>&nbsp;</font></B></td>\n";
881
                        } else {
882
                                echo "  <td height=\"15\" valign=\"middle\" bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B>&nbsp;&nbsp;&nbsp;<a href='{$ta[
883
2]}'>";
884
                                echo "<font color='{$font_color}'>{$ta[0]}</font></a>&nbsp;&nbsp;&nbsp;";
885
                                echo "<font size='-12'>&nbsp;</font></B></td>\n";
886
                        }
887
                }
888
                echo "</tr>\n<tr>\n";
889
                foreach ($tab_array as $ta) {
890
                        if ($ta[1] == true) {
891
                                echo "  <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
892
                        } else {
893
                                echo "  <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
894
                        }
895
                        $tabscounter++;
896
                }
897
                echo " </tr>\n";
898
                echo "</table>\n";
899
                echo "<script type=\"text/javascript\">";
900
                echo "NiftyCheck();\n";
901
                echo "Rounded(\"div#tabactive\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_active_bg}\",\"smooth\");\n";
902
                for ($x = 0; $x < $tabscounter; $x++)
903
                        echo "Rounded(\"div#tabdeactive{$x}\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_inactive_bg}\",\"smooth\");\n";
904
                echo "</script>";
905
        }
906
}
907

    
908
function add_package_tabs($tabgroup, & $tab_array) {
909
        global $config, $g;
910

    
911
        if(!is_array($config['installedpackages']))
912
                return;
913
        if(!is_array($config['installedpackages']['tab']))
914
                return;
915

    
916
        foreach($config['installedpackages']['tab'] as $tab) {
917
                if ($tab['group'] !== $group)
918
                        continue;
919
                $tab_entry = array();
920
                if($tab['name']) {
921
                        $tab_entry[] = $tab['name'];
922
                        $tab_entry[] = false;
923
                        $tab_entry[] = $tab['url'];
924
                        $tab_array[] = $tab_entry;
925
                }
926
        }
927
}
928

    
929
function rule_popup($src,$srcport,$dst,$dstport){
930
	global $config;
931
	$aliases_array = array();
932
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
933
	{
934
		$span_begin = "";
935
                $alias_src_span_begin = "";
936
                $alias_src_span_end = "";
937
                $alias_src_port_span_begin = "";
938
                $alias_src_port_span_end = "";
939
                $alias_dst_span_begin = "";
940
                $alias_dst_span_end = "";
941
                $alias_dst_port_span_begin = "";
942
                $alias_dst_port_span_end = "";
943
                $alias_content_text = "";
944
        	foreach($config['aliases']['alias'] as $alias_name)
945
        	{
946
                	$alias_addresses = explode (" ", $alias_name['address']);
947
                	$alias_details = explode ("||", $alias_name['detail']);
948
                	$alias_objects_with_details = "";
949
                	$counter = 0;
950
			if ($alias_name['url']) {
951
				$alias_objects_with_details .= $alias_name['url'] . "<br/>";
952
			}
953
                	foreach($alias_addresses as $alias_ports_address)
954
                	{
955
                        	$alias_objects_with_details .= $alias_addresses[$counter];
956
                        	$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
957
                        	if ($alias_details[$counter] != "" && $alias_detail_default === False){
958
                                	$alias_objects_with_details .=" - " . $alias_details[$counter];
959
                        	}
960
                        	$alias_objects_with_details .= "<br>";
961
                        	$counter++;
962
                	}
963
                	//max character length for caption field
964
                	$maxlength = 60;
965

    
966
                	$alias_descr_substr = $alias_name['descr'];
967
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
968
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
969
                	$strlength = strlen ($alias_caption);
970
                	if ($strlength >= $maxlength)
971
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
972

    
973
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
974
			$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>";
975

    
976
                	if ($alias_name['name'] == $src)
977
                        	$alias_src_span_begin = $span_begin;
978
                	if ($alias_name['name'] == $srcport)
979
                        	$alias_src_port_span_begin = $span_begin;
980
                	if ($alias_name['name'] == $dst)
981
                        	$alias_dst_span_begin = $span_begin;
982
                	if ($alias_name['name'] == $dstport)
983
                        	$alias_dst_port_span_begin = $span_begin;
984
        	}
985
        	$descriptions = array ();
986
        	$descriptions['src'] = $alias_src_span_begin;
987
        	$descriptions['srcport'] = $alias_src_port_span_begin;
988
        	$descriptions['dst'] = $alias_dst_span_begin;
989
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
990

    
991
        	return $descriptions;
992
  	}
993
}
994

    
995
?>
(71-71/216)