Projet

Général

Profil

Télécharger (33,4 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / guiconfig.inc @ 7be297a2

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
Header("X-Frame-Options: SAMEORIGIN");
56
require_once("authgui.inc");
57

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

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

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

    
70
/* Set the default interface language */
71
if($config['system']['language'] <> "") {
72
	$g['language'] = $config['system']['language'];
73
} elseif ($g['language'] == "") {
74
	$g['language'] = 'en_US';
75
}
76

    
77
set_language($g['language']);
78

    
79
/* used by progress bar */
80
$lastseen = "-1";
81

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

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

    
98
/* Reserved table names to avoid colision */
99
$reserved_table_names = array(
100
        "bogons",
101
        "bogonsv6",
102
        "negate_networks",
103
        "snort2c",
104
        "sshlockout",
105
        "tonatsubnets",
106
        "virusprot",
107
        "vpn_networks",
108
        "webConfiguratorlockout"
109
);
110

    
111
$firewall_rules_dscp_types = array("af11",
112
				"af12",
113
				"af13",
114
				"af21",
115
				"af22",
116
				"af23",
117
				"af31",
118
				"af32",
119
				"af33",
120
				"af41",
121
				"af42",
122
				"af43",
123
				"VA",
124
				"EF",
125
				"cs1",
126
				"cs2",
127
				"cs3",
128
				"cs4",
129
				"cs5",
130
				"cs6",
131
				"cs7",
132
				"0x01 (reliability, ToS 0x04)",
133
				"0x02 (throughput, ToS 0x08)",
134
				"0x04 (lowdelay, ToS 0x10)");
135

    
136
$auth_server_types = array(
137
	'ldap' => "LDAP",
138
	'radius' => "Radius");
139

    
140
$ldap_urltypes = array(
141
	'TCP - Standard' => 389,
142
	'SSL - Encrypted' => 636);
143

    
144
$ldap_scopes = array(
145
	'one' => "One Level",
146
	'subtree' => "Entire Subtree");
147

    
148
$ldap_protvers = array(
149
	2,
150
	3);
151

    
152
$ldap_templates = array(
153

    
154
	'open' => array(
155
				'desc' => "OpenLDAP",
156
				'attr_user' => "cn",
157
				'attr_group' => "cn",
158
				'attr_member' => "member"),
159

    
160
	'msad' => array(
161
				'desc' => "Microsoft AD",
162
				'attr_user' => "samAccountName",
163
				'attr_group' => "cn",
164
				'attr_member' => "memberOf"),
165

    
166
	'edir' => array(
167
				'desc' => "Novell eDirectory",
168
				'attr_user' => "cn",
169
				'attr_group' => "cn",
170
				'attr_member' => "uniqueMember"));
171

    
172
$radius_srvcs = array(
173
	'both' => "Authentication and Accounting",
174
	'auth' => "Authentication",
175
	'acct' => "Accounting");
176

    
177
$netbios_nodetypes = array(
178
	'0' => "none",
179
	'1' => "b-node",
180
	'2' => "p-node",
181
	'4' => "m-node",
182
	'5' => "h-node");
183

    
184
/* some well knows ports */
185
$wkports = array(
186
	5999 => "CVSup",
187
	53 => "DNS",
188
	21 => "FTP",
189
	3000 => "HBCI",
190
	80 => "HTTP",
191
	443 => "HTTPS",
192
	5190 => "ICQ",
193
	113 => "IDENT/AUTH",
194
	143 => "IMAP",
195
	993 => "IMAP/S",
196
	4500 => "IPsec NAT-T",
197
	500 => "ISAKMP",
198
	1701 => "L2TP",
199
	389 => "LDAP",
200
	1755 => "MMS/TCP",
201
	7000 => "MMS/UDP",
202
	445 => "MS DS",
203
	3389 => "MS RDP",
204
	1512 => "MS WINS",
205
	1863 => "MSN",
206
	119 => "NNTP",
207
	123 => "NTP",
208
	138 => "NetBIOS-DGM",
209
	137 => "NetBIOS-NS",
210
	139 => "NetBIOS-SSN",
211
	1194 => "OpenVPN",
212
	110 => "POP3",
213
	995 => "POP3/S",
214
	1723 => "PPTP",
215
	1812 => "RADIUS",
216
	1813 => "RADIUS accounting",
217
	5004 => "RTP",
218
	5060 => "SIP",
219
	25 => "SMTP",
220
	465 => "SMTP/S",
221
	161 => "SNMP",
222
	162 => "SNMP-Trap",
223
	22 => "SSH",
224
	3478 => "STUN",
225
	587 => "SUBMISSION",
226
	3544 => "Teredo",
227
	23 => "Telnet",
228
	69 => "TFTP",
229
	5900 => "VNC");
230

    
231
/* TCP flags */
232
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
233

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

    
236
$spiflist = get_configured_interface_with_descr(false, true);
237
foreach ($spiflist as $ifgui => $ifdesc) {
238
	$specialnets[$ifgui] = $ifdesc . " net";
239
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
240
}
241

    
242
$medias = array("auto" => "autoselect", "100full" => "100BASE-TX full-duplex",
243
	"100half" => "100BASE-TX half-duplex", "10full" => "10BASE-T full-duplex",
244
	"10half" => "10BASE-T half-duplex");
245

    
246
$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
247
	"hostap" => "Access Point");
