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
	}
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
	$filter_related = false;
422
	$filter_pages = array("nat", "filter");
423
	$to_return = "The changes have been applied successfully.";
424
	foreach($filter_pages as $fp) 
425
		if(stristr($_SERVER['SCRIPT_FILENAME'], $fp))
426
			$filter_related = true;	
427
	if($filter_related)
428
		$to_return .= "<br/>You can also <a href='status_filter_reload.php'>monitor</a> the filter reload progress.";
429
	return $to_return;
430
}
431

    
432
function pprint_address($adr) {
433
	global $specialnets;
434

    
435
	if (isset($adr['any'])) {
436
		$padr = "*";
437
	} else if ($adr['network']) {
438
		$padr = $specialnets[$adr['network']];
439
	} else {
440
		$padr = $adr['address'];
441
	}
442

    
443
	if (isset($adr['not']))
444
		$padr = "! " . $padr;
445

    
446
	return $padr;
447
}
448

    
449
function pprint_port($port) {
450
	global $wkports;
451

    
452
	$pport = "";
453

    
454
	if (!$port)
455
		return "*";
456
	else {
457
		$srcport = explode("-", $port);
458
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
459
			$pport = $srcport[0];
460
			if ($wkports[$srcport[0]]) {
461
				$pport .= " (" . $wkports[$srcport[0]] . ")";
462
			}
463
		} else
464
			$pport .= $srcport[0] . " - " . $srcport[1];
465
	}
466

    
467
	return $pport;
468
}
469

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

    
509
        return $item_set;
510
}
511

    
512
function gentitle($title) {
513
	global $navlevelsep;
514
	if(!is_array($title))
515
		return $title;
516
	else
517
		return join($navlevelsep, $title);
518
}
519

    
520
function genhtmltitle($title) {
521
        global $config;
522
        return gentitle($title);
523
}
524

    
525
/* update the changedesc and changecount(er) variables */
526
function update_changedesc($update) {
527
	global $changedesc;
528
	global $changecount;
529

    
530
	$changedesc .= " {$update}";
531
	$changecount++;
532
}
533

    
534
function clear_log_file($logfile = "/var/log/system.log") {
535
	global $config, $g;
536
	exec("/usr/bin/killall syslogd");
537
	if(isset($config['system']['disablesyslogclog'])) {
538
		unlink($logfile);
539
		touch($logfile);
540
	} else {
541
		if(isset($config['system']['usefifolog'])) 
542
			exec("/usr/sbin/fifolog_create -s 511488 {$logfile}");
543
		else
544
			exec("/usr/sbin/clog -i -s 511488 {$logfile}");
545
	}
546
	system_syslogd_start();	
547
}
548

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

    
586
			} else {
587
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
588
			}
589
			echo "</tr>\n";
590
	}
591
}
592

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

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

    
635
	} else {
636
		if ($orig != $new) {
637
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
638
			$orig = $new;
639
			return true;
640
		}
641
	}
642
	return false;
643
}
644

    
645
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
646

    
647
        if (isset($adr['any']))
648
                $padr = "any";
649
        else if ($adr['network'])
650
                $padr = $adr['network'];
651
        else if ($adr['address']) {
652
                list($padr, $pmask) = explode("/", $adr['address']);
653
                if (!$pmask)
654
                        $pmask = 32;
655
        }
656

    
657
        if (isset($adr['not']))
658
                $pnot = 1;
659
        else
660
                $pnot = 0;
661

    
662
        if ($adr['port']) {
663
                list($pbeginport, $pendport) = explode("-", $adr['port']);
664
                if (!$pendport)
665
                        $pendport = $pbeginport;
666
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
667
		$pbeginport = "any";
668
		$pendport = "any";
669
        }
670
}
671

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

    
674
        $adr = array();
675

    
676
        if ($padr == "any")
677
                $adr['any'] = true;
678
        else if (is_specialnet($padr))
679
                $adr['network'] = $padr;
680
        else {
681
                $adr['address'] = $padr;
682
                if ($pmask != 32)
683
                        $adr['address'] .= "/" . $pmask;
684
        }
685

    
686
        if ($pnot)
687
                $adr['not'] = true;
688
        else
689
                unset($adr['not']);
690

    
691
        if (($pbeginport != 0) && ($pbeginport != "any")) {
692
                if ($pbeginport != $pendport)
693
                        $adr['port'] = $pbeginport . "-" . $pendport;
694
                else
695
                        $adr['port'] = $pbeginport;
696
        }
697

    
698
        if(is_alias($pbeginport)) {
699
                $adr['port'] = $pbeginport;
700
        }
