Project

General

Profile

Download (32.6 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
if(!$nocsrf) {
38
	function csrf_startup() {
39
		csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
40
	}
41
	require_once("csrf/csrf-magic.php");
42
}
43
require_once("authgui.inc");
44

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

    
54
/* parse the configuration and include all configuration functions */
55
require_once("functions.inc");
56

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

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

    
81
/* used by progress bar */
82
$lastseen = "-1";
83

    
84
$navlevelsep = ": ";	/* navigation level separator string */
85
$mandfldhtml = "";		/* display this before mandatory input fields */
86
$mandfldhtmlspc = "";	/* same as above, but with spacing */
87

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

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

    
117
$auth_server_types = array(
118
	'ldap' => "LDAP",
119
	'radius' => "Radius");
120

    
121
$ldap_urltypes = array(
122
	'TCP - Standard' => 389,
123
	'SSL - Encrypted' => 636);
124

    
125
$ldap_scopes = array(
126
	'one' => "One Level",
127
	'subtree' => "Entire Subtree");
128

    
129
$ldap_protvers = array(
130
	2,
131
	3);
132

    
133
$ldap_templates = array(
134

    
135
	'open' => array(
136
				'desc' => "OpenLDAP",
137
				'attr_user' => "cn",
138
				'attr_group' => "cn",
139
				'attr_member' => "member"),
140

    
141
	'msad' => array(
142
				'desc' => "Microsoft AD",
143
				'attr_user' => "samAccountName",
144
				'attr_group' => "cn",
145
				'attr_member' => "memberOf"),
146

    
147
	'edir' => array(
148
				'desc' => "Novell eDirectory",
149
				'attr_user' => "cn",
150
				'attr_group' => "cn",
151
				'attr_member' => "uniqueMember"));
152

    
153
$radius_srvcs = array(
154
	'both' => "Authentication and Accounting",
155
	'auth' => "Authentication",
156
	'acct' => "Accounting");
157

    
158
$netbios_nodetypes = array(
159
	'0' => "none",
160
	'1' => "b-node",
161
	'2' => "p-node",
162
	'4' => "m-node",
163
	'5' => "h-node");
164

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

    
211
/* TCP flags */
212
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg");
213

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

    
216
$spiflist = get_configured_interface_with_descr(false, true);
217
foreach ($spiflist as $ifgui => $ifdesc) {
218
	$specialnets[$ifgui] = $ifdesc . " net";
219
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
220
}
221

    
222
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
223
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
224
	"10half" => "10BASE-T half-duplex");
225

    
226
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
227
	"hostap" => "Access Point");
228

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

    
232
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
233

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

    
241
	for ($i = 0; $i < count($reqdfields); $i++) {
242
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
243
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
244
		}
245
	}
246
}
247

    
248
function print_input_errors($input_errors) {
249
	global $g;
250

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

    
267
	print <<<EOF2
268
				</ul>
269
			</span>
270
		</td></tr>
271
	</table>
272
	</p>&nbsp;<br>
273
EOF2;
274
	
275
}
276

    
277
function verify_gzip_file($fname) {
278

    
279
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
280
	if ($returnvar != 0)
281
		return 0;
282
	else
283
		return 1;
284
}
285

    
286
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
287
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
288

    
289
	// Set the Nifty background color if one is not set already (defaults to white)
290
	if($nifty_background == "")
291
		$nifty_background = "#FFF";
