Project

General

Profile

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
94
$firewall_rules_dscp_types = array("af11", 
95
				"af12", 
96
				"af13", 
97
				"af21", 
98
				"af22", 
99
				"af23", 
100
				"af31", 
101
				"af32", 
102
				"af33", 
103
				"af41", 
104
				"af42", 
105
				"af43", 
106
				"EF", 
107
				"1-64", 
108
				"0x10",
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' => "memberOf"),
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
/* TCP flags */
206
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg");
207

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

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

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

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

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

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

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

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

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

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

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

    
271
function verify_gzip_file($fname) {
272

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

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

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

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

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

    
343
}
344

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

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

    
407
}
408

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

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

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

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

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

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

    
433
	return $padr;
434
}
435

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

    
439
	$pport = "";
440

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

    
454
	return $pport;
455
}
456

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
642
        $adr = array();
643

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

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

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

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

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

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

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

    
718

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

    
731

    
732

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

    
743

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

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

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

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

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

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

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

    
851
/****f* pfsense-utils/display_top_tabs
852
 * NAME
853
 *   display_top_tabs - display tabs with rounded edges
854
 * INPUTS
855
 *   $text      - array of tabs
856
 * RESULT
857
 *   null
858
 ******/
859
function display_top_tabs(& $tab_array) {
860
        global $HTTP_SERVER_VARS;
861
        global $config;
862
        global $g;
863
		global $tab_array_indent;
864
		global $tab_array_space;
865
		global $tab_array_char_limit;
866
		
867
        /*  does the user have access to this tab?
868
         *  master user has access to everything.
869
         *  if the user does not have access, simply
870
         *  unset the tab item.
871
         */
872
		 
873
		/* empty string code */ 
874
		if ($tab_array_indent == '')
875
		{
876
			$tab_array_indent = 0;
877
		}
878
		if ($tab_array_space == '')
879
		{
880
			$tab_array_space = 1;
881
		}
882
		if ($tab_array_char_limit == '')
883
		{
884
			$tab_array_char_limit = 82;
885
		}
886

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1054
        	return $descriptions;
1055
  	}
1056
}
1057

    
1058
?>
(74-74/222)