Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
128
$ldap_templates = array(
129

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
271
function verify_gzip_file($fname) {
272

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

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

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

    
339
}
340

    
341
function print_info_box($msg) {
342
	print_info_box_np($msg);
343
}
344

    
345
function get_std_save_message($ok) {
346
	global $d_sysrebootreqd_path;
347

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

    
351
function pprint_address($adr) {
352
	global $specialnets;
353

    
354
	if (isset($adr['any'])) {
355
		$padr = "*";
356
	} else if ($adr['network']) {
357
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
358
			$padr = "Interface IP address";
359
		} else {
360
			$padr = $specialnets[$adr['network']];
361
		}
362
	} else {
363
		$padr = $adr['address'];
364
	}
365

    
366
	if (isset($adr['not']))
367
		$padr = "! " . $padr;
368

    
369
	return $padr;
370
}
371

    
372
function pprint_port($port) {
373
	global $wkports;
374

    
375
	$pport = "";
376

    
377
	if (!$port)
378
		return "*";
379
	else {
380
		$srcport = explode("-", $port);
381
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
382
			$pport = $srcport[0];
383
			if ($wkports[$srcport[0]]) {
384
				$pport .= " (" . $wkports[$srcport[0]] . ")";
385
			}
386
		} else
387
			$pport .= $srcport[0] . " - " . $srcport[1];
388
	}
389

    
390
	return $pport;
391
}
392

    
393
/* sort by interface only, retain the original order of rules that apply to
394
   the same interface */
395
function filter_rules_sort() {
396
	global $config;
397

    
398
	/* mark each rule with the sequence number (to retain the order while sorting) */
399
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
400
		$config['filter']['rule'][$i]['seq'] = $i;
401

    
402
	function filtercmp($a, $b) {
403
		if ($a['interface'] == $b['interface'])
404
			return $a['seq'] - $b['seq'];
405
		else
406
			return -strcmp($a['interface'], $b['interface']);
407
	}
408

    
409
	usort($config['filter']['rule'], "filtercmp");
410

    
411
	/* strip the sequence numbers again */
412
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
413
		unset($config['filter']['rule'][$i]['seq']);
414
}
415

    
416
function gentitle($title) {
417
	global $navlevelsep;
418
	if(!is_array($title))
419
		return $title;
420
	else
421
		return join($navlevelsep, $title);
422
}
423

    
424
function genhtmltitle($title) {
425
        global $config;
426
        return gentitle($title);
427
}
428

    
429
/* update the changedesc and changecount(er) variables */
430
function update_changedesc($update) {
431
	global $changedesc;
432
	global $changecount;
433

    
434
	$changedesc .= " {$update}";
435
	$changecount++;
436
}
437

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

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

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

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

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

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

    
549
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
550

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

    
561
        if (isset($adr['not']))
562
                $pnot = 1;
563
        else
564
                $pnot = 0;
565

    
566
        if ($adr['port']) {
567
                list($pbeginport, $pendport) = explode("-", $adr['port']);
568
                if (!$pendport)
569
                        $pendport = $pbeginport;
570
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
571
		$pbeginport = "any";
572
		$pendport = "any";
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(is_alias($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' onchange='tabs_will_go(this)'>\n";
858
                foreach ($tab_array as $ta) {
859
                        if($ta[1]=="true")
860
                                $selected = " SELECTED";
861
                        else
862
                                $selected = "";
863
                        // Onclick in option will not work in some browser
864
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
865
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
866
                }
867
                echo "</select>\n<p/>";
868
                echo "<script type=\"text/javascript\">";
869
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
870
                echo "</script>";
871
        }  else {
872
                echo "<table cellpadding='0' cellspacing='0'>\n";
873
                echo " <tr>\n";
874
                $tabscounter = 0;
875
                foreach ($tab_array as $ta) {
876
                        if ($ta[1] == true) {
877
                                echo "  <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabactive'></div></td>\n";
878
                        } else {
879
                                echo "  <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabdeactive{$tabscounter}'></div></td>\n";
880
                        }
881
                        $tabscounter++;
882
                }
883
                echo "</tr>\n<tr>\n";
884
                foreach ($tab_array as $ta) {
885
                        if ($ta[1] == true) {
886
                                echo "  <td height=\"15\" valign=\"middle\" bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
887
                                echo "&nbsp;&nbsp;&nbsp;";
888
                                echo "<font size='-12'>&nbsp;</font></B></td>\n";
889
                        } else {
890
                                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[
891
2]}'>";
892
                                echo "<font color='{$font_color}'>{$ta[0]}</font></a>&nbsp;&nbsp;&nbsp;";
893
                                echo "<font size='-12'>&nbsp;</font></B></td>\n";
894
                        }
895
                }
896
                echo "</tr>\n<tr>\n";
897
                foreach ($tab_array as $ta) {
898
                        if ($ta[1] == true) {
899
                                echo "  <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
900
                        } else {
901
                                echo "  <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
902
                        }
903
                        $tabscounter++;
904
                }
905
                echo " </tr>\n";
906
                echo "</table>\n";
907
                echo "<script type=\"text/javascript\">";
908
                echo "NiftyCheck();\n";
909
                echo "Rounded(\"div#tabactive\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_active_bg}\",\"smooth\");\n";
910
                for ($x = 0; $x < $tabscounter; $x++)
911
                        echo "Rounded(\"div#tabdeactive{$x}\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_inactive_bg}\",\"smooth\");\n";
912
                echo "</script>";
913
        }
914
}
915

    
916
function add_package_tabs($tabgroup, & $tab_array) {
917
        global $config, $g;
918

    
919
        if(!is_array($config['installedpackages']))
920
                return;
921
        if(!is_array($config['installedpackages']['tab']))
922
                return;
923

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

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

    
974
                	$alias_descr_substr = $alias_name['descr'];
975
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
976
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
977
                	$strlength = strlen ($alias_caption);
978
                	if ($strlength >= $maxlength)
979
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
980

    
981
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
982
			$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>";
983

    
984
                	if ($alias_name['name'] == $src)
985
                        	$alias_src_span_begin = $span_begin;
986
                	if ($alias_name['name'] == $srcport)
987
                        	$alias_src_port_span_begin = $span_begin;
988
                	if ($alias_name['name'] == $dst)
989
                        	$alias_dst_span_begin = $span_begin;
990
                	if ($alias_name['name'] == $dstport)
991
                        	$alias_dst_port_span_begin = $span_begin;
992
        	}
993
        	$descriptions = array ();
994
        	$descriptions['src'] = $alias_src_span_begin;
995
        	$descriptions['srcport'] = $alias_src_port_span_begin;
996
        	$descriptions['dst'] = $alias_dst_span_begin;
997
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
998

    
999
        	return $descriptions;
1000
  	}
1001
}
1002

    
1003
?>
(73-73/221)