Project

General

Profile

Download (30.6 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 {
568
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
569
                        /* Item is a port alias */
570
                } else {
571
                        $pbeginport = "any";
572
                        $pendport = "any";
573
                }
574
        }
575
}
576

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

    
579
        $adr = array();
580

    
581
        if ($padr == "any")
582
                $adr['any'] = true;
583
        else if (is_specialnet($padr))
584
                $adr['network'] = $padr;
585
        else {
586
                $adr['address'] = $padr;
587
                if ($pmask != 32)
588
                        $adr['address'] .= "/" . $pmask;
589
        }
590

    
591
        if ($pnot)
592
                $adr['not'] = true;
593
        else
594
                unset($adr['not']);
595

    
596
        if (($pbeginport != 0) && ($pbeginport != "any")) {
597
                if ($pbeginport != $pendport)
598
                        $adr['port'] = $pbeginport . "-" . $pendport;
599
                else
600
                        $adr['port'] = $pbeginport;
601
        }
602

    
603
        if(alias_expand($pbeginport)) {
604
                $adr['port'] = $pbeginport;
605
        }
606
}
607

    
608
function is_specialnet($net) {
609
        global $specialsrcdst;
610

    
611
	if(!$net) 
612
		return false;
613
        if (in_array($net, $specialsrcdst))
614
                return true;
615
        else
616
                return false;
617
}
618

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

    
655

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

    
668

    
669

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

    
680

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

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

    
735
function is_rfc2616_code($code) {
736
	global $rfc2616;
737
	if (isset($rfc2616[$code]))
738
		return true;
739
	else
740
		return false;
741
}
742

    
743
function print_rfc2616_select($tag, $current){
744
	global $rfc2616;
745

    
746
	/* Default to 200 OK if not set */
747
	if ($current == "")
748
		$current = 200;
749

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

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

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

    
801
        /*  does the user have access to this tab?
802
         *  master user has access to everything.
803
         *  if the user does not have access, simply
804
         *  unset the tab item.
805
         */
806

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

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

    
834
        unset ($tab_array);
835
        $tab_array = & $tab_temp;
836

    
837
        $tab_active_bg   = "#EEEEEE";
838
        $tab_inactive_bg = "#777777";
839
        $nifty_tabs_corners = "#FFF";
840
        $font_color = "white";
841

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

    
850
        $tabcharcount = 0;
851
        foreach ($tab_array as $ta)
852
                $tabcharcount = $tabcharcount + strlen($ta[0]);
853

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

    
912
function add_package_tabs($tabgroup, & $tab_array) {
913
        global $config, $g;
914

    
915
        if(!is_array($config['installedpackages']))
916
                return;
917
        if(!is_array($config['installedpackages']['tab']))
918
                return;
919

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

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

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

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

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

    
992
        	return $descriptions;
993
  	}
994
}
995

    
996
?>
(71-71/214)