Project

General

Profile

Download (34.9 KB) Statistics
| Branch: | Tag: | Revision:
1 667b2b60 Ermal
<?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 45b4ffc6 Phil Davis
if (!$nocsrf) {
38 64ec1ddf Scott Ullrich
	function csrf_startup() {
39
		csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
40 6c07db48 Phil Davis
		$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ? $config['system']['webgui']['session_timeout'] : 240;
41 56befec1 jim-p
		csrf_conf('expires', $timeout_minutes * 60);
42 64ec1ddf Scott Ullrich
	}
43
	require_once("csrf/csrf-magic.php");
44 fafd303e Scott Ullrich
}
45 667b2b60 Ermal
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 2ebbb0bc Jose Luis Duran
	header("Cache-Control: no-cache, no-store, must-revalidate");
51 667b2b60 Ermal
	header("Pragma: no-cache");
52
}
53
54 6f3d2063 Renato Botelho
header("X-Frame-Options: SAMEORIGIN");
55 9c59f962 Ermal
require_once("authgui.inc");
56
57 667b2b60 Ermal
/* parse the configuration and include all configuration functions */
58
require_once("functions.inc");
59
60
/* Pull in all the gui related display classes) */
61
foreach (scandir("/usr/local/www/classes/") as $file) {
62 d7a1532b jim-p
	if (substr($file, -4) == ".inc") {
63 667b2b60 Ermal
		require_once("classes/{$file}");
64
	}
65
}
66
67 1e1e1ec8 jim-p
$g['theme'] = get_current_theme();
68 667b2b60 Ermal
69 3e139f90 Vinicius Coque
/* Set the default interface language */
70 45b4ffc6 Phil Davis
if ($config['system']['language'] <> "") {
71 3e139f90 Vinicius Coque
	$g['language'] = $config['system']['language'];
72
} elseif ($g['language'] == "") {
73
	$g['language'] = 'en_US';
74
}
75
76
set_language($g['language']);
77
78 667b2b60 Ermal
/* used by progress bar */
79
$lastseen = "-1";
80
81
$navlevelsep = ": ";	/* navigation level separator string */
82
$mandfldhtml = "";		/* display this before mandatory input fields */
83
$mandfldhtmlspc = "";	/* same as above, but with spacing */
84
85
/* Some ajax scripts still need access to GUI */
86 45b4ffc6 Phil Davis
if (!$ignorefirmwarelock) {
87 667b2b60 Ermal
	if (is_subsystem_dirty('firmwarelock')) {
88
		if (!$d_isfwfile) {
89
			header("Location: system_firmware.php");
90
			exit;
91
		} else {
92
			return;
93
		}
94
	}
95
}
96
97 45b4ffc6 Phil Davis
/* Reserved table names to avoid collision */
98 ee9783e9 Ermal
$reserved_table_names = array(
99 45b4ffc6 Phil Davis
	"bogons",
100
	"bogonsv6",
101
	"negate_networks",
102
	"snort2c",
103
	"sshlockout",
104
	"tonatsubnets",
105
	"virusprot",
106
	"vpn_networks",
107
	"webConfiguratorlockout"
108 ee9783e9 Ermal
);
109
110 45b4ffc6 Phil Davis
$firewall_rules_dscp_types = array(
111
	"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",
133
	"0x02",
134
	"0x04");
135 667b2b60 Ermal
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 6c07db48 Phil Davis
		'desc' => "OpenLDAP",
156
		'attr_user' => "cn",
157
		'attr_group' => "cn",
158
		'attr_member' => "member"),
159 667b2b60 Ermal
160
	'msad' => array(
161 6c07db48 Phil Davis
		'desc' => "Microsoft AD",
162
		'attr_user' => "samAccountName",
163
		'attr_group' => "cn",
164
		'attr_member' => "memberOf"),
165 667b2b60 Ermal
166
	'edir' => array(
167 6c07db48 Phil Davis
		'desc' => "Novell eDirectory",
168
		'attr_user' => "cn",
169
		'attr_group' => "cn",
170
		'attr_member' => "uniqueMember"));
171 667b2b60 Ermal
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 13ec619c Chris Buechler
	'8' => "h-node");
183 667b2b60 Ermal
184 45b4ffc6 Phil Davis
/* some well known ports */
185 667b2b60 Ermal
$wkports = array(
186 96ccd009 Renato Botelho
	5999 => "CVSup",
187 667b2b60 Ermal
	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 96ccd009 Renato Botelho
	1723 => "PPTP",
215 667b2b60 Ermal
	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 76e91d3f Warren Baker
	587 => "SUBMISSION",
226 667b2b60 Ermal
	3544 => "Teredo",
227
	23 => "Telnet",
228
	69 => "TFTP",
229
	5900 => "VNC");
230
231
/* TCP flags */
232 79cc9e6b bcyrill
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
233 667b2b60 Ermal
234 0d0c01ca jim-p
$specialnets = array("(self)" => "This Firewall", "pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
235 667b2b60 Ermal
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 45b4ffc6 Phil Davis
$medias = array(
243
	"auto" => "autoselect",
244
	"100full" => "100BASE-TX full-duplex",
245
	"100half" => "100BASE-TX half-duplex",
246
	"10full" => "10BASE-T full-duplex",
247 667b2b60 Ermal
	"10half" => "10BASE-T half-duplex");
248
249 45b4ffc6 Phil Davis
$wlan_modes = array(
250
	"bss" => "Infrastructure (BSS)",
251
	"adhoc" => "Ad-hoc (IBSS)",
252 667b2b60 Ermal
	"hostap" => "Access Point");
253
254
/* platforms that support firmware updating */
255
$fwupplatforms = array('pfSense', 'net45xx', 'net48xx', 'generic-pc', 'embedded', 'wrap', 'nanobsd');
256
257 eb4ac13e Renato Botelho
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
258 667b2b60 Ermal
259
	/* check for bad control characters */
260
	foreach ($postdata as $pn => $pd) {
261
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
262 41602469 Luiz Gustavo Costa
			$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
263 667b2b60 Ermal
		}
264
	}
265
266
	for ($i = 0; $i < count($reqdfields); $i++) {
267
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
268 bd757043 Renato Botelho
			$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
269 667b2b60 Ermal
		}
270
	}