292

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

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

    
349
}
350

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

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

    
413
}
414

    
415
function print_info_box($msg) {
416
	print_info_box_np($msg);
417
}
418

    
419
function get_std_save_message($ok) {
420
	global $d_sysrebootreqd_path;
421

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

    
425
function pprint_address($adr) {
426
	global $specialnets;
427

    
428
	if (isset($adr['any'])) {
429
		$padr = "*";
430
	} else if ($adr['network']) {
431
		$padr = $specialnets[$adr['network']];
432
	} else {
433
		$padr = $adr['address'];
434
	}
435

    
436
	if (isset($adr['not']))
437
		$padr = "! " . $padr;
438

    
439
	return $padr;
440
}
441

    
442
function pprint_port($port) {
443
	global $wkports;
444

    
445
	$pport = "";
446

    
447
	if (!$port)
448
		return "*";
449
	else {
450
		$srcport = explode("-", $port);
451
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
452
			$pport = $srcport[0];
453
			if ($wkports[$srcport[0]]) {
454
				$pport .= " (" . $wkports[$srcport[0]] . ")";
455
			}
456
		} else
457
			$pport .= $srcport[0] . " - " . $srcport[1];
458
	}
459

    
460
	return $pport;
461
}
462

    
463
function firewall_check_for_advanced_options(&$item) {
464
        $item_set = "";
465
        if($item['max'])
466
                $item_set .= "max {$item['max']} ";
467
        if($item['max-src-nodes'])
468
                $item_set .= "max-src-nodes {$item['max-src-nodes']} ";
469
        if($item['max-src-conn'])
470
                $item_set .= "max-src-conn {$item['max-src-conn']} ";
471
        if($item['max-src-states'])
472
                $item_set .= "max-src-states {$item['max-src-states']} ";
473
        if($item['statetype'] != "keep state" && $item['statetype'] != "")
474
                $item_set .= "statetype {$item['statetype']} ";
475
        if($item['statetimeout'])
476
                $item_set .= "statetimeout {$item['statetimeout']} ";
477
        if($item['nosync'])
478
                $item_set .= "nosync ";
479
        if($item['max-src-conn-rate'])
480
                $item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
481
        if($item['max-src-conn-rates'])
482
                $item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
483
        if($item['gateway'])
484
                $item_set .= "gateway {$item['gateway']} ";
485
        if($item['dnpipe'])
486
                $item_set .= "limiter {$item['dnpipe']} ";
487
        if($item['pdnpipe'])
488
                $item_set .= "limiter {$item['pdnpipe']} ";
489
        if($item['l7container'])
490
                $item_set .= "layer7 {$item['l7container']} ";
491
        if($item['tag'])
492
                $item_set .= "tag {$item['tag']} ";
493
        if($item['tagged'])
494
                $item_set .= "tagged {$item['tagged']} ";
495
        if(isset($item['allowopts']))
496
                $item_set .= "allowopts ";
497
        if(isset($item['disablereplyto']))
498
                $item_set .= "disable reply-to ";
499
        if($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2'])
500
                $item_set .= "tcpflags set";
501

    
502
        return $item_set;
503
}
504

    
505
function gentitle($title) {
506
	global $navlevelsep;
507
	if(!is_array($title))
508
		return $title;
509
	else
510
		return join($navlevelsep, $title);
511
}
512

    
513
function genhtmltitle($title) {
514
        global $config;
515
        return gentitle($title);
516
}
517

    
518
/* update the changedesc and changecount(er) variables */
519
function update_changedesc($update) {
520
	global $changedesc;
521
	global $changecount;
522

    
523
	$changedesc .= " {$update}";
524
	$changecount++;
525
}
526

    
527
function clear_log_file($logfile = "/var/log/system.log") {
528
	global $config, $g;
529
	exec("/usr/bin/killall syslogd");
530
	if(isset($config['system']['disablesyslogclog'])) {
531
		unlink($logfile);
532
		touch($logfile);
533
	} else {
534
		if(isset($config['system']['usefifolog'])) 
535
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
536
		else
537
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
538
	}
539
	system_syslogd_start();	
540
}
541

    
542
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
543
	global $g, $config;
544
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
545
	$logarr = "";
546
	$grepline = "  ";
547
	if(is_array($grepfor))
548
		foreach($grepfor as $agrep)
549
			$grepline .= " | grep \"$agrep\"";
550
	if(is_array($grepinvert))
551
		foreach($grepinvert as $agrep)
552
			$grepline .= " | grep -v \"$agrep\"";
553
	if(file_exists($logfile) && filesize($logfile) == 0) {
554
		$logarr = array("Log file started.");
555
	} else {
556
		if($config['system']['disablesyslogclog']) {
557
			exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
558
		} else {
559
			if(isset($config['system']['usefifolog']))
560
				exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
561
			else
562
				exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
563
		}
564
	}
565
	foreach ($logarr as $logent) {
566
			$logent = preg_split("/\s+/", $logent, 6);
567
			echo "<tr valign=\"top\">\n";
568
			if ($withorig) {
569
					if(isset($config['system']['usefifolog'])) {
570
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
571
						$entry_text = htmlspecialchars($logent[5]);
572
					} else {
573
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
574
						$entry_text = htmlspecialchars($logent[4] . " " . $logent[5]);
575
					}
576
					echo "<td class=\"listlr\" nowrap>{$entry_date_time}</td>\n";
577
					echo "<td class=\"listr\">{$entry_text}</td>\n";
578

    
579
			} else {
580
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
581
			}
582
			echo "</tr>\n";
583
	}
584
}
585

    
586
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
587
	global $g, $config;
