Project

General

Profile

Download (33.4 KB) Statistics
| Branch: | Tag: | Revision:
1 667b2b60 Ermal
<?php
2
/*
3
	guiconfig.inc
4
*/
5 fd9ebcd5 Stephen Beaver
/* ====================================================================
6 2f1f9a98 Stephen Beaver
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7 9da2cf1c Stephen Beaver
 *
8 c9df279d Stephen Beaver
 *  Some or all of this file is based on the m0n0wall project which is
9 9da2cf1c Stephen Beaver
 *  Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
10 fd9ebcd5 Stephen Beaver
 *
11 2f1f9a98 Stephen Beaver
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13 fd9ebcd5 Stephen Beaver
 *
14 2f1f9a98 Stephen Beaver
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16 fd9ebcd5 Stephen Beaver
 *
17 2f1f9a98 Stephen Beaver
 *	2. Redistributions in binary form must reproduce the above copyright
18
 *		notice, this list of conditions and the following disclaimer in
19
 *		the documentation and/or other materials provided with the
20
 *		distribution.
21 fd9ebcd5 Stephen Beaver
 *
22 2f1f9a98 Stephen Beaver
 *	3. All advertising materials mentioning features or use of this software
23
 *		must display the following acknowledgment:
24
 *		"This product includes software developed by the pfSense Project
25
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
26 fd9ebcd5 Stephen Beaver
 *
27 2f1f9a98 Stephen Beaver
 *	4. The names "pfSense" and "pfSense Project" must not be used to
28
 *		 endorse or promote products derived from this software without
29
 *		 prior written permission. For written permission, please contact
30
 *		 coreteam@pfsense.org.
31 fd9ebcd5 Stephen Beaver
 *
32 2f1f9a98 Stephen Beaver
 *	5. Products derived from this software may not be called "pfSense"
33
 *		nor may "pfSense" appear in their names without prior written
34
 *		permission of the Electric Sheep Fencing, LLC.
35 fd9ebcd5 Stephen Beaver
 *
36 2f1f9a98 Stephen Beaver
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38 fd9ebcd5 Stephen Beaver
 *
39 2f1f9a98 Stephen Beaver
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41 fd9ebcd5 Stephen Beaver
 *
42 2f1f9a98 Stephen Beaver
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
54 fd9ebcd5 Stephen Beaver
 *
55 2f1f9a98 Stephen Beaver
 *	====================================================================
56 fd9ebcd5 Stephen Beaver
 *
57
 */
58 667b2b60 Ermal
/*
59 0074384f sbeaver
	pfSense_MODULE: base
60 667b2b60 Ermal
*/
61
62
/* Include authentication routines */
63
/* THIS MUST BE ABOVE ALL OTHER CODE */
64 45b4ffc6 Phil Davis
if (!$nocsrf) {
65 64ec1ddf Scott Ullrich
	function csrf_startup() {
66
		csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
67 6c07db48 Phil Davis
		$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ? $config['system']['webgui']['session_timeout'] : 240;
68 56befec1 jim-p
		csrf_conf('expires', $timeout_minutes * 60);
69 64ec1ddf Scott Ullrich
	}
70
	require_once("csrf/csrf-magic.php");
71 fafd303e Scott Ullrich
}
72 667b2b60 Ermal
73
/* make sure nothing is cached */
74
if (!$omit_nocacheheaders) {
75
	header("Expires: 0");
76
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
77 2ebbb0bc Jose Luis Duran
	header("Cache-Control: no-cache, no-store, must-revalidate");
78 667b2b60 Ermal
	header("Pragma: no-cache");
79
}
80
81 6f3d2063 Renato Botelho
header("X-Frame-Options: SAMEORIGIN");
82 9c59f962 Ermal
require_once("authgui.inc");
83
84 667b2b60 Ermal
/* parse the configuration and include all configuration functions */
85
require_once("functions.inc");
86
87
/* Pull in all the gui related display classes) */
88
foreach (scandir("/usr/local/www/classes/") as $file) {
89 d7a1532b jim-p
	if (substr($file, -4) == ".inc") {
90 667b2b60 Ermal
		require_once("classes/{$file}");
91
	}
92
}
93
94 3e139f90 Vinicius Coque
/* Set the default interface language */
95 45b4ffc6 Phil Davis
if ($config['system']['language'] <> "") {
96 3e139f90 Vinicius Coque
	$g['language'] = $config['system']['language'];
97
} elseif ($g['language'] == "") {
98
	$g['language'] = 'en_US';
99
}
100
101
set_language($g['language']);
102
103 667b2b60 Ermal
/* used by progress bar */
104
$lastseen = "-1";
105
106
$navlevelsep = ": ";	/* navigation level separator string */
107
$mandfldhtml = "";		/* display this before mandatory input fields */
108
$mandfldhtmlspc = "";	/* same as above, but with spacing */
109
110
/* Some ajax scripts still need access to GUI */
111 45b4ffc6 Phil Davis
if (!$ignorefirmwarelock) {
112 667b2b60 Ermal
	if (is_subsystem_dirty('firmwarelock')) {
113
		if (!$d_isfwfile) {
114
			header("Location: system_firmware.php");
115
			exit;
116
		} else {
117
			return;
118
		}
119
	}
120
}
121
122 45b4ffc6 Phil Davis
/* Reserved table names to avoid collision */
123 ee9783e9 Ermal
$reserved_table_names = array(
124 45b4ffc6 Phil Davis
	"bogons",
125
	"bogonsv6",
126
	"negate_networks",
127
	"snort2c",
128
	"sshlockout",
129
	"tonatsubnets",
130
	"virusprot",
131
	"vpn_networks",
132
	"webConfiguratorlockout"
133 ee9783e9 Ermal
);
134
135 45b4ffc6 Phil Davis
$firewall_rules_dscp_types = array(
136
	"af11",
137
	"af12",
138
	"af13",
139
	"af21",
140
	"af22",
141
	"af23",
142
	"af31",
143
	"af32",
144
	"af33",
145
	"af41",
146
	"af42",
147
	"af43",
148
	"VA",
149
	"EF",
150
	"cs1",
151
	"cs2",
152
	"cs3",
153
	"cs4",
154
	"cs5",
155
	"cs6",
156
	"cs7",
157
	"0x01",
158
	"0x02",
159
	"0x04");
160 667b2b60 Ermal
161
$auth_server_types = array(
162
	'ldap' => "LDAP",
163
	'radius' => "Radius");
164
165
$ldap_urltypes = array(
166
	'TCP - Standard' => 389,
167
	'SSL - Encrypted' => 636);
168
169
$ldap_scopes = array(
170
	'one' => "One Level",
171
	'subtree' => "Entire Subtree");
172
173
$ldap_protvers = array(
174
	2,
175
	3);
176
177
$ldap_templates = array(
178
179
	'open' => array(
180 6c07db48 Phil Davis
		'desc' => "OpenLDAP",
181
		'attr_user' => "cn",
182
		'attr_group' => "cn",
183
		'attr_member' => "member"),
184 667b2b60 Ermal
185
	'msad' => array(
186 6c07db48 Phil Davis
		'desc' => "Microsoft AD",
187
		'attr_user' => "samAccountName",
188
		'attr_group' => "cn",
189
		'attr_member' => "memberOf"),
190 667b2b60 Ermal
191
	'edir' => array(
192 6c07db48 Phil Davis
		'desc' => "Novell eDirectory",
193
		'attr_user' => "cn",
194
		'attr_group' => "cn",
195
		'attr_member' => "uniqueMember"));
