Project

General

Profile

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