Project

General

Profile

Download (30.6 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 gentitle($title) {
406
	global $navlevelsep;
407
	if(!is_array($title))
408
		return $title;
409
	else
410
		return join($navlevelsep, $title);
411
}
412

    
413
function genhtmltitle($title) {
414
        global $config;
415
        return gentitle($title);
416
}
417

    
418
/* update the changedesc and changecount(er) variables */
419
function update_changedesc($update) {
420
	global $changedesc;
421
	global $changecount;
422

    
423
	$changedesc .= " {$update}";
424
	$changecount++;
425
}
426

    
427
function clear_log_file($logfile = "/var/log/system.log") {
428
	global $config, $g;
429
	exec("/usr/bin/killall syslogd");
430
	if(isset($config['system']['disablesyslogclog'])) {
431
		unlink($logfile);
432
		touch($logfile);
433
	} else {
434
		if(isset($config['system']['usefifolog'])) 
435
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
436
		else
437
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
438
	}
439
	system_syslogd_start();	
440
}
441

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

    
479
			} else {
480
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
481
			}
482
			echo "</tr>\n";
483
	}
484
}
485

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

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

    
528
	} else {
529
		if ($orig != $new) {
530
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
531
			$orig = $new;
532
			return true;
533
		}
534
	}
535
	return false;
536
}
537

    
538
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
539

    
540
        if (isset($adr['any']))
541
                $padr = "any";
542
        else if ($adr['network'])
543
                $padr = $adr['network'];
544
        else if ($adr['address']) {
545
                list($padr, $pmask) = explode("/", $adr['address']);
546
                if (!$pmask)
547
                        $pmask = 32;
548
        }
549

    
550
        if (isset($adr['not']))
551
                $pnot = 1;
552
        else
553
                $pnot = 0;
554

    
555
        if ($adr['port']) {
556
                list($pbeginport, $pendport) = explode("-", $adr['port']);
557
                if (!$pendport)
558
                        $pendport = $pbeginport;
559
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
560
		$pbeginport = "any";
561
		$pendport = "any";
562
        }
563
}
564

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

    
567
        $adr = array();
568

    
569
        if ($padr == "any")
570
                $adr['any'] = true;
571
        else if (is_specialnet($padr))
572
                $adr['network'] = $padr;
573
        else {
574
                $adr['address'] = $padr;
575
                if ($pmask != 32)
576
                        $adr['address'] .= "/" . $pmask;
577
        }
578

    
579
        if ($pnot)
580
                $adr['not'] = true;
581
        else
582
                unset($adr['not']);
583

    
584
        if (($pbeginport != 0) && ($pbeginport != "any")) {
585
                if ($pbeginport != $pendport)
586
                        $adr['port'] = $pbeginport . "-" . $pendport;
587
                else
588
                        $adr['port'] = $pbeginport;
589
        }
590

    
591
        if(is_alias($pbeginport)) {
592
                $adr['port'] = $pbeginport;
593
        }
594
}
595

    
596
function is_specialnet($net) {
597
        global $specialsrcdst;
598

    
599
	if(!$net) 
600
		return false;
601
        if (in_array($net, $specialsrcdst))
602
                return true;
603
        else
604
                return false;
605
}
606

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

    
643

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

    
656

    
657

    
658
function outputCSSPrintFileInline($css) {
659
	if(file_exists($css)) {
660
		echo "\n<style media=\"print\" type=\"text/css\">\n";
661
		include($css);
662
		echo "\n</style>\n";
663
	} else {
664
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
665
	}
666
}
667

    
668

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

    
723
function is_rfc2616_code($code) {
724
	global $rfc2616;
725
	if (isset($rfc2616[$code]))
726
		return true;
727
	else
728
		return false;
729
}
730

    
731
function print_rfc2616_select($tag, $current){
732
	global $rfc2616;
733

    
734
	/* Default to 200 OK if not set */
735
	if ($current == "")
736
		$current = 200;
737

    
738
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
739
	foreach($rfc2616 as $code => $message) {
740
		if ($code == $current) {
741
			$sel = " selected";
742
		} else {
743
			$sel = "";
744
		}
745
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
746
	}
747
}
748

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

    
776
/****f* pfsense-utils/display_top_tabs
777
 * NAME
778
 *   display_top_tabs - display tabs with rounded edges
779
 * INPUTS
780
 *   $text      - array of tabs
781
 * RESULT
782
 *   null
783
 ******/
784
function display_top_tabs(& $tab_array) {
785
        global $HTTP_SERVER_VARS;
786
        global $config;
787
        global $g;
788

    
789
        /*  does the user have access to this tab?
790
         *  master user has access to everything.
791
         *  if the user does not have access, simply
792
         *  unset the tab item.
793
         */
794

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

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

    
822
        unset ($tab_array);
823
        $tab_array = & $tab_temp;
824

    
825
        $tab_active_bg   = "#EEEEEE";
826
        $tab_inactive_bg = "#777777";
827
        $nifty_tabs_corners = "#FFF";
828
        $font_color = "white";
829

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

    
838
        $tabcharcount = 0;
839
        foreach ($tab_array as $ta)
840
                $tabcharcount = $tabcharcount + strlen($ta[0]);
841

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

    
905
function add_package_tabs($tabgroup, & $tab_array) {
906
        global $config, $g;
907

    
908
        if(!is_array($config['installedpackages']))
909
                return;
910
        if(!is_array($config['installedpackages']['tab']))
911
                return;
912

    
913
        foreach($config['installedpackages']['tab'] as $tab) {
914
                if ($tab['group'] !== $group)
915
                        continue;
916
                $tab_entry = array();
917
                if($tab['name']) {
918
                        $tab_entry[] = $tab['name'];
919
                        $tab_entry[] = false;
920
                        $tab_entry[] = $tab['url'];
921
                        $tab_array[] = $tab_entry;
922
                }
923
        }
924
}
925

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

    
960
                	$alias_descr_substr = $alias_name['descr'];
961
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
962
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
963
                	$strlength = strlen ($alias_caption);
964
                	if ($strlength >= $maxlength)
965
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
966

    
967
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
968
			$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>";
969

    
970
                	if ($alias_name['name'] == $src)
971
                        	$alias_src_span_begin = $span_begin;
972
                	if ($alias_name['name'] == $srcport)
973
                        	$alias_src_port_span_begin = $span_begin;
974
                	if ($alias_name['name'] == $dst)
975
                        	$alias_dst_span_begin = $span_begin;
976
                	if ($alias_name['name'] == $dstport)
977
                        	$alias_dst_port_span_begin = $span_begin;
978
        	}
979
        	$descriptions = array ();
980
        	$descriptions['src'] = $alias_src_span_begin;
981
        	$descriptions['srcport'] = $alias_src_port_span_begin;
982
        	$descriptions['dst'] = $alias_dst_span_begin;
983
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
984

    
985
        	return $descriptions;
986
  	}
987
}
988

    
989
?>
(72-72/215)