196 667b2b60 Ermal
197
$radius_srvcs = array(
198
	'both' => "Authentication and Accounting",
199
	'auth' => "Authentication",
200
	'acct' => "Accounting");
201
202
$netbios_nodetypes = array(
203
	'0' => "none",
204
	'1' => "b-node",
205
	'2' => "p-node",
206
	'4' => "m-node",
207 13ec619c Chris Buechler
	'8' => "h-node");
208 667b2b60 Ermal
209 45b4ffc6 Phil Davis
/* some well known ports */
210 667b2b60 Ermal
$wkports = array(
211 96ccd009 Renato Botelho
	5999 => "CVSup",
212 667b2b60 Ermal
	53 => "DNS",
213
	21 => "FTP",
214
	3000 => "HBCI",
215
	80 => "HTTP",
216
	443 => "HTTPS",
217
	5190 => "ICQ",
218
	113 => "IDENT/AUTH",
219
	143 => "IMAP",
220
	993 => "IMAP/S",
221
	4500 => "IPsec NAT-T",
222
	500 => "ISAKMP",
223
	1701 => "L2TP",
224
	389 => "LDAP",
225
	1755 => "MMS/TCP",
226
	7000 => "MMS/UDP",
227
	445 => "MS DS",
228
	3389 => "MS RDP",
229
	1512 => "MS WINS",
230
	1863 => "MSN",
231
	119 => "NNTP",
232
	123 => "NTP",
233
	138 => "NetBIOS-DGM",
234
	137 => "NetBIOS-NS",
235
	139 => "NetBIOS-SSN",
236
	1194 => "OpenVPN",
237
	110 => "POP3",
238
	995 => "POP3/S",
239 96ccd009 Renato Botelho
	1723 => "PPTP",
240 667b2b60 Ermal
	1812 => "RADIUS",
241
	1813 => "RADIUS accounting",
242
	5004 => "RTP",
243
	5060 => "SIP",
244
	25 => "SMTP",
245
	465 => "SMTP/S",
246
	161 => "SNMP",
247
	162 => "SNMP-Trap",
248
	22 => "SSH",
249
	3478 => "STUN",
250 76e91d3f Warren Baker
	587 => "SUBMISSION",
251 667b2b60 Ermal
	3544 => "Teredo",
252
	23 => "Telnet",
253
	69 => "TFTP",
254
	5900 => "VNC");
255
256
/* TCP flags */
257 79cc9e6b bcyrill
$tcpflags = array("fin", "syn", "rst", "psh", "ack", "urg", "ece", "cwr");
258 667b2b60 Ermal
259 c9d46a8e Renato Botelho
$specialnets = array("(self)" => "This Firewall", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");
260 667b2b60 Ermal
261
$spiflist = get_configured_interface_with_descr(false, true);
262
foreach ($spiflist as $ifgui => $ifdesc) {
263
	$specialnets[$ifgui] = $ifdesc . " net";
264
	$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
265
}
266
267 45b4ffc6 Phil Davis
$medias = array(
268
	"auto" => "autoselect",
269
	"100full" => "100BASE-TX full-duplex",
270
	"100half" => "100BASE-TX half-duplex",
271
	"10full" => "10BASE-T full-duplex",
272 667b2b60 Ermal
	"10half" => "10BASE-T half-duplex");
273
274 45b4ffc6 Phil Davis
$wlan_modes = array(
275
	"bss" => "Infrastructure (BSS)",
276
	"adhoc" => "Ad-hoc (IBSS)",
277 667b2b60 Ermal
	"hostap" => "Access Point");
278
279 eb4ac13e Renato Botelho
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
280 667b2b60 Ermal
281
	/* check for bad control characters */
282
	foreach ($postdata as $pn => $pd) {
283
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
284 41602469 Luiz Gustavo Costa
			$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
285 667b2b60 Ermal
		}
286
	}
287
288
	for ($i = 0; $i < count($reqdfields); $i++) {
289
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
290 bd757043 Renato Botelho
			$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
291 667b2b60 Ermal
		}
292
	}
