1
0
mirror of https://github.com/Mowie/Mowie synced 2024-06-14 06:34:09 +00:00

Fixed Update-Function

This commit is contained in:
kolaente 2016-10-21 19:58:27 +02:00
parent 5911138b65
commit a2cfd99d02
8 changed files with 1708 additions and 49 deletions

View File

@ -1,5 +1,7 @@
<?php
require_once '../inc/autoload_adm.php';
require_once '../inc/libs/YAML/autoload.php';
use Symfony\Component\Yaml\Yaml;
//Datenbank Backup
if (isset($_GET['dbbackup']) && is_loggedin() && hasPerm('db_dump'))
{
@ -26,15 +28,13 @@ if (isset($_GET['dbbackup']) && is_loggedin() && hasPerm('db_dump'))
echo $backup['msg'];
exit;
}
} else
{
printHeader($lang->get('action_edit_content'));
}
if (hasPerm('manage_system'))
{
//construction
if (isset($_GET['construction']))
{
printHeader($lang->get('action_construction_message_edit'));
if (isset($_GET['constr_message']))
{
if (isset($_POST['constr_message']))
@ -119,9 +119,11 @@ if (hasPerm('manage_system'))
}
}
}
//Generelle Änderungen
//General Changes
if (isset($_GET['general']))
{
printHeader($lang->get('general_config'));
//Header
if (hasPerm('edit_title'))
{
@ -147,66 +149,97 @@ if (hasPerm('manage_system'))
}
}
}
//Update
if (isset($_GET['update']))
{
printHeader($lang->get('general_update'));
if (hasPerm('update'))
{
$version_remote = json_decode(file_get_contents($MCONF['update_uri'] . 'version.json'));
if ($version_remote->versionNum > $MCONF['version_num'])
$nextVersion = $MCONF['version_num'] + 1;
//Check for version.json on the remote server
$dUri = $MCONF['update_uri'] . 'v' . $nextVersion . '/';
if(remote_file_exists($dUri . 'version.json'))
{
if (copy($MCONF['update_uri'] . 'update.v' . $version_remote->versionNum . '.incremental.zip', 'update.zip'))
$version_remote = json_decode(file_get_contents($dUri . 'version.json'));
//Check if the remote version is newer
if ($version_remote->versionNum > $MCONF['version_num'])
{
if (md5_file('update.zip') == $version_remote->md5)
//Download the update
if (copy($dUri . 'update.v' . $version_remote->versionNum . '.incremental.zip', 'update.zip'))
{
if (!file_exists('updateNeu/'))
//Check for md5 hash
if (md5_file('update.zip') == $version_remote->md5)
{
mkdir('updateNeu/');
}
$zip = new ZipArchive;
$res = $zip->open('update.zip');
if ($res === true)
{
$zip->extractTo('updateNeu/');
$zip->close();
$updateInfos = json_decode(file_get_contents('updateNeu/filesToUpdate.json'));
//array mit dateine erstellen
$isUp = false;
$fTU = [];
foreach ($updateInfos->files as $num => $file)
//unzip to temporary folder
$updateTmpDir = 'updateTmp/';
if (!file_exists($updateTmpDir))
{
$fTU[] = $file;
$upNeu = 'updateNeu/' . $file;
$upRem = '../' . $file;
if (copy($upNeu, $upRem))
if(mkdir($updateTmpDir, 0777) === false)
{
echo msg('succes', sprintf($lang->get('action_update_item_succss'), $file));
$isUp = true;
} else
{
echo msg('fail', sprintf($lang->get('action_update_item_fail'), $file));
echo msg('fail', 'Error creating temporary folder.');
}
}
//Jetzt altes update entfernen
if (rrmdir('updateNeu') && $isUp && unlink('update.zip'))
$zip = new ZipArchive;
$res = $zip->open('update.zip');
if ($res === true)
{
echo msg('succes', $lang->get('action_update_success') . ' <a href="general_config.php">' . $lang->get('back') . '</a>');
$zip->extractTo($updateTmpDir);
$zip->close();
$updateInfos = json_decode(file_get_contents($updateTmpDir . 'filesToUpdate.json'));
$isUp = false;
$fTU = [];
foreach ($updateInfos->files as $num => $file)
{
$fTU[] = $file;
$upNeu = $updateTmpDir . $file;
$upRem = '../' . $file;
if (copy($upNeu, $upRem))
{
echo msg('succes', sprintf($lang->get('action_update_item_succss'), $file));
$isUp = true;
} else
{
echo msg('fail', sprintf($lang->get('action_update_item_fail'), $file));
}
}
//Update Version in Config File
$config = Yaml::parse(file_get_contents('../inc/config.yml', FILE_USE_INCLUDE_PATH));
$config['Versioning']['version'] = $version_remote->version;
$config['Versioning']['version_num'] = $version_remote->versionNum;
$configfile = Yaml::dump($config);
if (!file_put_contents('../inc/config.yml', $configfile))
{
echo msg('fail', $lang->get('action_update_config_fail'));
}
//Remove "old" update
if (rrmdir($updateTmpDir) && $isUp && unlink('update.zip'))
{
echo msg('succes', $lang->get('action_update_succss') . ' <a href="general_config.php">' . $lang->get('back') . '</a>');
} else
{
echo msg('fail', $lang->get('action_update_fail') . ' <a href="general_config.php">' . $lang->get('back') . '</a>');
}
} else
{
echo msg('fail', $lang->get('action_update_fail') . ' <a href="general_config.php">' . $lang->get('back') . '</a>');
echo msg('fail', $lang->get('action_update_fail_unzip'));
}
} else
{
echo msg('fail', $lang->get('action_update_fail_unzip'));
echo msg('fail', $lang->get('action_update_md5_fake'));
}
} else
{
echo msg('fail', $lang->get('action_update_md5_fake'));
echo msg('fail', $lang->get('action_update_fail_copy'));
}
} else
{
echo msg('fail', $lang->get('action_update_fail_copy'));
echo msg('info', $lang->get('general_version_current_new'));
}
} else
{
@ -214,8 +247,37 @@ if (hasPerm('manage_system'))
}
}
}
//Show Changelog
if(isset($_GET['showChangelog']))
{
printHeader($lang->get('general_showChangelog'));
echo '<div class="main">';
if(hasPerm('update'))
{
if(isset($_GET['v']))
{
if(remote_file_exists($MCONF['update_uri'] . 'v' . $_GET['v'] . '/changelog.md'))
{
require_once '../inc/libs/Parsedown.php';
$Parsedown = new Parsedown();
echo $Parsedown->text(file_get_contents($MCONF['update_uri'] . 'v' . $_GET['v'] . '/changelog.md'));
}
}
else
{
echo 'Missing Version.';
}
}
else
{
echo msg('info', $lang->get('missing_permission'));
}
echo '</div>';
}
} else
{
printHeader($lang->get('action_edit_content'));
echo msg('info', $lang->get('missing_permission'));
}
require_once '../inc/footer.php';