588
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
589
	$logarr = "";
590
	$grepline = "  ";
591
	if(is_array($grepfor))
592
		foreach($grepfor as $agrep)
593
			$grepline .= " | grep \"$agrep\"";
594
	if(is_array($grepinvert))
595
		foreach($grepinvert as $agrep)
596
			$grepline .= " | grep -v \"$agrep\"";
597
	if($config['system']['disablesyslogclog']) {
598
		exec("cat {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);
599
	} else {
600
		if(isset($config['system']['usefifolog'])) {
601
			exec("/usr/sbin/fifolog_reader {$logfile}{$grepline} | /usr/bin/tail {$sor} -n {$tail}", $logarr);			
602
		} else {
603
			exec("/usr/sbin/clog {$logfile}{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n {$tail}", $logarr);
604
		}
605
	}
606
	return($logarr);
607
}
608

    
609
/* Check if variable has changed, update and log if it has
610
 * returns true if var changed
611
 * varname = variable name in plain text
612
 * orig = original value
613
 * new = new value
614
 */
615
function update_if_changed($varname, & $orig, $new) {
616
	if (is_array($orig) && is_array($new)) {
617
		$a_diff = array_diff($orig, $new);
618
		foreach ($a_diff as $diff) {
619
			update_changedesc("removed {$varname}: \"{$diff}\"");
620
		}
621
		$a_diff = array_diff($new, $orig);
622
		foreach ($a_diff as $diff) {
623
			update_changedesc("added {$varname}: \"{$diff}\"");
624
		}
625
		$orig = $new;
626
		return true;
627

    
628
	} else {
629
		if ($orig != $new) {
630
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
631
			$orig = $new;
632
			return true;
633
		}
634
	}
635
	return false;
636
}
637

    
638
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
639

    
640
        if (isset($adr['any']))
641
                $padr = "any";
642
        else if ($adr['network'])
643
                $padr = $adr['network'];
644
        else if ($adr['address']) {
645
                list($padr, $pmask) = explode("/", $adr['address']);
646
                if (!$pmask)
647
                        $pmask = 32;
648
        }
649

    
650
        if (isset($adr['not']))
651
                $pnot = 1;
652
        else
653
                $pnot = 0;
654

    
655
        if ($adr['port']) {
656
                list($pbeginport, $pendport) = explode("-", $adr['port']);
657
                if (!$pendport)
658
                        $pendport = $pbeginport;
659
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
660
		$pbeginport = "any";
661
		$pendport = "any";
662
        }
663
}
664

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

    
667
        $adr = array();
668

    
669
        if ($padr == "any")
670
                $adr['any'] = true;
671
        else if (is_specialnet($padr))
672
                $adr['network'] = $padr;
673
        else {
674
                $adr['address'] = $padr;
675
                if ($pmask != 32)
676
                        $adr['address'] .= "/" . $pmask;
677
        }
678

    
679
        if ($pnot)
680
                $adr['not'] = true;
681
        else
682
                unset($adr['not']);
683

    
684
        if (($pbeginport != 0) && ($pbeginport != "any")) {
685
                if ($pbeginport != $pendport)
686
                        $adr['port'] = $pbeginport . "-" . $pendport;
687
                else
688
                        $adr['port'] = $pbeginport;
689
        }
690

    
691
        if(is_alias($pbeginport)) {
692
                $adr['port'] = $pbeginport;
693
        }