293
}
294
295
function print_input_errors($input_errors) {
296 c4a7740d Sander van Leeuwen
	echo '<div class="alert alert-danger input-errors">';
297
	echo '<p>' . gettext('The following input errors were detected:') . '</p>';
298
	echo '<ul>';
299 667b2b60 Ermal
300 e28307d0 Luiz Gustavo Costa
	foreach ($input_errors as $ierr) {
301 c4a7740d Sander van Leeuwen
		echo '<li>' . htmlspecialchars($ierr) . '</li>';
302 e28307d0 Luiz Gustavo Costa
	}
303 667b2b60 Ermal
304 c4a7740d Sander van Leeuwen
	echo '</ul>';
305
	echo '</div>';
306 667b2b60 Ermal
}
307
308
function verify_gzip_file($fname) {
309 96ccd009 Renato Botelho
	$returnvar = mwexec("/usr/bin/gzip -t " . escapeshellarg($fname));
310 45b4ffc6 Phil Davis
	if ($returnvar != 0) {
311 667b2b60 Ermal
		return 0;
312 45b4ffc6 Phil Davis
	} else {
313 667b2b60 Ermal
		return 1;
314 45b4ffc6 Phil Davis
	}
315 667b2b60 Ermal
}
316
317 ecffb0bb Phil Davis
function print_info_box_np($msg, $name="apply", $value="", $showapply=false, $class="alert-warning") {
318 01752a98 Sjon Hortensius
	global $g;
319 667b2b60 Ermal
320 ecffb0bb Phil Davis
	if (strpos($class, "alert-") !== 0)
321 0074384f sbeaver
		$class = 'alert-' . $class;
322
323 ecffb0bb Phil Davis
	if (empty($value)) {
324 c9eb66f6 Vinicius Coque
		$value = gettext("Apply changes");
325
	}
326
327 ff916cd2 Sander van Leeuwen
	$msg = '<div class="pull-left">' . $msg . '</div>';
328
329 01752a98 Sjon Hortensius
	if (stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
330 e14400b2 Sjon Hortensius
		$msg .= '<form method="post" class="pull-right"><button type="submit" class="btn btn-default" name="'. $name .'" value="'.$value.'">'.$name.'</button>';
331 667b2b60 Ermal
332 01752a98 Sjon Hortensius
		if ($_POST['if'])
333
			$msg .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
334 1180e4f0 Sjon Hortensius
335 ff916cd2 Sander van Leeuwen
		$msg .= '</form>';
336 1180e4f0 Sjon Hortensius
	} else
337 01752a98 Sjon Hortensius
		$msg = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'. $msg;
338 667b2b60 Ermal
339 0074384f sbeaver
	echo '<div class="alert ' . $class . ' clearfix" role="alert">'.$msg.'</div>';
340 667b2b60 Ermal
}
341
342 6c07db48 Phil Davis
function print_info_box_np_undo($msg, $name = "apply", $value = "Apply changes", $undo) {
343 667b2b60 Ermal
	global $g;
344 f326b978 Colin Fleming
345 45b4ffc6 Phil Davis
	if (stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {
346 f326b978 Colin Fleming
		$savebutton = "<td class=\"infoboxsave nowrap\">";
347 e28307d0 Luiz Gustavo Costa
		$savebutton .= "<input type=\"button\" value=\"". gettext("Undo") . "\" onclick=\"document.location='{$undo}'\" />";
348 f326b978 Colin Fleming
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";
349
		$savebutton .= "</td>";
350 45b4ffc6 Phil Davis
		if ($_POST['if']) {
351 f326b978 Colin Fleming
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
352 45b4ffc6 Phil Davis
		}
353 667b2b60 Ermal
	}
354 180508d1 Stephen Beaver
355 667b2b60 Ermal
	$nifty_redbox = "#990000";
356
	$nifty_blackbox = "#000000";
357 f326b978 Colin Fleming
358 45b4ffc6 Phil Davis
	if (!$savebutton) {
359 370b4666 bruno
		$savebutton = "<td class=\"infoboxsave\"><input value=\"" . gettext("Close") . "\" type=\"button\" onclick=\"jQuery(this).parents('table[id=redboxtable]').hide();\" /></td>";
360 667b2b60 Ermal
	}
361
362
	echo <<<EOFnp
363 f326b978 Colin Fleming
	<table class="infobox" id="redboxtable" summary="red box table">
364 667b2b60 Ermal
		<tr>
365
			<td>
366 f326b978 Colin Fleming
				<div class="infoboxnp" id="redbox">
367
					<table class="infoboxnptable2" summary="message">
368 667b2b60 Ermal
						<tr>
369 f326b978 Colin Fleming
							<td class="infoboxnptd">
370 7ea65674 Jared Dillard
								&nbsp;&nbsp;&nbsp;<i class="fa fa-exclamation-circle"></i>
371 667b2b60 Ermal
							</td>
372 f326b978 Colin Fleming
							<td class="infoboxnptd2">
373 667b2b60 Ermal
								<b>{$msg}</b>
374
							</td>
375 96ccd009 Renato Botelho
							{$savebutton}
376 667b2b60 Ermal
							{$undobutton}
377
						</tr>
378
					</table>
379
				</div>
380
				<div>
381 f326b978 Colin Fleming
					<p>&nbsp;</p>
382 667b2b60 Ermal
				</div>
383
			</td>
384
		</tr>
385
	</table>
386
	<script type="text/javascript">
387 f326b978 Colin Fleming
	//<![CDATA[
388 667b2b60 Ermal
		Rounded("div#redbox","all","#FFF","{$nifty_redbox}","smooth");
389
		Rounded("td#blackbox","all","#FFF","{$nifty_blackbox}","smooth");
390 f326b978 Colin Fleming
	//]]>
391 667b2b60 Ermal
	</script>
392
EOFnp;
393
394
}
395
396 0074384f sbeaver
function print_info_box($msg, $class="alert-warning") {
397
	print_info_box_np($msg, null, null, false, $class);
398
399 667b2b60 Ermal
}
400
401
function get_std_save_message($ok) {
402
	global $d_sysrebootreqd_path;
403 cfaf6e69 Scott Ullrich
	$filter_related = false;
404
	$filter_pages = array("nat", "filter");
405 e28307d0 Luiz Gustavo Costa
	$to_return = gettext("The changes have been applied successfully.");
406 45b4ffc6 Phil Davis
	foreach ($filter_pages as $fp) {
407
		if (stristr($_SERVER['SCRIPT_FILENAME'], $fp)) {
408 96ccd009 Renato Botelho
			$filter_related = true;
409 45b4ffc6 Phil Davis
		}
410
	}
411
	if ($filter_related) {
412 8cd558b6 ayvis
		$to_return .= "<br />" . gettext("You can also <a href=\"status_filter_reload.php\">monitor</a> the filter reload progress.");
413 45b4ffc6 Phil Davis
	}
414 cfaf6e69 Scott Ullrich
	return $to_return;
415 667b2b60 Ermal
}
416
417
function pprint_address($adr) {
418
	global $specialnets;
419
420
	if (isset($adr['any'])) {
421
		$padr = "*";
422
	} else if ($adr['network']) {
423
		$padr = $specialnets[$adr['network']];
424
	} else {
425
		$padr = $adr['address'];
426
	}
427
428 45b4ffc6 Phil Davis
	if (isset($adr['not'])) {
429 667b2b60 Ermal
		$padr = "! " . $padr;
430 45b4ffc6 Phil Davis
	}
431 667b2b60 Ermal
432
	return $padr;
433
}
434
435
function pprint_port($port) {
436
	global $wkports;
437
438
	$pport = "";
439
440 45b4ffc6 Phil Davis
	if (!$port) {
441 667b2b60 Ermal
		return "*";
442 45b4ffc6 Phil Davis
	} else {
443 667b2b60 Ermal
		$srcport = explode("-", $port);
444
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
445
			$pport = $srcport[0];
446
			if ($wkports[$srcport[0]]) {
447
				$pport .= " (" . $wkports[$srcport[0]] . ")";
448
			}
449 45b4ffc6 Phil Davis
		} else {
450 667b2b60 Ermal
			$pport .= $srcport[0] . " - " . $srcport[1];
451 45b4ffc6 Phil Davis
		}
452 667b2b60 Ermal
	}
453
454
	return $pport;
455
}
456
457 8e0c3760 Ermal
function firewall_check_for_advanced_options(&$item) {
458 96ccd009 Renato Botelho
	$item_set = "";
459 45b4ffc6 Phil Davis
	if ($item['os']) {
460
			$item_set .= "os {$item['os']} ";
461
	}
462
	if ($item['dscp']) {
463 f0c1ce21 Phil Davis
		$item_set .= "dscp {$item['dscp']} ";
464 45b4ffc6 Phil Davis
	}
465
	if ($item['max']) {
466 96ccd009 Renato Botelho
		$item_set .= "max {$item['max']} ";
467 45b4ffc6 Phil Davis
	}
468
	if ($item['max-src-nodes']) {
469 96ccd009 Renato Botelho
		$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
470 45b4ffc6 Phil Davis
	}
471
	if ($item['max-src-conn']) {
472 96ccd009 Renato Botelho
		$item_set .= "max-src-conn {$item['max-src-conn']} ";
473 45b4ffc6 Phil Davis
	}
474
	if ($item['max-src-states']) {
475 96ccd009 Renato Botelho
		$item_set .= "max-src-states {$item['max-src-states']} ";
476 45b4ffc6 Phil Davis
	}
477
	if (isset($item['nopfsync'])) {
478 f0c1ce21 Phil Davis
		$item_set .= "nopfsync ";
479 45b4ffc6 Phil Davis
	}
480
	if ($item['statetype'] != "keep state" && $item['statetype'] != "") {
481 96ccd009 Renato Botelho
		$item_set .= "statetype {$item['statetype']} ";
482 45b4ffc6 Phil Davis
	}
483
	if ($item['statetimeout']) {
484 96ccd009 Renato Botelho
		$item_set .= "statetimeout {$item['statetimeout']} ";
485 45b4ffc6 Phil Davis
	}
486
	if (isset($item['nosync'])) {
487 f0c1ce21 Phil Davis
		$item_set .= "no XMLRPC Sync ";
488 45b4ffc6 Phil Davis
	}
489
	if ($item['max-src-conn-rate']) {
490 96ccd009 Renato Botelho
		$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
491 45b4ffc6 Phil Davis
	}
492
	if ($item['max-src-conn-rates']) {
493 96ccd009 Renato Botelho
		$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
494 45b4ffc6 Phil Davis
	}
495
	if ($item['vlanprio']) {
496 f0c1ce21 Phil Davis
		$item_set .= "vlanprio {$item['vlanprio']} ";
497 45b4ffc6 Phil Davis
	}
498
	if ($item['vlanprioset']) {
499 f0c1ce21 Phil Davis
		$item_set .= "vlanprioset {$item['vlanprioset']} ";
500 45b4ffc6 Phil Davis
	}
501
	if ($item['gateway']) {
502 96ccd009 Renato Botelho
		$item_set .= "gateway {$item['gateway']} ";
503 45b4ffc6 Phil Davis
	}
504
	if ($item['dnpipe']) {
505 96ccd009 Renato Botelho
		$item_set .= "limiter {$item['dnpipe']} ";
506 45b4ffc6 Phil Davis
	}
507
	if ($item['pdnpipe']) {
508 96ccd009 Renato Botelho
		$item_set .= "limiter {$item['pdnpipe']} ";
509 45b4ffc6 Phil Davis
	}
510
	if ($item['ackqueue']) {
511 f0c1ce21 Phil Davis
		$item_set .= "ackqueue {$item['ackqueue']} ";
512 45b4ffc6 Phil Davis
	}
513
	if ($item['defaultqueue']) {
514 f0c1ce21 Phil Davis
		$item_set .= "defaultqueue {$item['defaultqueue']} ";
515 45b4ffc6 Phil Davis
	}
516
	if ($item['l7container']) {
517 96ccd009 Renato Botelho
		$item_set .= "layer7 {$item['l7container']} ";
518 45b4ffc6 Phil Davis
	}
519
	if ($item['tag']) {
520 96ccd009 Renato Botelho
		$item_set .= "tag {$item['tag']} ";
521 45b4ffc6 Phil Davis
	}
522
	if ($item['tagged']) {
523 96ccd009 Renato Botelho
		$item_set .= "tagged {$item['tagged']} ";
524 45b4ffc6 Phil Davis
	}
525
	if (isset($item['allowopts'])) {
526 96ccd009 Renato Botelho
		$item_set .= "allowopts ";
527 45b4ffc6 Phil Davis
	}
528
	if (isset($item['disablereplyto'])) {
529 96ccd009 Renato Botelho
		$item_set .= "disable reply-to ";
530 45b4ffc6 Phil Davis
	}
531
	if ($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2']) {
532 96ccd009 Renato Botelho
		$item_set .= "tcpflags set";
533 45b4ffc6 Phil Davis
	}
534 96ccd009 Renato Botelho
535
	return $item_set;
536 8e0c3760 Ermal
}
537
538 667b2b60 Ermal
function gentitle($title) {
539
	global $navlevelsep;
540 45b4ffc6 Phil Davis
	if (!is_array($title)) {
541 667b2b60 Ermal
		return $title;
542 45b4ffc6 Phil Davis
	} else {
543 667b2b60 Ermal
		return join($navlevelsep, $title);
544 45b4ffc6 Phil Davis
	}
545 667b2b60 Ermal
}
546
547
function genhtmltitle($title) {
548 ecffb0bb Phil Davis
	if (!is_array($title))
549 ad6b0ac0 Stephen Beaver
		return '<h1 class="page-header"><a href="">' . $title . '</a></h1>';
550 45eebe10 Sander van Leeuwen
551 ad6b0ac0 Stephen Beaver
	$heading = '<h1 class="page-header"><a href="">' . end($title) . '</a></h1>';
552 2d26ee5e Sjon Hortensius
553 2f1f9a98 Stephen Beaver
	// If the array contains only one element, there are no breadcrumbs, so don't
554
	// add anything else
555
	if(count($title) > 1) {
556
		$bc = '<ol class="breadcrumb">';
557 2d26ee5e Sjon Hortensius
558 2f1f9a98 Stephen Beaver
		foreach ($title as $el)
559
			$bc .= '<li>'.$el.'</li>';
560 2d26ee5e Sjon Hortensius
561 2f1f9a98 Stephen Beaver
		$bc .= '</ol>';
562
	} else {
563
		$bc = "";
564
	}
565 2d26ee5e Sjon Hortensius
566 45eebe10 Sander van Leeuwen
	return $heading . $bc;
567 667b2b60 Ermal
}
568
569
/* update the changedesc and changecount(er) variables */
570
function update_changedesc($update) {
571
	global $changedesc;
572
	global $changecount;
573
574
	$changedesc .= " {$update}";
575
	$changecount++;
576
}
577
578 c7a3356e jim-p
function clear_log_file($logfile = "/var/log/system.log", $restart_syslogd = true) {
579 667b2b60 Ermal
	global $config, $g;
580 45b4ffc6 Phil Davis
	if ($restart_syslogd) {
581 c7a3356e jim-p
		exec("/usr/bin/killall syslogd");
582 45b4ffc6 Phil Davis
	}
583
	if (isset($config['system']['disablesyslogclog'])) {
584 667b2b60 Ermal
		unlink($logfile);
585
		touch($logfile);
586
	} else {
587 c7a3356e jim-p
		$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "511488";
588 45b4ffc6 Phil Davis
		if (isset($config['system']['usefifolog'])) {
589 d31ca336 Renato Botelho
			exec("/usr/sbin/fifolog_create -s {$log_size} " . escapeshellarg($logfile));
590 45b4ffc6 Phil Davis
		} else {
591 2a50fd8a Renato Botelho
			exec("/usr/local/sbin/clog -i -s {$log_size} " . escapeshellarg($logfile));
592 45b4ffc6 Phil Davis
		}
593 c7a3356e jim-p
	}
594 45b4ffc6 Phil Davis
	if ($restart_syslogd) {
595 c7a3356e jim-p
		system_syslogd_start();
596 45b4ffc6 Phil Davis
	}
597 c7a3356e jim-p
}
598
599
function clear_all_log_files() {
600
	global $g;
601
	exec("/usr/bin/killall syslogd");
602
603
	$log_files = array("system", "filter", "dhcpd", "vpn", "pptps", "poes", "l2tps", "openvpn", "portalauth", "ipsec", "ppp", "relayd", "wireless", "lighttpd", "ntpd", "gateways", "resolver", "routing");
604
	foreach ($log_files as $lfile) {
605
		clear_log_file("{$g['varlog_path']}/{$lfile}.log", false);
606 667b2b60 Ermal
	}
607 c7a3356e jim-p
608 96ccd009 Renato Botelho
	system_syslogd_start();
609 c7a3356e jim-p
	killbyname("dhcpd");
610
	services_dhcpd_configure();
611
	return;
612 667b2b60 Ermal
}
613
614 65a0e193 Stephen Beaver
// This version of dump_clog() does not output <td></td> or any other table elements.
615 33d52df1 sbeaver
function dump_clog_no_table($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
616
	global $g, $config;
617
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
618
	$logarr = "";
619
	$grepline = "  ";
620 ecffb0bb Phil Davis
	if (is_array($grepfor))
621 33d52df1 sbeaver
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
622 ecffb0bb Phil Davis
	if (is_array($grepinvert))
623 33d52df1 sbeaver
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
624
	if (is_dir($logfile)) {
625
		$logarr = array("File $logfile is a directory.");
626
	} elseif (file_exists($logfile) && filesize($logfile) == 0) {
627
		$logarr = array("Log file started.");
628
	} else {
629 ecffb0bb Phil Davis
		if ($config['system']['disablesyslogclog']) {
630 33d52df1 sbeaver
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
631
		} else {
632 ecffb0bb Phil Davis
			if (isset($config['system']['usefifolog']))
633 33d52df1 sbeaver
				exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
634
			else
635
				exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
636
		}
637
	}
638
	echo "\n";
639 01752a98 Sjon Hortensius
640 0074384f sbeaver
	$rows = 0;
641 33d52df1 sbeaver
	foreach ($logarr as $logent) {
642 0074384f sbeaver
		$rows++;
643
		$logent = preg_split("/\s+/", $logent, 6);
644
645
		if ($withorig) {
646 ecffb0bb Phil Davis
				if (isset($config['system']['usefifolog'])) {
647 0074384f sbeaver
					$entry_date_time = htmlspecialchars(date("F j, Y, g:i a","" . $logent[1] . ""));
648
					$entry_text = htmlspecialchars($logent[5]);
649
				} else {
650
					$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
651
					$entry_text = ($logent[3] ==  $config['system']['hostname']) ? "" : $logent[3] . " ";
652
					$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
653
				}
654
				echo "{$entry_date_time}";
655
				echo " " . "{$entry_text}"	. "\n";
656
		} else {
657
				echo htmlspecialchars($logent[5]) . "\n";
658
		}
659 33d52df1 sbeaver
660
	}
661 0074384f sbeaver
	return($rows);
662 33d52df1 sbeaver
}
663
664 667b2b60 Ermal
function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
665
	global $g, $config;
