Project

General

Profile

Download (30.5 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
	23 => "Telnet",
198
	69 => "TFTP",
199
	5900 => "VNC");
200

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

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

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

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

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

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

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

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

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

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

    
260
function verify_gzip_file($fname) {
261

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

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

    
322
}
323

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

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

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

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

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

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

    
354
	return $padr;
355
}
356

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

    
360
	$pport = "";
361

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

    
375
	return $pport;
376
}
377

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
562
        if ($adr['port']) {
563
                list($pbeginport, $pendport) = explode("-", $adr['port']);
564
                if (!$pendport)
565
                        $pendport = $pbeginport;
566
        } else {
567
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
568
                        /* Item is a port alias */
569
                } else {
570
                        $pbeginport = "any";
571
                        $pendport = "any";
572
                }
573
        }
574
}
575

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

    
578
        $adr = array();
579

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

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

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

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

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

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

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

    
654

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

    
667

    
668

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

    
679

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
932
function rule_popup($src,$srcport,$dst,$dstport){
933
	global $config;
934
	$aliases_array = array();
935
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
936
	{
937
		$span_begin = "";
938
                $alias_src_span_begin = "";
939
                $alias_src_span_end = "";
940
                $alias_src_port_span_begin = "";
941
                $alias_src_port_span_end = "";
942
                $alias_dst_span_begin = "";
943
                $alias_dst_span_end = "";
944
                $alias_dst_port_span_begin = "";
945
                $alias_dst_port_span_end = "";
946
                $alias_content_text = "";
947
        	foreach($config['aliases']['alias'] as $alias_name)
948
        	{
949
                	$alias_addresses = explode (" ", $alias_name['address']);
950
                	$alias_details = explode ("||", $alias_name['detail']);
951
                	$alias_objects_with_details = "";
952
                	$counter = 0;
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/214)