Project

General

Profile

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