Project

General

Profile

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