248

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

    
252
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
253

    
254
	/* check for bad control characters */
255
	foreach ($postdata as $pn => $pd) {
256
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
257
			$input_errors[] = "The field '" . $pn . "' contains invalid characters.";
258
		}
259
	}
260

    
261
	for ($i = 0; $i < count($reqdfields); $i++) {
262
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
263
			$input_errors[] = "The field '" . $reqdfieldsn[$i] . "' is required.";
264
		}
265
	}
266
}
267

    
268
function print_input_errors($input_errors) {
269
	global $g;
270

    
271
	print <<<EOF
272
	<div id="inputerrorsdiv">
273
	<table border="0" cellspacing="0" cellpadding="4" width="100%" summary="input errors">
274
	<tr>
275
		<td class="inputerrorsleft">
276
			<img src="/themes/{$g['theme']}/images/icons/icon_error.gif" alt="errors" />
277
		</td>
278
		<td class="inputerrorsright errmsg">
279
			<p>The following input errors were detected:</p>
280
				<ul>
281
EOF;
282
		foreach ($input_errors as $ierr) {
283
			echo "<li>" . htmlspecialchars($ierr) . "</li>";
284
		}
285

    
286
	print <<<EOF2
287
				</ul>
288
		</td></tr>
289
	</table>
290
	</div>
291
	&nbsp;<br />
292
EOF2;
293

    
294
}
295

    
296
function verify_gzip_file($fname) {
297
	$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
298
	if ($returnvar != 0)
299
		return 0;
300
	else
301
		return 1;
302
}
303

    
304
function print_info_box_np($msg, $name="apply",$value="", $showapply=false) {
305
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
306

    
307
	if(empty($value)) {
308
		$value = gettext("Apply changes");
309
	}
310

    
311
	// Set the Nifty background color if one is not set already (defaults to white)
312
	if($nifty_background == "")
313
		$nifty_background = "#FFF";
314

    
315
	if(stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
316
		$savebutton = "<td class=\"infoboxsave\">";
317
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
318
		if($_POST['if'])
319
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
320
		$savebutton.="</td>";
321
	}
322
	$nifty_redbox = "#990000";
323
	$nifty_blackbox = "#000000";
324

    
325
	$themename = $g['theme'];
326

    
327
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
328
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
329
		eval($toeval);
330
	}
331

    
332
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
333
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
334
		eval($toeval);
335
	}
336

    
337
	if(!$savebutton) {
338
		$savebutton = "<td class=\"infoboxsave\"><input value=\"Close\" type=\"button\" onclick=\"jQuery('#redboxtable').hide();\" /></td>";
339
	}
340

    
341
	echo <<<EOFnp
342
	<table class="infobox" id="redboxtable" summary="red box table">
343
		<tr>
344
			<td>
345
				<div class="infoboxnp" id="redbox">
346
					<table class="infoboxnptable2" summary="message">
347
						<tr>
348
							<td class="infoboxnptd">
349
								&nbsp;&nbsp;&nbsp;<img class="infoboxnpimg" src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" alt="exclamation" />
350
							</td>
351
							<td class="infoboxnptd2">
352
								{$msg}
353
							</td>
354
							{$savebutton}
355
						</tr>
356
					</table>
357
				</div>
358
				<div>
359
					<p>&nbsp;</p>
360
				</div>
361
			</td>
362
		</tr>
363
	</table>
364
	<script type="text/javascript">
365
	//<![CDATA[
366
		NiftyCheck();
367
		Rounded("div#redbox","all","{$nifty_background}","{$nifty_redbox}","smooth");
368
		Rounded("td#blackbox","all","{$nifty_background}","{$nifty_blackbox}","smooth");
369
	//]]>
370
	</script>
371
EOFnp;
372

    
373
}
374

    
375
function print_info_box_np_undo($msg, $name="apply",$value="Apply changes", $undo) {
376
	global $g;
377

    
378
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
379
		$savebutton = "<td class=\"infoboxsave nowrap\">";
380
		$savebutton .= "<input type=\"button\" value=\"Undo\" onclick=\"document.location='{$undo}'\" />";
381
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
382
		$savebutton .= "</td>";
383
		if($_POST['if'])
384
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
385
	}
