Skip to content

Commit

Permalink
* Change updater source to GitHub branches which gives more info abou…
Browse files Browse the repository at this point in the history
…t changes.
  • Loading branch information
nuxsmin committed Aug 4, 2014
1 parent dc9537c commit 1c28e78
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 75 deletions.
61 changes: 31 additions & 30 deletions ajax/ajax_checkUpds.php
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2014 Rubén Domínguez [email protected]
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2014 Rubén Domínguez [email protected]
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*
*/

define('APP_ROOT', '..');
require_once APP_ROOT.DIRECTORY_SEPARATOR.'inc'.DIRECTORY_SEPARATOR.'init.php';
require_once APP_ROOT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'init.php';

SP_Util::checkReferer('GET');

$checkVersion = SP_Common::parseParams('s', 'UPDATED', false, true);

// Una vez por sesión
if ( ! $checkVersion ){
if (!$checkVersion) {
$_SESSION["UPDATED"] = $checkVersion = SP_Util::checkUpdates();
}

session_write_close();

if ( is_array($checkVersion) ){
echo '<a href="'.$checkVersion['url'].'" target="_blank" title="'._('Descargar nueva versión').'"><img src="imgs/update.png" />&nbsp;'.$checkVersion['version'].'</a>';
} elseif ( $checkVersion == true ){
echo '<img src="imgs/ok.png" title="'._('Actualizado').'"/>';
} elseif ( $checkVersion == false ){
if (is_array($checkVersion)) {
$title = _('Descargar nueva versión') . ' - ' . $checkVersion['version'] . '<br><br>' . nl2br($checkVersion['description']);
echo '<a href="' . $checkVersion['url'] . '" target="_blank" title="' . $title . '"><img src="imgs/update.png" />&nbsp;' . $checkVersion['title'] . '</a>';
} elseif ($checkVersion === true) {
echo '<img src="imgs/ok.png" title="' . _('Actualizado') . '"/>';
} elseif ($checkVersion === false) {
echo '!';
}
2 changes: 1 addition & 1 deletion ajax/ajax_getContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,6 @@
// Se comprueba si hay actualizaciones.
// Es necesario que se haga al final de obtener el contenido ya que la
// consulta ajax detiene al resto si se ejecuta antes
if ($_SESSION['uisadminapp'] && SP_Config::getValue('checkupdates') === 1 && !SP_Common::parseParams('s', 'UPDATED', false, true)) {
if ($_SESSION['uisadminapp'] && SP_Config::getValue('checkupdates') === true && !SP_Common::parseParams('s', 'UPDATED', false, true)) {
echo '<script>checkUpds();</script>';
}
92 changes: 49 additions & 43 deletions inc/util.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static function ldapIsAvailable()
*/
public static function curlIsAvailable()
{
return (function_exists(curl_init));
return (function_exists('curl_init'));
}

/**
Expand All @@ -187,63 +187,69 @@ public static function getVersionString()
}

/**
* @brief Comprobar si hay actualizaciones de sysPass disponibles desde internet (sourceforge.net)
* @brief Comprobar si hay actualizaciones de sysPass disponibles desde internet (github.com)
* @return array|bool
*
* Esta función comprueba el feed RSS de sourceforge.net y lo parsea para verificar si la aplicación está actualizada
* Esta función hace una petición a GitHub y parsea el JSON devuelto para verificar si la aplicación está actualizada
*/
public static function checkUpdates()
{
//if ( ! self::curlIsAvailable() || ! SP_Config::getValue('checkupdates') ){
if (!SP_Config::getValue('checkupdates')) {
if (! self::curlIsAvailable() || !SP_Config::getValue('checkupdates')) {
return false;
}

// $ch = curl_init("http://sourceforge.net/api/file/index/project-id/775555/mtime/desc/limit/1/rss");
//
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_HEADER, 0);
//
// if ( ! $data = curl_exec($ch) ) return false;
//
// curl_close($ch);
$githubUrl = 'https://api.github.com/repos/nuxsmin/sysPass/releases';
$ch = curl_init($githubUrl);

$feedUrl = 'https://sourceforge.net/api/file/index/project-id/1257402/mtime/desc/limit/20/rss';
$feed = file_get_contents($feedUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, "sysPass App Updater");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);

if ($feed) {
$xmlUpd = new SimpleXMLElement($feed, LIBXML_NOCDATA);
} else {
$data = curl_exec($ch);

if ($data === false) {
return false;
echo 'Curl error: ' . curl_error($ch);
}

if ($xmlUpd->channel->item->title) {

$pubVer = '';

foreach ($xmlUpd->channel->item as $item) {
$url = (string)$item->link;
$title = (string)$item->title;
$description = (string)$item->description;

if (preg_match("/.*\/sysPass_(\d)\.(\d{1,})\.(\d{1,})(\-[a-z0-9]+)?\.(tar\.gz|zip)$/", $title, $pubVer)) {
break;
}
}

if (is_array($pubVer) && SP_Init::isLoggedIn()) {
$appVersion = implode('', self::getVersion());
$pubVersion = $pubVer[1] . $pubVer[2] . $pubVer[3];

if ($pubVersion > $appVersion) {
$version = $pubVer[1] . '.' . $pubVer[2] . '.' . $pubVer[3];
return array('version' => $version, 'url' => $url);
} else {
return true;
}
curl_close($ch);

$updateInfo = json_decode($data);

// $updateInfo[0]->tag_name
// $updateInfo[0]->name
// $updateInfo[0]->body
// $updateInfo[0]->tarball_url
// $updateInfo[0]->zipball_url
// $updateInfo[0]->published_at
// $updateInfo[0]->html_url

$version = $updateInfo[0]->tag_name;
$url = $updateInfo[0]->html_url;
$title = $updateInfo[0]->name;
$description = $updateInfo[0]->body;
$date = $updateInfo[0]->published_at;

preg_match("/v?(\d+)\.(\d+)\.(\d+)\.(\d+)(\-[a-z0-9.]+)?$/", $version, $realVer);

if (is_array($realVer) && SP_Init::isLoggedIn()) {
$appVersion = implode('', self::getVersion(true));
$pubVersion = $realVer[1] . $realVer[2] . $realVer[3] . $realVer[4];

if ($pubVersion > $appVersion) {
return array(
'version' => $version,
'url' => $url,
'title' => $title,
'description' => $description,
'date' => $date);
} else {
return false;
return true;
}
} else {
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion js/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ function checkUpds() {
type: 'GET',
dataType: 'html',
url: APP_ROOT + '/ajax/ajax_checkUpds.php',
timeout: 5000,
timeout: 10000,
success: function (response) {
$('#updates').html(response);
},
Expand Down

0 comments on commit 1c28e78

Please sign in to comment.