guiconfig.inc 18.8 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1
<?php
2

Ad Schellevis's avatar
Ad Schellevis committed
3
/*
4
	Copyright (C) 2015-2016 Franco Fichtner <franco@opnsense.org>
5
	Copyright (C) 2014 Deciso B.V.
6
	Copyright (C) 2004 Scott Ullrich
Ad Schellevis's avatar
Ad Schellevis committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
	All rights reserved.

	Redistribution and use in source and binary forms, with or without
	modification, are permitted provided that the following conditions are met:

	1. Redistributions of source code must retain the above copyright notice,
	   this list of conditions and the following disclaimer.

	2. Redistributions in binary form must reproduce the above copyright
	   notice, this list of conditions and the following disclaimer in the
	   documentation and/or other materials provided with the distribution.

	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/
31

32
require_once("util.inc");
33
require_once("config.inc");
34

Ad Schellevis's avatar
Ad Schellevis committed
35
/* THIS MUST BE ABOVE ALL OTHER CODE */
36 37 38
if (empty($nocsrf)) {
	function csrf_startup()
	{
Ad Schellevis's avatar
Ad Schellevis committed
39 40 41 42
		csrf_conf('rewrite-js', '/csrf/csrf-magic.js');
		$timeout_minutes = isset($config['system']['webgui']['session_timeout']) ?  $config['system']['webgui']['session_timeout'] : 240;
		csrf_conf('expires', $timeout_minutes * 60);
	}
43
	require_once('csrf/csrf-magic.php');
44 45 46 47 48

        // make sure the session is closed after executing csrf-magic
        if (session_status() != PHP_SESSION_NONE) {
            session_write_close();
        }
49
}
Ad Schellevis's avatar
Ad Schellevis committed
50

51
function set_language()
52
{
53 54 55 56 57 58 59
	global $config;

	$lang = 'en_US';
	if (!empty($config['system']['language'])) {
		$lang = $config['system']['language'];
	}

60 61 62 63 64 65 66 67
	$lang_encoding = $lang . '.UTF-8';
	$textdomain = 'OPNsense';

	putenv('LANG=' . $lang_encoding);
	setlocale(LC_ALL, $lang_encoding);
	textdomain($textdomain);
	bindtextdomain($textdomain, '/usr/local/share/locale');
	bind_textdomain_codeset($textdomain, $lang_encoding);
Ad Schellevis's avatar
Ad Schellevis committed
68 69
}

70 71 72 73 74 75 76 77 78
function get_current_theme()
{
	global $config;

	$theme = 'opnsense';

	if (isset($config['theme']) && is_dir('/usr/local/opnsense/www/themes/' . $config['theme'])) {
		$theme = $config['theme'];
	}
79

80 81
	return $theme;
}
82

83 84 85 86 87 88
function html_safe($text)
{
	/* gettext() embedded in JavaScript can cause syntax errors */
	return htmlspecialchars($text, ENT_QUOTES | ENT_HTML401);
}

Ad Schellevis's avatar
Ad Schellevis committed
89
/* make sure nothing is cached */
90
if (isset($omit_nocacheheaders) && $omit_nocacheheaders) {
Ad Schellevis's avatar
Ad Schellevis committed
91 92 93 94 95 96 97 98 99
	header("Expires: 0");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
}

header("X-Frame-Options: SAMEORIGIN");

100
set_language();
Ad Schellevis's avatar
Ad Schellevis committed
101

102 103
require_once("authgui.inc");

Ad Schellevis's avatar
Ad Schellevis committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
/* Reserved table names to avoid colision */
$reserved_table_names = array(
        "bogons",
        "bogonsv6",
        "negate_networks",
        "sshlockout",
        "tonatsubnets",
        "virusprot",
        "vpn_networks",
        "webConfiguratorlockout"
);


