Project

General

Profile

Download (30.2 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
$auth_server_types = array(
93
	'ldap' => "LDAP",
94
	'radius' => "Radius");
95

    
96
$ldap_urltypes = array(
97
	'TCP - Standard' => 389,
98
	'SSL - Encrypted' => 636);
99

    
100
$ldap_scopes = array(
101
	'one' => "One Level",
102
	'subtree' => "Entire Subtree");
103

    
104
$ldap_protvers = array(
105
	2,
106
	3);
107

    
108
$ldap_templates = array(
109

    
110
	'open' => array(
111
				'desc' => "OpenLDAP",
112
				'attr_user' => "cn",
113
				'attr_group' => "cn",
114
				'attr_member' => "member"),
115

    
116
	'msad' => array(
117
				'desc' => "Microsoft AD",
118
				'attr_user' => "samAccountNAme",
119
				'attr_group' => "cn",
120
				'attr_member' => "member"),
121

    
122
	'edir' => array(
123
				'desc' => "Novell eDirectory",
124
				'attr_user' => "cn",
125
				'attr_group' => "cn",
126
				'attr_member' => "uniqueMember"));
127

    
128
$radius_srvcs = array(
129
	'both' => "Authentication and Accounting",
130
	'auth' => "Authentication",
131
	'acct' => "Accounting");
132

    
133
$netbios_nodetypes = array(
134
	'0' => "none",
135
	'1' => "b-node",
136
	'2' => "p-node",
137
	'4' => "m-node",
138
	'5' => "h-node");
139

    
140
/* some well knows ports */
141
$wkports = array(
142
	5999 => "CVSup",	
143
	53 => "DNS",
144
	21 => "FTP",
145
	3000 => "HBCI",
146
	80 => "HTTP",
147
	443 => "HTTPS",
148
	5190 => "ICQ",
149
	113 => "IDENT/AUTH",
150
	143 => "IMAP",
151
	993 => "IMAP/S",
152
	4500 => "IPsec NAT-T",
153
	500 => "ISAKMP",
154
	1701 => "L2TP",
155
	389 => "LDAP",
156
	1755 => "MMS/TCP",
157
	7000 => "MMS/UDP",
158
	445 => "MS DS",
159
	3389 => "MS RDP",
160
	1512 => "MS WINS",
161
	1863 => "MSN",
162
	119 => "NNTP",
163
	123 => "NTP",
164
	138 => "NetBIOS-DGM",
165
	137 => "NetBIOS-NS",
166
	139 => "NetBIOS-SSN",
167
	1194 => "OpenVPN",
168
	110 => "POP3",
169
	995 => "POP3/S",
170
	1723 => "PPTP",	
171
	1812 => "RADIUS",
172
	1813 => "RADIUS accounting",
173
	5004 => "RTP",
174
	5060 => "SIP",
175
	25 => "SMTP",
176
	465 => "SMTP/S",
177
	161 => "SNMP",
178
	162 => "SNMP-Trap",
179
	22 => "SSH",
180
	3478 => "STUN",
181
	23 => "Telnet",
182
	69 => "TFTP",
183
	5900 => "VNC");
184

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

    
187
$spiflist = get_configured_interface_with_descr(true, true);
188
foreach ($spiflist as $ifgui => $ifdesc) {
189
	$specialnets[$ifgui] = $ifdesc . " net";
190
}
191

    
192
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
193
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
194
	"10half" => "10BASE-T half-duplex");
195

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

    
199
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
200

    
201
	/* check for bad control characters */
202
	foreach ($postdata as $pn => $pd) {
203
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
204
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
205
		}
206
	}
207

    
208
	for ($i = 0; $i < count($reqdfields); $i++) {
209
		if ($_POST[$reqdfields[$i]] == "") {
210
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
211
		}
212
	}
