Project

General

Profile

Download (30.4 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");
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
if (is_subsystem_dirty('firmwarelock')) {
84
	if (!$d_isfwfile) {
85
		header("Location: system_firmware.php");
86
		exit;
87
	} else {
88
		return;
89
	}
90
}
91

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

    
108
$auth_server_types = array(
109
	'ldap' => "LDAP",
110
	'radius' => "Radius");
111

    
112
$ldap_urltypes = array(
113
	'TCP - Standard' => 389,
114
	'SSL - Encrypted' => 636);
115

    
116
$ldap_scopes = array(
117
	'one' => "One Level",
118
	'subtree' => "Entire Subtree");
119

    
120
$ldap_protvers = array(
121
	2,
122
	3);
123

    
124
$ldap_templates = array(
125

    
126
	'open' => array(
127
				'desc' => "OpenLDAP",
128
				'attr_user' => "cn",
129
				'attr_group' => "cn",
130
				'attr_member' => "member"),
131

    
132
	'msad' => array(
133
				'desc' => "Microsoft AD",
134
				'attr_user' => "samAccountNAme",
135
				'attr_group' => "cn",
136
				'attr_member' => "member"),
137

    
138
	'edir' => array(
139
				'desc' => "Novell eDirectory",
140
				'attr_user' => "cn",
141
				'attr_group' => "cn",
142
				'attr_member' => "uniqueMember"));
143

    
144
$radius_srvcs = array(
145
	'both' => "Authentication and Accounting",
146
	'auth' => "Authentication",
147
	'acct' => "Accounting");
148

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

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

    
202
$specialnets = array("wanip" => "WAN address", "lanip" => "LAN address", "lan" => "LAN net", "pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
203

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

    
209
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
210
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
211
	"10half" => "10BASE-T half-duplex");
212

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

    
216
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
217

    
218
	/* check for bad control characters */
219
	foreach ($postdata as $pn => $pd) {
220
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
221
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
222
		}
223
	}
224

    
225
	for ($i = 0; $i < count($reqdfields); $i++) {
226
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
227
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
228
		}
229
	}
230
}
231

    
232
function print_input_errors($input_errors) {
233
	global $g;
234

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

    
251
	print <<<EOF2
252
				</ul>
253
			</span>
254
		</td></tr>
255
	</table>
256
	</p>&nbsp;<br>
257
EOF2;
258
	
259
}
260

    
261
function verify_gzip_file($fname) {
262

    
263
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
264
	if ($returnvar != 0)
265
		return 0;
266
	else
267
		return 1;
268
}
269

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

    
323
}
324

    
325
function print_info_box($msg) {
326
	echo "<p>";
327
	print_info_box_np($msg);
328
	echo "</p>";
329
}
330

    
331
function get_std_save_message($ok) {
332
	global $d_sysrebootreqd_path;
333

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

    
337
function pprint_address($adr) {
338
	global $specialnets;
339

    
340
	if (isset($adr['any'])) {
341
		$padr = "*";
342
	} else if ($adr['network']) {
343
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
344
			$padr = "Interface IP address";
345
		} else {
346
			$padr = $specialnets[$adr['network']];
347
		}
348
	} else {
349
		$padr = $adr['address'];
350
	}
351

    
352
	if (isset($adr['not']))
353
		$padr = "! " . $padr;
354

    
355
	return $padr;
356
}
357

    
358
function pprint_port($port) {
359
	global $wkports;
360

    
361
	$pport = "";
362

    
363
	if (!$port)
364
		return "*";
365
	else {
366
		$srcport = explode("-", $port);
367
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
368
			$pport = $srcport[0];
369
			if ($wkports[$srcport[0]]) {
370
				$pport .= " (" . $wkports[$srcport[0]] . ")";
371
			}
372
		} else
373
			$pport .= $srcport[0] . " - " . $srcport[1];
374
	}
375

    
376
	return $pport;
377
}
378

    
379
/* sort by interface only, retain the original order of rules that apply to
380
   the same interface */
381
function filter_rules_sort() {
382
	global $config;
383

    
384
	/* mark each rule with the sequence number (to retain the order while sorting) */
385
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
386
		$config['filter']['rule'][$i]['seq'] = $i;
387

    
388
	function filtercmp($a, $b) {
389
		if ($a['interface'] == $b['interface'])
390
			return $a['seq'] - $b['seq'];
391
		else
392
			return -strcmp($a['interface'], $b['interface']);
393
	}
394

    
395
	usort($config['filter']['rule'], "filtercmp");
396

    
397
	/* strip the sequence numbers again */
398
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
399
		unset($config['filter']['rule'][$i]['seq']);
400
}
401

    
402
function aliases_sort() {
403
	global $g, $config;
404

    
405
	function aliascmp($a, $b) {
406
		return strcmp($a['name'], $b['name']);
407
	}
408

    
409
	if($config['aliases'])
410
		usort($config['aliases']['alias'], "aliascmp");
411
}
412

    
413
function gentitle($title) {
414
	global $navlevelsep;
415
	if(!is_array($title))
416
		return $title;
417
	else
418
		return join($navlevelsep, $title);
419
}
420

    
421
function genhtmltitle($title) {
422
        global $config;
423
        return gentitle($title);
424
}
425

    
426
/* update the changedesc and changecount(er) variables */
427
function update_changedesc($update) {
428
	global $changedesc;
429
	global $changecount;
430

    
431
	$changedesc .= " {$update}";
432
	$changecount++;
433
}
434

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

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

    
487
			} else {
488
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
489
			}
490
			echo "</tr>\n";