$netbios_nodetypes = array(
	'0' => "none",
	'1' => "b-node",
	'2' => "p-node",
	'4' => "m-node",
	'5' => "h-node");

/* some well knows ports */
$wkports = array(
	5999 => "CVSup",
	53 => "DNS",
	21 => "FTP",
	3000 => "HBCI",
	80 => "HTTP",
	443 => "HTTPS",
	5190 => "ICQ",
	113 => "IDENT/AUTH",
	143 => "IMAP",
	993 => "IMAP/S",
	4500 => "IPsec NAT-T",
	500 => "ISAKMP",
	1701 => "L2TP",
	389 => "LDAP",
	1755 => "MMS/TCP",
	7000 => "MMS/UDP",
	445 => "MS DS",
	3389 => "MS RDP",
	1512 => "MS WINS",
	1863 => "MSN",
	119 => "NNTP",
	123 => "NTP",
	138 => "NetBIOS-DGM",
	137 => "NetBIOS-NS",
	139 => "NetBIOS-SSN",
	1194 => "OpenVPN",
	110 => "POP3",
	995 => "POP3/S",
	1723 => "PPTP",
	1812 => "RADIUS",
	1813 => "RADIUS accounting",
	5004 => "RTP",
	5060 => "SIP",
	25 => "SMTP",
	465 => "SMTP/S",
	161 => "SNMP",
	162 => "SNMP-Trap",
	22 => "SSH",
	3478 => "STUN",
	587 => "SUBMISSION",
	3544 => "Teredo",
	23 => "Telnet",
	69 => "TFTP",
	5900 => "VNC");

171 172 173 174 175
$wlan_modes = array(
	'bss' => 'Infrastructure (BSS)',
	'adhoc' => 'Ad-hoc (IBSS)',
	'hostap' => 'Access Point'
);
Ad Schellevis's avatar
Ad Schellevis committed
176

177 178
function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors)
{
Ad Schellevis's avatar
Ad Schellevis committed
179 180 181 182 183 184 185 186
	/* check for bad control characters */
	foreach ($postdata as $pn => $pd) {
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
			$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
		}
	}

	for ($i = 0; $i < count($reqdfields); $i++) {
187 188
		// why.. do you want to do this? we send data to validate and then validate something else....
		// can't now for sure if any page uses this wrong behaviour, but it should die eventually.
189
		// TODO: kill
190
		if (empty($_POST[$reqdfields[$i]]) && empty($_REQUEST[$reqdfields[$i]])) {
Ad Schellevis's avatar
Ad Schellevis committed
191 192 193 194 195
			$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
		}
	}
}

196 197 198
function print_input_errors($input_errors)
{
	echo '<div class="col-xs-12"><div class="alert alert-danger" role="alert">
199 200
            <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
	';
201 202

	echo "<p>" . gettext("The following input errors were detected:") . "</p>\n<ul>";
Ad Schellevis's avatar
Ad Schellevis committed
203 204 205
	foreach ($input_errors as $ierr) {
		echo "<li>" . htmlspecialchars($ierr) . "</li>";
	}
206
	echo "</ul></div></div>";
Ad Schellevis's avatar
Ad Schellevis committed
207 208
}

209 210 211 212 213 214 215 216 217 218 219 220
function print_alert_box($msg, $alert = 'warning', $button = '')
{
	echo <<<EOFnp
<div class="col-xs-12">
	<div class="alert alert-{$alert}" role="alert">
		{$button}
		<p>{$msg}</p>
	</div>
</div>
EOFnp;
}