666
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
667
	$logarr = "";
668
	$grepline = "  ";
669 45b4ffc6 Phil Davis
	if (is_array($grepfor)) {
670 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
671 45b4ffc6 Phil Davis
	}
672
	if (is_array($grepinvert)) {
673 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
674 45b4ffc6 Phil Davis
	}
675 b67cdd05 Matt Smith
	if (is_dir($logfile)) {
676
		$logarr = array("File $logfile is a directory.");
677 56bd2035 jim-p
	} elseif (file_exists($logfile) && filesize($logfile) == 0) {
678 667b2b60 Ermal
		$logarr = array("Log file started.");
679
	} else {
680 45b4ffc6 Phil Davis
		if ($config['system']['disablesyslogclog']) {
681 d31ca336 Renato Botelho
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
682 667b2b60 Ermal
		} else {
683 45b4ffc6 Phil Davis
			if (isset($config['system']['usefifolog'])) {
684 d31ca336 Renato Botelho
				exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
685 45b4ffc6 Phil Davis
			} else {
686 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);
687 45b4ffc6 Phil Davis
			}
688 667b2b60 Ermal
		}
689
	}
690 ba6c5357 Stephen Beaver
691 667b2b60 Ermal
	foreach ($logarr as $logent) {
692 45b4ffc6 Phil Davis
		$logent = preg_split("/\s+/", $logent, 6);
693 ba6c5357 Stephen Beaver
		echo "<tr>\n";
694 45b4ffc6 Phil Davis
		if ($withorig) {
695
			if (isset($config['system']['usefifolog'])) {
696 6c07db48 Phil Davis
				$entry_date_time = htmlspecialchars(date("F j, Y, g:i a", "" . $logent[1] . ""));
697 45b4ffc6 Phil Davis
				$entry_text = htmlspecialchars($logent[5]);
698 667b2b60 Ermal
			} else {
699 45b4ffc6 Phil Davis
				$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
700 6c07db48 Phil Davis
				$entry_text = ($logent[3] == $config['system']['hostname']) ? "" : $logent[3] . " ";
701 45b4ffc6 Phil Davis
				$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
702 667b2b60 Ermal
			}
703 67bfaf25 Stephen Beaver
			echo "<td style=\"white-space:nowrap;\">{$entry_date_time}</td>\n";
704 247418f1 heper
			echo "<td style=\"word-wrap:break-word; word-break:break-all; white-space:normal\">{$entry_text}</td>\n";
705 45b4ffc6 Phil Davis
		} else {
706 ba6c5357 Stephen Beaver
				echo "<td>" . htmlspecialchars($logent[5]) . "</td>\n";
707 45b4ffc6 Phil Davis
		}
708
		echo "</tr>\n";
709 667b2b60 Ermal
	}
