Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
127
$ldap_templates = array(
128

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

    
135
	'msad' => array(
136
				'desc' => "Microsoft AD",
137
				'attr_user' => "samAccountNAme",
138
				'attr_group' => "cn",
139
				'attr_member' => "member"),
140

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

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

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

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

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

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

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

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

    
219
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
220

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

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

    
235
function print_input_errors($input_errors) {
236
	global $g;
237

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

    
254
	print <<<EOF2
255
				</ul>
256
			</span>
257
		</td></tr>
258
	</table>
259
	</p>&nbsp;<br>
260
EOF2;
261
	
262
}
263

    
264
function verify_gzip_file($fname) {
265

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

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

    
326
}
327

    
328
function print_info_box($msg) {
329
	echo "<p>";
330
	print_info_box_np($msg);
331
	echo "</p>";
332
}
333

    
334
function get_std_save_message($ok) {
335
	global $d_sysrebootreqd_path;
336

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

    
340
function pprint_address($adr) {
341
	global $specialnets;
342

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

    
355
	if (isset($adr['not']))
356
		$padr = "! " . $padr;
357

    
358
	return $padr;
359
}
360

    
361
function pprint_port($port) {
362
	global $wkports;
363

    
364
	$pport = "";
365

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

    
379
	return $pport;
380
}
381

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

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

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

    
398
	usort($config['filter']['rule'], "filtercmp");
399

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

    
405
function aliases_sort() {
406
	global $g, $config;
407

    
408
	function aliascmp($a, $b) {
409
		return strcmp($a['name'], $b['name']);
410
	}
411

    
412
	if($config['aliases'])
413
		usort($config['aliases']['alias'], "aliascmp");
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
                	foreach($alias_addresses as $alias_ports_address)
959
                	{
960
                        	$alias_objects_with_details .= $alias_addresses[$counter];
961
                        	$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
962
                        	if ($alias_details[$counter] != "" && $alias_detail_default === False){
963
                                	$alias_objects_with_details .=" - " . $alias_details[$counter];
964
                        	}
965
                        	$alias_objects_with_details .= "<br>";
966
                        	$counter++;
967
                	}
968
                	//max character length for caption field
969
                	$maxlength = 60;
970

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

    
978
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
979
			$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>";
980

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

    
996
        	return $descriptions;
997
  	}
998
}
999

    
1000
?>
(72-72/215)