221 222
function print_info_box_apply($msg)
{
223 224 225
	$iface = !empty($_POST['if']) ? $_POST['if'] : (!empty($_GET['if']) ? $_GET['if'] : '');
	$label = gettext('Apply changes');
	$value = 'Apply changes';
226 227
	$name= 'apply';

228 229 230 231 232 233 234 235 236 237 238 239 240
	$savebutton = sprintf('<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">', $_SERVER['REQUEST_URI']);
	$savebutton .= sprintf(
		'<button type="submit" name="%s" id="%s" class="btn btn-primary pull-right" value="%s">%s</button>',
		$name,
		$name,
		$value,
		$label
	);
	if (!empty($iface)) {
		$savebutton .= sprintf(
			'<input type="hidden" name="if" value="%s"/>',
			htmlspecialchars($iface)
		);
241 242 243
	}
	$savebutton .= '</form>';

244
	print_alert_box($msg, 'info', $savebutton);
245 246
}

247
function print_info_box($msg)
248
{
249
	print_alert_box($msg, 'info');
Ad Schellevis's avatar
Ad Schellevis committed
250 251
}

252 253
function print_service_banner($service)
{
254 255 256 257
	global $config;

	switch ($service) {
		case 'firewall':
258
			if (!isset($config['system']['disablefilter'])) {
259
				break;
260 261 262 263 264 265 266 267 268 269 270 271 272
			}
			print_alert_box(sprintf(
				gettext(
					'The firewall has globally been disabled and configured rules are ' .
					'currently not enforced. It can be enabled in the %sFirewall/NAT%s ' .
					'settings.'
				),
				'<a href="/system_advanced_firewall.php">',
				'</a>'
			));
			break;
		default:
			break;
273 274 275
	}
}

276
function get_std_save_message() {
Ad Schellevis's avatar
Ad Schellevis committed
277 278 279 280 281 282 283 284 285 286 287 288 289
	global $d_sysrebootreqd_path;
	$filter_related = false;
	$filter_pages = array("nat", "filter");
	$to_return = gettext("The changes have been applied successfully.");
	foreach($filter_pages as $fp)
		if(stristr($_SERVER['SCRIPT_FILENAME'], $fp))
			$filter_related = true;
	if($filter_related)
		$to_return .= "<br />" . gettext("You can also <a href=\"status_filter_reload.php\">monitor</a> the filter reload progress.");
	return $to_return;
}

function pprint_address($adr) {
290 291 292 293 294 295 296 297 298 299
	if (!isset($specialnets)) {
		global $specialnets;
		$specialnets = array("(self)" => "This Firewall", "pptp" => "PPTP clients", "pppoe" => "PPPoE clients", "l2tp" => "L2TP clients");

		$spiflist = get_configured_interface_with_descr(false, true);
		foreach ($spiflist as $ifgui => $ifdesc) {
			$specialnets[$ifgui] = $ifdesc . " net";
			$specialnets[$ifgui . 'ip'] = $ifdesc . " address";
		}
	}
Ad Schellevis's avatar
Ad Schellevis committed
300 301 302

	if (isset($adr['any'])) {
		$padr = "*";
303
	} else if (isset($adr['network'])) {
Ad Schellevis's avatar
Ad Schellevis committed
304 305
		$padr = $specialnets[$adr['network']];
	} else {
306
		$padr = isset($adr['address']) ? $adr['address'] : null;
Ad Schellevis's avatar
Ad Schellevis committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
	}

	if (isset($adr['not']))
		$padr = "! " . $padr;

	return $padr;
}

function pprint_port($port) {
	global $wkports;

	$pport = "";

	if (!$port)
		return "*";
	else {
		$srcport = explode("-", $port);
324
		if ((empty($srcport[1])) || ($srcport[0] == $srcport[1])) {
Ad Schellevis's avatar
Ad Schellevis committed
325
			$pport = $srcport[0];
326
			if (!empty($wkports[$srcport[0]])) {
Ad Schellevis's avatar
Ad Schellevis committed
327 328 329 330 331 332 333 334 335
				$pport .= " (" . $wkports[$srcport[0]] . ")";
			}
		} else
			$pport .= $srcport[0] . " - " . $srcport[1];
	}

	return $pport;
}