271
}
272
273
function print_input_errors($input_errors) {
274
	global $g;
275
276
	print <<<EOF
277 f326b978 Colin Fleming
	<div id="inputerrorsdiv">
278
	<table border="0" cellspacing="0" cellpadding="4" width="100%" summary="input errors">
279 667b2b60 Ermal
	<tr>
280
		<td class="inputerrorsleft">
281 f326b978 Colin Fleming
			<img src="/themes/{$g['theme']}/images/icons/icon_error.gif" alt="errors" />
282 667b2b60 Ermal
		</td>
283 45b4ffc6 Phil Davis
		<td class="inputerrorsright errmsg">
284 667b2b60 Ermal
EOF;
285 45b4ffc6 Phil Davis
	echo "<p>" . gettext("The following input errors were detected:") . "</p>\n<ul>";
286 e28307d0 Luiz Gustavo Costa
	foreach ($input_errors as $ierr) {
287
		echo "<li>" . htmlspecialchars($ierr) . "</li>";
288
	}
289 667b2b60 Ermal
290
	print <<<EOF2
291
				</ul>
292 45b4ffc6 Phil Davis
		</td>
293
	</tr>
294 667b2b60 Ermal
	</table>
295 60ccf01c Scott Ullrich
	</div>
296 8cbda52b Colin Fleming
	&nbsp;<br />
297 667b2b60 Ermal
EOF2;
298 f326b978 Colin Fleming
299 667b2b60 Ermal
}
300
301
function verify_gzip_file($fname) {
302 96ccd009 Renato Botelho
	$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
303 45b4ffc6 Phil Davis
	if ($returnvar != 0) {
304 667b2b60 Ermal
		return 0;
305 45b4ffc6 Phil Davis
	} else {
306 667b2b60 Ermal
		return 1;
307 45b4ffc6 Phil Davis
	}
308 667b2b60 Ermal
}
309
310 6c07db48 Phil Davis
function print_info_box_np($msg, $name = "apply", $value = "", $showapply = false) {
311 667b2b60 Ermal
	global $g, $nifty_redbox, $nifty_blackbox, $nifty_background;
312
313 45b4ffc6 Phil Davis
	if (empty($value)) {
314 c9eb66f6 Vinicius Coque
		$value = gettext("Apply changes");
315
	}
316
317 667b2b60 Ermal
	// Set the Nifty background color if one is not set already (defaults to white)
318 45b4ffc6 Phil Davis
	if ($nifty_background == "") {
319 667b2b60 Ermal
		$nifty_background = "#FFF";
320 45b4ffc6 Phil Davis
	}
321 667b2b60 Ermal
322 45b4ffc6 Phil Davis
	if (stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
323 f326b978 Colin Fleming
		$savebutton = "<td class=\"infoboxsave\">";
324
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
325 45b4ffc6 Phil Davis
		if ($_POST['if']) {
326 f326b978 Colin Fleming
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
327 45b4ffc6 Phil Davis
		}
328 6c07db48 Phil Davis
		$savebutton .= "</td>";
329 667b2b60 Ermal
	}
330
	$nifty_redbox = "#990000";
331
	$nifty_blackbox = "#000000";
332 f326b978 Colin Fleming
333 667b2b60 Ermal
	$themename = $g['theme'];
334 f326b978 Colin Fleming
335 45b4ffc6 Phil Davis
	if (file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
336 667b2b60 Ermal
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
337
		eval($toeval);
338
	}
339 f326b978 Colin Fleming
340 45b4ffc6 Phil Davis
	if (file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
341 667b2b60 Ermal
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
342
		eval($toeval);
343 96ccd009 Renato Botelho
	}
344 f326b978 Colin Fleming
345 45b4ffc6 Phil Davis
	if (!$savebutton) {
346 370b4666 bruno
		$savebutton = "<td class=\"infoboxsave\"><input value=\"" . gettext("Close") . "\" type=\"button\" onclick=\"jQuery(this).parents('table[id=redboxtable]').hide();\" /></td>";
347 667b2b60 Ermal
	}
348
349
	echo <<<EOFnp
350 f326b978 Colin Fleming
	<table class="infobox" id="redboxtable" summary="red box table">
351 667b2b60 Ermal
		<tr>
352
			<td>
353 f326b978 Colin Fleming
				<div class="infoboxnp" id="redbox">
354
					<table class="infoboxnptable2" summary="message">
355 667b2b60 Ermal
						<tr>
356 f326b978 Colin Fleming
							<td class="infoboxnptd">
357
								&nbsp;&nbsp;&nbsp;<img class="infoboxnpimg" src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" alt="exclamation" />
358 667b2b60 Ermal
							</td>
359 f326b978 Colin Fleming
							<td class="infoboxnptd2">
360 667b2b60 Ermal
								<b>{$msg}</b>
361
							</td>
362
							{$savebutton}
363
						</tr>
364
					</table>
365
				</div>
366
				<div>
367 f326b978 Colin Fleming
					<p>&nbsp;</p>
368 667b2b60 Ermal
				</div>
369
			</td>
370
		</tr>
371
	</table>
372
	<script type="text/javascript">
373 f326b978 Colin Fleming
	//<![CDATA[
374 667b2b60 Ermal
		NiftyCheck();
375
		Rounded("div#redbox","all","{$nifty_background}","{$nifty_redbox}","smooth");
376
		Rounded("td#blackbox","all","{$nifty_background}","{$nifty_blackbox}","smooth");
377 f326b978 Colin Fleming
	//]]>
378 667b2b60 Ermal
	</script>
379
EOFnp;
380
381
}
382
383 6c07db48 Phil Davis
function print_info_box_np_undo($msg, $name = "apply", $value = "Apply changes", $undo) {
384 667b2b60 Ermal
	global $g;
385 f326b978 Colin Fleming
386 45b4ffc6 Phil Davis
	if (stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
387 f326b978 Colin Fleming
		$savebutton = "<td class=\"infoboxsave nowrap\">";
388 e28307d0 Luiz Gustavo Costa
		$savebutton .= "<input type=\"button\" value=\"". gettext("Undo") . "\" onclick=\"document.location='{$undo}'\" />";
389 f326b978 Colin Fleming
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
390
		$savebutton .= "</td>";
391 45b4ffc6 Phil Davis
		if ($_POST['if']) {
392 f326b978 Colin Fleming
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
393 45b4ffc6 Phil Davis
		}
394 667b2b60 Ermal
	}
395
	$nifty_redbox = "#990000";
396
	$nifty_blackbox = "#000000";
397 f326b978 Colin Fleming
398 667b2b60 Ermal
	$themename = $g['theme'];
399 f326b978 Colin Fleming
400 45b4ffc6 Phil Davis
	if (file_exists("/usr/local/www/themes/{$themename}/tabcontrols.php")) {
401 667b2b60 Ermal
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/tabcontrols.php");
402
		eval($toeval);
403
	}
404 f326b978 Colin Fleming
405 45b4ffc6 Phil Davis
	if (file_exists("/usr/local/www/themes/{$themename}/infobox.php")) {
406 667b2b60 Ermal
		$toeval = file_get_contents("/usr/local/www/themes/{$themename}/infobox.php");
407
		eval($toeval);
408 96ccd009 Renato Botelho
	}
409 f326b978 Colin Fleming
410
411 45b4ffc6 Phil Davis
	if (!$savebutton) {
412 370b4666 bruno
		$savebutton = "<td class=\"infoboxsave\"><input value=\"" . gettext("Close") . "\" type=\"button\" onclick=\"jQuery(this).parents('table[id=redboxtable]').hide();\" /></td>";
413 667b2b60 Ermal
	}
414
415
	echo <<<EOFnp
416 f326b978 Colin Fleming
	<table class="infobox" id="redboxtable" summary="red box table">
417 667b2b60 Ermal
		<tr>
418
			<td>
419 f326b978 Colin Fleming
				<div class="infoboxnp" id="redbox">
420
					<table class="infoboxnptable2" summary="message">
421 667b2b60 Ermal
						<tr>
422 f326b978 Colin Fleming
							<td class="infoboxnptd">
423
								&nbsp;&nbsp;&nbsp;<img class="infoboxnpimg" src="/themes/{$g['theme']}/images/icons/icon_exclam.gif" alt="exclamation" />
424 667b2b60 Ermal
							</td>
425 f326b978 Colin Fleming
							<td class="infoboxnptd2">
426 667b2b60 Ermal
								<b>{$msg}</b>
427
							</td>
428 96ccd009 Renato Botelho
							{$savebutton}
429 667b2b60 Ermal
							{$undobutton}
430
						</tr>
431
					</table>
432
				</div>
433
				<div>
434 f326b978 Colin Fleming
					<p>&nbsp;</p>
435 667b2b60 Ermal
				</div>
436
			</td>
437
		</tr>
438
	</table>
439
	<script type="text/javascript">
440 f326b978 Colin Fleming
	//<![CDATA[
441 667b2b60 Ermal
		NiftyCheck();
442
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
443
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
444 f326b978 Colin Fleming
	//]]>
445 667b2b60 Ermal
	</script>
446
EOFnp;
447
448
}
449
450
function print_info_box($msg) {
451
	print_info_box_np($msg);
452
}
453
454
function get_std_save_message($ok) {
455
	global $d_sysrebootreqd_path;
456 cfaf6e69 Scott Ullrich
	$filter_related = false;
457
	$filter_pages = array("nat", "filter");
458 e28307d0 Luiz Gustavo Costa
	$to_return = gettext("The changes have been applied successfully.");
459 45b4ffc6 Phil Davis
	foreach ($filter_pages as $fp) {
460
		if (stristr($_SERVER['SCRIPT_FILENAME'], $fp)) {
461 96ccd009 Renato Botelho
			$filter_related = true;
462 45b4ffc6 Phil Davis
		}
463
	}
464
	if ($filter_related) {
465 8cd558b6 ayvis
		$to_return .= "<br />" . gettext("You can also <a href=\"status_filter_reload.php\">monitor</a> the filter reload progress.");
466 45b4ffc6 Phil Davis
	}
467 cfaf6e69 Scott Ullrich
	return $to_return;
468 667b2b60 Ermal
}
469
470
function pprint_address($adr) {
471
	global $specialnets;
472
473
	if (isset($adr['any'])) {
474
		$padr = "*";
475
	} else if ($adr['network']) {
476
		$padr = $specialnets[$adr['network']];
477
	} else {
478
		$padr = $adr['address'];
479
	}
480
481 45b4ffc6 Phil Davis
	if (isset($adr['not'])) {
482 667b2b60 Ermal
		$padr = "! " . $padr;
483 45b4ffc6 Phil Davis
	}
484 667b2b60 Ermal
485
	return $padr;
486
}
487
488
function pprint_port($port) {
489
	global $wkports;
490
491
	$pport = "";
492
493 45b4ffc6 Phil Davis
	if (!$port) {
494 667b2b60 Ermal
		return "*";
495 45b4ffc6 Phil Davis
	} else {
496 667b2b60 Ermal
		$srcport = explode("-", $port);
497
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
498
			$pport = $srcport[0];
499
			if ($wkports[$srcport[0]]) {
500
				$pport .= " (" . $wkports[$srcport[0]] . ")";
501
			}
502 45b4ffc6 Phil Davis
		} else {
503 667b2b60 Ermal
			$pport .= $srcport[0] . " - " . $srcport[1];
504 45b4ffc6 Phil Davis
		}
505 667b2b60 Ermal
	}