710
}
711
712
function return_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "", $grepreverse = false) {
713
	global $g, $config;
714
	$sor = (isset($config['syslog']['reverse']) || $grepreverse) ? "-r" : "";
715
	$logarr = "";
716
	$grepline = "  ";
717 45b4ffc6 Phil Davis
	if (is_array($grepfor)) {
718 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
719 45b4ffc6 Phil Davis
	}
720
	if (is_array($grepinvert)) {
721 7b7ad7f6 Renato Botelho
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
722 45b4ffc6 Phil Davis
	}
723
	if ($config['system']['disablesyslogclog']) {
724 d31ca336 Renato Botelho
		exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
725 667b2b60 Ermal
	} else {
726 45b4ffc6 Phil Davis
		if (isset($config['system']['usefifolog'])) {
727 d31ca336 Renato Botelho
			exec("/usr/sbin/fifolog_reader " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
728 667b2b60 Ermal
		} else {
729 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);
730 667b2b60 Ermal
		}
731
	}
732
	return($logarr);
733
}
734
735
/* Check if variable has changed, update and log if it has
736
 * returns true if var changed
737
 * varname = variable name in plain text
738
 * orig = original value
739
 * new = new value
740
 */
741
function update_if_changed($varname, & $orig, $new) {
742
	if (is_array($orig) && is_array($new)) {
743
		$a_diff = array_diff($orig, $new);
744
		foreach ($a_diff as $diff) {
745
			update_changedesc("removed {$varname}: \"{$diff}\"");
746
		}
747
		$a_diff = array_diff($new, $orig);
748
		foreach ($a_diff as $diff) {
749
			update_changedesc("added {$varname}: \"{$diff}\"");
750
		}
751
		$orig = $new;
752
		return true;
753
754
	} else {
755
		if ($orig != $new) {
756
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
757
			$orig = $new;
758
			return true;
759
		}
760
	}
761
	return false;
762
}
763
764
function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
765 45b4ffc6 Phil Davis
	if (isset($adr['any'])) {
766 96ccd009 Renato Botelho
		$padr = "any";
767 45b4ffc6 Phil Davis
	} else if ($adr['network']) {
768 96ccd009 Renato Botelho
		$padr = $adr['network'];
769 45b4ffc6 Phil Davis
	} else if ($adr['address']) {
770 96ccd009 Renato Botelho
		list($padr, $pmask) = explode("/", $adr['address']);
771 cb2b59b8 Renato Botelho
		if (!$pmask) {
772 45b4ffc6 Phil Davis
			if (is_ipaddrv6($padr)) {
773 cb2b59b8 Renato Botelho
				$pmask = 128;
774 45b4ffc6 Phil Davis
			} else {
775 cb2b59b8 Renato Botelho
				$pmask = 32;
776 45b4ffc6 Phil Davis
			}
777 cb2b59b8 Renato Botelho
		}
778 96ccd009 Renato Botelho
	}
779 667b2b60 Ermal
780 45b4ffc6 Phil Davis
	if (isset($adr['not'])) {
781 96ccd009 Renato Botelho
		$pnot = 1;
782 45b4ffc6 Phil Davis
	} else {
783 96ccd009 Renato Botelho
		$pnot = 0;
784 45b4ffc6 Phil Davis
	}
785 96ccd009 Renato Botelho
786
	if ($adr['port']) {
787
		list($pbeginport, $pendport) = explode("-", $adr['port']);
788 45b4ffc6 Phil Davis
		if (!$pendport) {
789 96ccd009 Renato Botelho
			$pendport = $pbeginport;
790 45b4ffc6 Phil Davis
		}
791 667b2b60 Ermal
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
792
		$pbeginport = "any";
793
		$pendport = "any";
794 96ccd009 Renato Botelho
	}