386
	$nifty_redbox = "#990000";
387
	$nifty_blackbox = "#000000";
388

    
389
	$themename = $g['theme'];
390

    
391
	if(file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
392
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
393
		eval($toeval);
394
	}
395

    
396
	if(file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
397
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
398
		eval($toeval);
399
	}
400

    
401

    
402
	if(!$savebutton) {
403
		$savebutton = "<td class=\"infoboxsave\"><input value=\"Close\" type=\"button\" onclick=\"jQuery('#redboxtable').hide();\" /></td>";
404
	}
405

    
406
	echo <<<EOFnp
407
	<table class="infobox" id="redboxtable" summary="red box table">
408
		<tr>
409
			<td>
410
				<div class="infoboxnp" id="redbox">
411
					<table class="infoboxnptable2" summary="message">
412
						<tr>
413
							<td class="infoboxnptd">
414
								&nbsp;&nbsp;&nbsp;<img class="infoboxnpimg" src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" alt="exclamation" />
415
							</td>
416
							<td class="infoboxnptd2">
417
								<b>{$msg}</b>
418
							</td>
419
							{$savebutton}
420
							{$undobutton}
421
						</tr>
422
					</table>
423
				</div>
424
				<div>
425
					<p>&nbsp;</p>
426
				</div>
427
			</td>
428
		</tr>
429
	</table>
430
	<script type="text/javascript">
431
	//<![CDATA[
432
		NiftyCheck();
433
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
434
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
435
	//]]>
436
	</script>
437
EOFnp;
438

    
439
}
440

    
441
function print_info_box($msg) {
442
	print_info_box_np($msg);
443
}
444

    
445
function get_std_save_message($ok) {
446
	global $d_sysrebootreqd_path;
447
	$filter_related = false;
448
	$filter_pages = array("nat", "filter");
449
	$to_return = "The changes have been applied successfully.";
450
	foreach($filter_pages as $fp)
451
		if(stristr($_SERVER['SCRIPT_FILENAME'], $fp))
452
			$filter_related = true;
453
	if($filter_related)
454
		$to_return .= "<br/>You can also <a href=\"status_filter_reload.php\">monitor</a> the filter reload progress.";
455
	return $to_return;
456
}
457

    
458
function pprint_address($adr) {
459
	global $specialnets;
460

    
461
	if (isset($adr['any'])) {
462
		$padr = "*";
463
	} else if ($adr['network']) {
464
		$padr = $specialnets[$adr['network']];
465
	} else {
466
		$padr = $adr['address'];
467
	}
468

    
469
	if (isset($adr['not']))
470
		$padr = "! " . $padr;
471

    
472
	return $padr;
473
}
474

    
475
function pprint_port($port) {
476
	global $wkports;
477

    
478
	$pport = "";
479

    
480
	if (!$port)
481
		return "*";
482
	else {
483
		$srcport = explode("-", $port);
484
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
485
			$pport = $srcport[0];
486
			if ($wkports[$srcport[0]]) {
487
				$pport .= " (" . $wkports[$srcport[0]] . ")";
488
			}
489
		} else
490
			$pport .= $srcport[0] . " - " . $srcport[1];
491
	}
492

    
493
	return $pport;