213
}
214

    
215
function print_input_errors($input_errors) {
216
	global $g;
217

    
218
	print <<<EOF
219
	<p>
220
	<table border="0" cellspacing="0" cellpadding="4" width="100%">
221
	<tr>
222
		<td class="inputerrorsleft">
223
			<img src="./themes/{$g['theme']}/images/icons/icon_error.gif">
224
		</td>
225
		<td class="inputerrorsright">
226
			<span class="errmsg"><p>
227
				The following input errors were detected:
228
				<ul>
229
EOF;
230
		foreach ($input_errors as $ierr) {
231
			echo "<li>" . htmlspecialchars($ierr) . "</li>";
232
		}
233

    
234
	print <<<EOF2
235
				</ul>
236
			</span>
237
		</td></tr>
238
	</table>
239
	</p>&nbsp;<br>
240
EOF2;
241
	
242
}
243

    
244
function verify_gzip_file($fname) {
245

    
246
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
247
	if ($returnvar != 0)
248
		return 0;
249
	else
250
		return 1;
251
}
252

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

    
306
}
307

    
308
function print_info_box($msg) {
309
	echo "<p>";
310
	print_info_box_np($msg);
311
	echo "</p>";
312
}
313

    
314
function get_std_save_message($ok) {
315
	global $d_sysrebootreqd_path;
316

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

    
320
function pprint_address($adr) {
321
	global $specialnets;
322

    
323
	if (isset($adr['any'])) {
324
		$padr = "*";
325
	} else if ($adr['network']) {
326
		if (preg_match("/opt[0-999]ip/", $adr['network'])) {
327
			$padr = "Interface IP address";
328
		} else {
329
			$padr = $specialnets[$adr['network']];
330
		}
331
	} else {
332
		$padr = $adr['address'];
333
	}
334

    
335
	if (isset($adr['not']))
336
		$padr = "! " . $padr;
337

    
338
	return $padr;
339
}
340

    
341
function pprint_port($port) {
342
	global $wkports;
343

    
344
	$pport = "";
345

    
346
	if (!$port)
347
		return "*";
348
	else {
349
		$srcport = explode("-", $port);
350
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
351
			$pport = $srcport[0];
352
			if ($wkports[$srcport[0]]) {
353
				$pport .= " (" . $wkports[$srcport[0]] . ")";
354
			}
355
		} else
356
			$pport .= $srcport[0] . " - " . $srcport[1];
357
	}
358

    
359
	return $pport;
360
}
361

    
362
/* sort by interface only, retain the original order of rules that apply to
363
   the same interface */
364
function filter_rules_sort() {
365
	global $config;
366

    
367
	/* mark each rule with the sequence number (to retain the order while sorting) */
368
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
369
		$config['filter']['rule'][$i]['seq'] = $i;
370

    
371
	function filtercmp($a, $b) {
372
		if ($a['interface'] == $b['interface'])
373
			return $a['seq'] - $b['seq'];
374
		else
375
			return -strcmp($a['interface'], $b['interface']);
376
	}
377

    
378
	usort($config['filter']['rule'], "filtercmp");
379

    
380
	/* strip the sequence numbers again */
381
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
382
		unset($config['filter']['rule'][$i]['seq']);
383
}
384

    
385
function aliases_sort() {
386
	global $g, $config;
387

    
388
	function aliascmp($a, $b) {
389
		return strcmp($a['name'], $b['name']);
390
	}
391

    
392
	if($config['aliases'])
393
		usort($config['aliases']['alias'], "aliascmp");
394
}
395

    
396
function gentitle($title) {
397
	global $navlevelsep;
398
	if(!is_array($title))
399
		return $title;
400
	else
401
		return join($navlevelsep, $title); 
402
}
403

    
404
function genhtmltitle($title) {
405
        global $config;
406
        return gentitle($title);
407
}
408

    
409
/* update the changedesc and changecount(er) variables */
410
function update_changedesc($update) {
411
	global $changedesc;
412
	global $changecount;
413

    
414
	$changedesc .= " {$update}";
415
	$changecount++;
416
}
417

    
418
function clear_log_file($logfile = "/var/log/system.log") {
419
	global $config, $g;
420
	exec("/usr/bin/killall syslogd");
421
	if(isset($config['system']['disablesyslogclog'])) {
422
		unlink($logfile);
423
		touch($logfile);
424
	} else {
425
		if(isset($config['system']['usefifolog'])) 
426
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
427
		else
428
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
429
	}
430
	system_syslogd_start();	
431
}
432

    
433
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
434
	global $g, $config;
435
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
436
	$logarr = "";
437
	$grepline = "  ";
438
	if(is_array($grepfor))