491
	}
492
}
493

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

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

    
536
	} else {
537
		if ($orig != $new) {
538
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
539
			$orig = $new;
540
			return true;
541
		}
542
	}
543
	return false;
544
}
545

    
546
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
547

    
548
        if (isset($adr['any']))
549
                $padr = "any";
550
        else if ($adr['network'])
551
                $padr = $adr['network'];
552
        else if ($adr['address']) {
553
                list($padr, $pmask) = explode("/", $adr['address']);
554
                if (!$pmask)
555
                        $pmask = 32;
556
        }
557

    
558
        if (isset($adr['not']))
559
                $pnot = 1;
560
        else
561
                $pnot = 0;
562

    
563
        if ($adr['port']) {
564
                list($pbeginport, $pendport) = explode("-", $adr['port']);
565
                if (!$pendport)
566
                        $pendport = $pbeginport;
567
	else if (!is_alias($pbeginport) && !is_alias($pendport)) {
568
		$pbeginport = "any";
569
		$pendport = "any";
570
        }
571
}
572

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

    
575
        $adr = array();
576

    
577
        if ($padr == "any")
578
                $adr['any'] = true;
579
        else if (is_specialnet($padr))
580
                $adr['network'] = $padr;
581
        else {
582
                $adr['address'] = $padr;
583
                if ($pmask != 32)
584
                        $adr['address'] .= "/" . $pmask;
585
        }
586

    
587
        if ($pnot)
588
                $adr['not'] = true;
589
        else
590
                unset($adr['not']);
591

    
592
        if (($pbeginport != 0) && ($pbeginport != "any")) {
593
                if ($pbeginport != $pendport)
594
                        $adr['port'] = $pbeginport . "-" . $pendport;
595
                else
596
                        $adr['port'] = $pbeginport;
597
        }
598

    
599
        if(is_alias($pbeginport)) {
600
                $adr['port'] = $pbeginport;
601
        }
602
}
603

    
604
function is_specialnet($net) {
605
        global $specialsrcdst;
606

    
607
	if(!$net) 
608
		return false;
609
        if (in_array($net, $specialsrcdst))
610
                return true;
611
        else
612
                return false;
613
}
614

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

    
651

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

    
664

    
665

    
666
function outputCSSPrintFileInline($css) {
667
	if(file_exists($css)) {
668
		echo "\n<style media=\"print\" type=\"text/css\">\n";
669
		include($css);
670
		echo "\n</style>\n";
671
	} else {
672
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
673
	}
674
}
675

    
676

    
677
function outputCSSFileInline($css) {
678
	if(file_exists($css)) {
679
		echo "\n<style type=\"text/css\">\n";
680
		include($css);
681
		echo "\n</style>\n";
682
	} else {
683
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
684
	}
685
}
686

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

    
731
function is_rfc2616_code($code) {
732
	global $rfc2616;
733
	if (isset($rfc2616[$code]))
734
		return true;
735
	else
736
		return false;
737
}
738

    
739
function print_rfc2616_select($tag, $current){
740
	global $rfc2616;
741

    
742
	/* Default to 200 OK if not set */
743
	if ($current == "")
744
		$current = 200;
745

    
746
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
747
	foreach($rfc2616 as $code => $message) {
748
		if ($code == $current) {
749
			$sel = " selected";
750
		} else {
751
			$sel = "";
752
		}
753
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
754
	}
755
}
756

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

    
784
/****f* pfsense-utils/display_top_tabs
785
 * NAME
786
 *   display_top_tabs - display tabs with rounded edges
787
 * INPUTS
788
 *   $text      - array of tabs
789
 * RESULT
790
 *   null
791
 ******/
792
function display_top_tabs(& $tab_array) {
793
        global $HTTP_SERVER_VARS;
794
        global $config;
795
        global $g;
796

    
797
        /*  does the user have access to this tab?
798
         *  master user has access to everything.
799
         *  if the user does not have access, simply
800
         *  unset the tab item.
801
         */
802

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

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

    
830
        unset ($tab_array);
831
        $tab_array = & $tab_temp;
832

    
833
        $tab_active_bg   = "#EEEEEE";
834
        $tab_inactive_bg = "#777777";
835
        $nifty_tabs_corners = "#FFF";
836
        $font_color = "white";
837

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

    
846
        $tabcharcount = 0;
847
        foreach ($tab_array as $ta)
848
                $tabcharcount = $tabcharcount + strlen($ta[0]);
849

    
850
        // If the character count of the tab names is > 670
851
        // then show a select item dropdown menubox.
852
        if($tabcharcount > 82) {
853
                echo "Currently viewing: ";
854
                echo "<select name='TabSelect'>\n";
855
                foreach ($tab_array as $ta) {
856
                        if($ta[1]=="true")
857
                                $selected = " SELECTED";
858
                        else
859
                                $selected = "";
860
                        echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
861
                }
862
                echo "</select>\n<p/>";
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
                	foreach($alias_addresses as $alias_ports_address)
951
                	{
952
                        	$alias_objects_with_details .= $alias_addresses[$counter];
953
                        	$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
954
                        	if ($alias_details[$counter] != "" && $alias_detail_default === False){
955
                                	$alias_objects_with_details .=" - " . $alias_details[$counter];
956
                        	}
957
                        	$alias_objects_with_details .= "<br>";
958
                        	$counter++;
959
                	}
960
                	//max character length for caption field
961
                	$maxlength = 60;
962

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

    
970
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
971
			$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>";
972

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

    
988
        	return $descriptions;
989
  	}
990
}
991

    
992
?>
(71-71/214)