Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
128
$ldap_templates = array(
129

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

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

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

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

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

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

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

    
209
$specialnets = array("pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
210

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

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

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

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

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

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

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

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

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

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

    
272
function verify_gzip_file($fname) {
273

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

    
281
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
282
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
283

    
284
	// Set the Nifty background color if one is not set already (defaults to white)
285
	if($nifty_background == "")
286
		$nifty_background = "#FFF";
287

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

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

    
344
}
345

    
346
function print_info_box_np_undo($msg, $name="apply",$value="Apply changes", $undo) {
347
	global $g;
348
	
349
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
350
		$savebutton = "<td class='infoboxsave'><nobr>";
351
		$savebutton .= " <input type=\"button\" value=\"Undo\" onClick=\"document.location='{$undo}'\">";
352
		$savebutton .= " <input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\">";
353
		$savebutton.="</nobr></td>";
354
		if($_POST['if']) 
355
			$savebutton .= "<input type='hidden' name='if' value='{$_POST['if']}'>";
356
	}
357
	$nifty_redbox = "#990000";
358
	$nifty_blackbox = "#000000";
359
	
360
	$themename = $g['theme'];
361
	
362
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
363
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
364
		eval($toeval);
365
	}
366
	
367
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
368
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
369
		eval($toeval);
370
	}	
371
	
372
		
373
	if(!$savebutton) {
374
		$savebutton = '<td class="infoboxsave"><input value="Close" type="button" onClick="$(\'redboxtable\').hide();"></td>';
375
	}
376

    
377
	echo <<<EOFnp
378
	<table class='infobox' id='redboxtable'>
379
		<tr>
380
			<td>
381
				<div class='infoboxnp' id='redbox'>
382
					<table class='infoboxnptable2'>
383
						<tr>
384
							<td class='infoboxnptd'>
385
								&nbsp;&nbsp;&nbsp;<img class='infoboxnpimg' src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" >
386
							</td>
387
							<td class='infoboxnptd2'>
388
								<b>{$msg}</b>
389
							</td>
390
							{$savebutton} 
391
							{$undobutton}
392
						</tr>
393
					</table>
394
				</div>
395
				<div>
396
					<p/>
397
				</div>
398
			</td>
399
		</tr>
400
	</table>
401
	<script type="text/javascript">
402
		NiftyCheck();
403
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
404
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
405
	</script>
406
EOFnp;
407

    
408
}
409

    
410
function print_info_box($msg) {
411
	print_info_box_np($msg);
412
}
413

    
414
function get_std_save_message($ok) {
415
	global $d_sysrebootreqd_path;
416

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

    
420
function pprint_address($adr) {
421
	global $specialnets;
422

    
423
	if (isset($adr['any'])) {
424
		$padr = "*";
425
	} else if ($adr['network']) {
426
		$padr = $specialnets[$adr['network']];
427
	} else {
428
		$padr = $adr['address'];
429
	}
430

    
431
	if (isset($adr['not']))
432
		$padr = "! " . $padr;
433

    
434
	return $padr;
435
}
436

    
437
function pprint_port($port) {
438
	global $wkports;
439

    
440
	$pport = "";
441

    
442
	if (!$port)
443
		return "*";
444
	else {
445
		$srcport = explode("-", $port);
446
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
447
			$pport = $srcport[0];
448
			if ($wkports[$srcport[0]]) {
449
				$pport .= " (" . $wkports[$srcport[0]] . ")";
450
			}
451
		} else
452
			$pport .= $srcport[0] . " - " . $srcport[1];
453
	}
454

    
455
	return $pport;
456
}
457

    
458
/* sort by interface only, retain the original order of rules that apply to
459
   the same interface */
