Project

General

Profile

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