2016-02-08 12:34:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2016-02-08 12:53:08 +00:00
|
|
|
* This file is part of the Froxlor project.
|
|
|
|
* Copyright (c) 2016 the Froxlor Team (see authors).
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the COPYING
|
|
|
|
* file that was distributed with this source code. You can also view the
|
|
|
|
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
2016-02-08 12:34:24 +00:00
|
|
|
*
|
|
|
|
* @copyright (c) the authors
|
2016-02-08 12:53:08 +00:00
|
|
|
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
|
|
|
* @author Froxlor team <team@froxlor.org> (2010-)
|
|
|
|
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
|
|
|
* @package Frontend
|
|
|
|
*
|
|
|
|
* @since 0.9.35
|
|
|
|
*
|
2016-02-08 12:34:24 +00:00
|
|
|
*/
|
|
|
|
define('AREA', 'admin');
|
|
|
|
require './lib/init.php';
|
|
|
|
|
2018-12-18 12:45:05 +00:00
|
|
|
use \Froxlor\Http\HttpClient;
|
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// define update-uri
|
2018-02-16 09:56:27 +00:00
|
|
|
define('UPDATE_URI', "https://version.froxlor.org/Froxlor/api/" . $version);
|
2016-02-23 20:52:35 +00:00
|
|
|
define('RELEASE_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip");
|
|
|
|
define('CHECKSUM_URI', "https://autoupdate.froxlor.org/froxlor-{version}.zip.sha256");
|
2016-02-08 12:34:24 +00:00
|
|
|
|
|
|
|
// check for archive-stuff
|
2016-08-20 07:16:33 +00:00
|
|
|
if (! extension_loaded('zip')) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 2
|
|
|
|
));
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// display initial version check
|
|
|
|
if ($page == 'overview') {
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// log our actions
|
|
|
|
$log->logAction(ADM_ACTION, LOG_NOTICE, "checking auto-update");
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// check for new version
|
2018-02-09 09:50:14 +00:00
|
|
|
$latestversion = HttpClient::urlGet(UPDATE_URI);
|
|
|
|
|
|
|
|
$latestversion = explode('|', $latestversion);
|
|
|
|
|
|
|
|
if (is_array($latestversion) && count($latestversion) >= 1) {
|
|
|
|
$_version = $latestversion[0];
|
|
|
|
$_message = isset($latestversion[1]) ? $latestversion[1] : '';
|
|
|
|
$_link = isset($latestversion[2]) ? $latestversion[2] : htmlspecialchars($filename . '?s=' . urlencode($s) . '&page=' . urlencode($page) . '&lookfornewversion=yes');
|
|
|
|
|
|
|
|
// add the branding so debian guys are not gettings confused
|
|
|
|
// about their version-number
|
|
|
|
$version_label = $_version . $branding;
|
|
|
|
$version_link = $_link;
|
|
|
|
$message_addinfo = $_message;
|
|
|
|
|
|
|
|
// not numeric -> error-message
|
|
|
|
if (! preg_match('/^((\d+\\.)(\d+\\.)(\d+\\.)?(\d+)?(\-(svn|dev|rc)(\d+))?)$/', $_version)) {
|
|
|
|
// check for customized version to not output
|
|
|
|
// "There is a newer version of froxlor" besides the error-message
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 3
|
|
|
|
));
|
|
|
|
} elseif (version_compare2($version, $_version) == - 1) {
|
|
|
|
// there is a newer version - yay
|
|
|
|
$isnewerversion = 1;
|
|
|
|
} else {
|
|
|
|
// nothing new
|
|
|
|
$isnewerversion = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// anzeige über version-status mit ggfls. formular
|
|
|
|
// zum update schritt #1 -> download
|
|
|
|
if ($isnewerversion == 1) {
|
|
|
|
$text = 'There is a newer version available. Update to version <b>' . $_version . '</b> now?<br/>(Your current version is: ' . $version . ')';
|
|
|
|
$hiddenparams = '<input type="hidden" name="newversion" value="' . $_version . '" />';
|
|
|
|
$yesfile = $filename . '?s=' . $s . '&page=getdownload';
|
2018-12-21 10:22:03 +00:00
|
|
|
eval("echo \"" . \Froxlor\UI\Template::getTemplate("misc/question_yesno", true) . "\";");
|
2018-02-09 09:50:14 +00:00
|
|
|
exit();
|
|
|
|
} elseif ($isnewerversion == 0) {
|
|
|
|
// all good
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::standard_success('noupdatesavail');
|
2018-02-09 09:50:14 +00:00
|
|
|
} else {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::standard_error('customized_version');
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
}// download the new archive
|
2016-02-08 12:34:24 +00:00
|
|
|
elseif ($page == 'getdownload') {
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-16 20:56:32 +00:00
|
|
|
// retrieve the new version from the form
|
2016-02-08 12:34:24 +00:00
|
|
|
$newversion = isset($_POST['newversion']) ? $_POST['newversion'] : null;
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// valid?
|
|
|
|
if ($newversion !== null) {
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// define files to get
|
|
|
|
$toLoad = str_replace('{version}', $newversion, RELEASE_URI);
|
2016-02-23 20:52:35 +00:00
|
|
|
$toCheck = str_replace('{version}', $newversion, CHECKSUM_URI);
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// check for local destination folder
|
2018-02-09 09:50:14 +00:00
|
|
|
if (! is_dir(FROXLOR_INSTALL_DIR . '/updates/')) {
|
|
|
|
mkdir(FROXLOR_INSTALL_DIR . '/updates/');
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// name archive
|
2018-02-09 09:50:14 +00:00
|
|
|
$localArchive = FROXLOR_INSTALL_DIR . '/updates/' . basename($toLoad);
|
|
|
|
|
|
|
|
$log->logAction(ADM_ACTION, LOG_NOTICE, "Downloading " . $toLoad . " to " . $localArchive);
|
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// remove old archive
|
|
|
|
if (file_exists($localArchive)) {
|
2016-08-04 19:49:33 +00:00
|
|
|
@unlink($localArchive);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
|
|
|
|
// get archive data
|
|
|
|
try {
|
|
|
|
HttpClient::fileGet($toLoad, $localArchive);
|
|
|
|
} catch (Exception $e) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 4
|
|
|
|
));
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-23 20:52:35 +00:00
|
|
|
// validate the integrity of the downloaded file
|
2018-02-09 09:50:14 +00:00
|
|
|
$_shouldsum = HttpClient::urlGet($toCheck);
|
|
|
|
if (! empty($_shouldsum)) {
|
2016-08-04 19:49:33 +00:00
|
|
|
$_t = explode(" ", $_shouldsum);
|
|
|
|
$shouldsum = $_t[0];
|
2016-02-08 12:34:24 +00:00
|
|
|
} else {
|
2016-08-04 19:49:33 +00:00
|
|
|
$shouldsum = null;
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2016-02-23 20:52:35 +00:00
|
|
|
$filesum = hash_file('sha256', $localArchive);
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
if ($filesum != $shouldsum) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 9
|
|
|
|
));
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// to the next step
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'extract',
|
|
|
|
'archive' => basename($localArchive)
|
|
|
|
));
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 6
|
|
|
|
));
|
|
|
|
}// extract and install new version
|
2016-02-08 12:34:24 +00:00
|
|
|
elseif ($page == 'extract') {
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
$toExtract = isset($_GET['archive']) ? $_GET['archive'] : null;
|
2018-02-09 09:50:14 +00:00
|
|
|
$localArchive = FROXLOR_INSTALL_DIR . '/updates/' . $toExtract;
|
|
|
|
|
|
|
|
if (isset($_POST['send']) && $_POST['send'] == 'send') {
|
2016-02-08 12:34:24 +00:00
|
|
|
// decompress from zip
|
2018-02-09 09:50:14 +00:00
|
|
|
$zip = new ZipArchive();
|
2016-02-08 12:34:24 +00:00
|
|
|
$res = $zip->open($localArchive);
|
|
|
|
if ($res === true) {
|
2018-02-09 09:50:14 +00:00
|
|
|
$log->logAction(ADM_ACTION, LOG_NOTICE, "Extracting " . $localArchive . " to " . FROXLOR_INSTALL_DIR);
|
2016-08-04 19:49:33 +00:00
|
|
|
$zip->extractTo(FROXLOR_INSTALL_DIR);
|
2016-02-08 12:34:24 +00:00
|
|
|
$zip->close();
|
|
|
|
// success - remove unused archive
|
|
|
|
@unlink($localArchive);
|
|
|
|
} else {
|
|
|
|
// error
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 8
|
|
|
|
));
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// redirect to update-page?
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo('admin_updates.php', array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s
|
|
|
|
));
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
|
|
|
|
if (! file_exists($localArchive)) {
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::redirectTo($filename, array(
|
2018-02-09 09:50:14 +00:00
|
|
|
's' => $s,
|
|
|
|
'page' => 'error',
|
|
|
|
'errno' => 7
|
|
|
|
));
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
2018-02-09 09:50:14 +00:00
|
|
|
|
|
|
|
$text = 'Extract downloaded archive "' . $toExtract . '"?';
|
2016-02-08 12:34:24 +00:00
|
|
|
$hiddenparams = '';
|
2018-02-09 09:50:14 +00:00
|
|
|
$yesfile = $filename . '?s=' . $s . '&page=extract&archive=' . $toExtract;
|
2018-12-21 10:22:03 +00:00
|
|
|
eval("echo \"" . \Froxlor\UI\Template::getTemplate("misc/question_yesno", true) . "\";");
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|
|
|
|
// display error
|
|
|
|
elseif ($page == 'error') {
|
2018-02-09 09:50:14 +00:00
|
|
|
|
2016-02-16 20:56:32 +00:00
|
|
|
// retrieve error-number via url-parameter
|
2018-02-09 09:50:14 +00:00
|
|
|
$errno = isset($_GET['errno']) ? (int) $_GET['errno'] : 0;
|
|
|
|
|
2016-02-08 12:34:24 +00:00
|
|
|
// 2 = no Zlib
|
|
|
|
// 3 = custom version detected
|
|
|
|
// 4 = could not store archive to local hdd
|
|
|
|
// 5 = some weird value came from version.froxlor.org
|
|
|
|
// 6 = download without valid version
|
|
|
|
// 7 = local archive does not exist
|
|
|
|
// 8 = could not extract archive
|
2016-02-23 20:52:35 +00:00
|
|
|
// 9 = checksum mismatch
|
2018-12-21 10:22:03 +00:00
|
|
|
\Froxlor\UI\Response::standard_error('autoupdate_' . $errno);
|
2016-02-08 12:34:24 +00:00
|
|
|
}
|