Project

General

Profile

Download (32.4 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
		global $tab_array_indent;
865
		global $tab_array_space;
866
		global $tab_array_char_limit;
867
		
868
        /*  does the user have access to this tab?
869
         *  master user has access to everything.
870
         *  if the user does not have access, simply
871
         *  unset the tab item.
872
         */
873
		 
874
		/* empty string code */ 
875
		if ($tab_array_indent == '')
876
		{
877
			$tab_array_indent = 0;
878
		}
879
		if ($tab_array_space == '')
880
		{
881
			$tab_array_space = 1;
882
		}
883
		if ($tab_array_char_limit == '')
884
		{
885
			$tab_array_char_limit = 82;
886
		}
887

    
888
        $tab_temp = array ();
889
        foreach ($tab_array as $ta)
890
                if(isAllowedPage($ta[2]))
891
                        $tab_temp[] = $ta;
892
        /*
893
                // FIXME :      if the checks are not good enough
894
                //                      in isAllowedPage, it needs to be
895
                //                      fixed instead of kludging here
896

    
897
                // TODO: humm what shall we do with pkg_edit.php and pkg.php?
898
                if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) {
899
                        $pos_equal = strpos($link, "=");
900
                        $pos_xmlsuffix = strpos($link, ".xml");
901
                        // do we match an absolute url including ?xml= foo
902
                        if(!isAllowedPage($link, $allowed))
903
                                $link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3));
904
                }
905
                // next check - what if the basename contains a query string?
906
                if ((strpos($link, "?")) !== false) {
907
                        $pos_qmark = strpos($link, "?");
908
                        $link = substr($link, 0, $pos_qmark);
909
                }
910
                $authorized_text = print_r($allowed, true);
911
                if(is_array($authorized))
912
                        if (in_array(basename($link), $authorized))
913
        */
914

    
915
        unset ($tab_array);
916
        $tab_array = & $tab_temp;
917

    
918
        $tab_active_bg   = "#EEEEEE";
919
        $tab_inactive_bg = "#777777";
920
        $nifty_tabs_corners = "#FFF";
921
        $font_color = "white";
922

    
923
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
924
        $themename = $config['theme'];
925
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
926
        if(file_exists($filename)) {
927
                $eval_code = file_get_contents($filename);
928
                eval($eval_code);
929
        }
930

    
931
        $tabcharcount = 0;
932
        foreach ($tab_array as $ta)
933
                $tabcharcount = $tabcharcount + strlen($ta[0]);
934

    
935
        // If the character count of the tab names is > 670
936
        // then show a select item dropdown menubox.
937
         if($tabcharcount > $tab_array_char_limit) {
938
                echo "Currently viewing: ";
939
                echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
940
                foreach ($tab_array as $ta) {
941
                        if($ta[1]=="true")
942
                                $selected = " SELECTED";
943
                        else
944
                                $selected = "";
945
                        // Onclick in option will not work in some browser
946
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
947
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
948
                }
949
                echo "</select>\n<p/>";
950
                echo "<script type=\"text/javascript\">";
951
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
952
                echo "</script>";
953
        }  else {
954
		//////>>>
955
                echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
956
                echo "<!-- Tabbed bar code-->\n";
957
				echo "<ul class=\"newtabmenu\">\n";
958
                $tabscounter = 0;
959
                foreach ($tab_array as $ta) {
960
                        if ($ta[1] == true) {
961
								echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
962
                        } else {
963
								echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
964
                        }
965
                        $tabscounter++;
966
                }
967
                echo "</ul>\n</div>\n";
968
		////////>>>>
969
        }
970
}
971

    
972
function add_package_tabs($tabgroup, & $tab_array) {
973
        global $config, $g;
974

    
975
        if(!is_array($config['installedpackages']))
976
                return;
977
        if(!is_array($config['installedpackages']['tab']))
978
                return;
979

    
980
        foreach($config['installedpackages']['tab'] as $tab) {
981
                if ($tab['group'] !== $group)
982
                        continue;
983
                $tab_entry = array();
984
                if($tab['name']) {
985
                        $tab_entry[] = $tab['name'];
986
                        $tab_entry[] = false;
987
                        $tab_entry[] = $tab['url'];
988
                        $tab_array[] = $tab_entry;
989
                }
990
        }
991
}
992

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

    
1030
                	$alias_descr_substr = $alias_name['descr'];
1031
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
1032
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
1033
                	$strlength = strlen ($alias_caption);
1034
                	if ($strlength >= $maxlength)
1035
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
1036

    
1037
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
1038
			$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>";
1039

    
1040
                	if ($alias_name['name'] == $src)
1041
                        	$alias_src_span_begin = $span_begin;
1042
                	if ($alias_name['name'] == $srcport)
1043
                        	$alias_src_port_span_begin = $span_begin;
1044
                	if ($alias_name['name'] == $dst)
1045
                        	$alias_dst_span_begin = $span_begin;
1046
                	if ($alias_name['name'] == $dstport)
1047
                        	$alias_dst_port_span_begin = $span_begin;
1048
        	}
1049
        	$descriptions = array ();
1050
        	$descriptions['src'] = $alias_src_span_begin;
1051
        	$descriptions['srcport'] = $alias_src_port_span_begin;
1052
        	$descriptions['dst'] = $alias_dst_span_begin;
1053
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
1054

    
1055
        	return $descriptions;
1056
  	}
1057
}
1058

    
1059
?>
(74-74/222)