336
function gentitle($breadcrumbs, $navlevelsep = ': ')
337 338 339 340 341 342 343 344 345 346 347
{
	$output = $breadcrumbs;

	if (isset($breadcrumbs[0]['name'])) {
		$output = array();
		foreach ($breadcrumbs as $crumb) {
			$output[] = gettext($crumb['name']);
		}
	}

	return join($navlevelsep, $output);
Ad Schellevis's avatar
Ad Schellevis committed
348 349
}

350
function clear_log($logfile, $restart_syslogd = true)
351
{
352 353
	if ($restart_syslogd) {
		killbyname('syslogd');
Ad Schellevis's avatar
Ad Schellevis committed
354
	}
355 356 357 358 359 360

	foreach (glob($logfile . '.*') as $rotated) {
		@unlink($rotated);
	}

	/* preserve file ownership and permissions */
361 362 363 364 365 366
	if (file_exists($logfile)) {
		$handle = fopen($logfile, 'r+');
		if ($handle) {
			ftruncate($handle, 0);
			fclose($handle);
		}
367 368
	}

369
	if ($restart_syslogd) {
Ad Schellevis's avatar
Ad Schellevis committed
370
		system_syslogd_start();
371
	}
Ad Schellevis's avatar
Ad Schellevis committed
372 373
}

374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
function clear_clog($logfile, $restart_syslogd = true)
{
	global $config;

	if ($restart_syslogd) {
		killbyname('syslogd');
	}

	$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : '511488';
	mwexecf('/usr/local/sbin/clog -i -s %s %s', array($log_size, $logfile));

	if ($restart_syslogd) {
		system_syslogd_start();
	}
}

390
function print_dump($logarr)
391 392 393
{
	global $config;

394 395 396 397 398 399 400
	if (!is_array($logarr)) {
		echo "<tr valign=\"top\">\n";
		echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logarr) . "</td>\n";
		echo "</tr>\n";
		return;
	}

401 402 403
	foreach ($logarr as $logent) {
		$logent = preg_split("/\s+/", $logent, 6);
		echo "<tr valign=\"top\">\n";
404 405 406 407 408
		$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
		$entry_text = ($logent[3] ==  $config['system']['hostname']) ? "" : $logent[3] . " ";
		$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
		echo "<td class=\"listlr nowrap\">{$entry_date_time}</td>\n";
		echo "<td class=\"listr\">{$entry_text}</td>\n";
409 410 411 412
		echo "</tr>\n";
	}
}

413
function dump_clog($logfile, $tail, $grepfor = '')
414 415 416 417
{
	global $config;

	$sor = isset($config['syslog']['reverse']) ? '-r' : '';
418 419
	$logarr = array();
	$grepline = '';
420

421
	$grepfor = preg_split('/\s+/', trim($grepfor));
422

423 424
	foreach ($grepfor as $pattern) {
		$grepline .= ' | /usr/bin/egrep -i ' . escapeshellarg($pattern);
425 426
	}

Ad Schellevis's avatar
Ad Schellevis committed
427
	if (is_dir($logfile)) {
428
		$logarr = sprintf(gettext('File %s is a directory.'), $logfile);
429
	} elseif (!file_exists($logfile)) {
430
		$logarr = sprintf(gettext('File %s doesn\'t exist.'), $logfile);
Ad Schellevis's avatar
Ad Schellevis committed
431
	} else {
432
		exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . " {$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
Ad Schellevis's avatar
Ad Schellevis committed
433
	}
434

435 436
	if (is_array($logarr) && !count($logarr)) {
		$logarr = sprintf(gettext('File %s yielded no results.'), $logfile);
437 438
	}

439
	print_dump($logarr);
Ad Schellevis's avatar
Ad Schellevis committed
440 441
}

