Projet

Général

Profil

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

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

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(file_exists($logfile) && filesize($logfile) == 0) {
599
		$logarr = array("Log file started.");
600
	} else {
601
		if($config['system']['disablesyslogclog']) {
602
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
603
		} else {
604
			if(isset($config['system']['usefifolog']))
605
				exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
606
			else
607
				exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
608
		}
609
	}
610
	foreach ($logarr as $logent) {
611
			$logent = preg_split("/\s+/", $logent, 6);
612
			echo "<tr valign=\"top\">\n";
613
			if ($withorig) {
614
					if(isset($config['system']['usefifolog'])) {
615
						$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
616
						$entry_text = htmlspecialchars($logent[5]);
617
					} else {
618
						$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
619
						$entry_text = ($logent[3] ==  $config['system']['hostname']) ? "" : $logent[3] . " ";
620
						$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
621
					}
622
					echo "<td class=\"listlr nowrap\">{$entry_date_time}</td>\n";
623
					echo "<td class=\"listr\">{$entry_text}</td>\n";
624

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

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

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

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

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

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

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

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

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

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

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

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

    
747
function is_specialnet($net) {
748
	global $specialsrcdst;
749

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

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

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

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

    
796

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

    
809

    
810

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

    
821

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

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

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

    
884
function print_rfc2616_select($tag, $current){
885
	global $rfc2616;
886

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

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

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

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

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

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

    
956
	if ($tab_array_space == '') {
957
		$tab_array_space = 1;
958
	}
959

    
960
	if ($tab_array_char_limit == '') {
961
		$tab_array_char_limit = 92;
962
	}
963

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

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

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

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

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

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

    
1028
function add_package_tabs($tabgroup, & $tab_array) {
1029
	global $config, $g;
1030

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

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

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

    
1114
function rule_popup($src,$srcport,$dst,$dstport){
1115
	global $config,$g;
1116
	$aliases_array = array();
1117
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
1118
		$descriptions = array ();
1119
		foreach ($config['aliases']['alias'] as $alias_id=>$alias_name){
1120
			$loading_image= htmlspecialchars("<a><img src=\'/themes/{$g['theme']}/images/misc/loader.gif\' alt=\'loader\' /> " .gettext("loading...")."</a>");
1121
			switch ($alias_name['type']){
1122
			case "port":
1123
				$width="250";
1124
				break;
1125
			case "urltable":
1126
				$width="500";
1127
				break;
1128
			default:
1129
				$width="350";
1130
				break;
1131
			}
1132
			$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>";
1133
			$span_end = "</u></span>";
1134
			if ($alias_name['name'] == $src) {
1135
				$descriptions['src'] = $span_begin;
1136
				$descriptions['src_end'] = $span_end;
1137
			}
1138
			if ($alias_name['name'] == $srcport) {
1139
				$descriptions['srcport'] = $span_begin;
1140
				$descriptions['srcport_end'] = $span_end;
1141
			}
1142
			if ($alias_name['name'] == $dst ) {
1143
				$descriptions['dst'] = $span_begin;
1144
				$descriptions['dst_end'] = $span_end;
1145
			}
1146
			if ($alias_name['name'] == $dstport) {
1147
				$descriptions['dstport'] = $span_begin;
1148
				$descriptions['dstport_end'] = $span_end;
1149
			}
1150
		}
1151
		return $descriptions;
1152
	}
1153
}
1154

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

    
1159
date_default_timezone_set($timezone);
1160

    
1161
?>
(86-86/246)