Project

General

Profile

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