442
function dump_log($logfile, $tail, $grepfor = '')
443 444 445 446
{
	global $config;

	$sor = isset($config['syslog']['reverse']) ? '-r' : '';
447 448
	$logarr = array();
	$grepline = '';
449

450
	$grepfor = preg_split('/\s+/', trim($grepfor));
451

452 453
	foreach ($grepfor as $pattern) {
		$grepline .= ' | /usr/bin/egrep -i ' . escapeshellarg($pattern);
454 455 456
	}

	if (is_dir($logfile)) {
457
		$logarr = sprintf(gettext('File %s is a directory.'), $logfile);
458
	} elseif (!file_exists($logfile)) {
459
		$logarr = sprintf(gettext('File %s doesn\'t exist.'), $logfile);
460
	} else {
461
		exec("cat " . escapeshellarg($logfile) . " {$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
462 463
	}

464 465
	if (is_array($logarr) && !count($logarr)) {
		$logarr = sprintf(gettext('File %s yielded no results.'), $logfile);
466 467
	}

468
	print_dump($logarr);
469
}
Ad Schellevis's avatar
Ad Schellevis committed
470 471 472 473

function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
	if (isset($adr['any']))
		$padr = "any";
474
	else if (isset($adr['network']))
Ad Schellevis's avatar
Ad Schellevis committed
475
		$padr = $adr['network'];
476
	else if (isset($adr['address'])) {
477 478 479 480
		if (strpos($adr['address'], '/') !== false) {
			list($padr, $pmask) = explode("/", $adr['address']);
		} else {
			$padr = $adr['address'];
Ad Schellevis's avatar
Ad Schellevis committed
481 482 483 484 485
			if (is_ipaddrv6($padr))
				$pmask = 128;
			else
				$pmask = 32;
		}
486

Ad Schellevis's avatar
Ad Schellevis committed
487 488 489 490 491 492 493
	}

	if (isset($adr['not']))
		$pnot = 1;
	else
		$pnot = 0;

494
	if (isset($adr['port'])) {
495
		if (strpos($adr['port'], '-') !== false) {
496 497 498
			list($pbeginport, $pendport) = explode("-", $adr['port']);
		} else {
			$pbeginport = $adr['port'];
Ad Schellevis's avatar
Ad Schellevis committed
499
			$pendport = $pbeginport;
500
		}
Ad Schellevis's avatar
Ad Schellevis committed
501 502 503 504 505 506 507
	} else if (!is_alias($pbeginport) && !is_alias($pendport)) {
		$pbeginport = "any";
		$pendport = "any";
	}
}

function pconfig_to_address(&$adr, $padr, $pmask, $pnot=false, $pbeginport=0, $pendport=0) {
508 509 510 511 512 513 514
		$adr = array();
		if ($padr == "any") {
				$adr['any'] = true;
		} elseif (is_specialnet($padr)) {
				$adr['network'] = $padr;
		} elseif (is_alias($padr)) {
				$adr['address'] = $padr;
Ad Schellevis's avatar
Ad Schellevis committed
515
		} else {
516 517 518 519 520 521 522 523
			$adr['address'] = $padr;
			if (is_ipaddrv6($padr)) {
				if ($pmask != 128)
					$adr['address'] .= "/" . $pmask;
			} else {
				if ($pmask != 32)
					$adr['address'] .= "/" . $pmask;
			}
Ad Schellevis's avatar
Ad Schellevis committed
524 525
		}

526 527 528 529 530
		if ($pnot) {
				$adr['not'] = true;
		} elseif (isset($adr['not'])) {
				unset($adr['not']);
		}
Ad Schellevis's avatar
Ad Schellevis committed
531

532 533 534 535 536 537 538 539 540
		if(is_alias($pbeginport)) {
				$adr['port'] = $pbeginport;
		} elseif (($pbeginport != 0) && ($pbeginport != "any")) {
				if ($pbeginport != $pendport) {
						$adr['port'] = $pbeginport . "-" . $pendport;
				} else {
						$adr['port'] = $pbeginport;
				}
		}
Ad Schellevis's avatar
Ad Schellevis committed
541 542 543 544 545 546 547
}

