Store current Adminer version server-side to avoid excessive requests

This commit is contained in:
Jakub Vrana 2018-01-24 14:15:55 +01:00
parent f4662d5e27
commit 6c96b060e7
4 changed files with 21 additions and 2 deletions

View file

@ -33,8 +33,16 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<?php } ?>
<body class="<?php echo lang('ltr'); ?> nojs">
<?php
$filename = get_temp_dir() . "/adminer.version";
if (!$_COOKIE["adminer_version"] && file_exists($filename) && filemtime($filename) + 86400 > time()) { // 86400 - 1 day in seconds
$_COOKIE["adminer_version"] = file_get_contents($filename); // doesn't need to send to the browser
}
?>
<script<?php echo nonce(); ?>>
mixin(document.body, {onkeydown: bodyKeydown, onclick: bodyClick<?php echo (isset($_COOKIE["adminer_version"]) ? "" : ", onload: partial(verifyVersion, '$VERSION')"); ?>});
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.')); ?>';
</script>

View file

@ -34,6 +34,12 @@ if ($_GET["script"] == "db") {
} elseif ($_GET["script"] == "kill") {
$connection->query("KILL " . number($_POST["kill"]));
} elseif ($_GET["script"] == "version") {
$fp = file_open_lock(get_temp_dir() . "/adminer.version");
if ($fp) {
file_write_unlock($fp, $_POST["version"]);
}
} else { // connect
foreach (count_tables($adminer->databases()) as $db => $val) {
json_row("tables-$db", $val);

View file

@ -95,8 +95,10 @@ function cookie(assign, days) {
/** Verify current Adminer version
* @param string
* @param string own URL base
* @param string
*/
function verifyVersion(current) {
function verifyVersion(current, url, token) {
cookie('adminer_version=0', 1);
var iframe = document.createElement('iframe');
iframe.src = 'https://www.adminer.org/version/?current=' + current;
@ -112,6 +114,8 @@ function verifyVersion(current) {
var match = /version=(.+)/.exec(event.data);
if (match) {
cookie('adminer_version=' + match[1], 1);
ajax(url + 'script=version', function () {
}, 'version=' + match[1] + '&token=' + token);
}
}
}, false);

View file

@ -2,6 +2,7 @@ Adminer 4.4.1-dev:
Display newlines in column comments (bug #573)
Support current_timestamp() as default of time fields (bug #572)
Hide window.opener from pages opened in a new window (bug #561)
Store current Adminer version server-side to avoid excessive requests
Adminer: Fix Search data in tables (regression from 4.4.0)
CSP: Allow any styles, images, media and fonts, disallow base-uri
MySQL: Support geometry in MySQL 8 (bug #574)