460
function filter_rules_sort() {
461
	global $config;
462

    
463
	/* mark each rule with the sequence number (to retain the order while sorting) */
464
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
465
		$config['filter']['rule'][$i]['seq'] = $i;
466

    
467
	function filtercmp($a, $b) {
468
		if ($a['interface'] == $b['interface'])
469
			return $a['seq'] - $b['seq'];
470
		else
471
			return -strcmp($a['interface'], $b['interface']);
472
	}
473

    
474
	usort($config['filter']['rule'], "filtercmp");
475

    
476
	/* strip the sequence numbers again */
477
	for ($i = 0; isset($config['filter']['rule'][$i]); $i++)
478
		unset($config['filter']['rule'][$i]['seq']);
479
}
480

    
481
function gentitle($title) {
482
	global $navlevelsep;
483
	if(!is_array($title))
484
		return $title;
485
	else
486
		return join($navlevelsep, $title);
487
}
488

    
489
function genhtmltitle($title) {
490
        global $config;
491
        return gentitle($title);
492
}
493

    
494
/* update the changedesc and changecount(er) variables */
495
function update_changedesc($update) {
496
	global $changedesc;
497
	global $changecount;
498

    
499
	$changedesc .= " {$update}";
500
	$changecount++;
501
}
502

    
503
function clear_log_file($logfile = "/var/log/system.log") {
504
	global $config, $g;
505
	exec("/usr/bin/killall syslogd");
506
	if(isset($config['system']['disablesyslogclog'])) {
507
		unlink($logfile);
508
		touch($logfile);
509
	} else {
510
		if(isset($config['system']['usefifolog'])) 
511
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
512
		else
513
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
514
	}
515
	system_syslogd_start();	
516
}
517

    
518
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
519
	global $g, $config;
520
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
521
	$logarr = "";
522
	$grepline = "  ";
523
	if(is_array($grepfor))
524
		foreach($grepfor as $agrep)
525
			$grepline .= " | grep \"$agrep\"";
526
	if(is_array($grepinvert))
527
		foreach($grepinvert as $agrep)
528
			$grepline .= " | grep -v \"$agrep\"";
529
	if(file_exists($logfile) && filesize($logfile) == 0) {
530
		$logarr = array("Log file started.");
531
	} else {
532
		if($config['system']['disablesyslogclog']) {
533
			exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
534
		} else {
535
			if(isset($config['system']['usefifolog']))
536
				exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
537
			else
538
				exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
539
		}
540
	}
541
	foreach ($logarr as $logent) {
542
			$logent = preg_split("/\s+/", $logent, 6);
543
			echo "<tr valign=\"top\">\n";
544
			if ($withorig) {
545
					if(isset($config['system']['usefifolog'])) {
546
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
547
						$entry_text = htmlspecialchars($logent[5]);
548
					} else {
549
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
550
						$entry_text = htmlspecialchars($logent[4] . " " . $logent[5]);
551
					}
552
					echo "<td class=\"listlr\" nowrap>{$entry_date_time}</td>\n";
553
					echo "<td class=\"listr\">{$entry_text}</td>\n";
554

    
555
			} else {
556
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
557
			}
558
			echo "</tr>\n";
559
	}
560
}
561

    
562
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
563
	global $g, $config;
564
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
565
	$logarr = "";
566
	$grepline = "  ";
567
	if(is_array($grepfor))
568
		foreach($grepfor as $agrep)
569
			$grepline .= " | grep \"$agrep\"";
570
	if(is_array($grepinvert))
571
		foreach($grepinvert as $agrep)
572
			$grepline .= " | grep -v \"$agrep\"";
573
	if($config['system']['disablesyslogclog']) {
574
		exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
575
	} else {
576
		if(isset($config['system']['usefifolog'])) {
577
			exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);			
578
		} else {
579
			exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
580
		}
581
	}
582
	return($logarr);
583
}
584

    
585
/* Check if variable has changed, update and log if it has
586
 * returns true if var changed
587
 * varname = variable name in plain text
588
 * orig = original value
589
 * new = new value
590
 */