494
}
495

    
496
function firewall_check_for_advanced_options(&$item) {
497
	$item_set = "";
498
	if($item['os'])
499
		$item_set .= "os {$item['os']} ";
500
	if($item['dscp'])
501
		$item_set .= "dscp {$item['dscp']} ";
502
	if($item['max'])
503
		$item_set .= "max {$item['max']} ";
504
	if($item['max-src-nodes'])
505
		$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
506
	if($item['max-src-conn'])
507
		$item_set .= "max-src-conn {$item['max-src-conn']} ";
508
	if($item['max-src-states'])
509
		$item_set .= "max-src-states {$item['max-src-states']} ";
510
	if(isset($item['nopfsync']))
511
		$item_set .= "nopfsync ";
512
	if($item['statetype'] != "keep state" && $item['statetype'] != "")
513
		$item_set .= "statetype {$item['statetype']} ";
514
	if($item['statetimeout'])
515
		$item_set .= "statetimeout {$item['statetimeout']} ";
516
	if(isset($item['nosync']))
517
		$item_set .= "no XMLRPC Sync ";
518
	if($item['max-src-conn-rate'])
519
		$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
520
	if($item['max-src-conn-rates'])
521
		$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
522
	if($item['vlanprio'])
523
		$item_set .= "vlanprio {$item['vlanprio']} ";
524
	if($item['vlanprioset'])
525
		$item_set .= "vlanprioset {$item['vlanprioset']} ";
526
	if($item['gateway'])
527
		$item_set .= "gateway {$item['gateway']} ";
528
	if($item['dnpipe'])
529
		$item_set .= "limiter {$item['dnpipe']} ";
530
	if($item['pdnpipe'])
531
		$item_set .= "limiter {$item['pdnpipe']} ";
532
	if($item['ackqueue'])
533
		$item_set .= "ackqueue {$item['ackqueue']} ";
534
	if($item['defaultqueue'])
535
		$item_set .= "defaultqueue {$item['defaultqueue']} ";
536
	if($item['l7container'])
537
		$item_set .= "layer7 {$item['l7container']} ";
538
	if($item['tag'])
539
		$item_set .= "tag {$item['tag']} ";
540
	if($item['tagged'])
541
		$item_set .= "tagged {$item['tagged']} ";
542
	if(isset($item['allowopts']))
543
		$item_set .= "allowopts ";
544
	if(isset($item['disablereplyto']))
545
		$item_set .= "disable reply-to ";
546
	if($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2'])
547
		$item_set .= "tcpflags set";
548

    
549
	return $item_set;
550
}
551

    
552
function gentitle($title) {
553
	global $navlevelsep;
554
	if(!is_array($title))
555
		return $title;
556
	else
557
		return join($navlevelsep, $title);
558
}
559

    
560
function genhtmltitle($title) {
561
	global $config;
562
	return gentitle($title);
563
}
564

    
565
/* update the changedesc and changecount(er) variables */
566
function update_changedesc($update) {
567
	global $changedesc;
568
	global $changecount;
569

    
570
	$changedesc .= " {$update}";
571
	$changecount++;
572
}
573

    
574
function clear_log_file($logfile = "/var/log/system.log") {
575
	global $config, $g;
576
	exec("/usr/bin/killall syslogd");
577
	if(isset($config['system']['disablesyslogclog'])) {
578
		unlink($logfile);
579
		touch($logfile);
580
	} else {
581
		if(isset($config['system']['usefifolog']))
582
			exec("/usr/sbin/fifolog_create -s 511488 " . escapeshellarg($logfile));
583
		else
584
			exec("/usr/local/sbin/clog -i -s 511488 " . escapeshellarg($logfile));
585
	}
586
	system_syslogd_start();
587
}
588

    
589
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
590
	global $g, $config;
591
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
592
	$logarr = "";
593
	$grepline = "  ";
594
	if(is_array($grepfor))
595
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
596
	if(is_array($grepinvert))
597
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
598
	if (is_dir($logfile)) {
599
		$logarr = array("File $logfile is a directory.");
600
	} elseif(file_exists($logfile) && filesize($logfile) == 0) {
601
		$logarr = array("Log file started.");
602
	} else {
603
		if($config['system']['disablesyslogclog']) {
604
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
605
		} else {
606
			if(isset($config['system']['usefifolog']))
607
				exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
608
			else
609
				exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
610
		}
611
	}
612
	foreach ($logarr as $logent) {
613
			$logent = preg_split("/\s+/", $logent, 6);
614
			echo "<tr valign=\"top\">\n";
615
			if ($withorig) {
616
					if(isset($config['system']['usefifolog'])) {
617
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
618
						$entry_text = htmlspecialchars($logent[5]);
619
					} else {
620
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
621
						$entry_text = ($logent[3] ==  $config['system']['hostname']) ? "" : $logent[3] . " ";
622
						$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
623
					}
624
					echo "<td class=\"listlr nowrap\">{$entry_date_time}</td>\n";
625
					echo "<td class=\"listr\">{$entry_text}</td>\n";
626

    
627
			} else {
628
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
629
			}
630
			echo "</tr>\n";
631
	}
632
}
633

    
634
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
635
	global $g, $config;
636
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
637
	$logarr = "";
638
	$grepline = "  ";
639
	if(is_array($grepfor))
640
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
641
	if(is_array($grepinvert))
642
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
643
	if($config['system']['disablesyslogclog']) {
644
		exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
645
	} else {
646
		if(isset($config['system']['usefifolog'])) {
647
			exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
648
		} else {
649
			exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
650
		}
651
	}
652
	return($logarr);
653
}
654

    
655
/* Check if variable has changed, update and log if it has
656
 * returns true if var changed
657
 * varname = variable name in plain text
658
 * orig = original value
659
 * new = new value
660
 */
