improve update notice: timeout, config
The updater in the dashboard needed a timeout to not kill the backend if github is not reachable Also, this makes the check configurable
This commit is contained in:
@ -23,6 +23,12 @@ switch($serendipity['POST']['adminAction']) {
|
|||||||
$data['error_publish'] = $success;
|
$data['error_publish'] = $success;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'updateCheckDisable':
|
||||||
|
if ( !serendipity_checkFormToken() || !serendipity_checkPermission('blogConfiguration') ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
serendipity_set_config_var('updateCheck', false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -40,6 +46,7 @@ $data['backend_frontpage_display'] = $output['more'];
|
|||||||
|
|
||||||
$data['curVersion'] = serendipity_getCurrentVersion();
|
$data['curVersion'] = serendipity_getCurrentVersion();
|
||||||
$data['usedVersion'] = $serendipity['version'];
|
$data['usedVersion'] = $serendipity['version'];
|
||||||
|
$data['updateCheck'] = $serendipity['updateCheck'];
|
||||||
$data['update'] = version_compare($data['usedVersion'], $data['curVersion'], '<');
|
$data['update'] = version_compare($data['usedVersion'], $data['curVersion'], '<');
|
||||||
|
|
||||||
|
|
||||||
|
@ -1196,21 +1196,44 @@ function serendipity_verifyFTPChecksums() {
|
|||||||
return $badsums;
|
return $badsums;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check https://raw.github.com/s9y/Serendipity/master/docs/RELEASE for the newest available version
|
||||||
|
*
|
||||||
|
* If the file is not fetch- or parseable (behind a proxy, malformed by Garvin), this will return -1
|
||||||
|
* */
|
||||||
function serendipity_getCurrentVersion() {
|
function serendipity_getCurrentVersion() {
|
||||||
$updateURL = 'https://raw.github.com/s9y/Serendipity/master/docs/RELEASE';
|
global $serendipity;
|
||||||
|
if ($serendipity['updateCheck'] != "stable" && $serendipity['updateCheck'] != "beta") {
|
||||||
$file = fopen($updateURL, 'r');
|
return -1;
|
||||||
if (!$file) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
$updateURL = 'https://raw.github.com/s9y/Serendipity/master/docs/RELEASE';
|
||||||
|
$context = stream_context_create( array('http'=>array('timeout' => 5.0)) );
|
||||||
|
|
||||||
while (!feof($file)) {
|
$file = @file_get_contents($updateURL, false, $context);
|
||||||
$line = fgets($file);
|
|
||||||
|
|
||||||
if (preg_match('/stable:(.+$)/', $line, $match)) {
|
if ( ! $file) {
|
||||||
return $match[1];
|
if (function_exists('curl_init')) {
|
||||||
|
$ch = curl_init($updateURL);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_TIMEOUT, "5");
|
||||||
|
$file = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($file) {
|
||||||
|
if ($serendipity['updateCheck'] == "stable") {
|
||||||
|
if (preg_match('/^stable:(.+)\b/', $file, $match)) {
|
||||||
|
return $match[1];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (preg_match('/^beta:(.+)\b/', $file, $match)) {
|
||||||
|
return $match[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set sts=4 ts=4 sw=4 expandtab : */
|
/* vim: set sts=4 ts=4 sw=4 expandtab : */
|
||||||
|
@ -398,6 +398,12 @@
|
|||||||
'type' => 'bool',
|
'type' => 'bool',
|
||||||
'default' => false,
|
'default' => false,
|
||||||
'permission' => 'blogConfiguration'),
|
'permission' => 'blogConfiguration'),
|
||||||
|
array('var' => 'updateCheck',
|
||||||
|
'title' => UPDATE_NOTIFICATION,
|
||||||
|
'description' => "Show the update notification in the Dashboard, and for which channel?", # i18n
|
||||||
|
'type' => 'list',
|
||||||
|
'default' => array('stable' => 'stable', 'beta' => 'beta', 'false' => NO ), # i18n
|
||||||
|
'permission' => 'blogConfiguration'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$res['display'] =
|
$res['display'] =
|
||||||
|
@ -11,12 +11,25 @@
|
|||||||
<span class="msg_error"><span class="icon-attention-circled"></span> {$CONST.PUBLISH_ERROR}: {$error_publish}</span>
|
<span class="msg_error"><span class="icon-attention-circled"></span> {$CONST.PUBLISH_ERROR}: {$error_publish}</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{if $update}
|
{if $updateCheck == "stable" || $updateCheck == "beta" }
|
||||||
<section id="dashboard_update">
|
{if $curVersion == -1}
|
||||||
<h3>{$CONST.UPDATE_NOTIFICATION}</h3>
|
<section id="dashboard_update">
|
||||||
|
<h3>{$CONST.UPDATE_NOTIFICATION}</h3>
|
||||||
|
|
||||||
<span class="msg_notice"><span class="icon-info-circled"></span> {$CONST.NEW_VERSION_AVAILABLE} {$curVersion}</span>
|
<span class="msg_notice"><span class="icon-info-circled"></span> Check for new Serendipity version failed</span> {* i18n *}
|
||||||
</section>
|
<form id="updateCheckDisable" method="POST">
|
||||||
|
<input type="hidden" name="serendipity[adminAction]" value="updateCheckDisable" />
|
||||||
|
{$token}
|
||||||
|
<button type="submit">Disable update check</button> {* i18n *}
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
{else if $update}
|
||||||
|
<section id="dashboard_update">
|
||||||
|
<h3>{$CONST.UPDATE_NOTIFICATION}</h3>
|
||||||
|
|
||||||
|
<span class="msg_notice"><span class="icon-info-circled"></span> {$CONST.NEW_VERSION_AVAILABLE} {$curVersion}</span>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
<section id="dashboard_comments" class="odd equal_heights quick_list">
|
<section id="dashboard_comments" class="odd equal_heights quick_list">
|
||||||
<h3>{if 'adminComments'|checkPermission}<a href="serendipity_admin.php?serendipity[adminModule]=comments">{/if}{$CONST.COMMENTS}{if 'adminComments'|checkPermission}</a>{/if}</h3>
|
<h3>{if 'adminComments'|checkPermission}<a href="serendipity_admin.php?serendipity[adminModule]=comments">{/if}{$CONST.COMMENTS}{if 'adminComments'|checkPermission}</a>{/if}</h3>
|
||||||
|
Reference in New Issue
Block a user