<?php

/*
	Copyright (C) 2014 Deciso B.V.
	Copyright (C) 2004 Scott Ullrich
	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.
*/
require_once("config.inc");
require_once("util.inc");

/* Include authentication routines */
/* THIS MUST BE ABOVE ALL OTHER CODE */
if(empty($nocsrf)) {

function csrf_startup() {
		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);
	}
	require_once("csrf/csrf-magic.php");
}

function set_language($lang)
{
	$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);
}



/* make sure nothing is cached */
if (isset($omit_nocacheheaders) && $omit_nocacheheaders) {
	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");

$g['theme'] = get_current_theme();

/* Set the default interface language */
if(isset($config['system']['language']) && $config['system']['language'] <> "") {
	$g['language'] = $config['system']['language'];
} elseif (!isset($g['language']) || $g['language'] == "") {
	$g['language'] = 'en_US';
}

set_language($g['language']);

require_once("authgui.inc");

/* Reserved table names to avoid colision */
$reserved_table_names = array(
        "bogons",
        "bogonsv6",
        "negate_networks",
        "snort2c",
        "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");

$wlan_modes = array("bss" => "Infrastructure (BSS)", "adhoc" => "Ad-hoc (IBSS)",
	"hostap" => "Access Point");

function do_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors)
{
	/* 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++) {
		if ($_POST[$reqdfields[$i]] == "" && $_REQUEST[$reqdfields[$i]] == "") {
			$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
		}
	}
}

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

	echo "<p>" . gettext("The following input errors were detected:") . "</p>\n<ul>";
	foreach ($input_errors as $ierr) {
		echo "<li>" . htmlspecialchars($ierr) . "</li>";
	}
	echo "</ul></div></div>";
}

function print_info_box_np($msg, $name="apply",$value="", $showapply=false) {
	if(empty($value)) {
		$value = gettext("Apply changes");
	}

	if(stristr($msg, gettext("apply")) != false || stristr($msg, gettext("save")) != false || stristr($msg, gettext("create")) != false || $showapply) {
		$savebutton = "<form action=\"".$_SERVER['REQUEST_URI']."\" method=\"post\">";
		$savebutton .= "<input name=\"{$name}\" type=\"submit\" class=\"btn btn-default\" id=\"${name}\" value=\"{$value}\" />";
		if($_POST['if'])
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
		$savebutton.="</form>";
	} else {
		$savebutton = '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
	}

	echo <<<EOFnp
	    <div class="col-xs-12">
		<div class="alert alert-info alert-dismissible" role="alert">
			{$savebutton}
            <p>{$msg}</p>
		</div>
		</div>
EOFnp;

}

function print_info_box_np_undo($msg, $name="apply",$value="Apply changes", $undo) {
	if(stristr($msg, "apply") != false || stristr($msg, "save") != false || stristr($msg, "create") != false) {

		$savebutton .= "<input class=\"btn btn-default\"  type=\"button\" value=\"". gettext("Undo") . "\" onclick=\"document.location='{$undo}'\" />";
		$savebutton .= "<input class=\"btn btn-default\"  name=\"{$name}\" type=\"submit\" class=\"formbtn\" id=\"${name}\" value=\"{$value}\" />";

		if(isset($_POST['if']))
			$savebutton .= "<input type=\"hidden\" name=\"if\" value=\"" . htmlspecialchars($_POST['if']) . "\" />";
	} else {
		$savebutton = "<input class=\"btn btn-default\" value=\"" . gettext("Close") . "\" type=\"button\" onclick=\"$('#redboxtable').hide();\" />";
	}


	$url = $_SERVER['REQUEST_URI'];

	echo <<<EOFnp

	<div class="col-xs-12" id="redboxtable"><form action="{$url}" method="post">
		<div class="alert alert-warning"  summary="red box table">
			<p>{$msg}<br /><br /></p>
			<div class="btn-group">
				{$savebutton}
				{$undobutton}
			</div>
		</div>
	</form></div>
EOFnp;

}

function print_info_box($msg) {
	print_info_box_np($msg);
}

function get_std_save_message($ok) {
	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) {
	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";
		}
	}

	if (isset($adr['any'])) {
		$padr = "*";
	} else if (isset($adr['network'])) {
		$padr = $specialnets[$adr['network']];
	} else {
		$padr = $adr['address'];
	}

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

	return $padr;
}

function pprint_port($port) {
	global $wkports;

	$pport = "";

	if (!$port)
		return "*";
	else {
		$srcport = explode("-", $port);
		if ((!$srcport[1]) || ($srcport[0] == $srcport[1])) {
			$pport = $srcport[0];
			if ($wkports[$srcport[0]]) {
				$pport .= " (" . $wkports[$srcport[0]] . ")";
			}
		} else
			$pport .= $srcport[0] . " - " . $srcport[1];
	}

	return $pport;
}

function firewall_check_for_advanced_options(&$item) {
	$item_set = "";
	if($item['os'])
		$item_set .= "os {$item['os']} ";
	if($item['dscp'])
		$item_set .= "dscp {$item['dscp']} ";
	if($item['max'])
		$item_set .= "max {$item['max']} ";
	if($item['max-src-nodes'])
		$item_set .= "max-src-nodes {$item['max-src-nodes']} ";
	if($item['max-src-conn'])
		$item_set .= "max-src-conn {$item['max-src-conn']} ";
	if($item['max-src-states'])
		$item_set .= "max-src-states {$item['max-src-states']} ";
	if(isset($item['nopfsync']))
		$item_set .= "nopfsync ";
	if($item['statetype'] != "keep state" && $item['statetype'] != "")
		$item_set .= "statetype {$item['statetype']} ";
	if($item['statetimeout'])
		$item_set .= "statetimeout {$item['statetimeout']} ";
	if(isset($item['nosync']))
		$item_set .= "no XMLRPC Sync ";
	if($item['max-src-conn-rate'])
		$item_set .= "max-src-conn-rate {$item['max-src-conn-rate']} ";
	if($item['max-src-conn-rates'])
		$item_set .= "max-src-conn-rates {$item['max-src-conn-rates']} ";
	if($item['gateway'])
		$item_set .= "gateway {$item['gateway']} ";
	if($item['tag'])
		$item_set .= "tag {$item['tag']} ";
	if($item['tagged'])
		$item_set .= "tagged {$item['tagged']} ";
	if(isset($item['allowopts']))
		$item_set .= "allowopts ";
	if(isset($item['disablereplyto']))
		$item_set .= "disable reply-to ";
	if($item['tcpflags_any'] || $item['tcpflags1'] || $item['tcpflags2'])
		$item_set .= "tcpflags set";

	return $item_set;
}

function gentitle($title) {
	$navlevelsep = ": ";	/* navigation level separator string */
	if(!is_array($title))
		return $title;
	else
		return join($navlevelsep, $title);
}