439
		foreach($grepfor as $agrep)
440
			$grepline .= " | grep \"$agrep\"";
441
	if(is_array($grepinvert))
442
		foreach($grepinvert as $agrep)
443
			$grepline .= " | grep -v \"$agrep\"";
444
	if(file_exists($logfile) && filesize($logfile) == 0) {
445
		$logarr = array("Log file started.");
446
	} else {
447
		if($config['system']['disablesyslogclog']) {
448
			exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
449
		} else {
450
			if(isset($config['system']['usefifolog']))
451
				exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
452
			else
453
				exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
454
		}
455
	}
456
	foreach ($logarr as $logent) {
457
			$logent = preg_split("/\s+/", $logent, 6);
458
			echo "<tr valign=\"top\">\n";
459
			if ($withorig) {
460
					if(isset($config['system']['usefifolog'])) {
461
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
462
						$entry_text = htmlspecialchars($logent[5]);
463
					} else {
464
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
465
						$entry_text = htmlspecialchars($logent[4] . " " . $logent[5]);
466
					}
467
					echo "<td class=\"listlr\" nowrap>{$entry_date_time}</td>\n";
468
					echo "<td class=\"listr\">{$entry_text}</td>\n";
469

    
470
			} else {
471
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
472
			}
473
			echo "</tr>\n";
474
	}
475
}
476

    
477
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
478
	global $g, $config;
479
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
480
	$logarr = "";
481
	$grepline = "  ";
482
	if(is_array($grepfor))
483
		foreach($grepfor as $agrep)
484
			$grepline .= " | grep \"$agrep\"";
485
	if(is_array($grepinvert))
486
		foreach($grepinvert as $agrep)
487
			$grepline .= " | grep -v \"$agrep\"";
488
	if($config['system']['disablesyslogclog']) {
489
		exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
490
	} else {
491
		if(isset($config['system']['usefifolog'])) {
492
			exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);			
493
		} else {
494
			exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
495
		}
496
	}
497
	return($logarr);
498
}
499

    
500
/* Check if variable has changed, update and log if it has
501
 * returns true if var changed
502
 * varname = variable name in plain text
503
 * orig = original value
504
 * new = new value
505
 */
506
function update_if_changed($varname, & $orig, $new) {
507
	if (is_array($orig) && is_array($new)) {
508
		$a_diff = array_diff($orig, $new);
509
		foreach ($a_diff as $diff) {
510
			update_changedesc("removed {$varname}: \"{$diff}\"");
511
		}
512
		$a_diff = array_diff($new, $orig);
513
		foreach ($a_diff as $diff) {
514
			update_changedesc("added {$varname}: \"{$diff}\"");
515
		}
516
		$orig = $new;
517
		return true;
518

    
519
	} else {
520
		if ($orig != $new) {
521
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
522
			$orig = $new;
523
			return true;
524
		}
525
	}
526
	return false;
527
}
528

    
529
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
530

    
531
        if (isset($adr['any']))
532
                $padr = "any";
533
        else if ($adr['network'])
534
                $padr = $adr['network'];
535
        else if ($adr['address']) {
536
                list($padr, $pmask) = explode("/", $adr['address']);
537
                if (!$pmask)
538
                        $pmask = 32;
539
        }
540

    
541
        if (isset($adr['not']))
542
                $pnot = 1;
543
        else
544
                $pnot = 0;
545

    
546
        if ($adr['port']) {
547
                list($pbeginport, $pendport) = explode("-", $adr['port']);
548
                if (!$pendport)
549
                        $pendport = $pbeginport;
550
        } else {
551
                if(alias_expand($pbeginport) <> "" || alias_expand($pendport) <> "") {
552
                        /* Item is a port alias */
553
                } else {
554
                        $pbeginport = "any";
555
                        $pendport = "any";
556
                }
557
        }
558
}
559

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

    
562
        $adr = array();
563

    
564
        if ($padr == "any")
565
                $adr['any'] = true;
566
        else if (is_specialnet($padr))
567
                $adr['network'] = $padr;
568
        else {
569
                $adr['address'] = $padr;
570
                if ($pmask != 32)
571
                        $adr['address'] .= "/" . $pmask;
572
        }