591
function update_if_changed($varname, & $orig, $new) {
592
	if (is_array($orig) && is_array($new)) {
593
		$a_diff = array_diff($orig, $new);
594
		foreach ($a_diff as $diff) {
595
			update_changedesc("removed {$varname}: \"{$diff}\"");
596
		}
597
		$a_diff = array_diff($new, $orig);
598
		foreach ($a_diff as $diff) {
599
			update_changedesc("added {$varname}: \"{$diff}\"");
600
		}
601
		$orig = $new;
602
		return true;
603

    
604
	} else {
605
		if ($orig != $new) {
606
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
607
			$orig = $new;
608
			return true;
609
		}
610
	}
611
	return false;
612
}
613

    
614
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
615

    
616
        if (isset($adr['any']))
617
                $padr = "any";
618
        else if ($adr['network'])
619
                $padr = $adr['network'];
620
        else if ($adr['address']) {
621
                list($padr, $pmask) = explode("/", $adr['address']);
622
                if (!$pmask)
623
                        $pmask = 32;
624
        }
625

    
626
        if (isset($adr['not']))
627
                $pnot = 1;
628
        else
629
                $pnot = 0;
630

    
631
        if ($adr['port']) {
632
                list($pbeginport, $pendport) = explode("-", $adr['port']);
633
                if (!$pendport)
634
                        $pendport = $pbeginport;
635
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
636
		$pbeginport = "any";
637
		$pendport = "any";
638
        }
639
}
640

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

    
643
        $adr = array();
644

    
645
        if ($padr == "any")
646
                $adr['any'] = true;
647
        else if (is_specialnet($padr))
648
                $adr['network'] = $padr;
649
        else {
650
                $adr['address'] = $padr;
651
                if ($pmask != 32)
652
                        $adr['address'] .= "/" . $pmask;
653
        }
654

    
655
        if ($pnot)
656
                $adr['not'] = true;
657
        else
658
                unset($adr['not']);
659

    
660
        if (($pbeginport != 0) && ($pbeginport != "any")) {
661
                if ($pbeginport != $pendport)
662
                        $adr['port'] = $pbeginport . "-" . $pendport;
663
                else
664
                        $adr['port'] = $pbeginport;
665
        }
666

    
667
        if(is_alias($pbeginport)) {
668
                $adr['port'] = $pbeginport;
669
        }