795 667b2b60 Ermal
}
796
797 6c07db48 Phil Davis
function pconfig_to_address(&$adr, $padr, $pmask, $pnot = false, $pbeginport = 0, $pendport = 0) {
798 96ccd009 Renato Botelho
	$adr = array();
799
800 45b4ffc6 Phil Davis
	if ($padr == "any") {
801 96ccd009 Renato Botelho
		$adr['any'] = true;
802 45b4ffc6 Phil Davis
	} else if (is_specialnet($padr)) {
803 96ccd009 Renato Botelho
		$adr['network'] = $padr;
804 45b4ffc6 Phil Davis
	} else {
805 96ccd009 Renato Botelho
		$adr['address'] = $padr;
806 cb2b59b8 Renato Botelho
		if (is_ipaddrv6($padr)) {
807 45b4ffc6 Phil Davis
			if ($pmask != 128) {
808 cb2b59b8 Renato Botelho
				$adr['address'] .= "/" . $pmask;
809 45b4ffc6 Phil Davis
			}
810 cb2b59b8 Renato Botelho
		} else {
811 45b4ffc6 Phil Davis
			if ($pmask != 32) {
812 cb2b59b8 Renato Botelho
				$adr['address'] .= "/" . $pmask;
813 45b4ffc6 Phil Davis
			}
814 cb2b59b8 Renato Botelho
		}
815 96ccd009 Renato Botelho
	}
816 667b2b60 Ermal
817 45b4ffc6 Phil Davis
	if ($pnot) {
818 96ccd009 Renato Botelho
		$adr['not'] = true;
819 45b4ffc6 Phil Davis
	} else {
820 96ccd009 Renato Botelho
		unset($adr['not']);
821 45b4ffc6 Phil Davis
	}
822 96ccd009 Renato Botelho
823
	if (($pbeginport != 0) && ($pbeginport != "any")) {
824 45b4ffc6 Phil Davis
		if ($pbeginport != $pendport) {
825 96ccd009 Renato Botelho
			$adr['port'] = $pbeginport . "-" . $pendport;
826 45b4ffc6 Phil Davis
		} else {
827 96ccd009 Renato Botelho
			$adr['port'] = $pbeginport;
828 45b4ffc6 Phil Davis
		}
829 96ccd009 Renato Botelho
	}
830
831 45b4ffc6 Phil Davis
	if (is_alias($pbeginport)) {
832 96ccd009 Renato Botelho
		$adr['port'] = $pbeginport;
833
	}
834 667b2b60 Ermal
}
835
836
function is_specialnet($net) {
837 96ccd009 Renato Botelho
	global $specialsrcdst;
838 667b2b60 Ermal
839 45b4ffc6 Phil Davis
	if (!$net) {
840 96ccd009 Renato Botelho
		return false;
841 45b4ffc6 Phil Davis
	}
842
	if (in_array($net, $specialsrcdst)) {
843 96ccd009 Renato Botelho
		return true;
844 45b4ffc6 Phil Davis
	} else {
845 667b2b60 Ermal
		return false;
846 45b4ffc6 Phil Davis
	}
847 667b2b60 Ermal
}
848
849
//function to create widget tabs when called
850 96ccd009 Renato Botelho
function display_widget_tabs(& $tab_array) {
851 f326b978 Colin Fleming
	echo "<div id=\"tabs\">";
852 667b2b60 Ermal
	$tabscounter = 0;
853
	foreach ($tab_array as $ta) {
854 6c07db48 Phil Davis
		$dashpos = strpos($ta[2], '-');
855 45b4ffc6 Phil Davis
		$tabname = $ta[2] . "-tab";
856 6c07db48 Phil Davis
		$tabclass = substr($ta[2], 0, $dashpos);
857 45b4ffc6 Phil Davis
		$tabclass = $tabclass . "-class";
858 667b2b60 Ermal
		if ($ta[1] == true) {
859
			$tabActive = "table-cell";
860
			$tabNonActive = "none";
861 45b4ffc6 Phil Davis
		} else {
862 667b2b60 Ermal
			$tabActive = "none";
863
			$tabNonActive = "table-cell";
864
		}
865 f326b978 Colin Fleming
		echo "<div id=\"{$ta[2]}-active\" class=\"{$tabclass}-tabactive\" style=\"display:{$tabActive}; background-color:#EEEEEE; color:black;\">";
866
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
867
		echo "&nbsp;&nbsp;&nbsp;</b>";
868 667b2b60 Ermal
		echo "</div>";
869 f326b978 Colin Fleming
870
		echo "<div id=\"{$ta[2]}-deactive\" class=\"{$tabclass}-tabdeactive\" style=\"display:{$tabNonActive}; background-color:#777777; color:white; cursor: pointer;\" onclick=\"return changeTabDIV('{$ta[2]}')\">";
871
		echo "<b>&nbsp;&nbsp;&nbsp;{$ta[0]}";
872
		echo "&nbsp;&nbsp;&nbsp;</b>";
873 667b2b60 Ermal
		echo "</div>";
874
	}
875 f326b978 Colin Fleming
876 667b2b60 Ermal
	echo "<script type=\"text/javascript\">";
877 3a2de75a jim-p
	echo "\n//<![CDATA[\n";
878 667b2b60 Ermal
	echo "Rounded(\"div.{$tabclass}-tabactive\",\"top\",\"#CCCCCC\",\"#EEEEEE\",\"smooth\");\n";
879
	echo "Rounded(\"div.{$tabclass}-tabdeactive\",\"top\",\"#CCCCCC\",\"#777777\",\"smooth\");\n";
880 3a2de75a jim-p
	echo "//]]>\n";
881 667b2b60 Ermal
	echo "</script>";
882
	echo "</div>";
883
}
884
885
886 45b4ffc6 Phil Davis
// Return inline javascript file or CSS to minimize
887 667b2b60 Ermal
// request count going back to server.
888
function outputJavaScriptFileInline($javascript) {
889 45b4ffc6 Phil Davis
	if (file_exists($javascript)) {
890 667b2b60 Ermal
		echo "\n<script type=\"text/javascript\">\n";
891
		include($javascript);
892
		echo "\n</script>\n";
893
	} else {
894 45b4ffc6 Phil Davis
		echo "\n\n<!-- Could not locate file:  {$javascript} -->\n\n";
895 667b2b60 Ermal
	}
896
}
897
898
899
900
function outputCSSPrintFileInline($css) {
901 45b4ffc6 Phil Davis
	if (file_exists($css)) {
902 667b2b60 Ermal
		echo "\n<style media=\"print\" type=\"text/css\">\n";
903
		include($css);
904
		echo "\n</style>\n";
905
	} else {
906 45b4ffc6 Phil Davis
		echo "\n\n<!-- Could not locate file:  {$css} -->\n\n";
907 667b2b60 Ermal
	}
908
}
909
910
911
function outputCSSFileInline($css) {
912 45b4ffc6 Phil Davis
	if (file_exists($css)) {
913 667b2b60 Ermal
		echo "\n<style type=\"text/css\">\n";
914
		include($css);
915
		echo "\n</style>\n";
916
	} else {
917 45b4ffc6 Phil Davis
		echo "\n\n<!-- Could not locate file:  {$css} -->\n\n";
918 667b2b60 Ermal
	}
919
}
920
921
$rfc2616 = array(
922
	100 => "100 Continue",
923
	101 => "101 Switching Protocols",
924
	200 => "200 OK",
925
	201 => "201 Created",
926
	202 => "202 Accepted",
927
	203 => "203 Non-Authoritative Information",
928
	204 => "204 No Content",
929
	205 => "205 Reset Content",
930
	206 => "206 Partial Content",
931
	300 => "300 Multiple Choices",
932
	301 => "301 Moved Permanently",
933
	302 => "302 Found",
934
	303 => "303 See Other",
935
	304 => "304 Not Modified",
936
	305 => "305 Use Proxy",
937
	306 => "306 (Unused)",
938
	307 => "307 Temporary Redirect",
939
	400 => "400 Bad Request",
940
	401 => "401 Unauthorized",
941
	402 => "402 Payment Required",
942
	403 => "403 Forbidden",
943
	404 => "404 Not Found",
944
	405 => "405 Method Not Allowed",
945
	406 => "406 Not Acceptable",
946
	407 => "407 Proxy Authentication Required",
947
	408 => "408 Request Timeout",
948
	409 => "409 Conflict",
949
	410 => "410 Gone",
950
	411 => "411 Length Required",
951
	412 => "412 Precondition Failed",
952
	413 => "413 Request Entity Too Large",
953
	414 => "414 Request-URI Too Long",
954
	415 => "415 Unsupported Media Type",
955
	416 => "416 Requested Range Not Satisfiable",
956
	417 => "417 Expectation Failed",
957
	500 => "500 Internal Server Error",
958
	501 => "501 Not Implemented",
959
	502 => "502 Bad Gateway",
960
	503 => "503 Service Unavailable",
961
	504 => "504 Gateway Timeout",
962
	505 => "505 HTTP Version Not Supported"
963
);
964
965
function is_rfc2616_code($code) {
966
	global $rfc2616;
967 45b4ffc6 Phil Davis
	if (isset($rfc2616[$code])) {
968 667b2b60 Ermal
		return true;
969 45b4ffc6 Phil Davis
	} else {
970 667b2b60 Ermal
		return false;
971 45b4ffc6 Phil Davis
	}
972 667b2b60 Ermal
}
973
974 45b4ffc6 Phil Davis
function print_rfc2616_select($tag, $current) {
975 667b2b60 Ermal
	global $rfc2616;
976
977
	/* Default to 200 OK if not set */
978 45b4ffc6 Phil Davis
	if ($current == "") {
979 667b2b60 Ermal
		$current = 200;
980 45b4ffc6 Phil Davis
	}
981 667b2b60 Ermal
982 96ccd009 Renato Botelho
	echo "<select id=\"{$tag}\" name=\"{$tag}\">\n";
983 45b4ffc6 Phil Davis
	foreach ($rfc2616 as $code => $message) {
984 667b2b60 Ermal
		if ($code == $current) {
985 f326b978 Colin Fleming
			$sel = " selected=\"selected\"";
986 667b2b60 Ermal
		} else {
987
			$sel = "";
988
		}
989
		echo "<option value=\"{$code}\"{$sel}>{$message}</option>\n";
990
	}
991 3f08e7ab Colin Fleming
	echo "</select>\n";
992 667b2b60 Ermal
}
993
994
// Useful debugging function, much cleaner than print_r
995 6c07db48 Phil Davis
function echo_array($array, $return_me = false) {
996 45b4ffc6 Phil Davis
	if (is_array($array) == false) {
997 96ccd009 Renato Botelho
		$return = "The provided variable is not an array.";
998 45b4ffc6 Phil Davis
	} else {
999
		foreach ($array as $name=>$value) {
1000
			if (is_array($value)) {
1001 96ccd009 Renato Botelho
				$return .= "";
1002
				$return .= "['<b>$name</b>'] {<div style=\"margin-left:10px;\">\n";
1003 6c07db48 Phil Davis
				$return .= echo_array($value, true);
1004 96ccd009 Renato Botelho
				$return .= "</div>}";
1005
				$return .= "\n\n";
1006 45b4ffc6 Phil Davis
			} else {
1007
				if (is_string($value)) {
1008 96ccd009 Renato Botelho
					$value = "\"$value\"";
1009
				}
1010
				$return .= "['<b>$name</b>'] = $value\n\n";
1011
			}
1012
		}
1013
	}
1014 45b4ffc6 Phil Davis
	if ($return_me == true) {
1015 96ccd009 Renato Botelho
		return $return;
1016 45b4ffc6 Phil Davis
	} else {
1017 96ccd009 Renato Botelho
		echo "<pre>".$return."</pre>";
1018
	}
1019 667b2b60 Ermal
}
1020
1021
/****f* pfsense-utils/display_top_tabs
1022
 * NAME
1023 0074384f sbeaver
 *	 display_top_tabs - display tabs with rounded edges
1024 667b2b60 Ermal
 * INPUTS
1025 0074384f sbeaver
 *	 $text	  - array of tabs
1026 667b2b60 Ermal
 * RESULT
1027 0074384f sbeaver
 *	 null
1028 667b2b60 Ermal
 ******/
