Project

General

Profile

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