573

    
574
        if ($pnot)
575
                $adr['not'] = true;
576
        else
577
                unset($adr['not']);
578

    
579
        if (($pbeginport != 0) && ($pbeginport != "any")) {
580
                if ($pbeginport != $pendport)
581
                        $adr['port'] = $pbeginport . "-" . $pendport;
582
                else
583
                        $adr['port'] = $pbeginport;
584
        }
585

    
586
        if(alias_expand($pbeginport)) {
587
                $adr['port'] = $pbeginport;
588
        }
589
}
590

    
591
function is_specialnet($net) {
592
        global $specialsrcdst;
593

    
594
	if(!$net) 
595
		return false;
596
        if (in_array($net, $specialsrcdst))
597
                return true;
598
        else
599
                return false;
600
}
601

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

    
638

    
639
// Return inline javascript file or CSS to minimizie 
640
// request count going back to server.
641
function outputJavaScriptFileInline($javascript) {
642
	if(file_exists($javascript)) {
643
		echo "\n<script type=\"text/javascript\">\n";
644
		include($javascript);
645
		echo "\n</script>\n";
646
	} else {
647
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
648
	}
649
}
650

    
651

    
652

    
653
function outputCSSPrintFileInline($css) {
654
	if(file_exists($css)) {
655
		echo "\n<style media=\"print\" type=\"text/css\">\n";
656
		include($css);
657
		echo "\n</style>\n";
658
	} else {
659
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
660
	}
661
}
662

    
663

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

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

    
718
function is_rfc2616_code($code) {
719
	global $rfc2616;
720
	if (isset($rfc2616[$code]))
721
		return true;
722
	else
723
		return false;
724
}
725

    
726
function print_rfc2616_select($tag, $current){
727
	global $rfc2616;
728

    
729
	/* Default to 200 OK if not set */
730
	if ($current == "")
731
		$current = 200;
732

    
733
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
734
	foreach($rfc2616 as $code => $message) {
735
		if ($code == $current) {
736
			$sel = " selected";
737
		} else {
738
			$sel = "";
739
		}
740
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
741
	}
742
}
743

    
744
// Useful debugging function, much cleaner than print_r
745
function echo_array($array,$return_me=false){
746
    if(is_array($array) == false){
747
        $return = "The provided variable is not an array.";
748
    }else{
749
        foreach($array as $name=>$value){
750
            if(is_array($value)){
751
                $return .= "";
752
                $return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
753
                $return .= echo_array($value,true);
754
                $return .= "</div>}";
755
                $return .= "\n\n";
756
            }else{
757
                if(is_string($value)){
758
                    $value = "\"$value\"";
759
                }
760
                $return .= "['<b>$name</b>'] = $value\n\n";
761
            }
762
        }
763
    }
764
    if($return_me == true){
765
        return $return;
766
    }else{
767
        echo "<pre>".$return."</pre>";
768
    }
769
}
770

    
771
/****f* pfsense-utils/display_top_tabs
772
 * NAME
773
 *   display_top_tabs - display tabs with rounded edges
774
 * INPUTS
775
 *   $text      - array of tabs
776
 * RESULT
777
 *   null
778
 ******/
