Project

General

Profile

Download (33 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
		$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ?  $config['system']['webgui']['session_timeout'] : 240;
41
		csrf_conf('expires', $timeout_minutes * 60);
42
	}
43
	require_once("csrf/csrf-magic.php");
44
}
45

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

    
55
require_once("authgui.inc");
56

    
57
/* parse the configuration and include all configuration functions */
58
require_once("functions.inc");
59

    
60
/* Pull in all the gui related display classes) */
61
foreach (scandir("/usr/local/www/classes/") as $file) {
62
	if (stristr($file, ".inc") !== false) {
63
		require_once("classes/{$file}");
64
	}
65
}
66

    
67
$g['theme'] = get_current_theme();
68

    
69
/* used by progress bar */
70
$lastseen = "-1";
71

    
72
$navlevelsep = ": ";	/* navigation level separator string */
73
$mandfldhtml = "";		/* display this before mandatory input fields */
74
$mandfldhtmlspc = "";	/* same as above, but with spacing */
75

    
76
/* Some ajax scripts still need access to GUI */
77
if(!$ignorefirmwarelock) {
78
	if (is_subsystem_dirty('firmwarelock')) {
79
		if (!$d_isfwfile) {
80
			header("Location: system_firmware.php");
81
			exit;
82
		} else {
83
			return;
84
		}
85
	}
86
}
87

    
88
$firewall_rules_dscp_types = array("af11", 
89
				"af12", 
90
				"af13", 
91
				"af21", 
92
				"af22", 
93
				"af23", 
94
				"af31", 
95
				"af32", 
96
				"af33", 
97
				"af41", 
98
				"af42", 
99
				"af43", 
100
				"EF", 
101
				"1-64", 
102
				"0x10",
103
				"0x04-0xfc");
104

    
105
$auth_server_types = array(
106
	'ldap' => "LDAP",
107
	'radius' => "Radius");
108

    
109
$ldap_urltypes = array(
110
	'TCP - Standard' => 389,
111
	'SSL - Encrypted' => 636);
112

    
113
$ldap_scopes = array(
114
	'one' => "One Level",
115
	'subtree' => "Entire Subtree");
116

    
117
$ldap_protvers = array(
118
	2,
119
	3);
120

    
121
$ldap_templates = array(
122

    
123
	'open' => array(
124
				'desc' => "OpenLDAP",
125
				'attr_user' => "cn",
126
				'attr_group' => "cn",
127
				'attr_member' => "member"),
128

    
129
	'msad' => array(
130
				'desc' => "Microsoft AD",
131
				'attr_user' => "samAccountName",
132
				'attr_group' => "cn",
133
				'attr_member' => "memberOf"),
134

    
135
	'edir' => array(
136
				'desc' => "Novell eDirectory",
137
				'attr_user' => "cn",
138
				'attr_group' => "cn",
139
				'attr_member' => "uniqueMember"));
140

    
141
$radius_srvcs = array(
142
	'both' => "Authentication and Accounting",
143
	'auth' => "Authentication",
144
	'acct' => "Accounting");
145

    
146
$netbios_nodetypes = array(
147
	'0' => "none",
148
	'1' => "b-node",
149
	'2' => "p-node",
150
	'4' => "m-node",
151
	'5' => "h-node");
152

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

    
199
/* TCP flags */
200
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg");
201

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

    
204
$spiflist = get_configured_interface_with_descr(false, true);
205
foreach ($spiflist as $ifgui => $ifdesc) {
206
	$specialnets[$ifgui] = $ifdesc . " net";
207
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
208
}
209

    
210
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
211
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
212
	"10half" => "10BASE-T half-duplex");
213

    
214
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
215
	"hostap" => "Access Point");
216

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

    
220
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, $input_errors) {
221

    
222
	/* check for bad control characters */
223
	foreach ($postdata as $pn => $pd) {
224
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
225
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
226
		}
227
	}
228

    
229
	for ($i = 0; $i < count($reqdfields); $i++) {
230
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
231
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
232
		}
233
	}