670
}
671

    
672
function is_specialnet($net) {
673
        global $specialsrcdst;
674

    
675
	if(!$net) 
676
		return false;
677
        if (in_array($net, $specialsrcdst))
678
                return true;
679
        else
680
                return false;
681
}
682

    
683
//function to create widget tabs when called
684
function display_widget_tabs(& $tab_array) {	
685
	echo "<div id='tabs'>";
686
	$tabscounter = 0;
687
	foreach ($tab_array as $ta) {
688
	$dashpos = strpos($ta[2],'-');
689
	$tabname = $ta[2] . "-tab";
690
	$tabclass = substr($ta[2],0,$dashpos);
691
	$tabclass = $tabclass . "-class";
692
		if ($ta[1] == true) {
693
			$tabActive = "table-cell";
694
			$tabNonActive = "none";
695
		} 
696
		else {
697
			$tabActive = "none";
698
			$tabNonActive = "table-cell";
699
		}
700
		echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
701
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
702
		echo "&nbsp;&nbsp;&nbsp;</B>";
703
		echo "</div>";
704
		
705
		echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
706
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
707
		echo "&nbsp;&nbsp;&nbsp;</B>";
708
		echo "</div>";
709
	}
710
	
711
	echo "<script type=\"text/javascript\">";
712
	echo "NiftyCheck();\n";
713
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
714
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
715
	echo "</script>";
716
	echo "</div>";
717
}
718

    
719

    
720
// Return inline javascript file or CSS to minimizie 
721
// request count going back to server.
722
function outputJavaScriptFileInline($javascript) {
723
	if(file_exists($javascript)) {
724
		echo "\n<script type=\"text/javascript\">\n";
725
		include($javascript);
726
		echo "\n</script>\n";
727
	} else {
728
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
729
	}
730
}
731

    
732

    
733

    
734
function outputCSSPrintFileInline($css) {
735
	if(file_exists($css)) {
736
		echo "\n<style media=\"print\" type=\"text/css\">\n";
737
		include($css);
738
		echo "\n</style>\n";
739
	} else {
740
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
741
	}
742
}
743

    
744

    
745
function outputCSSFileInline($css) {
746
	if(file_exists($css)) {
747
		echo "\n<style type=\"text/css\">\n";
748
		include($css);
749
		echo "\n</style>\n";
750
	} else {
751
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
752
	}
753
}
754

    
755
$rfc2616 = array(
756
	100 => "100 Continue",
757
	101 => "101 Switching Protocols",
758
	200 => "200 OK",
759
	201 => "201 Created",
760
	202 => "202 Accepted",
761
	203 => "203 Non-Authoritative Information",
762
	204 => "204 No Content",
763
	205 => "205 Reset Content",
764
	206 => "206 Partial Content",
765
	300 => "300 Multiple Choices",
766
	301 => "301 Moved Permanently",
767
	302 => "302 Found",
768
	303 => "303 See Other",
769
	304 => "304 Not Modified",
770
	305 => "305 Use Proxy",
771
	306 => "306 (Unused)",
772
	307 => "307 Temporary Redirect",
773
	400 => "400 Bad Request",
774
	401 => "401 Unauthorized",
775
	402 => "402 Payment Required",
776
	403 => "403 Forbidden",
777
	404 => "404 Not Found",
778
	405 => "405 Method Not Allowed",
779
	406 => "406 Not Acceptable",
780
	407 => "407 Proxy Authentication Required",
781
	408 => "408 Request Timeout",
782
	409 => "409 Conflict",
783
	410 => "410 Gone",
784
	411 => "411 Length Required",
785
	412 => "412 Precondition Failed",
786
	413 => "413 Request Entity Too Large",
787
	414 => "414 Request-URI Too Long",
788
	415 => "415 Unsupported Media Type",
789
	416 => "416 Requested Range Not Satisfiable",
790
	417 => "417 Expectation Failed",
791
	500 => "500 Internal Server Error",
792
	501 => "501 Not Implemented",
793
	502 => "502 Bad Gateway",
794
	503 => "503 Service Unavailable",
795
	504 => "504 Gateway Timeout",
796
	505 => "505 HTTP Version Not Supported"
797
);
798

    
799
function is_rfc2616_code($code) {
800
	global $rfc2616;
801
	if (isset($rfc2616[$code]))
802
		return true;
803
	else
804
		return false;
805
}
806

    
807
function print_rfc2616_select($tag, $current){
808
	global $rfc2616;
809

    
810
	/* Default to 200 OK if not set */
811
	if ($current == "")
812
		$current = 200;
813

    
814
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
815
	foreach($rfc2616 as $code => $message) {
816
		if ($code == $current) {
817
			$sel = " selected";
818
		} else {
819
			$sel = "";
820
		}
821
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
822
	}
823
}
824

    
825
// Useful debugging function, much cleaner than print_r
826
function echo_array($array,$return_me=false){
827
    if(is_array($array) == false){
828
        $return = "The provided variable is not an array.";
829
    }else{
830
        foreach($array as $name=>$value){
831
            if(is_array($value)){
832
                $return .= "";
833
                $return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
834
                $return .= echo_array($value,true);
835
                $return .= "</div>}";
836
                $return .= "\n\n";
837
            }else{
838
                if(is_string($value)){
839
                    $value = "\"$value\"";
840
                }
841
                $return .= "['<b>$name</b>'] = $value\n\n";
842
            }
843
        }
844
    }
845
    if($return_me == true){
846
        return $return;
847
    }else{
848
        echo "<pre>".$return."</pre>";
849
    }
850
}
851

    
852
/****f* pfsense-utils/display_top_tabs
853
 * NAME
854
 *   display_top_tabs - display tabs with rounded edges
855
 * INPUTS
856
 *   $text      - array of tabs
857
 * RESULT
858
 *   null
859
 ******/