701
}
702

    
703
function is_specialnet($net) {
704
        global $specialsrcdst;
705

    
706
	if(!$net) 
707
		return false;
708
        if (in_array($net, $specialsrcdst))
709
                return true;
710
        else
711
                return false;
712
}
713

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

    
750

    
751
// Return inline javascript file or CSS to minimizie 
752
// request count going back to server.
753
function outputJavaScriptFileInline($javascript) {
754
	if(file_exists($javascript)) {
755
		echo "\n<script type=\"text/javascript\">\n";
756
		include($javascript);
757
		echo "\n</script>\n";
758
	} else {
759
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
760
	}
761
}
762

    
763

    
764

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

    
775

    
776
function outputCSSFileInline($css) {
777
	if(file_exists($css)) {
778
		echo "\n<style type=\"text/css\">\n";
779
		include($css);
780
		echo "\n</style>\n";
781
	} else {
782
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
783
	}
784
}
785

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

    
830
function is_rfc2616_code($code) {
831
	global $rfc2616;
832
	if (isset($rfc2616[$code]))
833
		return true;
834
	else
835
		return false;
836
}
837

    
838
function print_rfc2616_select($tag, $current){
839
	global $rfc2616;
840

    
841
	/* Default to 200 OK if not set */
842
	if ($current == "")
843
		$current = 200;
844

    
845
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";	
846
	foreach($rfc2616 as $code => $message) {
847
		if ($code == $current) {
848
			$sel = " selected";
849
		} else {
850
			$sel = "";
851
		}
852
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
853
	}
854
}
855

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

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

    
910
		if ($tab_array_space == '') {
911
			$tab_array_space = 1;
912
		}
913

    
914
		if ($tab_array_char_limit == '') {
915
			$tab_array_char_limit = 82;
916
		}
917

    
918
        $tab_temp = array ();
919
        foreach ($tab_array as $ta)
920
                if(isAllowedPage($ta[2]))
921
                        $tab_temp[] = $ta;
922
        /*
923
                // FIXME :      if the checks are not good enough
924
                //                      in isAllowedPage, it needs to be
925
                //                      fixed instead of kludging here
926

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

    
945
        unset ($tab_array);
946
        $tab_array = & $tab_temp;
947

    
948
        $tab_active_bg   = "#EEEEEE";
949
        $tab_inactive_bg = "#777777";
950
        $nifty_tabs_corners = "#FFF";
951
        $font_color = "white";
952

    
953
        /* if tabcontrols.php exist for a theme, allow it to be overriden */
954
        $themename = $config['theme'];
955
        $filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
956
        if(file_exists($filename)) {
957
                $eval_code = file_get_contents($filename);
958
                eval($eval_code);
959
        }
960

    
961
        $tabcharcount = 0;
962
        foreach ($tab_array as $ta)
963
                $tabcharcount = $tabcharcount + strlen($ta[0]);
964

    
965
		if($no_drop_down == true) {
966
			$tabcharcount = 0;
967
			unset($tab_array_char_limit);
968
		}
969

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

    
1005
function add_package_tabs($tabgroup, & $tab_array) {
1006
        global $config, $g;
1007

    
1008
        if(!is_array($config['installedpackages']))
1009
                return;
1010
        if(!is_array($config['installedpackages']['tab']))
1011
                return;
1012

    
1013
        foreach($config['installedpackages']['tab'] as $tab) {
1014
                if ($tab['group'] !== $group)
1015
                        continue;
1016
                $tab_entry = array();
1017
                if($tab['name']) {
1018
                        $tab_entry[] = $tab['name'];
1019
                        $tab_entry[] = false;
1020
                        $tab_entry[] = $tab['url'];
1021
                        $tab_array[] = $tab_entry;
1022
                }
1023
        }
1024
}
1025

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

    
1063
                	$alias_descr_substr = $alias_name['descr'];
1064
                	$alias_content_text = htmlspecialchars($alias_objects_with_details);
1065
                	$alias_caption = htmlspecialchars($alias_descr_substr . ":");
1066
                	$strlength = strlen ($alias_caption);
1067
                	if ($strlength >= $maxlength)
1068
                        	$alias_caption = substr($alias_caption, 0, $maxlength) . "...";
1069

    
1070
			$alias_caption_escaped = str_replace("'", "\'", $alias_caption);
1071
			$alias_content_escaped = str_replace("'", "\'", $alias_content_text);
1072
			$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>";
1073

    
1074
                	if ($alias_name['name'] == $src)
1075
                        	$alias_src_span_begin = $span_begin;
1076
                	if ($alias_name['name'] == $srcport)
1077
                        	$alias_src_port_span_begin = $span_begin;
1078
                	if ($alias_name['name'] == $dst)
1079
                        	$alias_dst_span_begin = $span_begin;
1080
                	if ($alias_name['name'] == $dstport)
1081
                        	$alias_dst_port_span_begin = $span_begin;
1082
        	}
1083
        	$descriptions = array ();
1084
        	$descriptions['src'] = $alias_src_span_begin;
1085
        	$descriptions['srcport'] = $alias_src_port_span_begin;
1086
        	$descriptions['dst'] = $alias_dst_span_begin;
1087
        	$descriptions['dstport'] = $alias_dst_port_span_begin;
1088

    
1089
        	return $descriptions;
1090
  	}
1091
}
1092

    
1093
?>
(77-77/225)