779
function display_top_tabs(& $tab_array) {
780
        global $HTTP_SERVER_VARS;
781
        global $config;
782
        global $g;
783

    
784
        /*  does the user have access to this tab?
785
         *  master user has access to everything.
786
         *  if the user does not have access, simply
787
         *  unset the tab item.
788
         */
789

    
790
        $tab_temp = array ();
791
        foreach ($tab_array as $ta)
792
                if(isAllowedPage($ta[2]))
793
                        $tab_temp[] = $ta;
794
        /*
795
                // FIXME :      if the checks are not good enough
796
                //                      in isAllowedPage, it needs to be
797
                //                      fixed instead of kludging here
798

    
799
                // TODO: humm what shall we do with pkg_edit.php and pkg.php?
800
                if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) {
801
                        $pos_equal = strpos($link, "=");
802
                        $pos_xmlsuffix = strpos($link, ".xml");
803
                        // do we match an absolute url including ?xml= foo
804
                        if(!isAllowedPage($link, $allowed))
805
                                $link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3));
806
                }
807
                // next check - what if the basename contains a query string?
808
                if ((strpos($link, "?")) !== false) {
809
                        $pos_qmark = strpos($link, "?");
810
                        $link = substr($link, 0, $pos_qmark);
811
                }
812
                $authorized_text = print_r($allowed, true);
813
                if(is_array($authorized))
814
                        if (in_array(basename($link), $authorized))
815
        */
816

    
817
        unset ($tab_array);
818
        $tab_array = & $tab_temp;
819

    
820
        $tab_active_bg   = "#EEEEEE";
821
        $tab_inactive_bg = "#777777";
822
        $nifty_tabs_corners = "#FFF";
823
        $font_color = "white";
824

    
825
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
826
        $themename = $config['theme'];
827
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
828
        if(file_exists($filename)) {
829
                $eval_code = file_get_contents($filename);
830
                eval($eval_code);
831
        }
832

    
833
        $tabcharcount = 0;
834
        foreach ($tab_array as $ta)
835
                $tabcharcount = $tabcharcount + strlen($ta[0]);
836

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

    
895
function add_package_tabs($tabgroup, & $tab_array) {
896
        global $config, $g;
897

    
898
        if(!is_array($config['installedpackages']))
899
                return;
900
        if(!is_array($config['installedpackages']['tab']))
901
                return;
902

    
903
        foreach($config['installedpackages']['tab'] as $tab) {
904
                if ($tab['group'] !== $group)
905
                        continue;
906
                $tab_entry = array();
907
                if($tab['name']) {
908
                        $tab_entry[] = $tab['name'];
909
                        $tab_entry[] = false;
910
                        $tab_entry[] = $tab['url'];
911
                        $tab_array[] = $tab_entry;
912
                }
913
        }
914
}
915

    
916
function rule_popup($src,$srcport,$dst,$dstport){
917
	global $config;
918
	$aliases_array = array();
919
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
920
	{
921
		$span_begin = "";
922
                $alias_src_span_begin = "";
923
                $alias_src_span_end = "";
924
                $alias_src_port_span_begin = "";
925
                $alias_src_port_span_end = "";
926
                $alias_dst_span_begin = "";
927
                $alias_dst_span_end = "";
928
                $alias_dst_port_span_begin = "";
929
                $alias_dst_port_span_end = "";
930
                $alias_content_text = "";
931
        	foreach($config['aliases']['alias'] as $alias_name)
932
        	{
933
                	$alias_addresses = explode (" ", $alias_name['address']);
934
                	$alias_details = explode ("||", $alias_name['detail']);
935
                	$alias_objects_with_details = "";
936
                	$counter = 0;
937
                	foreach($alias_addresses as $alias_ports_address)
938
                	{
939
                        	$alias_objects_with_details .= $alias_addresses[$counter];
940
                        	$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
941
                        	if ($alias_details[$counter] != "" && $alias_detail_default === False){
942
                                	$alias_objects_with_details .=" - " . $alias_details[$counter];
943
                        	}
944
                        	$alias_objects_with_details .= "<br>";
945
                        	$counter++;
946
                	}
947
                	//max character length for caption field
948
                	$maxlength = 60;
949

    
950
                	$alias_descr_substr = $alias_name['descr'];
951
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
952
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
953
                	$strlength = strlen ($alias_caption);
954
                	if ($strlength >= $maxlength)
955
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
956

    
957
                	$span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>$alias_caption</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>";
958

    
959
                	if ($alias_name['name'] == $src)
960
                        	$alias_src_span_begin = $span_begin;
961
                	if ($alias_name['name'] == $srcport)
962
                        	$alias_src_port_span_begin = $span_begin;
963
                	if ($alias_name['name'] == $dst)
964
                        	$alias_dst_span_begin = $span_begin;
965
                	if ($alias_name['name'] == $dstport)
966
                        	$alias_dst_port_span_begin = $span_begin;
967
        	}
968
        	$descriptions = array ();
969
        	$descriptions['src'] = $alias_src_span_begin;
970
        	$descriptions['srcport'] = $alias_src_port_span_begin;
971
        	$descriptions['dst'] = $alias_dst_span_begin;
972
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
973

    
974
        	return $descriptions;
975
  	}
976
}
977

    
978
?>
(74-74/218)