506
507
	return $pport;
508
}
509
510 8e0c3760 Ermal
function firewall_check_for_advanced_options(&$item) {
511 96ccd009 Renato Botelho
	$item_set = "";
512 45b4ffc6 Phil Davis
	if ($item['os']) {
513
			$item_set .= "os {$item['os']} ";
514
	}
515
	if ($item['dscp']) {
516 f0c1ce21 Phil Davis
		$item_set .= "dscp {$item['dscp']} ";
517 45b4ffc6 Phil Davis
	}
518
	if ($item['max']) {
519 96ccd009 Renato Botelho
		$item_set .= "max {$item['max']} ";
520 45b4ffc6 Phil Davis
	}
521
	if ($item['max-src-nodes']) {
522 96ccd009 Renato Botelho
		$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
523 45b4ffc6 Phil Davis
	}
524
	if ($item['max-src-conn']) {
525 96ccd009 Renato Botelho
		$item_set .= "max-src-conn {$item['max-src-conn']} ";
526 45b4ffc6 Phil Davis
	}
527
	if ($item['max-src-states']) {
528 96ccd009 Renato Botelho
		$item_set .= "max-src-states {$item['max-src-states']} ";
529 45b4ffc6 Phil Davis
	}
530
	if (isset($item['nopfsync'])) {
531 f0c1ce21 Phil Davis
		$item_set .= "nopfsync ";
532 45b4ffc6 Phil Davis
	}
533
	if ($item['statetype'] != "keep state" && $item['statetype'] != "") {
534 96ccd009 Renato Botelho
		$item_set .= "statetype {$item['statetype']} ";
535 45b4ffc6 Phil Davis
	}
536
	if ($item['statetimeout']) {
537 96ccd009 Renato Botelho
		$item_set .= "statetimeout {$item['statetimeout']} ";
538 45b4ffc6 Phil Davis
	}
539
	if (isset($item['nosync'])) {
540 f0c1ce21 Phil Davis
		$item_set .= "no XMLRPC Sync ";
541 45b4ffc6 Phil Davis
	}
542
	if ($item['max-src-conn-rate']) {
543 96ccd009 Renato Botelho
		$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
544 45b4ffc6 Phil Davis
	}
545
	if ($item['max-src-conn-rates']) {
546 96ccd009 Renato Botelho
		$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
547 45b4ffc6 Phil Davis
	}
548
	if ($item['vlanprio']) {
549 f0c1ce21 Phil Davis
		$item_set .= "vlanprio {$item['vlanprio']} ";
550 45b4ffc6 Phil Davis
	}
551
	if ($item['vlanprioset']) {
552 f0c1ce21 Phil Davis
		$item_set .= "vlanprioset {$item['vlanprioset']} ";
553 45b4ffc6 Phil Davis
	}
554
	if ($item['gateway']) {
555 96ccd009 Renato Botelho
		$item_set .= "gateway {$item['gateway']} ";
556 45b4ffc6 Phil Davis
	}
557
	if ($item['dnpipe']) {
558 96ccd009 Renato Botelho
		$item_set .= "limiter {$item['dnpipe']} ";
559 45b4ffc6 Phil Davis
	}
560
	if ($item['pdnpipe']) {
561 96ccd009 Renato Botelho
		$item_set .= "limiter {$item['pdnpipe']} ";
562 45b4ffc6 Phil Davis
	}
563
	if ($item['ackqueue']) {
564 f0c1ce21 Phil Davis
		$item_set .= "ackqueue {$item['ackqueue']} ";
565 45b4ffc6 Phil Davis
	}
566
	if ($item['defaultqueue']) {
567 f0c1ce21 Phil Davis
		$item_set .= "defaultqueue {$item['defaultqueue']} ";
568 45b4ffc6 Phil Davis
	}
569
	if ($item['l7container']) {
570 96ccd009 Renato Botelho
		$item_set .= "layer7 {$item['l7container']} ";
571 45b4ffc6 Phil Davis
	}
572
	if ($item['tag']) {
573 96ccd009 Renato Botelho
		$item_set .= "tag {$item['tag']} ";
574 45b4ffc6 Phil Davis
	}
575
	if ($item['tagged']) {
576 96ccd009 Renato Botelho
		$item_set .= "tagged {$item['tagged']} ";
577 45b4ffc6 Phil Davis
	}
578
	if (isset($item['allowopts'])) {
579 96ccd009 Renato Botelho
		$item_set .= "allowopts ";
580 45b4ffc6 Phil Davis
	}
581
	if (isset($item['disablereplyto'])) {
582 96ccd009 Renato Botelho
		$item_set .= "disable reply-to ";
583 45b4ffc6 Phil Davis
	}
584
	if ($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2']) {
585 96ccd009 Renato Botelho
		$item_set .= "tcpflags set";
586 45b4ffc6 Phil Davis
	}
587 96ccd009 Renato Botelho
588
	return $item_set;
589 8e0c3760 Ermal
}
590
591 667b2b60 Ermal
function gentitle($title) {
592
	global $navlevelsep;
593 45b4ffc6 Phil Davis
	if (!is_array($title)) {
594 667b2b60 Ermal
		return $title;
595 45b4ffc6 Phil Davis
	} else {
596 667b2b60 Ermal
		return join($navlevelsep, $title);
597 45b4ffc6 Phil Davis
	}
598 667b2b60 Ermal
}
599
600
function genhtmltitle($title) {
601 96ccd009 Renato Botelho
	global $config;
602
	return gentitle($title);
603 667b2b60 Ermal
}
604
605
/* update the changedesc and changecount(er) variables */
606
function update_changedesc($update) {
607
	global $changedesc;
608
	global $changecount;
609
610
	$changedesc .= " {$update}";
611
	$changecount++;
612
}
613
614 c7a3356e jim-p
function clear_log_file($logfile = "/var/log/system.log", $restart_syslogd = true) {
615 667b2b60 Ermal
	global $config, $g;
616 45b4ffc6 Phil Davis
	if ($restart_syslogd) {
617 c7a3356e jim-p
		exec("/usr/bin/killall syslogd");
618 45b4ffc6 Phil Davis
	}
619
	if (isset($config['system']['disablesyslogclog'])) {
620 667b2b60 Ermal
		unlink($logfile);
621
		touch($logfile);
622
	} else {
623 c7a3356e jim-p
		$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "511488";
624 45b4ffc6 Phil Davis
		if (isset($config['system']['usefifolog'])) {
625 d31ca336 Renato Botelho
			exec("/usr/sbin/fifolog_create -s {$log_size} " . escapeshellarg($logfile));
626 45b4ffc6 Phil Davis
		} else {
627 2a50fd8a Renato Botelho
			exec("/usr/local/sbin/clog -i -s {$log_size} " . escapeshellarg($logfile));
628 45b4ffc6 Phil Davis
		}
629 c7a3356e jim-p
	}
630 45b4ffc6 Phil Davis
	if ($restart_syslogd) {
631 c7a3356e jim-p
		system_syslogd_start();
632 45b4ffc6 Phil Davis
	}
633 c7a3356e jim-p
}
634
635
function clear_all_log_files() {
636
	global $g;
637
	exec("/usr/bin/killall syslogd");
638
639
	$log_files = array("system", "filter", "dhcpd", "vpn", "pptps", "poes", "l2tps", "openvpn", "portalauth", "ipsec", "ppp", "relayd", "wireless", "lighttpd", "ntpd", "gateways", "resolver", "routing");
640
	foreach ($log_files as $lfile) {
641
		clear_log_file("{$g['varlog_path']}/{$lfile}.log", false);
642 667b2b60 Ermal
	}
643 c7a3356e jim-p
644 96ccd009 Renato Botelho
	system_syslogd_start();
645 c7a3356e jim-p
	killbyname("dhcpd");
646
	services_dhcpd_configure();
647
	return;
648 667b2b60 Ermal
}
649
650
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
651
	global $g, $config;