860
function display_top_tabs(& $tab_array) {
861
        global $HTTP_SERVER_VARS;
862
        global $config;
863
        global $g;
864

    
865
        /*  does the user have access to this tab?
866
         *  master user has access to everything.
867
         *  if the user does not have access, simply
868
         *  unset the tab item.
869
         */
870

    
871
        $tab_temp = array ();
872
        foreach ($tab_array as $ta)
873
                if(isAllowedPage($ta[2]))
874
                        $tab_temp[] = $ta;
875
        /*
876
                // FIXME :      if the checks are not good enough
877
                //                      in isAllowedPage, it needs to be
878
                //                      fixed instead of kludging here
879

    
880
                // TODO: humm what shall we do with pkg_edit.php and pkg.php?
881
                if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) {
882
                        $pos_equal = strpos($link, "=");
883
                        $pos_xmlsuffix = strpos($link, ".xml");
884
                        // do we match an absolute url including ?xml= foo
885
                        if(!isAllowedPage($link, $allowed))
886
                                $link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3));
887
                }
888
                // next check - what if the basename contains a query string?
889
                if ((strpos($link, "?")) !== false) {
890
                        $pos_qmark = strpos($link, "?");
891
                        $link = substr($link, 0, $pos_qmark);
892
                }
893
                $authorized_text = print_r($allowed, true);
894
                if(is_array($authorized))
895
                        if (in_array(basename($link), $authorized))
896
        */
897

    
898
        unset ($tab_array);
899
        $tab_array = & $tab_temp;
900

    
901
        $tab_active_bg   = "#EEEEEE";
902
        $tab_inactive_bg = "#777777";
903
        $nifty_tabs_corners = "#FFF";
904
        $font_color = "white";
905

    
906
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
907
        $themename = $config['theme'];
908
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
909
        if(file_exists($filename)) {
910
                $eval_code = file_get_contents($filename);
911
                eval($eval_code);
912
        }
913

    
914
        $tabcharcount = 0;
915
        foreach ($tab_array as $ta)
916
                $tabcharcount = $tabcharcount + strlen($ta[0]);
917

    
918
        // If the character count of the tab names is > 670
919
        // then show a select item dropdown menubox.
920
        if($tabcharcount > 82) {
921
                echo "Currently viewing: ";
922
                echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
923
                foreach ($tab_array as $ta) {
924
                        if($ta[1]=="true")
925
                                $selected = " SELECTED";
926
                        else
927
                                $selected = "";
928
                        // Onclick in option will not work in some browser
929
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
930
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
931
                }
932
                echo "</select>\n<p/>";
933
                echo "<script type=\"text/javascript\">";
934
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
935
                echo "</script>";
936
        }  else {
937
                echo "<table cellpadding='0' cellspacing='0'>\n";
938
                echo " <tr>\n";
939
                $tabscounter = 0;
940
                foreach ($tab_array as $ta) {
941
                        if ($ta[1] == true) {
942
                                echo "  <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabactive'></div></td>\n";
943
                        } else {
944
                                echo "  <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><div id='tabdeactive{$tabscounter}'></div></td>\n";
945
                        }
946
                        $tabscounter++;
947
                }
948
                echo "</tr>\n<tr>\n";
949
                foreach ($tab_array as $ta) {
950
                        if ($ta[1] == true) {
951
                                echo "  <td height=\"15\" valign=\"middle\" bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"><B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
952
                                echo "&nbsp;&nbsp;&nbsp;";
953
                                echo "<font size='-12'>&nbsp;</font></B></td>\n";
954
                        } else {
955
                                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[
956
2]}'>";
957
                                echo "<font color='{$font_color}'>{$ta[0]}</font></a>&nbsp;&nbsp;&nbsp;";
958
                                echo "<font size='-12'>&nbsp;</font></B></td>\n";
959
                        }
960
                }
961
                echo "</tr>\n<tr>\n";
962
                foreach ($tab_array as $ta) {
963
                        if ($ta[1] == true) {
964
                                echo "  <td bgcolor='{$tab_active_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
965
                        } else {
966
                                echo "  <td bgcolor='{$tab_inactive_bg}' onClick=\"document.location='{$ta[2]}'\" style=\"cursor: pointer;\"></td>\n";
967
                        }
968
                        $tabscounter++;
969
                }
970
                echo " </tr>\n";
971
                echo "</table>\n";
972
                echo "<script type=\"text/javascript\">";
973
                echo "NiftyCheck();\n";
974
                echo "Rounded(\"div#tabactive\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_active_bg}\",\"smooth\");\n";
975
                for ($x = 0; $x < $tabscounter; $x++)
976
                        echo "Rounded(\"div#tabdeactive{$x}\",\"top\",\"{$nifty_tabs_corners}\",\"{$tab_inactive_bg}\",\"smooth\");\n";
977
                echo "</script>";
978
        }
