From 528b843eac7c51fc6be1fcf7d53c8fbd96d94641 Mon Sep 17 00:00:00 2001 From: xevidos Date: Thu, 29 Nov 2018 16:22:59 -0500 Subject: [PATCH] Started initial update and install changes. --- README.md | 2 +- components/update/convert.php | 36 +--- components/update/update.php | 325 +++++++++++++++++++++++++++++----- 3 files changed, 281 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index c1b039b..f5db8ed 100755 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Current Tasks: - Permissions Management - Plugin Management - Project Management - - System Settigns + - System Settings - User Management Task List: diff --git a/components/update/convert.php b/components/update/convert.php index a7309d0..75248b4 100755 --- a/components/update/convert.php +++ b/components/update/convert.php @@ -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 ); -} \ No newline at end of file diff --git a/components/update/update.php b/components/update/update.php index 865def3..4be7ee0 100755 --- a/components/update/update.php +++ b/components/update/update.php @@ -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" ) ) ) { + + ?> +

+ Hello, this update requires new variables in your Codiad config.php
+ Please place the following code in your config.php with the correct values applying to your databse and then reload this page.
+
+ Please be aware that at the moment, only mysql databases are supported. However, more database support is planned. +

+ + +
+define( "DBHOST", "localhost" );
+define( "DBNAME", "database" );
+define( "DBUSER", "username" );
+define( "DBPASS", "password" );
+define( "DBTYPE", "mysql" );
+
+
+ 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 ""; - 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 ""; - if ( ! $this->download() ) { - - echo ""; - return; - } - - echo ""; - if ( ! $this->extract() ) { - - echo ""; - return; - } - - echo ""; - //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 ""; $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%); } +