661
function update_if_changed($varname, & $orig, $new) {
662
	if (is_array($orig) && is_array($new)) {
663
		$a_diff = array_diff($orig, $new);
664
		foreach ($a_diff as $diff) {
665
			update_changedesc("removed {$varname}: \"{$diff}\"");
666
		}
667
		$a_diff = array_diff($new, $orig);
668
		foreach ($a_diff as $diff) {
669
			update_changedesc("added {$varname}: \"{$diff}\"");
670
		}
671
		$orig = $new;
672
		return true;
673

    
674
	} else {
675
		if ($orig != $new) {
676
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
677
			$orig = $new;
678
			return true;
679
		}
680
	}
681
	return false;
682
}
683

    
684
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
685
	if (isset($adr['any']))
686
		$padr = "any";
687
	else if ($adr['network'])
688
		$padr = $adr['network'];
689
	else if ($adr['address']) {
690
		list($padr, $pmask) = explode("/", $adr['address']);
691
		if (!$pmask) {
692
			if (is_ipaddrv6($padr))
693
				$pmask = 128;
694
			else
695
				$pmask = 32;
696
		}
697
	}
698

    
699
	if (isset($adr['not']))
700
		$pnot = 1;
701
	else
702
		$pnot = 0;
703

    
704
	if ($adr['port']) {
705
		list($pbeginport, $pendport) = explode("-", $adr['port']);
706
		if (!$pendport)
707
			$pendport = $pbeginport;
708
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
709
		$pbeginport = "any";
710
		$pendport = "any";
711
	}
712
}
713

    
714
function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
715
	$adr = array();
716

    
717
	if ($padr == "any")
718
		$adr['any'] = true;
719
	else if (is_specialnet($padr))
720
		$adr['network'] = $padr;
721
	else {
722
		$adr['address'] = $padr;
723
		if (is_ipaddrv6($padr)) {
724
			if ($pmask != 128)
725
				$adr['address'] .= "/" . $pmask;
726
		} else {
727
			if ($pmask != 32)
728
				$adr['address'] .= "/" . $pmask;
729
		}
730
	}
731

    
732
	if ($pnot)
733
		$adr['not'] = true;
734
	else
735
		unset($adr['not']);
736

    
737
	if (($pbeginport != 0) && ($pbeginport != "any")) {
738
		if ($pbeginport != $pendport)
739
			$adr['port'] = $pbeginport . "-" . $pendport;
740
		else
741
			$adr['port'] = $pbeginport;
742
	}
743

    
744
	if(is_alias($pbeginport)) {
745
		$adr['port'] = $pbeginport;
746
	}