/* update the changedesc and changecount(er) variables */
function update_changedesc($update) {
	global $changedesc;
	global $changecount;

	$changedesc .= " {$update}";
	$changecount++;
}

function clear_log_file($logfile = '/var/log/system.log', $restart_syslogd = true)
{
	global $config, $g;
	if ($restart_syslogd)
		exec("/usr/bin/killall syslogd");
	if(isset($config['system']['disablesyslogclog'])) {
		unlink($logfile);
		touch($logfile);
	} else {
		$log_size = isset($config['syslog']['logfilesize']) ? $config['syslog']['logfilesize'] : "511488";
		exec("/usr/local/sbin/clog -i -s {$log_size} " . escapeshellarg($logfile));
	}
	if ($restart_syslogd) {
		system_syslogd_start();
	}
}

function dump_clog($logfile, $tail, $withorig = true, $grepfor = "", $grepinvert = "") {
	global $g, $config;
	$sor = isset($config['syslog']['reverse']) ? "-r" : "";
	$logarr = "";
	$grepline = "  ";
	if(is_array($grepfor))
		$grepline .= " | /usr/bin/egrep " . escapeshellarg(implode("|", $grepfor));
	if(is_array($grepinvert))
		$grepline .= " | /usr/bin/egrep -v " . escapeshellarg(implode("|", $grepinvert));
	if (is_dir($logfile)) {
		$logarr = array("File $logfile is a directory.");
	} elseif (file_exists($logfile) && filesize($logfile) == 0) {
		$logarr = array("Log file started.");
	} else {
		if($config['system']['disablesyslogclog']) {
			exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
		} else {
			exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
		}
	}
	foreach ($logarr as $logent) {
			$logent = preg_split("/\s+/", $logent, 6);
			echo "<tr valign=\"top\">\n";
			if ($withorig) {
					$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";
			} else {
					echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
			}
			echo "</tr>\n";
	}
}


/* Check if variable has changed, update and log if it has
 * returns true if var changed
 * varname = variable name in plain text
 * orig = original value
 * new = new value
 */
function update_if_changed($varname, & $orig, $new) {
	if (is_array($orig) && is_array($new)) {
		$a_diff = array_diff($orig, $new);
		foreach ($a_diff as $diff) {
			update_changedesc("removed {$varname}: \"{$diff}\"");
		}
		$a_diff = array_diff($new, $orig);
		foreach ($a_diff as $diff) {
			update_changedesc("added {$varname}: \"{$diff}\"");
		}
		$orig = $new;
		return true;

	} else {
		if ($orig != $new) {
			update_changedesc("{$varname}: \"{$orig}\" -> \"{$new}\"");
			$orig = $new;
			return true;
		}
	}
	return false;
}