function is_specialnet($net) {
	global $specialsrcdst;

	if(!$net)
		return false;
548
	if (is_array($specialsrcdst) && in_array($net, $specialsrcdst))
Ad Schellevis's avatar
Ad Schellevis committed
549 550 551 552 553 554 555
		return true;
	else
		return false;
}



556
/****f* guiconfig/display_top_tabs
Ad Schellevis's avatar
Ad Schellevis committed
557 558 559 560 561 562 563
 * NAME
 *   display_top_tabs - display tabs with rounded edges
 * INPUTS
 *   $text      - array of tabs
 * RESULT
 *   null
 ******/
564 565
function display_top_tabs(& $tab_array, $no_drop_down = false)
{
Ad Schellevis's avatar
Ad Schellevis committed
566
	global $config;
567

568
	$tab_array_char_limit = 92;
Ad Schellevis's avatar
Ad Schellevis committed
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591

	/*  does the user have access to this tab?
	 *  master user has access to everything.
	 *  if the user does not have access, simply
	 *  unset the tab item.
	 */
	foreach ($tab_array as $tab_id => $ta){
		if(!isAllowedPage($ta[2]))
			unset ($tab_array[$tab_id]);
	}

	$tabcharcount = 0;
	foreach ($tab_array as $ta)
		$tabcharcount = $tabcharcount + strlen($ta[0]);

	if($no_drop_down == true) {
		$tabcharcount = 0;
		unset($tab_array_char_limit);
	}

	// If the character count of the tab names is > 670
	// then show a select item dropdown menubox.
	if($tabcharcount > $tab_array_char_limit) {
592
		echo "<h2>".gettext("Currently viewing: ")."</h2>";
593
		echo "<select class=\"selectpicker\" name=\"TabSelect\" onchange=\"tabs_will_go(this)\" data-live-search=\"true\" data-style=\"btn-default\">\n";
Ad Schellevis's avatar
Ad Schellevis committed
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
		foreach ($tab_array as $ta) {
			if($ta[1]=="true")
				$selected = " selected=\"selected\"";
			else
				$selected = "";
			// Onclick in option will not work in some browser
			// echo "<option onclick=\"document.location='{$ta[2]}';\"{$selected}>{$ta['0']}</option>\n";
			echo "<option value=\"{$ta[2]}\"{$selected}>{$ta['0']}</option>\n";
		}
		echo "</select>\n<p>&nbsp;</p>";
		echo "<script type=\"text/javascript\">";
		echo "\n//<![CDATA[\n";
		echo " function tabs_will_go(obj){ document.location = obj.value; }\n";
		echo "//]]>\n";
		echo "</script>";
	}  else {
		echo "<!-- Tabbed bar code-->\n";
611
		echo "<ul class=\"nav nav-tabs nav-justified\" role=\"tablist\">\n";
Ad Schellevis's avatar
Ad Schellevis committed
612 613 614
		$tabscounter = 0;
		foreach ($tab_array as $ta) {
			if ($ta[1] == true) {
615
				echo "  <li class=\"active\"><a href=\"{$ta[2]}\" role=\"tab\">{$ta[0]}</a></li>\n";
Ad Schellevis's avatar
Ad Schellevis committed
616
			} else {
617
				echo "  <li><a href=\"{$ta[2]}\" role=\"tab\">{$ta[0]}</a></li>\n";
Ad Schellevis's avatar
Ad Schellevis committed
618 619 620
			}
			$tabscounter++;
		}
621
		echo "</ul>\n";
Ad Schellevis's avatar
Ad Schellevis committed
622 623 624 625
	}
}

$timezone = $config['system']['timezone'];
626 627 628
if (!$timezone) {
	$timezone = 'Etc/UTC';
}
Ad Schellevis's avatar
Ad Schellevis committed
629 630

