Check the server has a sensible time

DokuWiki assumes that the server's time is correct. Especially page
revisions and cache handling depend on correct time. If that's not the
case it can lead to problems later (as mentioned in #1644).

This patch adds a very simple time check using the Date response header
from the DokuWiki server to our do=check mechanism.
This commit is contained in:
Andreas Gohr 2016-08-09 21:06:02 +02:00
parent 3eb8980bcc
commit d6c7b502a6
1 changed files with 31 additions and 8 deletions

View File

@ -60,7 +60,7 @@ function getVersionData(){
//import version string
if(file_exists(DOKU_INC.'VERSION')){
//official release
$version['date'] = trim(io_readfile(DOKU_INC.'VERSION'));
$version['date'] = trim(io_readFile(DOKU_INC.'VERSION'));
$version['type'] = 'Release';
}elseif(is_dir(DOKU_INC.'.git')){
$version['type'] = 'Git';
@ -249,18 +249,41 @@ function check(){
}
}
if ($index_corrupted)
msg('The search index is corrupted. It might produce wrong results and most
if($index_corrupted) {
msg(
'The search index is corrupted. It might produce wrong results and most
probably needs to be rebuilt. See
<a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a>
for ways to rebuild the search index.', -1);
elseif (!empty($lengths))
for ways to rebuild the search index.', -1
);
} elseif(!empty($lengths)) {
msg('The search index seems to be working', 1);
else
msg('The search index is empty. See
} else {
msg(
'The search index is empty. See
<a href="http://www.dokuwiki.org/faq:searchindex">faq:searchindex</a>
for help on how to fix the search index. If the default indexer
isn\'t used or the wiki is actually empty this is normal.');
isn\'t used or the wiki is actually empty this is normal.'
);
}
// rough time check
$http = new DokuHTTPClient();
$http->max_redirect = 0;
$http->timeout = 3;
$http->sendRequest('http://www.dokuwiki.org', '', 'HEAD');
$now = time();
if(isset($http->resp_headers['date'])) {
$time = strtotime($http->resp_headers['date']);
$diff = $time - $now;
if(abs($diff) < 4) {
msg("Server time seems to be okay. Diff: {$diff}s", 1);
} else {
msg("Your server's clock seems to be out of sync! Consider configuring a sync with a NTP server. Diff: {$diff}s");
}
}
}
/**