234
}
235

    
236
function print_input_errors($input_errors) {
237
	global $g;
238

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

    
256
	print <<<EOF2
257
				</ul>
258
			</span>
259
		</td></tr>
260
	</table>
261
	</div>
262
	</p>&nbsp;<br>
263
EOF2;
264
	
265
}
266

    
267
function verify_gzip_file($fname) {
268

    
269
    $returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
270
	if ($returnvar != 0)
271
		return 0;
272
	else
273
		return 1;
274
}
275

    
276
function print_info_box_np($msg, $name="apply",$value="Apply changes") {
277
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
278

    
279
	// Set the Nifty background color if one is not set already (defaults to white)
280
	if($nifty_background == "")
281
		$nifty_background = "#FFF";
282

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

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

    
339
}
340

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

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

    
403
}
404

    
405
function print_info_box($msg) {
406
	print_info_box_np($msg);
407
}
408

    
409
function get_std_save_message($ok) {
410
	global $d_sysrebootreqd_path;
411
	$filter_related = false;
412
	$filter_pages = array("nat", "filter");
413
	$to_return = "The changes have been applied successfully.";
414
	foreach($filter_pages as $fp) 
415
		if(stristr($_SERVER['SCRIPT_FILENAME'], $fp))
416
			$filter_related = true;	
417
	if($filter_related)
418
		$to_return .= "<br/>You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
419
	return $to_return;
420
}
421

    
422
function pprint_address($adr) {
423
	global $specialnets;
424

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

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

    
436
	return $padr;
437
}
438

    
439
function pprint_port($port) {
440
	global $wkports;
441

    
442
	$pport = "";
443

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

    
457
	return $pport;
458
}
459

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

    
499
        return $item_set;
500
}
501

    
502
function gentitle($title) {
503
	global $navlevelsep;
504
	if(!is_array($title))
505
		return $title;
506
	else
507
		return join($navlevelsep, $title);
508
}
509

    
510
function genhtmltitle($title) {
511
        global $config;
512
        return gentitle($title);
513
}
514

    
515
/* update the changedesc and changecount(er) variables */
516
function update_changedesc($update) {
517
	global $changedesc;
518
	global $changecount;
519

    
520
	$changedesc .= " {$update}";
521
	$changecount++;
522
}
523

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

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

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

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

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

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

    
636
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
637

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

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

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

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

    
665
        $adr = array();
666

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

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

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

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

    
694
function is_specialnet($net) {
695
        global $specialsrcdst;
696

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

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

    
741

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

    
754

    
755

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

    
766

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

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

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

    
829
function print_rfc2616_select($tag, $current){
830
	global $rfc2616;
831

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

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

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

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

    
901
		if ($tab_array_space == '') {
902
			$tab_array_space = 1;
903
		}
904

    
905
		if ($tab_array_char_limit == '') {
906
			$tab_array_char_limit = 92;
907
		}
908

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

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

    
936
        unset ($tab_array);
937
        $tab_array = & $tab_temp;
938

    
939
        $tab_active_bg   = "#EEEEEE";
940
        $tab_inactive_bg = "#777777";
941
        $nifty_tabs_corners = "#FFF";
942
        $font_color = "white";
943

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

    
952
        $tabcharcount = 0;
953
        foreach ($tab_array as $ta)
954
                $tabcharcount = $tabcharcount + strlen($ta[0]);
955

    
956
		if($no_drop_down == true) {
957
			$tabcharcount = 0;
958
			unset($tab_array_char_limit);
959
		}
960

    
961
        // If the character count of the tab names is > 670
962
        // then show a select item dropdown menubox.
963
         if($tabcharcount > $tab_array_char_limit) {
964
                echo "Currently viewing: ";
965
                echo "<select name='TabSelect' onchange='tabs_will_go(this)'>\n";
966
                foreach ($tab_array as $ta) {
967
                        if($ta[1]=="true")
968
                                $selected = " SELECTED";
969
                        else
970
                                $selected = "";
971
                        // Onclick in option will not work in some browser
972
                        // echo "<option onClick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
973
                        echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
974
                }
975
                echo "</select>\n<p/>";
976
                echo "<script type=\"text/javascript\">";
977
                echo " function tabs_will_go(obj){ document.location = obj.value; }";
978
                echo "</script>";
979
        }  else {
980
                echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
981
                echo "<!-- Tabbed bar code-->\n";
982
				echo "<ul class=\"newtabmenu\">\n";
983
                $tabscounter = 0;
984
                foreach ($tab_array as $ta) {
985
                        if ($ta[1] == true) {
986
								echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
987
                        } else {
988
								echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
989
                        }
990
                        $tabscounter++;
991
                }
992
                echo "</ul>\n</div>\n";
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
			$alias_content_escaped = str_replace("'", "\'", $alias_content_text);
1063
			$span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>$alias_caption_escaped</h1><p>$alias_content_escaped</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><U>";
1064

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

    
1080
        	return $descriptions;
1081
  	}
1082
}
1083

    
1084
?>
(78-78/226)