1029 748cbea6 Sander van Leeuwen
function display_top_tabs(& $tab_array, $no_drop_down = false, $type = 'pills') {
1030 96ccd009 Renato Botelho
	global $config;
1031
	global $g;
1032
	global $tab_array_indent;
1033
	global $tab_array_space;
1034
	global $tab_array_char_limit;
1035
1036 0074384f sbeaver
	/*	does the user have access to this tab?
1037
	 *	master user has access to everything.
1038
	 *	if the user does not have access, simply
1039
	 *	unset the tab item.
1040 96ccd009 Renato Botelho
	 */
1041
1042
	/* empty string code */
1043
	if ($tab_array_indent == '') {
1044
		$tab_array_indent = 0;
1045
	}
1046 620ac186 Scott Ullrich
1047 96ccd009 Renato Botelho
	if ($tab_array_space == '') {
1048
		$tab_array_space = 1;
1049
	}
1050 620ac186 Scott Ullrich
1051 96ccd009 Renato Botelho
	if ($tab_array_char_limit == '') {
1052
		$tab_array_char_limit = 92;
1053
	}
1054 667b2b60 Ermal
1055 45b4ffc6 Phil Davis
	foreach ($tab_array as $tab_id => $ta) {
1056
		if (!isAllowedPage($ta[2])) {
1057 96ccd009 Renato Botelho
			unset ($tab_array[$tab_id]);
1058 45b4ffc6 Phil Davis
		}
1059 96ccd009 Renato Botelho
	}
1060 667b2b60 Ermal
1061 0074384f sbeaver
	$tab_active_bg	 = "#EEEEEE";
1062 96ccd009 Renato Botelho
	$tab_inactive_bg = "#777777";
1063
	$nifty_tabs_corners = "#FFF";
1064
	$font_color = "white";
1065
1066
	$tabcharcount = 0;
1067
	foreach ($tab_array as $ta)
1068
		$tabcharcount = $tabcharcount + strlen($ta[0]);
1069 620ac186 Scott Ullrich
1070 ecffb0bb Phil Davis
	if ($no_drop_down == true) {
1071 96ccd009 Renato Botelho
		$tabcharcount = 0;
1072
		unset($tab_array_char_limit);
1073
	}
1074
1075
	// If the character count of the tab names is > 670
1076
	// then show a select item dropdown menubox.
1077 02e2825a Stephen Beaver
	if ($tabcharcount > $tab_array_char_limit) {
1078 e28307d0 Luiz Gustavo Costa
		echo gettext("Currently viewing: ");
1079 96ccd009 Renato Botelho
		echo "<select name=\"TabSelect\" onchange=\"tabs_will_go(this)\">\n";
1080 02e2825a Stephen Beaver
1081 96ccd009 Renato Botelho
		foreach ($tab_array as $ta) {
1082 ecffb0bb Phil Davis
			if ($ta[1] == "true")
1083 96ccd009 Renato Botelho
				$selected = " selected=\"selected\"";
1084
			else
1085
				$selected = "";
1086
			// Onclick in option will not work in some browser
1087
			// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
1088
			echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
1089
		}
1090 02e2825a Stephen Beaver
1091 96ccd009 Renato Botelho
		echo "</select>\n<p>&nbsp;</p>";
1092
		echo "<script type=\"text/javascript\">";
1093
		echo "\n//<![CDATA[\n";
1094
		echo " function tabs_will_go(obj){ document.location = obj.value; }\n";
1095
		echo "//]]>\n";
1096
		echo "</script>";
1097 02e2825a Stephen Beaver
	} else {
1098
		echo '<ul class="nav nav-' . $type . '">';
1099
1100
		foreach ($tab_array as $ta) {
1101
			echo '<li role="presentation"';
1102
			if ($ta[1]) {
1103
				echo ' class="active"';
1104
			}
1105
1106
			echo '><a href="' . $ta[2] . '">' . $ta[0] . '</a></li>';
1107
		}
1108
1109
		echo '</ul>';
1110
	}
1111 667b2b60 Ermal
}
1112
1113 a2b0d909 Renato Botelho
function add_package_tabs($tabgroup, &$tab_array) {
1114 96ccd009 Renato Botelho
	global $config, $g;
1115
1116 a2b0d909 Renato Botelho
	if (!isset($config['installedpackages']['package'])) {
1117 96ccd009 Renato Botelho
		return;
1118 45b4ffc6 Phil Davis
	}
1119 253b37d8 Renato Botelho
1120 a2b0d909 Renato Botelho
	foreach ($config['installedpackages']['package'] as $pkg){
1121
		$pkg_config = read_package_configurationfile($pkg['name']);
1122 253b37d8 Renato Botelho
1123 a2b0d909 Renato Botelho
		if (!isset($pkg_config['tabs']['tab'])) {
1124
			continue;
1125
		}
1126 96ccd009 Renato Botelho
1127 a2b0d909 Renato Botelho
		foreach ($pkg_config['tabs']['tab'] as $tab) {
1128
			$tab_entry = array();
1129
			if ($tab['name']) {
1130
				$tab_entry[] = $tab['name'];
1131
				$tab_entry[] = false;
1132
				$tab_entry[] = $tab['url'];
1133
				$tab_array[] = $tab_entry;
1134
			}
1135 96ccd009 Renato Botelho
		}
1136
	}
1137 667b2b60 Ermal
}
1138
1139 45b4ffc6 Phil Davis
function alias_info_popup($alias_id) {
1140 667b2b60 Ermal
	global $config;
1141 3b2c83b8 Sjon Hortensius
1142
	if (!is_array($config['aliases']['alias'][$alias_id]))
1143
		return;
1144
1145 4e8854c6 Charlie Root
	$maxlength = 60;
1146 3b2c83b8 Sjon Hortensius
	$alias = $config['aliases']['alias'][$alias_id];
1147
	$content = "";
1148
1149
	if ($alias['url'])
1150
	{
1151
		// TODO: Change it when pf supports tables with ports
1152
		if ($alias['type'] == "urltable") {
1153
			exec("/sbin/pfctl -t {$alias['name']} -T show | wc -l", $total_entries);
1154
			$counter=preg_replace("/\D/","",$total_entries[0]);
1155
			exec("/sbin/pfctl -t {$alias['name']} -T show | head -10002", $alias_addresses);
1156
		} else {
1157
			$urlfn = alias_expand_urltable($alias['name']);
1158
			$alias_addresses = explode("\n", file_get_contents($urlfn));
1159
			$counter = count($alias_addresses);
1160 4e8854c6 Charlie Root
		}
1161 3b2c83b8 Sjon Hortensius
1162
		$content .= '<h5>'. $alias['url'] .'</h5><ul><li>'. implode('</li><li>', $alias_ports_address) .'</li></ul>';
1163
1164
		if ($counter > 10002)
1165
			$content .= '<i>'. gettext("listing only first 10k items") .'</i>';
1166 d329d587 Darren Embry
	}
1167 3b2c83b8 Sjon Hortensius
	else
1168
	{
1169
		$alias_addresses = explode (" ", $alias['address']);
1170
		$alias_details = explode ("||", $alias['detail']);
1171 8b53fe2f Stephen Beaver
		$idx = 0;
1172
1173
		$content .= "<table>\n";
1174
		$content .= "<thead>\n";
1175
		$content .= "<tr>\n";
1176
		$content .= "<th>" . gettext("Value") . "</th><th  style='padding-left: 10px;'>" . gettext("Description") . "</th></tr>\n";
1177
		$content .= "</thead>\n";
1178
		$content .= "<tbody>\n";
1179
1180
		foreach ($alias_addresses as $ap) {
1181
			$content .= "	<tr>\n";
1182
			$content .= "		<td>\n";
1183
			$content .= 			$ap;
1184
			$content .=	"		</td>\n";
1185
			$content .= "		<td style='padding-left: 10px;'>\n";
1186
			$content .= 			$alias_details[$idx];
1187
			$content .=	"		</td>\n";
1188
			$content .= "	</tr>\n";
1189
			$idx++;
1190
		}
1191 3b2c83b8 Sjon Hortensius
1192 8b53fe2f Stephen Beaver
		$content .= "</tbody>\n";
1193
		$content .= "<table>\n";
1194 3b2c83b8 Sjon Hortensius
	}
1195
1196
	if (strlen($alias['descr']) >= $maxlength)
1197
		$alias['descr'] = substr($alias['descr'], 0, $maxlength) . '&hellip;';
1198
1199
	return $content;
1200 4e8854c6 Charlie Root
}
1201
1202 ecffb0bb Phil Davis
function rule_columns_with_alias($src, $srcport, $dst, $dstport) {
1203 3b2c83b8 Sjon Hortensius
	global $config;
1204
1205
	if ($config['aliases']['alias'] == "" || !is_array($config['aliases']['alias']))
1206
		return;
1207
1208
	$columns = array();
1209 ecffb0bb Phil Davis
	foreach ($config['aliases']['alias'] as $alias_id => $alias_name) {
1210 3b2c83b8 Sjon Hortensius
		if ($alias_name['name'] == $src)
1211
			$columns['src'] = $alias_id;
1212 e83aaa50 Stephen Beaver
		if ($alias_name['name'] == $srcport)
1213 3b2c83b8 Sjon Hortensius
			$columns['srcport'] = $alias_id;
1214 e83aaa50 Stephen Beaver
		if ($alias_name['name'] == $dst )
1215 3b2c83b8 Sjon Hortensius
			$columns['dst'] = $alias_id;
1216 e83aaa50 Stephen Beaver
		if ($alias_name['name'] == $dstport)
1217 3b2c83b8 Sjon Hortensius
			$columns['dstport'] = $alias_id;
1218 96ccd009 Renato Botelho
	}
1219 e27eac0c Stephen Beaver
1220
	return $columns;
1221 667b2b60 Ermal
}
1222
1223 ecffb0bb Phil Davis
function form_output_row($name, $label, $content) {
1224 7d5b007c Sjon Hortensius
var_dump($content);die;
1225
?>
1226
<div class="form-group">
1227
	<label for="<?=$name?>" class="col-sm-2 control-label"><?=gettext($label); ?></label>
1228
	<div class="col-sm-10">
1229
		<?=$content?>
1230
	</div>
1231
</div>
1232
<?php
1233
}
1234
1235 ecaca752 Renato Botelho
/* set timezone */
1236
if (isset($config['system']['timezone']) &&
1237
    !empty($config['system']['timezone'])) {
1238
	$timezone = $config['system']['timezone'];
1239
} elseif (isset($g['default_timezone']) && !empty($g['default_timezone'])) {
1240
	$timezone = $g['default_timezone'];
1241
} else {
1242 3b49bc25 Scott Ullrich
	$timezone = "Etc/UTC";
1243 45b4ffc6 Phil Davis
}
1244 3b49bc25 Scott Ullrich
1245
date_default_timezone_set($timezone);
1246
1247 667b2b60 Ermal
?>