652
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
653
	$logarr = "";
654
	$grepline = "  ";
655 45b4ffc6 Phil Davis
	if (is_array($grepfor)) {
656 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
657 45b4ffc6 Phil Davis
	}
658
	if (is_array($grepinvert)) {
659 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
660 45b4ffc6 Phil Davis
	}
661 b67cdd05 Matt Smith
	if (is_dir($logfile)) {
662
		$logarr = array("File $logfile is a directory.");
663 56bd2035 jim-p
	} elseif (file_exists($logfile) && filesize($logfile) == 0) {
664 667b2b60 Ermal
		$logarr = array("Log file started.");
665
	} else {
666 45b4ffc6 Phil Davis
		if ($config['system']['disablesyslogclog']) {
667 d31ca336 Renato Botelho
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
668 667b2b60 Ermal
		} else {
669 45b4ffc6 Phil Davis
			if (isset($config['system']['usefifolog'])) {
670 d31ca336 Renato Botelho
				exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
671 45b4ffc6 Phil Davis
			} else {
672 2a50fd8a Renato Botelho
				exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
673 45b4ffc6 Phil Davis
			}
674 667b2b60 Ermal
		}
675
	}
676
	foreach ($logarr as $logent) {
677 45b4ffc6 Phil Davis
		$logent = preg_split("/\s+/", $logent, 6);
678
		echo "<tr valign=\"top\">\n";
679
		if ($withorig) {
680
			if (isset($config['system']['usefifolog'])) {
681 6c07db48 Phil Davis
				$entry_date_time = htmlspecialchars(date("F j, Y, g:i a", "" . $logent[1] . ""));
682 45b4ffc6 Phil Davis
				$entry_text = htmlspecialchars($logent[5]);
683 667b2b60 Ermal
			} else {
684 45b4ffc6 Phil Davis
				$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
685 6c07db48 Phil Davis
				$entry_text = ($logent[3] == $config['system']['hostname']) ? "" : $logent[3] . " ";
686 45b4ffc6 Phil Davis
				$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
687 667b2b60 Ermal
			}
688 45b4ffc6 Phil Davis
			echo "<td class=\"listlr nowrap\">{$entry_date_time}</td>\n";
689
			echo "<td class=\"listr\">{$entry_text}</td>\n";
690
		} else {
691
				echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
692
		}
693
		echo "</tr>\n";
694 667b2b60 Ermal
	}
695
}
696
697
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
698
	global $g, $config;
699
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
700
	$logarr = "";
701
	$grepline = "  ";
702 45b4ffc6 Phil Davis
	if (is_array($grepfor)) {
703 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
704 45b4ffc6 Phil Davis
	}
705
	if (is_array($grepinvert)) {
706 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
707 45b4ffc6 Phil Davis
	}
708
	if ($config['system']['disablesyslogclog']) {
709 d31ca336 Renato Botelho
		exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
710 667b2b60 Ermal
	} else {
711 45b4ffc6 Phil Davis
		if (isset($config['system']['usefifolog'])) {
712 d31ca336 Renato Botelho
			exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
713 667b2b60 Ermal
		} else {
714 2a50fd8a Renato Botelho
			exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
715 667b2b60 Ermal
		}
716
	}