747
}
748

    
749
function is_specialnet($net) {
750
	global $specialsrcdst;
751

    
752
	if(!$net)
753
		return false;
754
	if (in_array($net, $specialsrcdst))
755
		return true;
756
	else
757
		return false;
758
}
759

    
760
//function to create widget tabs when called
761
function display_widget_tabs(& $tab_array) {
762
	echo "<div id=\"tabs\">";
763
	$tabscounter = 0;
764
	foreach ($tab_array as $ta) {
765
	$dashpos = strpos($ta[2],'-');
766
	$tabname = $ta[2] . "-tab";
767
	$tabclass = substr($ta[2],0,$dashpos);
768
	$tabclass = $tabclass . "-class";
769
		if ($ta[1] == true) {
770
			$tabActive = "table-cell";
771
			$tabNonActive = "none";
772
		}
773
		else {
774
			$tabActive = "none";
775
			$tabNonActive = "table-cell";
776
		}
777
		echo "<div id=\"{$ta[2]}-active\" class=\"{$tabclass}-tabactive\" style=\"display:{$tabActive}; background-color:#EEEEEE; color:black;\">";
778
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
779
		echo "&nbsp;&nbsp;&nbsp;</b>";
780
		echo "</div>";
781

    
782
		echo "<div id=\"{$ta[2]}-deactive\" class=\"{$tabclass}-tabdeactive\" style=\"display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;\" onclick=\"return changeTabDIV('{$ta[2]}')\">";
783
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
784
		echo "&nbsp;&nbsp;&nbsp;</b>";
785
		echo "</div>";
786
	}
787

    
788
	echo "<script type=\"text/javascript\">";
789
	echo "\n//<![CDATA[\n";
790
	echo "NiftyCheck();\n";
791
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
792
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
793
	echo "//]]>\n";
794
	echo "</script>";
795
	echo "</div>";
796
}
797

    
798

    
799
// Return inline javascript file or CSS to minimizie
800
// request count going back to server.
801
function outputJavaScriptFileInline($javascript) {
802
	if(file_exists($javascript)) {
803
		echo "\n<script type=\"text/javascript\">\n";
804
		include($javascript);
805
		echo "\n</script>\n";
806
	} else {
807
		echo "\n\n<!-- Could not location file:  {$javascript} -->\n\n";
808
	}
809
}
810

    
811

    
812

    
813
function outputCSSPrintFileInline($css) {
814
	if(file_exists($css)) {
815
		echo "\n<style media=\"print\" type=\"text/css\">\n";
816
		include($css);
817
		echo "\n</style>\n";
818
	} else {
819
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
820
	}
821
}
822

    
823

    
824
function outputCSSFileInline($css) {
825
	if(file_exists($css)) {
826
		echo "\n<style type=\"text/css\">\n";
827
		include($css);
828
		echo "\n</style>\n";
829
	} else {
830
		echo "\n\n<!-- Could not location file:  {$css} -->\n\n";
831
	}
832
}
833

    
834
$rfc2616 = array(
835
	100 => "100 Continue",
836
	101 => "101 Switching Protocols",
837
	200 => "200 OK",
838
	201 => "201 Created",
839
	202 => "202 Accepted",
840
	203 => "203 Non-Authoritative Information",
841
	204 => "204 No Content",
842
	205 => "205 Reset Content",
843
	206 => "206 Partial Content",
844
	300 => "300 Multiple Choices",
845
	301 => "301 Moved Permanently",
846
	302 => "302 Found",
847
	303 => "303 See Other",
848
	304 => "304 Not Modified",
849
	305 => "305 Use Proxy",
850
	306 => "306 (Unused)",
851
	307 => "307 Temporary Redirect",
852
	400 => "400 Bad Request",
853
	401 => "401 Unauthorized",
854
	402 => "402 Payment Required",
855
	403 => "403 Forbidden",
856
	404 => "404 Not Found",
857
	405 => "405 Method Not Allowed",
858
	406 => "406 Not Acceptable",
859
	407 => "407 Proxy Authentication Required",
860
	408 => "408 Request Timeout",
861
	409 => "409 Conflict",
862
	410 => "410 Gone",
863
	411 => "411 Length Required",
864
	412 => "412 Precondition Failed",
865
	413 => "413 Request Entity Too Large",
866
	414 => "414 Request-URI Too Long",
867
	415 => "415 Unsupported Media Type",
868
	416 => "416 Requested Range Not Satisfiable",
869
	417 => "417 Expectation Failed",
870
	500 => "500 Internal Server Error",
871
	501 => "501 Not Implemented",
872
	502 => "502 Bad Gateway",
873
	503 => "503 Service Unavailable",
874
	504 => "504 Gateway Timeout",
875
	505 => "505 HTTP Version Not Supported"
876
);
877

    
878
function is_rfc2616_code($code) {
879
	global $rfc2616;
880
	if (isset($rfc2616[$code]))
881
		return true;
882
	else
883
		return false;
884
}
885

    
886
function print_rfc2616_select($tag, $current){
887
	global $rfc2616;
888

    
889
	/* Default to 200 OK if not set */
890
	if ($current == "")
891
		$current = 200;
892

    
893
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";
894
	foreach($rfc2616 as $code => $message) {
895
		if ($code == $current) {
896
			$sel = " selected=\"selected\"";
897
		} else {
898
			$sel = "";
899
		}
900
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
901
	}
902
}
903

    
904
// Useful debugging function, much cleaner than print_r
905
function echo_array($array,$return_me=false){
906
	if(is_array($array) == false){
907
		$return = "The provided variable is not an array.";
908
	}else{
909
		foreach($array as $name=>$value){
910
			if(is_array($value)){
911
				$return .= "";
912
				$return .= "['<b>$name</b>'] {<div style=\"margin-left:10px;\">\n";
913
				$return .= echo_array($value,true);
914
				$return .= "</div>}";
915
				$return .= "\n\n";
916
			}else{
917
				if(is_string($value)){
918
					$value = "\"$value\"";
919
				}
920
				$return .= "['<b>$name</b>'] = $value\n\n";
921
			}
922
		}
923
	}
924
	if($return_me == true){
925
		return $return;
926
	}else{
927
		echo "<pre>".$return."</pre>";
928
	}
929
}
930

    
931
/****f* pfsense-utils/display_top_tabs
932
 * NAME
933
 *   display_top_tabs - display tabs with rounded edges
934
 * INPUTS
935
 *   $text      - array of tabs
936
 * RESULT
937
 *   null
938
 ******/
