added auto-update from within the panel; re-organized menu-entries (meaningful)

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-02-08 13:34:24 +01:00
parent 1cd776f660
commit aac9ee3ba7
4 changed files with 269 additions and 39 deletions

202
admin_autoupdate.php Normal file
View File

@@ -0,0 +1,202 @@
<?php
/**
* This file is part of the Froxlor-Autoupdate project.
* Copyright (c) 2013 NuTime UG (haftungsbeschraenkt).
*
* @copyright (c) the authors
* @author Michael Kaufmann, NuTime UG (haftungsbeschraenkt) <mkaufmann@nutime.de> (2016-)
* @license non-free
* @package Auto-Update
* @version 0.1
*/
define('AREA', 'admin');
require './lib/init.php';
// define update-uri
define('UPDATE_URI', "http://version.froxlor.org/Froxlor/legacy/" . $version);
define('RELEASE_URI', "http://autoupdate.froxlor.org/froxlor-{version}.zip");
define('MD5SUM_URI', "http://autoupdate.froxlor.org/froxlor-{version}.zip.md5");
// check for allow_url_fopen
if (ini_get('allow_url_fopen') === false) {
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 1));
}
// check for archive-stuff
if (function_exists('gzopen') === false) {
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 2));
}
// display initial version check
if ($page == 'overview') {
// log our actions
$log->logAction(ADM_ACTION, LOG_NOTICE, "checking auto-update");
// check for new version
$latestversion = @file(UPDATE_URI);
if (isset($latestversion[0])) {
$latestversion = explode('|', $latestversion[0]);
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
redirectTo($filename, array('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.'&amp;page=getdownload';
eval("echo \"" . getTemplate("misc/question_yesno", true) . "\";");
exit;
}
elseif ($isnewerversion == 0) {
// all good
standard_success ('noupdatesavail');
} else {
standard_error ('customized_version');
}
}
}
// error (something weird came from version.froxlor.org)
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 5));
}
// download the new archive
elseif ($page == 'getdownload') {
// retreive the new version from the form
$newversion = isset($_POST['newversion']) ? $_POST['newversion'] : null;
// valid?
if ($newversion !== null) {
// define files to get
$toLoad = str_replace('{version}', $newversion, RELEASE_URI);
$toCheck = str_replace('{version}', $newversion, MD5SUM_URI);
// get archive data
$newArchive = @file_get_contents($toLoad);
// check for local destination folder
if (!is_dir(FROXLOR_INSTALL_DIR.'/updates/')) {
mkdir(FROXLOR_INSTALL_DIR.'/updates/');
}
// name archive
$localArchive = FROXLOR_INSTALL_DIR.'/updates/'.basename($toLoad);
$log->logAction(ADM_ACTION, LOG_NOTICE, "Downloading ".$toLoad." to ".$localArchive);
// remove old archive
if (file_exists($localArchive)) {
@unlink($localArchive);
}
// store archive
$fh = fopen($localArchive, 'w');
if (!fwrite($fh, $newArchive)) {
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 4));
}
// close file-handle
fclose($fh);
// validate MD5
$_shouldsum = @file_get_contents($toCheck);
if (!empty($_shouldsum)) {
$_t = explode(" ", $_shouldsum);
$shouldsum = $_t[0];
} else {
$shouldsum = null;
}
$filesum = md5_file($localArchive);
if ($filesum != $shouldsum) {
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 9));
}
// to the next step
redirectTo($filename, array('s' => $s, 'page' => 'extract', 'archive' => basename($localArchive)));
}
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 6));
}
// extract and install new version
elseif ($page == 'extract') {
$toExtract = isset($_GET['archive']) ? $_GET['archive'] : null;
$localArchive = FROXLOR_INSTALL_DIR.'/updates/'.$toExtract;
if (isset($_POST['send'])
&& $_POST['send'] == 'send'
) {
// decompress from zip
$zip = new ZipArchive;
$res = $zip->open($localArchive);
if ($res === true) {
$log->logAction(ADM_ACTION, LOG_NOTICE, "Extracting ".$localArchive." to ".dirname(FROXLOR_INSTALL_DIR));
$zip->extractTo(dirname(FROXLOR_INSTALL_DIR));
$zip->close();
// success - remove unused archive
@unlink($localArchive);
} else {
// error
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 8));
}
// redirect to update-page?
redirectTo('admin_updates.php', array('s' => $s));
}
if (!file_exists($localArchive)) {
redirectTo($filename, array('s' => $s, 'page' => 'error', 'errno' => 7));
}
$text = 'Extract downloaded archive "'.$toExtract.'"?';
$hiddenparams = '';
$yesfile = $filename.'?s='.$s.'&amp;page=extract&amp;archive='.$toExtract;
eval("echo \"" . getTemplate("misc/question_yesno", true) . "\";");
}
// display error
elseif ($page == 'error') {
// retreive error-number via url-parameter
$errno = isset($_GET['errno']) ? (int)$_GET['errno'] : 0;
// 1 = no allow_url_fopen
// 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
// 9 = md5 mismatch
standard_error ('autoupdate_'.$errno);
}

View File