717
	return($logarr);
718
}
719
720
/* Check if variable has changed, update and log if it has
721
 * returns true if var changed
722
 * varname = variable name in plain text
723
 * orig = original value
724
 * new = new value
725
 */
726
function update_if_changed($varname, & $orig, $new) {
727
	if (is_array($orig) && is_array($new)) {
728
		$a_diff = array_diff($orig, $new);
729
		foreach ($a_diff as $diff) {
730
			update_changedesc("removed {$varname}: \"{$diff}\"");
731
		}
732
		$a_diff = array_diff($new, $orig);
733
		foreach ($a_diff as $diff) {
734
			update_changedesc("added {$varname}: \"{$diff}\"");
735
		}
736
		$orig = $new;
737
		return true;
738
739
	} else {
740
		if ($orig != $new) {
741
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
742
			$orig = $new;
743
			return true;
744
		}
745
	}
746
	return false;
747
}
748
749
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
750 45b4ffc6 Phil Davis
	if (isset($adr['any'])) {
751 96ccd009 Renato Botelho
		$padr = "any";
752 45b4ffc6 Phil Davis
	} else if ($adr['network']) {
753 96ccd009 Renato Botelho
		$padr = $adr['network'];
754 45b4ffc6 Phil Davis
	} else if ($adr['address']) {
755 96ccd009 Renato Botelho
		list($padr, $pmask) = explode("/", $adr['address']);
756 cb2b59b8 Renato Botelho
		if (!$pmask) {
757 45b4ffc6 Phil Davis
			if (is_ipaddrv6($padr)) {
758 cb2b59b8 Renato Botelho
				$pmask = 128;
759 45b4ffc6 Phil Davis
			} else {
760 cb2b59b8 Renato Botelho
				$pmask = 32;
761 45b4ffc6 Phil Davis
			}
762 cb2b59b8 Renato Botelho
		}
763 96ccd009 Renato Botelho
	}
764 667b2b60 Ermal
765 45b4ffc6 Phil Davis
	if (isset($adr['not'])) {
766 96ccd009 Renato Botelho
		$pnot = 1;
767 45b4ffc6 Phil Davis
	} else {
768 96ccd009 Renato Botelho
		$pnot = 0;
769 45b4ffc6 Phil Davis
	}
770 96ccd009 Renato Botelho
771
	if ($adr['port']) {
772
		list($pbeginport, $pendport) = explode("-", $adr['port']);
773 45b4ffc6 Phil Davis
		if (!$pendport) {
774 96ccd009 Renato Botelho
			$pendport = $pbeginport;
775 45b4ffc6 Phil Davis
		}
776 667b2b60 Ermal
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
777
		$pbeginport = "any";
778
		$pendport = "any";
779 96ccd009 Renato Botelho
	}
