Project

General

Profile

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