date_default_timezone_set($timezone);
631 632 633

function get_crash_report($pedantic = false)
{
634 635 636 637 638 639
	$savemsg = sprintf(
		gettext('A problem was detected. Click %shere%s for more information.'),
		'<a href="/crash_reporter.php">',
		'</a>'
	);
	$skip_files = array('.', '..', 'minfree', 'bounds', '');
640 641
	$PHP_errors_log = '/tmp/PHP_errors.log';
	$excludes = array();
642 643
	$count = 0;

644 645 646 647 648 649 650 651 652
	if (!$pedantic) {
		$excludes[] = 'PHP Notice:';
		$excludes[] = 'PHP Startup: Unable to load dynamic library \'/usr/local/lib/php/20131226/suhosin.so\' - /usr/local/lib/php/20131226/suhosin.so: Undefined symbol "ps_globals" in Unknown on line 0';
	}

	if (file_exists($PHP_errors_log)) {
		$extra = '';
		foreach ($excludes as $exclude) {
			$extra .= sprintf('/usr/bin/grep -v %s | ', escapeshellarg($exclude));
653
		}
654 655 656 657 658
		$total = shell_exec(sprintf(
			'/bin/cat %s | %s /usr/bin/wc -l | /usr/bin/awk \'{ print $1 }\'',
			$PHP_errors_log,
			$extra
		));
659
		if ($total > 0) {
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
			$count++;
		}
	}

	$crashes = glob('/var/crash/*');
	foreach ($crashes as $crash) {
		if (!in_array(basename($crash), $skip_files)) {
			$count++;
		}
	}

	if (!$count) {
		$savemsg = '';
	}

	return $savemsg;
}
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731

function get_menu_messages()
{
	global $config;

	$menu_messages = '';
	if (are_notices_pending()) {
		$notices = get_notices();
		$requests = array();

		## Get Query Arguments from URL ###
		foreach ($_REQUEST as $key => $value) {
			if ($key != "PHPSESSID") {
				$requests[] = $key.'='.$value;
			}
		}

		if (is_array($requests)) {
			$request_string = implode("&", $requests);
		}

		if (is_array($notices)) {
			$notice_msgs = "<ul class=\"dropdown-menu\" role=\"menu\">";

			$notice_msgs .= "<li><a href=\"#\" onclick=\"notice_action('acknowledge','all');\" >".gettext("Acknowledge All Notices")."</a></li><li class=\"divider\"></li>";

			foreach ($notices as $key => $value) {
				$date = date("m-d-y H:i:s", $key);
				$noticemsg = ($value['notice'] != "" ? $value['notice'] : $value['id']);
				$noticemsg = preg_replace("/(\"|\'|\n|<.?\w+>)/i","",$noticemsg);
				$alert_action ="onclick=\"notice_action('acknowledge','{$key}'); jQuery(this).parent().parent().remove();\"";
				$notice_msgs .= "<li><a href=\"#\"  {$alert_action}>{$date} [ ".htmlspecialchars($noticemsg)."]</a></li>";
			}

			$notice_msgs .="</ul>";

			if (count($notices) == 1) {
				$msg= sprintf("%1$02d",count($notices))." ".gettext("unread notice");
			} else {
				$msg= sprintf("%1$02d",count($notices))." ".gettext("unread notices");
			}

			$menu_messages.="<a href=\"/\" class=\"dropdown-toggle \" data-toggle=\"dropdown\" role=\"button\" aria-expanded=\"false\"><span class=\"text-primary\">{$msg}&nbsp;</span><span class=\"caret text-primary\"></span></a>{$notice_msgs}\n";
		}
	} else {
		$menu_messages .= sprintf(
			'<a href="#">%s@%s.%s</a>',
			$_SESSION['Username'],
			$config['system']['hostname'],
			$config['system']['domain']
		);
	}

	return ($menu_messages);
}