780 667b2b60 Ermal
}
781
782 6c07db48 Phil Davis
function pconfig_to_address(&$adr, $padr, $pmask, $pnot = false, $pbeginport = 0, $pendport = 0) {
783 96ccd009 Renato Botelho
	$adr = array();
784
785 45b4ffc6 Phil Davis
	if ($padr == "any") {
786 96ccd009 Renato Botelho
		$adr['any'] = true;
787 45b4ffc6 Phil Davis
	} else if (is_specialnet($padr)) {
788 96ccd009 Renato Botelho
		$adr['network'] = $padr;
789 45b4ffc6 Phil Davis
	} else {
790 96ccd009 Renato Botelho
		$adr['address'] = $padr;
791 cb2b59b8 Renato Botelho
		if (is_ipaddrv6($padr)) {
792 45b4ffc6 Phil Davis
			if ($pmask != 128) {
793 cb2b59b8 Renato Botelho
				$adr['address'] .= "/" . $pmask;
794 45b4ffc6 Phil Davis
			}
795 cb2b59b8 Renato Botelho
		} else {
796 45b4ffc6 Phil Davis
			if ($pmask != 32) {
797 cb2b59b8 Renato Botelho
				$adr['address'] .= "/" . $pmask;
798 45b4ffc6 Phil Davis
			}
799 cb2b59b8 Renato Botelho
		}
800 96ccd009 Renato Botelho
	}
801 667b2b60 Ermal
802 45b4ffc6 Phil Davis
	if ($pnot) {
803 96ccd009 Renato Botelho
		$adr['not'] = true;
804 45b4ffc6 Phil Davis
	} else {
805 96ccd009 Renato Botelho
		unset($adr['not']);
806 45b4ffc6 Phil Davis
	}
807 96ccd009 Renato Botelho
808
	if (($pbeginport != 0) && ($pbeginport != "any")) {
809 45b4ffc6 Phil Davis
		if ($pbeginport != $pendport) {
810 96ccd009 Renato Botelho
			$adr['port'] = $pbeginport . "-" . $pendport;
811 45b4ffc6 Phil Davis
		} else {
812 96ccd009 Renato Botelho
			$adr['port'] = $pbeginport;
813 45b4ffc6 Phil Davis
		}
814 96ccd009 Renato Botelho
	}
815
816 45b4ffc6 Phil Davis
	if (is_alias($pbeginport)) {
817 96ccd009 Renato Botelho
		$adr['port'] = $pbeginport;
818
	}
819 667b2b60 Ermal
}
820
821
function is_specialnet($net) {
822 96ccd009 Renato Botelho
	global $specialsrcdst;
823 667b2b60 Ermal
824 45b4ffc6 Phil Davis
	if (!$net) {
825 96ccd009 Renato Botelho
		return false;
826 45b4ffc6 Phil Davis
	}
827
	if (in_array($net, $specialsrcdst)) {
828 96ccd009 Renato Botelho
		return true;
829 45b4ffc6 Phil Davis
	} else {
830 667b2b60 Ermal
		return false;
831 45b4ffc6 Phil Davis
	}
832 667b2b60 Ermal
}
833
834
//function to create widget tabs when called
835 96ccd009 Renato Botelho
function display_widget_tabs(& $tab_array) {
836 f326b978 Colin Fleming
	echo "<div id=\"tabs\">";
837 667b2b60 Ermal
	$tabscounter = 0;
838
	foreach ($tab_array as $ta) {
839 6c07db48 Phil Davis
		$dashpos = strpos($ta[2], '-');
840 45b4ffc6 Phil Davis
		$tabname = $ta[2] . "-tab";
841 6c07db48 Phil Davis
		$tabclass = substr($ta[2], 0, $dashpos);
842 45b4ffc6 Phil Davis
		$tabclass = $tabclass . "-class";
843 667b2b60 Ermal
		if ($ta[1] == true) {
844
			$tabActive = "table-cell";
845
			$tabNonActive = "none";
846 45b4ffc6 Phil Davis
		} else {
847 667b2b60 Ermal
			$tabActive = "none";
848
			$tabNonActive = "table-cell";
849
		}
850 f326b978 Colin Fleming
		echo "<div id=\"{$ta[2]}-active\" class=\"{$tabclass}-tabactive\" style=\"display:{$tabActive}; background-color:#EEEEEE; color:black;\">";
851
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
852
		echo "&nbsp;&nbsp;&nbsp;</b>";
853 667b2b60 Ermal
		echo "</div>";
854 f326b978 Colin Fleming
855
		echo "<div id=\"{$ta[2]}-deactive\" class=\"{$tabclass}-tabdeactive\" style=\"display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;\" onclick=\"return changeTabDIV('{$ta[2]}')\">";
856
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
857
		echo "&nbsp;&nbsp;&nbsp;</b>";
858 667b2b60 Ermal
		echo "</div>";
859
	}
860 f326b978 Colin Fleming
861 667b2b60 Ermal
	echo "<script type=\"text/javascript\">";
862 3a2de75a jim-p
	echo "\n//<![CDATA[\n";
863 667b2b60 Ermal
	echo "NiftyCheck();\n";
864
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
865
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
866 3a2de75a jim-p
	echo "//]]>\n";
867 667b2b60 Ermal
	echo "</script>";
868
	echo "</div>";
869
}
870
871
872 45b4ffc6 Phil Davis
// Return inline javascript file or CSS to minimize
873 667b2b60 Ermal
// request count going back to server.
874
function outputJavaScriptFileInline($javascript) {
875 45b4ffc6 Phil Davis
	if (file_exists($javascript)) {
876 667b2b60 Ermal
		echo "\n<script type=\"text/javascript\">\n";
877
		include($javascript);
878
		echo "\n</script>\n";
879
	} else {
880 45b4ffc6 Phil Davis
		echo "\n\n<!-- Could not locate file:  {$javascript} -->\n\n";
881 667b2b60 Ermal
	}
882
}
883
884
885
886
function outputCSSPrintFileInline($css) {
887 45b4ffc6 Phil Davis
	if (file_exists($css)) {
888 667b2b60 Ermal
		echo "\n<style media=\"print\" type=\"text/css\">\n";
889
		include($css);
890
		echo "\n</style>\n";
891
	} else {
892 45b4ffc6 Phil Davis
		echo "\n\n<!-- Could not locate file:  {$css} -->\n\n";
893 667b2b60 Ermal
	}
894
}
895
896
897
function outputCSSFileInline($css) {
898 45b4ffc6 Phil Davis
	if (file_exists($css)) {
899 667b2b60 Ermal
		echo "\n<style type=\"text/css\">\n";
900
		include($css);
901
		echo "\n</style>\n";
902
	} else {
903 45b4ffc6 Phil Davis
		echo "\n\n<!-- Could not locate file:  {$css} -->\n\n";
904 667b2b60 Ermal
	}
905
}
906
907
$rfc2616 = array(
908
	100 => "100 Continue",
909
	101 => "101 Switching Protocols",
910
	200 => "200 OK",
911
	201 => "201 Created",
912
	202 => "202 Accepted",
913
	203 => "203 Non-Authoritative Information",
914
	204 => "204 No Content",
915
	205 => "205 Reset Content",
916
	206 => "206 Partial Content",
917
	300 => "300 Multiple Choices",
918
	301 => "301 Moved Permanently",
919
	302 => "302 Found",
920
	303 => "303 See Other",
921
	304 => "304 Not Modified",
922
	305 => "305 Use Proxy",
923
	306 => "306 (Unused)",
924
	307 => "307 Temporary Redirect",
925
	400 => "400 Bad Request",
926
	401 => "401 Unauthorized",
927
	402 => "402 Payment Required",
928
	403 => "403 Forbidden",
929
	404 => "404 Not Found",
930
	405 => "405 Method Not Allowed",
931
	406 => "406 Not Acceptable",
932
	407 => "407 Proxy Authentication Required",
933
	408 => "408 Request Timeout",
934
	409 => "409 Conflict",
935
	410 => "410 Gone",
936
	411 => "411 Length Required",
937
	412 => "412 Precondition Failed",
938
	413 => "413 Request Entity Too Large",
939
	414 => "414 Request-URI Too Long",
940
	415 => "415 Unsupported Media Type",
941
	416 => "416 Requested Range Not Satisfiable",
942
	417 => "417 Expectation Failed",
943
	500 => "500 Internal Server Error",
944
	501 => "501 Not Implemented",
945
	502 => "502 Bad Gateway",
946
	503 => "503 Service Unavailable",
947
	504 => "504 Gateway Timeout",
948
	505 => "505 HTTP Version Not Supported"
949
);
950
951
function is_rfc2616_code($code) {
952
	global $rfc2616;
953 45b4ffc6 Phil Davis
	if (isset($rfc2616[$code])) {
954 667b2b60 Ermal
		return true;
955 45b4ffc6 Phil Davis
	} else {
956 667b2b60 Ermal
		return false;
957 45b4ffc6 Phil Davis
	}
958 667b2b60 Ermal
}
959
960 45b4ffc6 Phil Davis
function print_rfc2616_select($tag, $current) {
961 667b2b60 Ermal
	global $rfc2616;
962
963
	/* Default to 200 OK if not set */
964 45b4ffc6 Phil Davis
	if ($current == "") {
965 667b2b60 Ermal
		$current = 200;
966 45b4ffc6 Phil Davis
	}
967 667b2b60 Ermal
968 96ccd009 Renato Botelho
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";
969 45b4ffc6 Phil Davis
	foreach ($rfc2616 as $code => $message) {
970 667b2b60 Ermal
		if ($code == $current) {
971 f326b978 Colin Fleming
			$sel = " selected=\"selected\"";
972 667b2b60 Ermal
		} else {
973
			$sel = "";
974
		}
975
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
976
	}
977 3f08e7ab Colin Fleming
	echo "</select>\n";
978 667b2b60 Ermal
}
979
980
// Useful debugging function, much cleaner than print_r
981 6c07db48 Phil Davis
function echo_array($array, $return_me = false) {
982 45b4ffc6 Phil Davis
	if (is_array($array) == false) {
983 96ccd009 Renato Botelho
		$return = "The provided variable is not an array.";
984 45b4ffc6 Phil Davis
	} else {
985
		foreach ($array as $name=>$value) {
986
			if (is_array($value)) {
987 96ccd009 Renato Botelho
				$return .= "";
988
				$return .= "['<b>$name</b>'] {<div style=\"margin-left:10px;\">\n";
989 6c07db48 Phil Davis
				$return .= echo_array($value, true);
990 96ccd009 Renato Botelho
				$return .= "</div>}";
991
				$return .= "\n\n";
992 45b4ffc6 Phil Davis
			} else {
993
				if (is_string($value)) {
994 96ccd009 Renato Botelho
					$value = "\"$value\"";
995
				}
996
				$return .= "['<b>$name</b>'] = $value\n\n";
997
			}
998
		}
999
	}
1000 45b4ffc6 Phil Davis
	if ($return_me == true) {
1001 96ccd009 Renato Botelho
		return $return;
1002 45b4ffc6 Phil Davis
	} else {
1003 96ccd009 Renato Botelho
		echo "<pre>".$return."</pre>";
1004
	}
1005 667b2b60 Ermal
}
1006
1007
/****f* pfsense-utils/display_top_tabs
1008
 * NAME
1009
 *   display_top_tabs - display tabs with rounded edges
1010
 * INPUTS
1011
 *   $text      - array of tabs
1012
 * RESULT
1013
 *   null
1014
 ******/
