diff --git a/ajax/ajax_checkUpds.php b/ajax/ajax_checkUpds.php index d8864939f..d1a555a77 100644 --- a/ajax/ajax_checkUpds.php +++ b/ajax/ajax_checkUpds.php @@ -1,46 +1,47 @@ . -* -*/ +/** + * sysPass + * + * @author nuxsmin + * @link http://syspass.org + * @copyright 2012-2014 Rubén Domínguez nuxsmin@syspass.org + * + * 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 . + * + */ 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 ' '.$checkVersion['version'].''; -} elseif ( $checkVersion == true ){ - echo ''; -} elseif ( $checkVersion == false ){ +if (is_array($checkVersion)) { + $title = _('Descargar nueva versión') . ' - ' . $checkVersion['version'] . '

' . nl2br($checkVersion['description']); + echo ' ' . $checkVersion['title'] . ''; +} elseif ($checkVersion === true) { + echo ''; +} elseif ($checkVersion === false) { echo '!'; } \ No newline at end of file diff --git a/ajax/ajax_getContent.php b/ajax/ajax_getContent.php index bdb3ac07e..1e07974e4 100644 --- a/ajax/ajax_getContent.php +++ b/ajax/ajax_getContent.php @@ -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 ''; } \ No newline at end of file diff --git a/inc/util.class.php b/inc/util.class.php index 3888ae590..0e310bfb2 100644 --- a/inc/util.class.php +++ b/inc/util.class.php @@ -174,7 +174,7 @@ public static function ldapIsAvailable() */ public static function curlIsAvailable() { - return (function_exists(curl_init)); + return (function_exists('curl_init')); } /** @@ -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; } } diff --git a/js/functions.js b/js/functions.js index d21671ec7..6bd296df8 100644 --- a/js/functions.js +++ b/js/functions.js @@ -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); },