939
function display_top_tabs(& $tab_array, $no_drop_down = false) {
940
	global $HTTP_SERVER_VARS;
941
	global $config;
942
	global $g;
943
	global $tab_array_indent;
944
	global $tab_array_space;
945
	global $tab_array_char_limit;
946

    
947
	/*  does the user have access to this tab?
948
	 *  master user has access to everything.
949
	 *  if the user does not have access, simply
950
	 *  unset the tab item.
951
	 */
952

    
953
	/* empty string code */
954
	if ($tab_array_indent == '') {
955
		$tab_array_indent = 0;
956
	}
957

    
958
	if ($tab_array_space == '') {
959
		$tab_array_space = 1;
960
	}
961

    
962
	if ($tab_array_char_limit == '') {
963
		$tab_array_char_limit = 92;
964
	}
965

    
966
	foreach ($tab_array as $tab_id => $ta){
967
		if(!isAllowedPage($ta[2]))
968
			unset ($tab_array[$tab_id]);
969
	}
970

    
971
	$tab_active_bg   = "#EEEEEE";
972
	$tab_inactive_bg = "#777777";
973
	$nifty_tabs_corners = "#FFF";
974
	$font_color = "white";
975

    
976
	/* if tabcontrols.php exist for a theme, allow it to be overriden */
977
	$themename = $config['theme'];
978
	$filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
979
	if(file_exists($filename)) {
980
		$eval_code = file_get_contents($filename);
981
		eval($eval_code);
982
	}
983

    
984
	$tabcharcount = 0;
985
	foreach ($tab_array as $ta)
986
		$tabcharcount = $tabcharcount + strlen($ta[0]);
987

    
988
	if($no_drop_down == true) {
989
		$tabcharcount = 0;
990
		unset($tab_array_char_limit);
991
	}
992

    
993
	// If the character count of the tab names is > 670
994
	// then show a select item dropdown menubox.
995
	if($tabcharcount > $tab_array_char_limit) {
996
		echo "Currently viewing: ";
997
		echo "<select name=\"TabSelect\" onchange=\"tabs_will_go(this)\">\n";
998
		foreach ($tab_array as $ta) {
999
			if($ta[1]=="true")
1000
				$selected = " selected=\"selected\"";
1001
			else
1002
				$selected = "";
1003
			// Onclick in option will not work in some browser
1004
			// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
1005
			echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
1006
		}
1007
		echo "</select>\n<p>&nbsp;</p>";
1008
		echo "<script type=\"text/javascript\">";
1009
		echo "\n//<![CDATA[\n";
1010
		echo " function tabs_will_go(obj){ document.location = obj.value; }\n";
1011
		echo "//]]>\n";
1012
		echo "</script>";
1013
	}  else {
1014
		echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
1015
		echo "<!-- Tabbed bar code-->\n";
1016
		echo "<ul class=\"newtabmenu\">\n";
1017
		$tabscounter = 0;
1018
		foreach ($tab_array as $ta) {
1019
			if ($ta[1] == true) {
1020
				echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1021
			} else {
1022
				echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1023
			}
1024
			$tabscounter++;
1025
		}
1026
		echo "</ul>\n</div>\n";
1027
	}
1028
}
1029

    
1030
function add_package_tabs($tabgroup, & $tab_array) {
1031
	global $config, $g;
1032

    
1033
	if(!is_array($config['installedpackages']))
1034
		return;
1035
	if(!is_array($config['installedpackages']['tab']))
1036
		return;
1037

    
1038
	foreach($config['installedpackages']['tab'] as $tab) {
1039
		if ($tab['group'] !== $group)
1040
			continue;
1041
		$tab_entry = array();
1042
		if($tab['name']) {
1043
			$tab_entry[] = $tab['name'];
1044
			$tab_entry[] = false;
1045
			$tab_entry[] = $tab['url'];
1046
			$tab_array[] = $tab_entry;
1047
		}
1048
	}
1049
}
1050

    
1051
function alias_info_popup($alias_id){
1052
	global $config;
1053
	$maxlength = 60;
1054
	$close_title="title='".gettext('move mouse out this alias to hide')."'";
1055
	if (is_array($config['aliases']['alias'][$alias_id])){
1056
		$alias_name=$config['aliases']['alias'][$alias_id];
1057
		$alias_objects_with_details = "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"alias info popup\">";
1058
		if ($alias_name['url']) {
1059
			exec("/sbin/pfctl -t {$alias_name['name']} -T show | wc -l", $total_entries);
1060
			$counter=preg_replace("/\D/","",$total_entries[0]);
1061
			exec("/sbin/pfctl -t {$alias_name['name']} -T show | head -10002", $alias_addresses);
1062
			$alias_objects_with_details .= "<tr><td colspan=\"3\" $close_title class=\"vncell\">{$alias_name['url']}</td></tr>";
1063
			$x=0;
1064
			foreach ($alias_addresses as $alias_ports_address ) {
1065
				switch ($x) {
1066
				case 0:
1067
					$x++;
1068
					$alias_objects_with_details .= "<tr><td $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td>";
1069
					break;
1070
				case 1:
1071
					$x++;
1072
					$alias_objects_with_details .= "<td $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td>";
1073
					break;
1074
				default:
1075
					$x=0;
1076
					$alias_objects_with_details .= "<td  $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td><tr>";
1077
					break;
1078
				}
1079
			}
1080
			for ($y = $x; $y <= $x; $y++) {
1081
				$alias_objects_with_details .= "<td $close_title class=\"vncell\" width=\"33%\">&nbsp;</td>";
1082
			}
1083
			if ($x > 0) {
1084
				$alias_objects_with_details .= "</tr>";
1085
			}
1086
			if ($counter > 10002) {
1087
				$alias_objects_with_details .= "<tr><td colspan=\"3\"> listing only first 10k items</td><tr>";
1088
			}
1089
		}
1090
		else{
1091
			$alias_addresses = explode (" ", $alias_name['address']);
1092
			$alias_details = explode ("||", $alias_name['detail']);
1093
			$counter = 0;
1094
			foreach ($alias_addresses as $alias_ports_address) {
1095
				$alias_objects_with_details .= "<tr><td $close_title width=\"5%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">{$alias_addresses[$counter]}</td>";
1096
				$alias_detail_default = strpos ($alias_details[$counter],"Entry added");
1097
				if ($alias_details[$counter] != "" && $alias_detail_default === False)
1098
					$alias_objects_with_details .="<td $close_title width=\"95%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">{$alias_details[$counter]}</td>";
1099
				else
1100
					$alias_objects_with_details .="<td $close_title width=\"95%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">&nbsp;</td>";
1101
				$alias_objects_with_details .= "</tr>";
1102
				$counter++;
1103
			}
1104
		}
1105
		$alias_objects_with_details .= "</table>";
1106
	}
1107
	$alias_descr_substr = $alias_name['descr'];
1108
	if ($strlength >= $maxlength)
1109
		$alias_descr_substr = substr($alias_descr_substr, 0, $maxlength) . "...";
1110
	$item_text = ($counter > 1 ? "items" : "item");
1111
	$alias_caption = "{$alias_descr_substr} - {$counter} {$item_text}<a href=\"/firewall_aliases_edit.php?id={$alias_id}\" title=\"".gettext('edit this alias')."\">&nbsp;&nbsp;edit </a>";
1112
	$strlength = strlen ($alias_caption);
1113
	print "<h1>{$alias_caption}</h1>" . $alias_objects_with_details;
1114
}
1115

    
1116
function rule_popup($src,$srcport,$dst,$dstport){
1117
	global $config,$g;
1118
	$aliases_array = array();
1119
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
1120
		$descriptions = array ();
1121
		foreach ($config['aliases']['alias'] as $alias_id=>$alias_name){
1122
			$loading_image= htmlspecialchars("<a><img src=\'/themes/{$g['theme']}/images/misc/loader.gif\' alt=\'loader\' /> " .gettext("loading...")."</a>");
1123
			switch ($alias_name['type']){
1124
			case "port":
1125
				$width="250";
1126
				break;
1127
			case "urltable":
1128
				$width="500";
1129
				break;
1130
			default:
1131
				$width="350";
1132
				break;
1133
			}
1134
			$span_begin = "<span style=\"cursor: help;\" onmouseover=\"var response_html=domTT_activate(this, event, 'id','ttalias_{$alias_id}','content','{$loading_image}', 'trail', true, 'delay', 300, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle','type','velcro','width',{$width});alias_popup('{$alias_id}','{$g['theme']}','".gettext('loading...')."');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><u>";
1135
			$span_end = "</u></span>";
1136
			if ($alias_name['name'] == $src) {
1137
				$descriptions['src'] = $span_begin;
1138
				$descriptions['src_end'] = $span_end;
1139
			}
1140
			if ($alias_name['name'] == $srcport) {
1141
				$descriptions['srcport'] = $span_begin;
1142
				$descriptions['srcport_end'] = $span_end;
1143
			}
1144
			if ($alias_name['name'] == $dst ) {
1145
				$descriptions['dst'] = $span_begin;
1146
				$descriptions['dst_end'] = $span_end;
1147
			}
1148
			if ($alias_name['name'] == $dstport) {
1149
				$descriptions['dstport'] = $span_begin;
1150
				$descriptions['dstport_end'] = $span_end;
1151
			}
1152
		}
1153
		return $descriptions;
1154
	}
1155
}
1156

    
1157
$timezone = $config['system']['timezone'];
1158
if (!$timezone)
1159
	$timezone = "Etc/UTC";
1160

    
1161
date_default_timezone_set($timezone);
1162

    
1163
?>
(86-86/246)