function address_to_pconfig($adr, &$padr, &$pmask, &$pnot, &$pbeginport, &$pendport) {
	if (isset($adr['any']))
		$padr = "any";
	else if ($adr['network'])
		$padr = $adr['network'];
	else if ($adr['address']) {
		list($padr, $pmask) = explode("/", $adr['address']);
		if (!$pmask) {
			if (is_ipaddrv6($padr))
				$pmask = 128;
			else
				$pmask = 32;
		}
	}

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

	if ($adr['port']) {
		list($pbeginport, $pendport) = explode("-", $adr['port']);
		if (!$pendport)
			$pendport = $pbeginport;
	} 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) {
	$adr = array();

	if ($padr == "any")
		$adr['any'] = true;
	else if (is_specialnet($padr))
		$adr['network'] = $padr;
	else {
		$adr['address'] = $padr;
		if (is_ipaddrv6($padr)) {
			if ($pmask != 128)
				$adr['address'] .= "/" . $pmask;
		} else {
			if ($pmask != 32)
				$adr['address'] .= "/" . $pmask;
		}
	}

	if ($pnot)
		$adr['not'] = true;
	else
		unset($adr['not']);

	if (($pbeginport != 0) && ($pbeginport != "any")) {
		if ($pbeginport != $pendport)
			$adr['port'] = $pbeginport . "-" . $pendport;
		else
			$adr['port'] = $pbeginport;
	}

	if(is_alias($pbeginport)) {
		$adr['port'] = $pbeginport;
	}
}

function is_specialnet($net) {
	global $specialsrcdst;

	if(!$net)
		return false;
	if (is_array($specialsrcdst) && in_array($net, $specialsrcdst))
		return true;
	else
		return false;
}



/****f* guiconfig/display_top_tabs
 * NAME
 *   display_top_tabs - display tabs with rounded edges
 * INPUTS
 *   $text      - array of tabs
 * RESULT
 *   null
 ******/
function display_top_tabs(& $tab_array, $no_drop_down = false) {
	global $config;
	global $g;
	$tab_array_char_limit = 92;

	/*  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) {
		echo "<h2>".gettext("Currently viewing: ")."</h2>";
		echo "<select class=\"selectpicker\" name=\"TabSelect\" onchange=\"tabs_will_go(this)\" data-live-search=\"true\" data-style=\"btn-default\">\n";
		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";
		echo "<ul class=\"nav nav-tabs nav-justified\" role=\"tablist\">\n";
		$tabscounter = 0;
		foreach ($tab_array as $ta) {
			if ($ta[1] == true) {
				echo "  <li class=\"active\"><a href=\"{$ta[2]}\" role=\"tab\">{$ta[0]}</a></li>\n";
			} else {
				echo "  <li><a href=\"{$ta[2]}\" role=\"tab\">{$ta[0]}</a></li>\n";
			}
			$tabscounter++;
		}
		echo "</ul>\n";
	}
}




$timezone = $config['system']['timezone'];
if (!$timezone) {
	$timezone = 'Etc/UTC';
}

date_default_timezone_set($timezone);

function get_crash_report($pedantic = false)
{
	global $g;

	$savemsg = "{$g['product_name']} has detected a crash report or programming bug. Click <a href='crash_reporter.php'>here</a> for more information.";
	$skip_files = array('.', '..', 'minfree', '');
	$count = 0;

	if (file_exists('/tmp/PHP_errors.log')) {
		if ($pedantic) {
			$total = `/usr/bin/wc -l /tmp/PHP_errors.log | /usr/bin/awk '{ print $1 }'`;
		} else {
			$total = `/usr/bin/grep -v 'PHP Notice:' /tmp/PHP_errors.log | /usr/bin/wc -l | /usr/bin/awk '{ print $1 }'`;
		}
		if ($total > 0) {
			$count++;
		}
	}

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

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

	return $savemsg;
}

function redirectHeader($text)
{
        global $_SERVER;

	if (isAjax()) {
                if ($_SERVER['HTTPS'] == 'on') {
                        $protocol = 'https';
                } else {
                        $protocol = 'http';
		}

		$port = '';

		if (
			!($_SERVER['SERVER_PORT'] == '80' && $protocol == 'http') &&
			!($_SERVER['SERVER_PORT'] == '443' && $protocol == 'https')
		) {
			$port = ":{$_SERVER['SERVER_PORT']}";
		}

		echo "\ndocument.location.href = '{$protocol}://{$_SERVER['SERVER_NAME']}{$port}/{$text}';\n";
	} else {
		header("Location: $text");
	}
}


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);
}

function get_current_theme()
{
	$theme = 'opnsense';

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

	return $theme;
}