694
}
695

    
696
function is_specialnet($net) {
697
        global $specialsrcdst;
698

    
699
	if(!$net) 
700
		return false;
701
        if (in_array($net, $specialsrcdst))
702
                return true;
703
        else
704
                return false;
705
}
706

    
707
//function to create widget tabs when called
708
function display_widget_tabs(& $tab_array) {	
709
	echo "<div id='tabs'>";
710
	$tabscounter = 0;
711
	foreach ($tab_array as $ta) {
712
	$dashpos = strpos($ta[2],'-');
713
	$tabname = $ta[2] . "-tab";
714
	$tabclass = substr($ta[2],0,$dashpos);
715
	$tabclass = $tabclass . "-class";
716
		if ($ta[1] == true) {
717
			$tabActive = "table-cell";
718
			$tabNonActive = "none";
719
		} 
720
		else {
721
			$tabActive = "none";
722
			$tabNonActive = "table-cell";
723
		}
724
		echo "<div id='{$ta[2]}-active' class='{$tabclass}-tabactive' style='display:{$tabActive}; background-color:#EEEEEE; color:black;'>";
725
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
726
		echo "&nbsp;&nbsp;&nbsp;</B>";
727
		echo "</div>";
728
		
729
		echo "<div id='{$ta[2]}-deactive' class='{$tabclass}-tabdeactive' style='display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;' onClick=\"return changeTabDIV('{$ta[2]}')\">";
730
		echo "<B>&nbsp;&nbsp;&nbsp;{$ta[0]}";
731
		echo "&nbsp;&nbsp;&nbsp;</B>";
732
		echo "</div>";
733
	}
734
	
735
	echo "<script type=\"text/javascript\">";
736
	echo "NiftyCheck();\n";
737
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
738
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
739
	echo "</script>";
740
	echo "</div>";
741
}
742

    
743

    
744
// Return inline javascript file or CSS to minimizie 
745
// request count going back to server.
746
function outputJavaScriptFileInline($javascript) {
747
	if(file_exists($javascript)) {
748
		echo "\n<script type=\"text/javascript\">\n";
749
		include($javascript);
750
		echo "\n</script>\n";
751
	} else {
752
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
753
	}
754
}
755

    
756

    
757

    
758
function outputCSSPrintFileInline($css) {
759
	if(file_exists($css)) {
760
		echo "\n<style media=\"print\" type=\"text/css\">\n";
761
		include($css);
762
		echo "\n</style>\n";
763
	} else {
764
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
765
	}
766
}
767

    
768

    
769
function outputCSSFileInline($css) {
770
	if(file_exists($css)) {
771
		echo "\n<style type=\"text/css\">\n";
772
		include($css);
773
		echo "\n</style>\n";
774
	} else {
775
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
776
	}
777
}
778

    
779
$rfc2616 = array(
780
	100 => "100 Continue",
781
	101 => "101 Switching Protocols",
782
	200 => "200 OK",
783
	201 => "201 Created",
784
	202 => "202 Accepted",
785
	203 => "203 Non-Authoritative Information",
786
	204 => "204 No Content",
787
	205 => "205 Reset Content",
788
	206 => "206 Partial Content",
789
	300 => "300 Multiple Choices",
790
	301 => "301 Moved Permanently",
791
	302 => "302 Found",
792
	303 => "303 See Other",
793
	304 => "304 Not Modified",
794
	305 => "305 Use Proxy",
795
	306 => "306 (Unused)",
796
	307 => "307 Temporary Redirect",
797
	400 => "400 Bad Request",
798
	401 => "401 Unauthorized",
799
	402 => "402 Payment Required",
800
	403 => "403 Forbidden",
801
	404 => "404 Not Found",
802
	405 => "405 Method Not Allowed",
803
	406 => "406 Not Acceptable",
804
	407 => "407 Proxy Authentication Required",
805
	408 => "408 Request Timeout",
806
	409 => "409 Conflict",
807
	410 => "410 Gone",
808
	411 => "411 Length Required",
809
	412 => "412 Precondition Failed",
810
	413 => "413 Request Entity Too Large",
811
	414 => "414 Request-URI Too Long",
812
	415 => "415 Unsupported Media Type",
813
	416 => "416 Requested Range Not Satisfiable",
814
	417 => "417 Expectation Failed",
815
	500 => "500 Internal Server Error",
816
	501 => "501 Not Implemented",
817
	502 => "502 Bad Gateway",
818
	503 => "503 Service Unavailable",
819
	504 => "504 Gateway Timeout",
820
	505 => "505 HTTP Version Not Supported"
821
);
822

    
823
function is_rfc2616_code($code) {
824
	global $rfc2616;
825
	if (isset($rfc2616[$code]))
826
		return true;
827
	else
828
		return false;
829
}
830

    
831
function print_rfc2616_select($tag, $current){
832
	global $rfc2616;
833

    
834
	/* Default to 200 OK if not set */
835
	if ($current == "")
836
		$current = 200;
837

    
838
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
839
	foreach($rfc2616 as $code => $message) {
840
		if ($code == $current) {
841
			$sel = " selected";
842
		} else {
843
			$sel = "";
844
		}
845
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
846
	}
847
}
848

    
849
// Useful debugging function, much cleaner than print_r
850
function echo_array($array,$return_me=false){
851
    if(is_array($array) == false){
852
        $return = "The provided variable is not an array.";
853
    }else{
854
        foreach($array as $name=>$value){
855
            if(is_array($value)){
856
                $return .= "";
857
                $return .= "['<b>$name</b>'] {<div style='margin-left:10px;'>\n";
858
                $return .= echo_array($value,true);
859
                $return .= "</div>}";
860
                $return .= "\n\n";
861
            }else{
862
                if(is_string($value)){
863
                    $value = "\"$value\"";
864
                }
865
                $return .= "['<b>$name</b>'] = $value\n\n";
866
            }
867
        }
868
    }
869
    if($return_me == true){
870
        return $return;
871
    }else{
872
        echo "<pre>".$return."</pre>";
873
    }
874
}
875

    
876
/****f* pfsense-utils/display_top_tabs
877
 * NAME
878
 *   display_top_tabs - display tabs with rounded edges
879
 * INPUTS
880
 *   $text      - array of tabs
881
 * RESULT
882
 *   null
883
 ******/
