adminerevo/adminer/include/design.inc.php

189 lines
6.6 KiB
PHP
Raw Permalink Normal View History

<?php
/** Print HTML header
2011-03-23 20:05:04 +00:00
* @param string used in title, breadcrumb and heading, should be HTML escaped
* @param string
* @param mixed array("key" => "link", "key2" => array("link", "desc")), null for nothing, false for driver only, true for driver and server
* @param string used after colon in title and heading, should be HTML escaped
* @return null
*/
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
2014-01-30 17:06:58 +00:00
global $LANG, $VERSION, $adminer, $drivers, $jush;
2013-06-29 19:41:35 +00:00
page_headers();
if (is_ajax() && $error) {
page_messages($error);
exit;
}
$title_all = $title . ($title2 != "" ? ": $title2" : "");
2011-03-23 20:05:04 +00:00
$title_page = strip_tags($title_all . (SERVER != "" && SERVER != "localhost" ? h(" - " . SERVER) : "") . " - " . $adminer->name());
2012-04-16 05:18:03 +00:00
?>
2012-12-05 21:11:36 +00:00
<!DOCTYPE html>
2010-11-11 09:12:26 +00:00
<html lang="<?php echo $LANG; ?>" dir="<?php echo lang('ltr'); ?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="robots" content="noindex">
2010-11-22 17:13:07 +00:00
<title><?php echo $title_page; ?></title>
2011-02-09 14:28:45 +00:00
<link rel="stylesheet" type="text/css" href="../adminer/static/default.css">
2018-01-13 15:25:11 +00:00
<?php echo script_src("../adminer/static/functions.js"); ?>
<?php echo script_src("static/editing.js"); ?>
2011-04-03 15:17:26 +00:00
<?php if ($adminer->head()) { ?>
2013-02-20 00:31:51 +00:00
<link rel="shortcut icon" type="image/x-icon" href="../adminer/static/favicon.ico">
<link rel="apple-touch-icon" href="../adminer/static/favicon.ico">
2018-01-23 11:15:38 +00:00
<?php foreach ($adminer->css() as $css) { ?>
<link rel="stylesheet" type="text/css" href="<?php echo h($css); ?>">
<?php } ?>
2011-04-03 15:17:26 +00:00
<?php } ?>
<body class="<?php echo lang('ltr'); ?> nojs <?php echo $GLOBALS['project']; ?>">
<?php
$filename = get_temp_dir() . "/adminer.version";
if (!$_COOKIE["adminer_version"] && file_exists($filename) && filemtime($filename) + 86400 > time()) { // 86400 - 1 day in seconds
$version = unserialize(file_get_contents($filename));
$_COOKIE["adminer_version"] = $version["version"]; // doesn't need to send to the browser
}
?>
2018-01-13 21:17:00 +00:00
<script<?php echo nonce(); ?>>
mixin(document.body, {onkeydown: bodyKeydown, onclick: bodyClick<?php
echo (isset($_COOKIE["adminer_version"]) ? "" : ", onload: partial(verifyVersion, '$VERSION', '" . js_escape(ME) . "', '" . get_token() . "')"); // $token may be empty in auth.inc.php
?>});
document.body.className = document.body.className.replace(/ nojs/, ' js');
var offlineMessage = '<?php echo js_escape(lang('You are offline.')); ?>';
2018-02-06 13:46:50 +00:00
var thousandsSeparator = '<?php echo js_escape(lang(',')); ?>';
</script>
2018-01-12 17:34:19 +00:00
<div id="help" class="jush-<?php echo $jush; ?> jsonly hidden"></div>
<?php echo script("mixin(qs('#help'), {onmouseover: function () { helpOpen = 1; }, onmouseout: helpMouseout});"); ?>
<div id="content">
<?php
2012-05-14 06:54:07 +00:00
if ($breadcrumb !== null) {
2013-07-03 17:34:19 +00:00
$link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1);
echo '<p id="breadcrumb"><a href="' . h($link ? $link : ".") . '">' . $drivers[DRIVER] . '</a> &raquo; ';
2013-07-03 17:34:19 +00:00
$link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', ME), 0, -1);
$server = $adminer->serverName(SERVER);
$server = ($server != "" ? $server : lang('Server'));
2010-11-18 11:17:06 +00:00
if ($breadcrumb === false) {
echo "$server\n";
} else {
echo "<a href='" . h($link) . "' accesskey='1' title='Alt+Shift+1'>$server</a> &raquo; ";
2010-11-18 11:17:06 +00:00
if ($_GET["ns"] != "" || (DB != "" && is_array($breadcrumb))) {
echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
}
if (is_array($breadcrumb)) {
if ($_GET["ns"] != "") {
echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; ';
}
2010-11-18 11:17:06 +00:00
foreach ($breadcrumb as $key => $val) {
2013-07-05 04:07:52 +00:00
$desc = (is_array($val) ? $val[1] : h($val));
2010-11-18 11:17:06 +00:00
if ($desc != "") {
2013-07-05 04:07:52 +00:00
echo "<a href='" . h(ME . "$key=") . urlencode(is_array($val) ? $val[0] : $val) . "'>$desc</a> &raquo; ";
}
}
}
2010-11-18 11:17:06 +00:00
echo "$title\n";
}
}
2010-11-18 11:17:06 +00:00
echo "<h2>$title_all</h2>\n";
echo "<div id='ajaxstatus' class='jsonly hidden'></div>\n";
restart_session();
2013-06-29 19:41:35 +00:00
page_messages($error);
$databases = &get_session("dbs");
if (DB != "" && $databases && !in_array(DB, $databases, true)) {
$databases = null;
}
stop_session();
define("PAGE_HEADER", 1);
}
/** Send HTTP headers
* @return null
*/
function page_headers() {
global $adminer;
header("Content-Type: text/html; charset=utf-8");
header("Cache-Control: no-cache");
header("X-Frame-Options: deny"); // ClickJacking protection in IE8, Safari 4, Chrome 2, Firefox 3.6.9
header("X-XSS-Protection: 0"); // prevents introducing XSS in IE8 by removing safe parts of the page
header("X-Content-Type-Options: nosniff");
header("Referrer-Policy: origin-when-cross-origin");
2018-01-17 10:05:59 +00:00
foreach ($adminer->csp() as $csp) {
$header = array();
foreach ($csp as $key => $val) {
$header[] = "$key $val";
}
header("Content-Security-Policy: " . implode("; ", $header));
2018-01-13 13:21:54 +00:00
}
$adminer->headers();
2013-06-29 19:41:35 +00:00
}
2018-01-09 17:53:17 +00:00
/** Get Content Security Policy headers
2018-01-17 10:05:59 +00:00
* @return array of arrays with directive name in key, allowed sources in value
2018-01-09 17:53:17 +00:00
*/
function csp() {
return array(
2018-01-17 10:05:59 +00:00
array(
"script-src" => "'self' 'unsafe-inline' 'nonce-" . get_nonce() . "' 'strict-dynamic'", // 'self' is a fallback for browsers not supporting 'strict-dynamic', 'unsafe-inline' is a fallback for browsers not supporting 'nonce-'
"connect-src" => "'self' https://api.github.com/repos/adminerevo/adminerevo/releases/latest",
"frame-src" => "'self'",
"object-src" => "'none'",
"base-uri" => "'none'",
2018-01-17 10:05:59 +00:00
"form-action" => "'self'",
),
2018-01-09 17:53:17 +00:00
);
}
2018-01-13 21:17:00 +00:00
/** Get a CSP nonce
* @return string Base64 value
*/
function get_nonce() {
static $nonce;
if (!$nonce) {
$nonce = base64_encode(rand_string());
}
return $nonce;
}
2013-06-29 19:41:35 +00:00
/** Print flash and error messages
* @param string
* @return null
*/
function page_messages($error) {
2011-02-03 09:15:52 +00:00
$uri = preg_replace('~^[^?]*~', '', $_SERVER["REQUEST_URI"]);
2023-11-17 05:24:10 +00:00
$messages = [];
if (isset($_SESSION["messages"][$uri])) {
$messages = $_SESSION["messages"][$uri];
}
if (count($messages) > 0) {
2018-01-13 22:42:48 +00:00
echo "<div class='message'>" . implode("</div>\n<div class='message'>", $messages) . "</div>" . script("messagesPrint();");
unset($_SESSION["messages"][$uri]);
}
if ($error) {
echo "<div class='error'>$error</div>\n";
}
}
/** Print HTML footer
2010-10-18 00:15:58 +00:00
* @param string "auth", "db", "ns"
* @return null
*/
function page_footer($missing = "") {
2013-07-09 06:34:17 +00:00
global $adminer, $token;
2012-04-16 05:18:03 +00:00
?>
2010-10-16 23:51:56 +00:00
</div>
<?php switch_lang(); ?>
2013-10-25 02:12:53 +00:00
<?php if ($missing != "auth") { ?>
2013-07-09 06:34:17 +00:00
<form action="" method="post">
<p class="logout">
<input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" id="logout">
<input type="hidden" name="token" value="<?php echo $token; ?>">
</p>
</form>
2013-10-25 02:12:53 +00:00
<?php } ?>
<div id="menu">
<?php $adminer->navigation($missing); ?>
</div>
<?php
2018-01-12 14:27:44 +00:00
echo script("setupSubmitHighlight(document);");
echo script("setupCopyToClipboard(document);");
2023-07-01 18:13:20 +00:00
echo "</body>\n</html>";
}