Project

General

Profile

Download (30.1 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
/* Include authentication routines */
34
/* THIS MUST BE ABOVE ALL OTHER CODE */
35
require_once("authgui.inc");
36

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

    
46
/* parse the configuration and include all configuration functions */
47
require_once("functions.inc");
48

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

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

    
73
/* used by progress bar */
74
$lastseen = "-1";
75

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

    
80
if (is_subsystem_dirty('firmwarelock')) {
81
	if (!$d_isfwfile) {
82
		header("Location: system_firmware.php");
83
		exit;
84
	} else {
85
		return;
86
	}
87
}
88

    
89
$auth_server_types = array(
90
	'ldap' => "LDAP",
91
	'radius' => "Radius");
92

    
93
$ldap_urltypes = array(
94
	'TCP - Standard' => 389,
95
	'SSL - Encrypted' => 636);
96

    
97
$ldap_scopes = array(
98
	'one' => "One Level",
99
	'subtree' => "Entire Subtree");
100

    
101
$ldap_protvers = array(
102
	2,
103
	3);
104

    
105
$ldap_templates = array(
106

    
107
	'open' => array(
108
				'desc' => "OpenLDAP",
109
				'attr_user' => "cn",
110
				'attr_group' => "cn",
111
				'attr_member' => "member"),
112

    
113
	'msad' => array(
114
				'desc' => "Microsoft AD",
115
				'attr_user' => "samAccountNAme",
116
				'attr_group' => "cn",
117
				'attr_member' => "member"),
118

    
119
	'edir' => array(
120
				'desc' => "Novell eDirectory",
121
				'attr_user' => "cn",
122
				'attr_group' => "cn",
123
				'attr_member' => "uniqueMember"));
124

    
125
$radius_srvcs = array(
126
	'both' => "Authentication and Accounting",
127
	'auth' => "Authentication",
128
	'acct' => "Accounting");
129

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

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

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

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

    
189
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
190
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
191
	"10half" => "10BASE-T half-duplex");
192

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

    
196
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
197

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

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

    
212
function print_input_errors($input_errors) {
213
	global $g;
214

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

    
231
	print <<<EOF2
232
				</ul>
233
			</span>
234
		</td></tr>
235
	</table>
236
	</p>&nbsp;<br>
237
EOF2;
238
	
239
}
240

    
241
function verify_gzip_file($fname) {
242

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

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

    
303
}
304

    
305
function print_info_box($msg) {
306
	echo "<p>";
307
	print_info_box_np($msg);
308
	echo "</p>";
309
}
310

    
311
function get_std_save_message($ok) {
312
	global $d_sysrebootreqd_path;
313

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

    
317
function pprint_address($adr) {
318
	global $specialnets;
319

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

    
332
	if (isset($adr['not']))
333
		$padr = "! " . $padr;
334

    
335
	return $padr;
336
}
337

    
338
function pprint_port($port) {
339
	global $wkports;
340

    
341
	$pport = "";
342

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

    
356
	return $pport;
357
}
358

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

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

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

    
375
	usort($config['filter']['rule'], "filtercmp");
376

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

    
382
function aliases_sort() {
383
	global $g, $config;
384

    
385
	function aliascmp($a, $b) {
386
		return strcmp($a['name'], $b['name']);
387
	}
388

    
389
	if($config['aliases'])
390
		usort($config['aliases']['alias'], "aliascmp");
391
}
392

    
393
function gentitle($title) {
394
	global $navlevelsep;
395
	if(!is_array($title))
396
		return $title;
397
	else
398
		return join($navlevelsep, $title); 
399
}
400

    
401
function genhtmltitle($title) {
402
        global $config;
403
        return gentitle($title);
404
}
405

    
406
/* update the changedesc and changecount(er) variables */
407
function update_changedesc($update) {
408
	global $changedesc;
409
	global $changecount;
410

    
411
	$changedesc .= " {$update}";
412
	$changecount++;
413
}
414

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

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

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

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

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

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

    
526
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
527

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

    
538
        if (isset($adr['not']))
539
                $pnot = 1;
540
        else
541
                $pnot = 0;
542

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

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

    
559
        $adr = array();
560

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

    
571
        if ($pnot)
572
                $adr['not'] = true;
573
        else
574
                unset($adr['not']);
575

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

    
583
        if(alias_expand($pbeginport)) {
584
                $adr['port'] = $pbeginport;
585
        }
586
}
587

    
588
function is_specialnet($net) {
589
        global $specialsrcdst;
590

    
591
	if(!$net) 
592
		return false;
593
        if (in_array($net, $specialsrcdst))
594
                return true;
595
        else
596
                return false;
597
}
598

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

    
635

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

    
648

    
649

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

    
660

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

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

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

    
723
function print_rfc2616_select($tag, $current){
724
	global $rfc2616;
725

    
726
	/* Default to 200 OK if not set */
727
	if ($current == "")
728
		$current = 200;
729

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

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

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

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

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

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

    
814
        unset ($tab_array);
815
        $tab_array = & $tab_temp;
816

    
817
        $tab_active_bg   = "#EEEEEE";
818
        $tab_inactive_bg = "#777777";
819
        $nifty_tabs_corners = "#FFF";
820
        $font_color = "white";
821

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

    
830
        $tabcharcount = 0;
831
        foreach ($tab_array as $ta)
832
                $tabcharcount = $tabcharcount + strlen($ta[0]);
833

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

    
892
function add_package_tabs($tabgroup, & $tab_array) {
893
        global $config, $g;
894

    
895
        if(!is_array($config['installedpackages']))
896
                return;
897
        if(!is_array($config['installedpackages']['tab']))
898
                return;
899

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

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

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

    
954
                	$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>";
955

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

    
971
        	return $descriptions;
972
  	}
973
}
974

    
975
?>
(72-72/217)