@@ -173,16 +173,21 @@ return array (
'label' => $lng['admin']['customers'],
'required_resources' => 'customers',
),
array (
'url' => 'admin_domains.php?page=domains',
'label' => $lng['admin']['domains'],
'required_resources' => 'domains',
),
array (
'url' => 'admin_admins.php?page=admins',
'label' => $lng['admin']['admins'],
'required_resources' => 'change_serversettings',
),
array (
'url' => 'admin_domains.php?page=domains',
'label' => $lng['admin']['domains'],
'required_resources' => 'domains',
),
array (
'url' => 'admin_ipsandports.php?page=ipsandports',
'label' => $lng['admin']['ipsandports']['ipsandports'],
'required_resources' => 'change_serversettings',
),
),
),
'traffic' => array (
@@ -210,32 +215,6 @@ return array (
'label' => $lng['admin']['serversettings'],
'required_resources' => 'change_serversettings',
),
array (
'url' => 'admin_settings.php?page=phpinfo',
'label' => $lng['admin']['phpinfo'],
'required_resources' => 'change_serversettings',
),
array (
'url' => 'admin_apcuinfo.php?page=showinfo',
'label' => $lng['admin']['apcuinfo'],
'required_resources' => 'change_serversettings',
'show_element' => (
function_exists('apcu_cache_info') === true
),
),
array (
'url' => 'admin_opcacheinfo.php?page=showinfo',
'label' => $lng['admin']['opcacheinfo'],
'required_resources' => 'change_serversettings',
'show_element' => (
function_exists('opcache_get_configuration') === true
),
),
array (
'url' => 'admin_ipsandports.php?page=ipsandports',
'label' => $lng['admin']['ipsandports']['ipsandports'],
'required_resources' => 'change_serversettings',
),
array (
'url' => 'admin_cronjobs.php?page=overview',
'label' => $lng['admin']['cron']['cronsettings'],
@@ -256,16 +235,48 @@ return array (
'label' => $lng['admin']['integritycheck'],
'required_resources' => 'change_serversettings',
),
array (
'url' => 'admin_phpsettings.php?page=overview',
'label' => $lng['menue']['phpsettings']['maintitle'],
'show_element' => (
Settings::Get('system.mod_fcgid') == true ||
Settings::Get('phpfpm.enabled') == true
),
),
array (
'url' => 'admin_autoupdate.php?page=overview',
'label' => $lng['admin']['autoupdate'],
'required_resources' => 'change_serversettings',
),
),
),
'server_php' => array (
'label' => $lng['admin']['server_php'],
'required_resources' => 'change_serversettings',
'elements' => array (
array (
'url' => 'admin_phpsettings.php?page=overview',
'label' => $lng['menue']['phpsettings']['maintitle'],
'show_element' => (
Settings::Get('system.mod_fcgid') == true ||
Settings::Get('phpfpm.enabled') == true
),
),
array (
'url' => 'admin_settings.php?page=phpinfo',
'label' => $lng['admin']['phpinfo'],
'required_resources' => 'change_serversettings',
),
array (
'url' => 'admin_apcuinfo.php?page=showinfo',
'label' => $lng['admin']['apcuinfo'],
'required_resources' => 'change_serversettings',
'show_element' => (
function_exists('apcu_cache_info') === true
),
),
array (
'url' => 'admin_opcacheinfo.php?page=showinfo',
'label' => $lng['admin']['opcacheinfo'],
'required_resources' => 'change_serversettings',
'show_element' => (
function_exists('opcache_get_configuration') === true
),
),
),
),
'misc' => array (
'label' => $lng['admin']['misc'],
'elements' => array (

View File

@@ -1940,3 +1940,17 @@ $lng['serversettings']['letsencryptcountrycode']['description'] = "2 letter coun
$lng['serversettings']['letsencryptstate']['title'] = "Let's Encrypt state";
$lng['serversettings']['letsencryptstate']['description'] = "State used to generate Let's Encrypt certificates.<br><strong class=\"red\">ATTENTION:</strong>Let's Encrypt is still in beta</strong>";
// Autoupdate
$lng['admin']['autoupdate'] = 'Auto-Update';
$lng['error']['customized_version'] = 'It looks like your Froxlor installation has been customized, no support sorry.';
$lng['error']['autoupdate_0'] = 'Unknown error';
$lng['error']['autoupdate_1'] = 'PHP setting allow_url_fopen is disabled. Autoupdate needs this setting to be enabled in the php.ini';
$lng['error']['autoupdate_2'] = 'PHP extension Zlib not found, please ensure it is installed and activated';
$lng['error']['autoupdate_4'] = 'The froxlor archive could not be stored to the disk :(';
$lng['error']['autoupdate_5'] = 'version.froxlor.org returned inacceptable values :(';
$lng['error']['autoupdate_6'] = 'Woops, there was no (valid) version given to download :(';
$lng['error']['autoupdate_7'] = 'The downloaded archive could not be found :(';
$lng['error']['autoupdate_8'] = 'The archive could not be extraxted :(';
$lng['error']['autoupdate_9'] = 'The MD5 sum of the downloaded file is not correct. Please try to update again.';
$lng['admin']['server_php'] = 'PHP';

View File

@@ -38,3 +38,6 @@ $lng['error']['notmorethanxopentickets'] = $lng['ticket']['notmorethanxopenticke
* other language-strings which need no translation
*/
$lng['domains']['ipandport_ssl_multi']['description'] = $lng['domains']['ipandport_multi']['description'];
$lng['success']['noupdatesavail'] = $lng['update']['noupdatesavail'];
$lng['error']['autoupdate_3'] = $lng['error']['customized_version'];