Started initial update and install changes.

This commit is contained in:
xevidos 2018-11-29 16:22:59 -05:00
parent 1d1f46a9df
commit 528b843eac
3 changed files with 281 additions and 82 deletions

View File

@ -34,7 +34,7 @@ Current Tasks:
- Permissions Management
- Plugin Management
- Project Management
- System Settigns
- System Settings
- User Management
Task List:

View File

@ -8,6 +8,7 @@ require_once('../../common.php');
require_once('../settings/class.settings.php');
require_once('../project/class.project.php');
require_once('../user/class.user.php');
checkSession();
if ( ! checkAccess() ) {
echo "Error, you do not have access to update Codiad.";
@ -24,38 +25,3 @@ $Common = new Common();
$Project = new Project();
$User = new User();
if( file_exists( $user_settings_file ) ) {
$user_settings = getJSON( 'settings.php' );
foreach( $user_settings as $user => $settings ) {
$Settings->username = $user;
foreach( $settings as $setting => $value ) {
$Settings->update_option( $setting, $value, true );
}
}
unlink( $user_settings_file );
}
if( file_exists( $projects_file ) ) {
$projects = getJSON( 'projects.php' );
foreach( $projects as $project => $data ) {
$Project->add_project( $data["name"], $data["path"], true );
}
unlink( $projects_file );
}
if( file_exists( $users_file ) ) {
$users = getJSON( 'users.php' );
foreach( $users as $user ) {
$User->username = $user["username"];
$User->password = $user["password"];
$User->add_user();
}
unlink( $users_file );
}

View File

@ -7,10 +7,36 @@ error_reporting(E_ALL);
require_once('../../common.php');
require_once('./class.update.php');
checkSession();
$user_settings_file = DATA . "/settings.php";
$projects_file = DATA . "/projects.php";
$users_file = DATA . "/users.php";
//checkSession();
if ( ! checkAccess() ) {
echo "Error, you do not have access to update Codiad.";
exit;
exit();
}
if ( ( file_exists( $user_settings_file ) || file_exists( $projects_file ) || file_exists( $users_file ) ) || ! ( defined( "DBHOST" ) && defined( "DBNAME" ) && defined( "DBUSER" ) && defined( "DBPASS" ) && defined( "DBTYPE" ) ) ) {
?>
<p>
Hello, this update requires new variables in your Codiad config.php<br />
Please place the following code in your config.php with the correct values applying to your databse and then reload this page. <br>
<br>
Please be aware that at the moment, only mysql databases are supported. However, more database support is planned.
</p>
<code>
<pre>
define( "DBHOST", "localhost" );
define( "DBNAME", "database" );
define( "DBUSER", "username" );
define( "DBPASS", "password" );
define( "DBTYPE", "mysql" );
</pre>
</code>
<?php
exit();
}
/**
@ -43,10 +69,11 @@ class updater {
function __construct() {
$this->update = new Update();
/*$this->archive = $update->archive;
$this->path = Common::getConstant('BASE_PATH');
$this->protocol = $this->check_protocol();
$this->archive = $this->update->archive;
$this->path = BASE_PATH;
/*
//Trigger update
$this->update();*/
}
@ -83,6 +110,63 @@ class updater {
return( $return );
}
function check_version() {
$local_version = $this->update::VERSION;
$remote_version = $response["name"];
$return = "false";
if( $local_version <= "v.2.9.2" ) {
$return = "convert";
}
return( $return );
}
function convert() {
require_once('../settings/class.settings.php');
require_once('../project/class.project.php');
require_once('../user/class.user.php');
if( file_exists( $user_settings_file ) ) {
$user_settings = getJSON( 'settings.php' );
foreach( $user_settings as $user => $settings ) {
$Settings->username = $user;
foreach( $settings as $setting => $value ) {
$Settings->update_option( $setting, $value, true );
}
}
unlink( $user_settings_file );
}
if( file_exists( $projects_file ) ) {
$projects = getJSON( 'projects.php' );
foreach( $projects as $project => $data ) {
$Project->add_project( $data["name"], $data["path"], true );
}
unlink( $projects_file );
}
if( file_exists( $users_file ) ) {
$users = getJSON( 'users.php' );
foreach( $users as $user ) {
$User->username = $user["username"];
$User->password = $user["password"];
$User->add_user();
}
unlink( $users_file );
}
}
function copyr( $source, $dest ) {
// Check for symlinks
if (is_link($source)) {
@ -131,22 +215,23 @@ class updater {
unlink( $filepath );
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->archive);
curl_setopt( $curl, CURLOPT_URL, $this->archive );
//curl_setopt($curl, CURLOPT_POSTFIELDS, "");
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13');
$raw_file_data = curl_exec($curl);
curl_close($curl);
curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13' );
$raw_file_data = curl_exec( $curl );
curl_close( $curl );
file_put_contents( $filepath, $raw_file_data );
return ( filesize( $filepath ) > 0 ) ? true : false;
break;
case( "fopen" ):
if( filesize( $filepath ) > 0 ) {
return( "true" );
} else {
return( "false" );
}
break;
}
}
@ -155,8 +240,7 @@ class updater {
if ( ! extension_loaded( 'zip' ) ) {
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"error_box\">Error, the php zip extension does not seem to be installed. Can not continue with update. Please install the <a href=\"http://php.net/manual/en/book.zip.php\" target=\"_blank\">php zip extension</a></p>'> ... </p>';</script>";
return false;
return "false";
}
$zip = new ZipArchive;
@ -165,10 +249,10 @@ class updater {
$zip->extractTo( $this->path );
$zip->close();
return true;
return "true";
} else {
return false;
return "false";
}
}
@ -179,30 +263,17 @@ class updater {
is_dir($file) ? $this->remove_directory($file) : unlink($file);
}
rmdir($path);
if( is_dir( $path ) ) {
rmdir( $path );
}
return;
}
function update() {
$sessions = "../../data/sessions";
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Downloading latest version ... </p>';</script>";
if ( ! $this->download() ) {
echo "<script>document.getElementById('progress').innerHTML += '<br><p class=\"error_box\">Error downloading latest version</p>';</script>";
return;
}
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Extracting update ... </p>';</script>";
if ( ! $this->extract() ) {
echo "<script>document.getElementById('progress').innerHTML += '<br><p class=\"error_box\">Error extracting update</p>';</script>";
return;
}
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Updating ... </p>';</script>";
//Add Sessions path if not there.
/**
@ -243,9 +314,12 @@ class updater {
$this->path . "/codiad-master/.travis.yml",
);
foreach( $folder_conflictions as $file ) {
foreach( $file_conflictions as $file ) {
unlink( $file );
if( is_file( $file ) ) {
unlink( $file );
}
}
@ -254,10 +328,19 @@ class updater {
$dest = $this->path . "/";
$this->copyr( $src, $dest );
echo "<script>document.getElementById('progress').innerHTML = '<p class=\"status_box\">Removing Update ... </p>';</script>";
$this->remove_directory( $src );
$this->convert();
return( "true" );
}
function version() {
$return = "";
if( file_exists( $user_settings_file ) || file_exists( $projects_file ) || file_exists( $users_file ) ) {
$return = "true";
}
}
}
@ -268,10 +351,35 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
switch( $action ) {
case( "apply" ):
echo $updater->update();
break;
case( "check_update" ):
echo $updater->check_update();
break;
case( "check_version" ):
echo $updater->check_version();
break;
case( "download" ):
echo $updater->download();
break;
case( "extract" ):
echo $updater->extract();
break;
case( "update" ):
echo $updater->update();
break;
}
exit();
@ -294,6 +402,7 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
font: normal 13px 'Ubuntu', sans-serif;
height: 100%;
overflow: hidden;
text-align: center;
width: 100%;
}
@ -306,6 +415,11 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}
#convert {
display: none;
}
#progress {
position: fixed;
@ -314,6 +428,7 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
transform: translate(-50%, -50%);
}
</style>
<script src="../../js/jquery-1.7.2.min.js"></script>
<script>
@ -328,6 +443,35 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
this.update();
},
apply: function() {
return jQuery.ajax({
url: "update.php",
type: "GET",
dataType: 'html',
data: {
action: 'apply',
},
success: function( result ) {
return result;
},
error: function( jqXHR, textStatus, errorThrown ) {
console.log( 'jqXHR:' );
console.log( jqXHR );
console.log( 'textStatus:' );
console.log( textStatus);
console.log( 'errorThrown:' );
console.log( errorThrown );
return null;
}
});
},
check_update: function() {
this.progress.innerText = "Checking for update ... ";
@ -358,6 +502,64 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
});
},
download: function() {
return jQuery.ajax({
url: "update.php",
type: "GET",
dataType: 'html',
data: {
action: 'download',
},
success: function( result ) {
return result;
},
error: function( jqXHR, textStatus, errorThrown ) {
console.log( 'jqXHR:' );
console.log( jqXHR );
console.log( 'textStatus:' );
console.log( textStatus);
console.log( 'errorThrown:' );
console.log( errorThrown );
return null;
}
});
},
extract: function() {
return jQuery.ajax({
url: "update.php",
type: "GET",
dataType: 'html',
data: {
action: 'extract',
},
success: function( result ) {
return result;
},
error: function( jqXHR, textStatus, errorThrown ) {
console.log( 'jqXHR:' );
console.log( jqXHR );
console.log( 'textStatus:' );
console.log( textStatus);
console.log( 'errorThrown:' );
console.log( errorThrown );
return null;
}
});
},
update: async function() {
let result = await this.check_update();
@ -365,7 +567,37 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
console.log( result );
if( result === "true" ) {
progress.innerText = "An update was found. Starting update.";
progress.innerText = "An update was found. Downloading update.";
let download = await this.download();
if( download !== "true" ) {
console.log( download );
progress.innerText = "Error downloading update.";
return;
}
progress.innerText = "Extracting update.";
let extract = await this.extract();
if( extract !== "true" ) {
console.log( extract );
progress.innerText = "Error extracting update.";
return;
}
progress.innerText = "Applying update.";
let apply = await this.apply();
if( apply !== "true" ) {
console.log( apply );
progress.innerText = "Error applying update.";
return;
}
progress.innerText = "Update Finished.";
} else if( result === "false" ) {
progress.innerText = "No update was found ...";
@ -382,6 +614,7 @@ if( isset( $_GET["action"] ) && $_GET["action"] !== '' ) {
Tela Codiad Updater
</h1>
<div>
<p>Do not leave this page until the process has finished.</p>
<p id="progress"></p>
</div>
<script>