View File

@ -35,6 +35,10 @@ h1, h2, h3, h4, h5, h6 {
font-weight: 400;
}
ul{
padding-left: 20px;
}
/*Inputs und co*/
input, textarea {
font-size: 15px;
@ -52,6 +56,7 @@ input, textarea {
background-repeat: no-repeat;
transition: 0.2s ease;
-webkit-transition: 0.2s ease;
color: #212121;
}
textarea {
@ -81,6 +86,11 @@ input:invalid:focus, textarea:invalid:focus {
border: 0;
}
/*Placeholder*
::-webkit-input-placeholder, :-moz-placeholder, ::-moz-placeholder, :-ms-input-placeholder, ::placeholder {
color: #ccc !important;
}*/
/*Checkbox*/
input[type=checkbox] {
display: none;
@ -760,6 +770,7 @@ nav header {
nav ul {
padding-top: 20px;
padding-left: 0;
}
nav ul li {

View File

@ -48,11 +48,26 @@ tinymce();
</p>
<p>
<?php
$version_remote = json_decode(file_get_contents($MCONF['update_uri'] . 'version.json'));
if ($version_remote->versionNum > $MCONF['version_num'])
//Check for newer Version
$nextVersion = $MCONF['version_num'] + 1;
if(remote_file_exists($MCONF['update_uri'] . 'v' . $nextVersion . '/version.json'))
{
echo $lang->get('general_new_version') . ' <b>' . $version_remote->version . '</b> <a href="action.php?update" class="button">' . $lang->get('general_update') . '</a>';
} else
$version_remote = json_decode(file_get_contents($MCONF['update_uri'] . 'v' . $nextVersion . '/version.json'));
if ($version_remote->versionNum > $MCONF['version_num'])
{
echo $lang->get('general_new_version') . ' <b>' . $version_remote->version . '</b> <a href="action.php?update" class="button">' . $lang->get('general_update') . '</a>';
//Check for Changelog
if(remote_file_exists($MCONF['update_uri'] . 'v' . $nextVersion . '/changelog.md'))
{
echo '<a href="action.php?showChangelog&v='.$nextVersion.'" class="button"><i class="fa fa-list-alt" aria-hidden="true"></i>&nbsp;&nbsp;Changelog</a>';
}
} else
{
echo $lang->get('general_version_current_new');
}
}else
{
echo $lang->get('general_version_current_new');
}

View File

@ -62,8 +62,8 @@ if (isset($_POST['submit']))
$CONFIG['Templating']['tpl_title'] = 'title';
$CONFIG['Templating']['tpl_content'] = 'content';
$CONFIG['Templating']['tpl_webUri'] = 'website_uri';
$CONFIG['Versioning']['version'] = '0.91 Beta';
$CONFIG['Versioning']['version_num'] = 1;
$CONFIG['Versioning']['version'] = '0.93 Beta';
$CONFIG['Versioning']['version_num'] = 4;
$CONFIG['Versioning']['update_uri'] = 'http://cdn.kola-entertainments.de/cms/';
$CONFIG['Mail']['smtp'] = false;
@ -73,11 +73,11 @@ if (isset($_POST['submit']))
if ($_POST['mail_host'] != '' && $_POST['mail_user'] != '' && $_POST['mail_pass'] != '' && $_POST['mail_secure'] != '' && $_POST['mail_port'] != '')
{
$CONFIG['Mail']['smtp'] = true;
$config['Mail']['host'] = $_POST['mail_host'];
$config['Mail']['username'] = $_POST['mail_user'];
$config['Mail']['password'] = $_POST['mail_pass'];
$config['Mail']['secure'] = $_POST['mail_secure'];
$config['Mail']['port'] = $_POST['mail_port'];
$CONFIG['Mail']['host'] = $_POST['mail_host'];
$CONFIG['Mail']['username'] = $_POST['mail_user'];
$CONFIG['Mail']['password'] = $_POST['mail_pass'];
$CONFIG['Mail']['secure'] = $_POST['mail_secure'];
$CONFIG['Mail']['port'] = $_POST['mail_port'];
} else
{
echo msg('fail', 'Please provide all SMTP-Informations.');

View File

@ -89,6 +89,7 @@ $lang['general_update'] = 'Update';
$lang['general_database'] = 'Datenbank';
$lang['general_create_backup'] = 'Datenbank Backup erstellen';
$lang['general_go_phpmyadmin'] = 'Zu phpmyadmin';
$lang['general_showChangelog'] = 'Changelog anzeigen';
/*
* Manage Admins
@ -203,6 +204,7 @@ $lang['action_update_item_succss'] = '"%1$s" wurde erfolgreich upgedatet.';
$lang['action_update_item_fail'] = 'Fehler beim Updaten von "%1$s"';
$lang['action_update_succss'] = 'Mowie CMS wurde erfolgreich upgedatet.';
$lang['action_update_fail'] = 'Fehler beim Updaten.';
$lang['action_update_config_fail'] = 'Beim Bearbeiten der Configdatei ist ein Fehler aufgetreten.';
$lang['action_update_fail_unzip'] = 'Fehler beim Entpacken des Updates.';
$lang['action_update_md5_fake'] = 'Die Heruntergeladene Datei ist vermutlich falsch.';
$lang['action_update_fail_copy'] = 'Fehler beim Herunterladen des Updates. <b>Hinweis:</b> Der Nutzer, unter welchem der Webserver läuft, muss im Verzeichnis /admin Schreibrechte haben!';

View File

@ -89,6 +89,7 @@ $lang['general_update'] = 'Update';
$lang['general_database'] = 'Database';
$lang['general_create_backup'] = 'Create Database Backup';
$lang['general_go_phpmyadmin'] = 'phpmyadmin';
$lang['general_showChangelog'] = 'Show Changelog';
/*
* Manage Admins
@ -203,6 +204,7 @@ $lang['action_update_item_succss'] = '"%1$s" was successfully updated.';
$lang['action_update_item_fail'] = 'An error occured while updating "%1$s"';
$lang['action_update_succss'] = 'Mowie CMS was updated successfully.';
$lang['action_update_fail'] = 'An error occured while updating.';
$lang['action_update_config_fail'] = 'An error occured while updating the config file.';
$lang['action_update_fail_unzip'] = 'An error occured while unpacking the update.';
$lang['action_update_md5_fake'] = 'The downloaded file has a wrong checksum.';
$lang['action_update_fail_copy'] = 'An error occured while downloading the update. <b>Hint:</b> The webserver needs writing permissions in the folder /admin!';

1548
inc/libs/Parsedown.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -655,4 +655,23 @@ function mmail($mailaddr, $subject, $message, $from, $html = false)
}
}
//File exists on remote Server
function remote_file_exists($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($retcode == 200)
{
return true;
}
else
{
return false;
}
}
?>