884
function display_top_tabs(& $tab_array) {
885
        global $HTTP_SERVER_VARS;
886
        global $config;
887
        global $g;
888
		global $tab_array_indent;
889
		global $tab_array_space;
890
		global $tab_array_char_limit;
891
		
892
        /*  does the user have access to this tab?
893
         *  master user has access to everything.
894
         *  if the user does not have access, simply
895
         *  unset the tab item.
896
         */
897
		 
898
		/* empty string code */ 
899
		if ($tab_array_indent == '')
900
		{
901
			$tab_array_indent = 0;
902
		}
903
		if ($tab_array_space == '')
904
		{
905
			$tab_array_space = 1;
906
		}
907
		if ($tab_array_char_limit == '')
908
		{
909
			$tab_array_char_limit = 82;
910
		}
911

    
912
        $tab_temp = array ();
913
        foreach ($tab_array as $ta)
914
                if(isAllowedPage($ta[2]))
915
                        $tab_temp[] = $ta;
916
        /*
917
                // FIXME :      if the checks are not good enough
918
                //                      in isAllowedPage, it needs to be
919
                //                      fixed instead of kludging here
920

    
921
                // TODO: humm what shall we do with pkg_edit.php and pkg.php?
922
                if ((strpos($link, "pkg.php")) !== false || (strpos($link, "pkg_edit.php")) !== false) {
923
                        $pos_equal = strpos($link, "=");
924
                        $pos_xmlsuffix = strpos($link, ".xml");
925
                        // do we match an absolute url including ?xml= foo
926
                        if(!isAllowedPage($link, $allowed))
927
                                $link = substr($link, $pos_equal +1, ($pos_xmlsuffix - $pos_equal +3));
928
                }
929
                // next check - what if the basename contains a query string?
930
                if ((strpos($link, "?")) !== false) {
931
                        $pos_qmark = strpos($link, "?");
932
                        $link = substr($link, 0, $pos_qmark);
933
                }
934
                $authorized_text = print_r($allowed, true);
935
                if(is_array($authorized))
936
                        if (in_array(basename($link), $authorized))
937
        */
938

    
939
        unset ($tab_array);
940
        $tab_array = & $tab_temp;
941

    
942
        $tab_active_bg   = "#EEEEEE";
943
        $tab_inactive_bg = "#777777";
944
        $nifty_tabs_corners = "#FFF";
945
        $font_color = "white";
946

    
947
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
948
        $themename = $config['theme'];
949
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
950
        if(file_exists($filename)) {
951
                $eval_code = file_get_contents($filename);
952
                eval($eval_code);
953
        }
954

    
955
        $tabcharcount = 0;
956
        foreach ($tab_array as $ta)
957
                $tabcharcount = $tabcharcount + strlen($ta[0]);
958

    
959
        // If the character count of the tab names is > 670
960
        // then show a select item dropdown menubox.
961
         if($tabcharcount > $tab_array_char_limit) {
962
                echo "Currently viewing: ";
963
                echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
964
                foreach ($tab_array as $ta) {
965
                        if($ta[1]=="true")
966
                                $selected = " SELECTED";
967
                        else
968
                                $selected = "";
969
                        // Onclick in option will not work in some browser
970
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
971
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
972
                }
973
                echo "</select>\n<p/>";
974
                echo "<script type=\"text/javascript\">";
975
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
976
                echo "</script>";
977
        }  else {
978
		//////>>>
979
                echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
980
                echo "<!-- Tabbed bar code-->\n";
981
				echo "<ul class=\"newtabmenu\">\n";
982
                $tabscounter = 0;
983
                foreach ($tab_array as $ta) {
984
                        if ($ta[1] == true) {
985
								echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
986
                        } else {
987
								echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
988
                        }
989
                        $tabscounter++;
990
                }
991
                echo "</ul>\n</div>\n";
992
		////////>>>>
993
        }
994
}
995

    
996
function add_package_tabs($tabgroup, & $tab_array) {
997
        global $config, $g;
998

    
999
        if(!is_array($config['installedpackages']))
1000
                return;
1001
        if(!is_array($config['installedpackages']['tab']))
1002
                return;
1003

    
1004
        foreach($config['installedpackages']['tab'] as $tab) {
1005
                if ($tab['group'] !== $group)
1006
                        continue;
1007
                $tab_entry = array();
1008
                if($tab['name']) {
1009
                        $tab_entry[] = $tab['name'];
1010
                        $tab_entry[] = false;
1011
                        $tab_entry[] = $tab['url'];
1012
                        $tab_array[] = $tab_entry;
1013
                }
1014
        }
1015
}
1016

    
1017
function rule_popup($src,$srcport,$dst,$dstport){
1018
	global $config;
1019
	$aliases_array = array();
1020
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1021
	{
1022
		$span_begin = "";
1023
                $alias_src_span_begin = "";
1024
                $alias_src_span_end = "";
1025
                $alias_src_port_span_begin = "";
1026
                $alias_src_port_span_end = "";
1027
                $alias_dst_span_begin = "";
1028
                $alias_dst_span_end = "";
1029
                $alias_dst_port_span_begin = "";
1030
                $alias_dst_port_span_end = "";
1031
                $alias_content_text = "";
1032
        	foreach($config['aliases']['alias'] as $alias_name)
1033
        	{
1034
                	$alias_addresses = explode (" ", $alias_name['address']);
1035
                	$alias_details = explode ("||", $alias_name['detail']);
1036
                	$alias_objects_with_details = "";
1037
                	$counter = 0;
1038
			if ($alias_name['url']) {
1039
				$alias_objects_with_details .= $alias_name['url'] . "<br/>";
1040
			}
1041
                	foreach($alias_addresses as $alias_ports_address)
1042
                	{
1043
                        	$alias_objects_with_details .= $alias_addresses[$counter];
1044
                        	$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
1045
                        	if ($alias_details[$counter] != "" && $alias_detail_default === False){
1046
                                	$alias_objects_with_details .=" - " . $alias_details[$counter];
1047
                        	}
1048
                        	$alias_objects_with_details .= "<br>";
1049
                        	$counter++;
1050
                	}
1051
                	//max character length for caption field
1052
                	$maxlength = 60;
1053

    
1054
                	$alias_descr_substr = $alias_name['descr'];
1055
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
1056
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
1057
                	$strlength = strlen ($alias_caption);
1058
                	if ($strlength >= $maxlength)
1059
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
1060

    
1061
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
1062
			$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>";
1063

    
1064
                	if ($alias_name['name'] == $src)
1065
                        	$alias_src_span_begin = $span_begin;
1066
                	if ($alias_name['name'] == $srcport)
1067
                        	$alias_src_port_span_begin = $span_begin;
1068
                	if ($alias_name['name'] == $dst)
1069
                        	$alias_dst_span_begin = $span_begin;
1070
                	if ($alias_name['name'] == $dstport)
1071
                        	$alias_dst_port_span_begin = $span_begin;
1072
        	}
1073
        	$descriptions = array ();
1074
        	$descriptions['src'] = $alias_src_span_begin;
1075
        	$descriptions['srcport'] = $alias_src_port_span_begin;
1076
        	$descriptions['dst'] = $alias_dst_span_begin;
1077
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
1078

    
1079
        	return $descriptions;
1080
  	}
1081
}
1082

    
1083
?>
(73-73/220)