1015 d413cd50 Scott Ullrich
function display_top_tabs(& $tab_array, $no_drop_down = false) {
1016 96ccd009 Renato Botelho
	global $config;
1017
	global $g;
1018
	global $tab_array_indent;
1019
	global $tab_array_space;
1020
	global $tab_array_char_limit;
1021
1022
	/*  does the user have access to this tab?
1023
	 *  master user has access to everything.
1024
	 *  if the user does not have access, simply
1025
	 *  unset the tab item.
1026
	 */
1027
1028
	/* empty string code */
1029
	if ($tab_array_indent == '') {
1030
		$tab_array_indent = 0;
1031
	}
1032 620ac186 Scott Ullrich
1033 96ccd009 Renato Botelho
	if ($tab_array_space == '') {
1034
		$tab_array_space = 1;
1035
	}
1036 620ac186 Scott Ullrich
1037 96ccd009 Renato Botelho
	if ($tab_array_char_limit == '') {
1038
		$tab_array_char_limit = 92;
1039
	}
1040 667b2b60 Ermal
1041 45b4ffc6 Phil Davis
	foreach ($tab_array as $tab_id => $ta) {
1042
		if (!isAllowedPage($ta[2])) {
1043 96ccd009 Renato Botelho
			unset ($tab_array[$tab_id]);
1044 45b4ffc6 Phil Davis
		}
1045 96ccd009 Renato Botelho
	}
1046 667b2b60 Ermal
1047 96ccd009 Renato Botelho
	$tab_active_bg   = "#EEEEEE";
1048
	$tab_inactive_bg = "#777777";
1049
	$nifty_tabs_corners = "#FFF";
1050
	$font_color = "white";
1051
1052 45b4ffc6 Phil Davis
	/* if tabcontrols.php exist for a theme, allow it to be overridden */
1053 96ccd009 Renato Botelho
	$themename = $config['theme'];
1054
	$filename = "/usr/local/www/themes/{$themename}/tabcontrols.php";
1055 45b4ffc6 Phil Davis
	if (file_exists($filename)) {
1056 96ccd009 Renato Botelho
		$eval_code = file_get_contents($filename);
1057
		eval($eval_code);
1058
	}
1059
1060
	$tabcharcount = 0;
1061 45b4ffc6 Phil Davis
	foreach ($tab_array as $ta) {
1062 96ccd009 Renato Botelho
		$tabcharcount = $tabcharcount + strlen($ta[0]);
1063 45b4ffc6 Phil Davis
	}
1064 620ac186 Scott Ullrich
1065 45b4ffc6 Phil Davis
	if ($no_drop_down == true) {
1066 96ccd009 Renato Botelho
		$tabcharcount = 0;
1067
		unset($tab_array_char_limit);
1068
	}
1069
1070
	// If the character count of the tab names is > 670
1071
	// then show a select item dropdown menubox.
1072 45b4ffc6 Phil Davis
	if ($tabcharcount > $tab_array_char_limit) {
1073 e28307d0 Luiz Gustavo Costa
		echo gettext("Currently viewing: ");
1074 96ccd009 Renato Botelho
		echo "<select name=\"TabSelect\" onchange=\"tabs_will_go(this)\">\n";
1075
		foreach ($tab_array as $ta) {
1076 6c07db48 Phil Davis
			if ($ta[1] == "true") {
1077 96ccd009 Renato Botelho
				$selected = " selected=\"selected\"";
1078 45b4ffc6 Phil Davis
			} else {
1079 96ccd009 Renato Botelho
				$selected = "";
1080 45b4ffc6 Phil Davis
			}
1081 96ccd009 Renato Botelho
			// Onclick in option will not work in some browser
1082
			// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
1083
			echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
1084
		}
1085
		echo "</select>\n<p>&nbsp;</p>";
1086
		echo "<script type=\"text/javascript\">";
1087
		echo "\n//<![CDATA[\n";
1088 45b4ffc6 Phil Davis
		echo " function tabs_will_go(obj) { document.location = obj.value; }\n";
1089 96ccd009 Renato Botelho
		echo "//]]>\n";
1090
		echo "</script>";
1091 45b4ffc6 Phil Davis
	} else {
1092 96ccd009 Renato Botelho
		echo "<div class=\"newtabmenu\" style=\"margin:{$tab_array_space}px {$tab_array_indent}px; width:775px;\">\n";
1093
		echo "<!-- Tabbed bar code-->\n";
1094
		echo "<ul class=\"newtabmenu\">\n";
1095
		$tabscounter = 0;
1096
		foreach ($tab_array as $ta) {
1097
			if ($ta[1] == true) {
1098
				echo "  <li class=\"newtabmenu_active\"><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1099
			} else {
1100
				echo "  <li><a href=\"{$ta[2]}\"><span>{$ta[0]}</span></a></li>\n";
1101
			}
1102
			$tabscounter++;
1103
		}
1104
		echo "</ul>\n</div>\n";
1105
	}
1106 667b2b60 Ermal
}
1107
1108 253b37d8 Renato Botelho
function add_package_tabs($pkgname, &$tab_array) {
1109 96ccd009 Renato Botelho
	global $config, $g;
1110
1111 253b37d8 Renato Botelho
	$pkg = get_pkg_data($pkgname);
1112
1113
	if (!isset($pkg['configurationfile']) || !file_exists('/usr/local/pkg/' . $pkg['configurationfile'])) {
1114 96ccd009 Renato Botelho
		return;
1115 45b4ffc6 Phil Davis
	}
1116 253b37d8 Renato Botelho
1117
	$pkg_config = parse_xml_config_pkg('/usr/local/pkg/' . $pkg['configurationfile'], "packagegui");
1118
1119
	if (!isset($pkg_config['tabs']['tab'])) {
1120 96ccd009 Renato Botelho
		return;
1121 45b4ffc6 Phil Davis
	}
1122 96ccd009 Renato Botelho
1123 6c07db48 Phil Davis
	foreach ($pkg_config['tabs']['tab'] as $tab) {
1124 96ccd009 Renato Botelho
		$tab_entry = array();
1125 45b4ffc6 Phil Davis
		if ($tab['name']) {
1126 96ccd009 Renato Botelho
			$tab_entry[] = $tab['name'];
1127
			$tab_entry[] = false;
1128
			$tab_entry[] = $tab['url'];
1129
			$tab_array[] = $tab_entry;
1130
		}
1131
	}
1132 667b2b60 Ermal
}
1133
1134 45b4ffc6 Phil Davis
function alias_info_popup($alias_id) {
1135 667b2b60 Ermal
	global $config;
1136 4e8854c6 Charlie Root
	$maxlength = 60;
1137 45b4ffc6 Phil Davis
	$close_title="title='".gettext('move mouse out of this alias to hide')."'";
1138
	if (is_array($config['aliases']['alias'][$alias_id])) {
1139 6c07db48 Phil Davis
		$alias_name = $config['aliases']['alias'][$alias_id];
1140 f326b978 Colin Fleming
		$alias_objects_with_details = "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" summary=\"alias info popup\">";
1141 4e8854c6 Charlie Root
		if ($alias_name['url']) {
1142 dd042c51 Renato Botelho
			// TODO: Change it when pf supports tables with ports
1143
			if ($alias_name['type'] == "urltable") {
1144
				exec("/sbin/pfctl -t {$alias_name['name']} -T show | wc -l", $total_entries);
1145 6c07db48 Phil Davis
				$counter = preg_replace("/\D/", "", $total_entries[0]);
1146 dd042c51 Renato Botelho
				exec("/sbin/pfctl -t {$alias_name['name']} -T show | head -10002", $alias_addresses);
1147
			} else {
1148
				$urlfn = alias_expand_urltable($alias_name['name']);
1149
				$alias_addresses = explode("\n", file_get_contents($urlfn));
1150
				$counter = count($alias_addresses);
1151
			}
1152 f326b978 Colin Fleming
			$alias_objects_with_details .= "<tr><td colspan=\"3\" $close_title class=\"vncell\">{$alias_name['url']}</td></tr>";
1153 6c07db48 Phil Davis
			$x = 0;
1154
			foreach ($alias_addresses as $alias_ports_address) {
1155 d329d587 Darren Embry
				switch ($x) {
1156 45b4ffc6 Phil Davis
					case 0:
1157
						$x++;
1158
						$alias_objects_with_details .= "<tr><td $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td>";
1159
						break;
1160
					case 1:
1161
						$x++;
1162
						$alias_objects_with_details .= "<td $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td>";
1163
						break;
1164
					default:
1165 6c07db48 Phil Davis
						$x = 0;
1166
						$alias_objects_with_details .= "<td $close_title class=\"vncell\" width=\"33%\" style=\"background: #FFFFFF;color: #000000;\">{$alias_ports_address}</td><tr>";
1167 45b4ffc6 Phil Davis
						break;
1168 4e8854c6 Charlie Root
				}
1169
			}
1170 d329d587 Darren Embry
			for ($y = $x; $y <= $x; $y++) {
1171 f326b978 Colin Fleming
				$alias_objects_with_details .= "<td $close_title class=\"vncell\" width=\"33%\">&nbsp;</td>";
1172 d329d587 Darren Embry
			}
1173
			if ($x > 0) {
1174
				$alias_objects_with_details .= "</tr>";
1175
			}
1176
			if ($counter > 10002) {
1177 e28307d0 Luiz Gustavo Costa
				$alias_objects_with_details .= "<tr><td colspan=\"3\"> ". gettext("listing only first 10k items") . "</td><tr>";
1178 d329d587 Darren Embry
			}
1179 45b4ffc6 Phil Davis
		} else {
1180 4e8854c6 Charlie Root
			$alias_addresses = explode (" ", $alias_name['address']);
1181
			$alias_details = explode ("||", $alias_name['detail']);
1182 d329d587 Darren Embry
			$counter = 0;
1183
			foreach ($alias_addresses as $alias_ports_address) {
1184 f326b978 Colin Fleming
				$alias_objects_with_details .= "<tr><td $close_title width=\"5%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">{$alias_addresses[$counter]}</td>";
1185 6c07db48 Phil Davis
				$alias_detail_default = strpos ($alias_details[$counter], "Entry added");
1186 45b4ffc6 Phil Davis
				if ($alias_details[$counter] != "" && $alias_detail_default === False) {
1187 f326b978 Colin Fleming
					$alias_objects_with_details .="<td $close_title width=\"95%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">{$alias_details[$counter]}</td>";
1188 45b4ffc6 Phil Davis
				} else {
1189 f326b978 Colin Fleming
					$alias_objects_with_details .="<td $close_title width=\"95%\" class=\"vncell\" style=\"background: #FFFFFF;color: #000000;\">&nbsp;</td>";
1190 45b4ffc6 Phil Davis
				}
1191 4e8854c6 Charlie Root
				$alias_objects_with_details .= "</tr>";
1192
				$counter++;
1193 d329d587 Darren Embry
			}
1194 4e8854c6 Charlie Root
		}
1195 d329d587 Darren Embry
		$alias_objects_with_details .= "</table>";
1196
	}
1197
	$alias_descr_substr = $alias_name['descr'];
1198 45b4ffc6 Phil Davis
	if ($strlength >= $maxlength) {
1199 d329d587 Darren Embry
		$alias_descr_substr = substr($alias_descr_substr, 0, $maxlength) . "...";
1200 45b4ffc6 Phil Davis
	}
1201 d329d587 Darren Embry
	$item_text = ($counter > 1 ? "items" : "item");
1202 f326b978 Colin Fleming
	$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>";
1203 d329d587 Darren Embry
	$strlength = strlen ($alias_caption);
1204
	print "<h1>{$alias_caption}</h1>" . $alias_objects_with_details;
1205 4e8854c6 Charlie Root
}
1206
1207 6c07db48 Phil Davis
function rule_popup($src, $srcport, $dst, $dstport) {
1208
	global $config, $g;
1209 667b2b60 Ermal
	$aliases_array = array();
1210 d329d587 Darren Embry
	if ($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias'])) {
1211 4e8854c6 Charlie Root
		$descriptions = array ();
1212 45b4ffc6 Phil Davis
		foreach ($config['aliases']['alias'] as $alias_id=>$alias_name) {
1213 133bda76 jim-p
			$loading_image="<a><img src=\'/themes/{$g['theme']}/images/misc/loader.gif\' alt=\'loader\' /> " .gettext("loading...")."</a>";
1214 45b4ffc6 Phil Davis
			switch ($alias_name['type']) {
1215
				case "port":
1216
					$width="250";
1217
					break;
1218
				case "urltable":
1219
					$width="500";
1220
					break;
1221
				default:
1222
					$width="350";
1223
					break;
1224 d329d587 Darren Embry
			}
1225 fb6c8051 jim-p
			$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>";
1226 c184fa27 Darren Embry
			$span_end = "</u></span>";
1227
			if ($alias_name['name'] == $src) {
1228
				$descriptions['src'] = $span_begin;
1229
				$descriptions['src_end'] = $span_end;
1230
			}
1231
			if ($alias_name['name'] == $srcport) {
1232 d329d587 Darren Embry
				$descriptions['srcport'] = $span_begin;
1233 c184fa27 Darren Embry
				$descriptions['srcport_end'] = $span_end;
1234
			}
1235 6c07db48 Phil Davis
			if ($alias_name['name'] == $dst) {
1236 d329d587 Darren Embry
				$descriptions['dst'] = $span_begin;
1237 c184fa27 Darren Embry
				$descriptions['dst_end'] = $span_end;
1238
			}
1239
			if ($alias_name['name'] == $dstport) {
1240
				$descriptions['dstport'] = $span_begin;
1241
				$descriptions['dstport_end'] = $span_end;
1242
			}
1243 d329d587 Darren Embry
		}
1244
		return $descriptions;
1245 96ccd009 Renato Botelho
	}
1246 667b2b60 Ermal
}
1247
1248 119f89c8 Phil Davis
$timezone = $config['system']['timezone'];
1249 45b4ffc6 Phil Davis
if (!$timezone) {
1250 3b49bc25 Scott Ullrich
	$timezone = "Etc/UTC";
1251 45b4ffc6 Phil Davis
}
1252 3b49bc25 Scott Ullrich
1253
date_default_timezone_set($timezone);
1254
1255 667b2b60 Ermal
?>