979
}
980

    
981
function add_package_tabs($tabgroup, & $tab_array) {
982
        global $config, $g;
983

    
984
        if(!is_array($config['installedpackages']))
985
                return;
986
        if(!is_array($config['installedpackages']['tab']))
987
                return;
988

    
989
        foreach($config['installedpackages']['tab'] as $tab) {
990
                if ($tab['group'] !== $group)
991
                        continue;
992
                $tab_entry = array();
993
                if($tab['name']) {
994
                        $tab_entry[] = $tab['name'];
995
                        $tab_entry[] = false;
996
                        $tab_entry[] = $tab['url'];
997
                        $tab_array[] = $tab_entry;
998
                }
999
        }
1000
}
1001

    
1002
function rule_popup($src,$srcport,$dst,$dstport){
1003
	global $config;
1004
	$aliases_array = array();
1005
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1006
	{
1007
		$span_begin = "";
1008
                $alias_src_span_begin = "";
1009
                $alias_src_span_end = "";
1010
                $alias_src_port_span_begin = "";
1011
                $alias_src_port_span_end = "";
1012
                $alias_dst_span_begin = "";
1013
                $alias_dst_span_end = "";
1014
                $alias_dst_port_span_begin = "";
1015
                $alias_dst_port_span_end = "";
1016
                $alias_content_text = "";
1017
        	foreach($config['aliases']['alias'] as $alias_name)
1018
        	{
1019
                	$alias_addresses = explode (" ", $alias_name['address']);
1020
                	$alias_details = explode ("||", $alias_name['detail']);
1021
                	$alias_objects_with_details = "";
1022
                	$counter = 0;
1023
			if ($alias_name['url']) {
1024
				$alias_objects_with_details .= $alias_name['url'] . "<br/>";
1025
			}
1026
                	foreach($alias_addresses as $alias_ports_address)
1027
                	{
1028
                        	$alias_objects_with_details .= $alias_addresses[$counter];
1029
                        	$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
1030
                        	if ($alias_details[$counter] != "" && $alias_detail_default === False){
1031
                                	$alias_objects_with_details .=" - " . $alias_details[$counter];
1032
                        	}
1033
                        	$alias_objects_with_details .= "<br>";
1034
                        	$counter++;
1035
                	}
1036
                	//max character length for caption field
1037
                	$maxlength = 60;
1038

    
1039
                	$alias_descr_substr = $alias_name['descr'];
1040
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
1041
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
1042
                	$strlength = strlen ($alias_caption);
1043
                	if ($strlength >= $maxlength)
1044
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
1045

    
1046
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
1047
			$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>";
1048

    
1049
                	if ($alias_name['name'] == $src)
1050
                        	$alias_src_span_begin = $span_begin;
1051
                	if ($alias_name['name'] == $srcport)
1052
                        	$alias_src_port_span_begin = $span_begin;
1053
                	if ($alias_name['name'] == $dst)
1054
                        	$alias_dst_span_begin = $span_begin;
1055
                	if ($alias_name['name'] == $dstport)
1056
                        	$alias_dst_port_span_begin = $span_begin;
1057
        	}
1058
        	$descriptions = array ();
1059
        	$descriptions['src'] = $alias_src_span_begin;
1060
        	$descriptions['srcport'] = $alias_src_port_span_begin;
1061
        	$descriptions['dst'] = $alias_dst_span_begin;
1062
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
1063

    
1064
        	return $descriptions;
1065
  	}
1066
}
1067

    
1068
?>
(74-74/222)