From eb10cccb1333a4ef741e940bccc19a618b9bc4c7 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Sun, 5 May 2019 15:30:02 +0200 Subject: [PATCH 01/27] KLEEJA UPDATER an example to update kleeja direcly to the last approved version in github --- includes/adm/update_kleeja.php | 139 +++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 includes/adm/update_kleeja.php diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php new file mode 100644 index 0000000..140728a --- /dev/null +++ b/includes/adm/update_kleeja.php @@ -0,0 +1,139 @@ + for developers only +if (!ig('install_again')) +{ + // not reinstall , he want to update , => check if kleeja need or not + if ( ! version_compare(strtolower(KLEEJA_VERSION), strtolower($new_version), '<') ) + { + // kleeja doesn't need to update + kleeja_admin_info('there is no update for your version' , ADMIN_PATH ); + exit; + } +} // $_GET['install_again'] is set => reinstall kleeja => check if he is a developer +else +{ + // please no . + if ( ! defined('DEV_STAGE') ) + { + kleeja_admin_err(":( NOOO!!"); + exit; + } +} + +/** + * we will download the last version from github and extract it in cache folder + * then scan the new version files , and put it to the PATH + * we don't need to create the folders again in PATH + * and if we have to update the DB or removing some old files , + * we can check if there any update file of this version from the new install folder + * EX : if file exists PATH . 'install/update/$old_version_$new_version.php': require_once the file + */ + +$kj_new_pack_link = 'https://github.com/kleeja-official/kleeja/archive/'; + +$old_version = KLEEJA_VERSION; +$new_version = unserialize( $config['new_version'] )['version_number']; + +$down_new_pack = fetch_remote_file($kj_new_pack_link . $new_version . '.zip', PATH . 'cache/kleeja.zip', 60, false, 10, true); + +if ($down_new_pack) // we connected to github & downloaded the last version to cache folder +{ + // let's extract the zip to cache + $zip = new ZipArchive; + + if ($zip->open( PATH . 'cache/kleeja.zip' ) == TRUE) + { + $zip->extractTo( PATH . 'cache/' ); + $zip->close(); + } + + // some folder don't need it + $no_need = array( + 'cache', // delete_cache() function + 'plugins', // kleeja now support plugins update + 'uploads', + 'styles', // kleeja will support style_update soon + 'install' // befor removing install folder , we will take what we want from it + ); + + // let's check if there any update files in install folder + $update_file = PATH . "cache/kleeja-{$new_version}/install/includes/update_files/{$old_version}_to_{$new_version}.php"; + if (file_exists($update_file)) + { + // move the update file from install folder to cache folder to include it later and delete install folder + // becuse if install folder is exists , it can make some problems if dev mode is not active + rename($update_file , PATH . "cache/update_{$old_version}_to_{$new_version}.php"); + } + + foreach ($no_need as $folderName) + { + delete_plugin_folder( PATH . "cache/kleeja-{$new_version}/{$folderName}" ); + } + + // delete plugin folder function with some changes :) + $it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS); + $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + + foreach ($files as $file) + { + if ($file->isLink()) + { + file_put_contents( + str_replace("cache/kleeja-{$new_version}/", '' , $file->getPathname()) , + file_get_contents( $file->getPathname() ) + ); + unlink($file->getPathname()); + } + else if ($file->isDir()) + { + // here is folder , when we finish update , we will delete all folders and files + continue; + } + else + { + file_put_contents( + str_replace("cache/kleeja-{$new_version}/", '' , $file->getPathname()) , + file_get_contents( $file->getPathname() ) + ); + unlink($file->getPathname()); + } + } + + if (file_exists( $updateFiles = PATH . "cache/update_{$old_version}_to_{$new_version}.php")) + { + require_once $updateFiles; // we will include what we want to do in this file , and kleeja will done + } + + // after we made success update , let's delete files and folders incache + + // kleeja new version files + delete_plugin_folder(PATH . "cache/kleeja-{$new_version}"); + + // delete old cache files + delete_cache('' , true); + + /** + * DDISPLAY SUCCESS MSG HERE , AND ALSO WE CAN INCLUDE SUCCESS MSG ON UPDATE FILE + * OR WE CAN INCLUDE UPDATE FILES IN GITHUB , AND DOWNLOAD IT IN CACHE FOLDER WHEN IT REQUEST + * AND DELETE AFTER WE FINISH ; + */ + +} From 6df022a20bf7388f35d34c608e19aefbe55a785e Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Sun, 5 May 2019 20:12:32 +0300 Subject: [PATCH 02/27] IDEAS --- .php_cs | 6 +- includes/adm/j_plugins.php | 10 +-- includes/adm/update_kleeja.php | 144 ++++++++++++++++++++------------- includes/functions.php | 47 ++++++++--- includes/functions_adm.php | 47 +++-------- 5 files changed, 149 insertions(+), 105 deletions(-) diff --git a/.php_cs b/.php_cs index 894a283..b754750 100644 --- a/.php_cs +++ b/.php_cs @@ -37,7 +37,11 @@ return PhpCsFixer\Config::create() 'visibility_required' => true, 'native_function_casing' => true, 'no_empty_comment' => true, - 'single_line_comment_style' => true + 'single_line_comment_style' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_around_offset' => true, + 'no_spaces_inside_parenthesis' => true, ]) ->setFinder($finder) ->setIndent(" ") diff --git a/includes/adm/j_plugins.php b/includes/adm/j_plugins.php index 8cf06c8..6690bb2 100755 --- a/includes/adm/j_plugins.php +++ b/includes/adm/j_plugins.php @@ -151,7 +151,7 @@ switch ($case): break; } - // plugins avilable in kleeja remote catalog + // plugins avilable in kleeja remote catalog if (! ($catalog_plugins = $cache->get('catalog_plugins'))) { $store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json'; @@ -179,7 +179,7 @@ switch ($case): } // is there a new version of this in the store - elseif ($case == 'check' && (! empty($installed_plugins[$plugin_info['name']]) && + elseif ($case == 'check' && (! empty($installed_plugins[$plugin_info['name']]) && version_compare( strtolower($installed_plugins[$plugin_info['name']]['extra_info']['plugin_version']), strtolower($plugin_info['file']['version']), @@ -552,7 +552,7 @@ switch ($case): exit; } - // plugins avilable in kleeja store + // plugins avilable in kleeja store $store_link = 'https://raw.githubusercontent.com/kleeja-official/store-catalog/master/catalog.json'; $catalog_plugins = fetch_remote_file($store_link); @@ -581,7 +581,7 @@ switch ($case): // check if the version of the plugin is compatible with our kleeja version or not if ( version_compare(strtolower($store_plugins[$download_plugin]['kj_min_version']), KLEEJA_VERSION, '<=') - && version_compare(strtolower($store_plugins[$download_plugin]['kj_max_version']), KLEEJA_VERSION, '>=') + && version_compare(strtolower($store_plugins[$download_plugin]['kj_max_version']), KLEEJA_VERSION, '>=') ) { $download_plugin_link = $store_plugins[$download_plugin]['url']; @@ -656,7 +656,7 @@ switch ($case): if (is_dir($plugin_folder_name)) { - delete_plugin_folder($plugin_folder_name); + kleeja_unlink($plugin_folder_name); } redirect($plugin_download_link . $update_plugin . '&update' ); diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index 140728a..b6a59d9 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -8,39 +8,41 @@ */ // not for directly open -if (!defined('IN_ADMIN')) +if (! defined('IN_ADMIN')) { - exit(); + exit(); } -$new_version = unserialize( $config['new_version'] )['version_number']; +$new_version = unserialize($config['new_version'])['version_number']; // he can reinstall kleeja if he want by $_GET['install_again'] => for developers only -if (!ig('install_again')) +if (! ig('install_again')) { // not reinstall , he want to update , => check if kleeja need or not - if ( ! version_compare(strtolower(KLEEJA_VERSION), strtolower($new_version), '<') ) + if (! version_compare(strtolower(KLEEJA_VERSION), strtolower($new_version), '<')) { // kleeja doesn't need to update - kleeja_admin_info('there is no update for your version' , ADMIN_PATH ); + kleeja_admin_info('there is no update for your version', ADMIN_PATH); + exit; } } // $_GET['install_again'] is set => reinstall kleeja => check if he is a developer -else +else { // please no . - if ( ! defined('DEV_STAGE') ) + if (! defined('DEV_STAGE')) { - kleeja_admin_err(":( NOOO!!"); + kleeja_admin_err(':( NOOO!!'); + exit; } } /** * we will download the last version from github and extract it in cache folder - * then scan the new version files , and put it to the PATH + * then scan the new version files , and put it to the PATH * we don't need to create the folders again in PATH * and if we have to update the DB or removing some old files , * we can check if there any update file of this version from the new install folder @@ -50,90 +52,124 @@ else $kj_new_pack_link = 'https://github.com/kleeja-official/kleeja/archive/'; $old_version = KLEEJA_VERSION; -$new_version = unserialize( $config['new_version'] )['version_number']; +$new_version = unserialize($config['new_version'])['version_number']; + // downloaded the last version to cache folder $down_new_pack = fetch_remote_file($kj_new_pack_link . $new_version . '.zip', PATH . 'cache/kleeja.zip', 60, false, 10, true); -if ($down_new_pack) // we connected to github & downloaded the last version to cache folder +if ($down_new_pack) { // let's extract the zip to cache $zip = new ZipArchive; - if ($zip->open( PATH . 'cache/kleeja.zip' ) == TRUE) + if ($zip->open(PATH . 'cache/kleeja.zip') == true) { - $zip->extractTo( PATH . 'cache/' ); + $zip->extractTo(PATH . 'cache/'); $zip->close(); } - - // some folder don't need it - $no_need = array( + + // some folder don't need it + $no_need = [ 'cache', // delete_cache() function 'plugins', // kleeja now support plugins update 'uploads', 'styles', // kleeja will support style_update soon 'install' // befor removing install folder , we will take what we want from it - ); + ]; // let's check if there any update files in install folder $update_file = PATH . "cache/kleeja-{$new_version}/install/includes/update_files/{$old_version}_to_{$new_version}.php"; - if (file_exists($update_file)) + + if (file_exists($update_file)) { // move the update file from install folder to cache folder to include it later and delete install folder // becuse if install folder is exists , it can make some problems if dev mode is not active - rename($update_file , PATH . "cache/update_{$old_version}_to_{$new_version}.php"); + rename($update_file, PATH . "cache/update_{$old_version}_to_{$new_version}.php"); } - - foreach ($no_need as $folderName) + + foreach ($no_need as $folderName) { - delete_plugin_folder( PATH . "cache/kleeja-{$new_version}/{$folderName}" ); + kleeja_unlink(PATH . "cache/kleeja-{$new_version}/{$folderName}"); } // delete plugin folder function with some changes :) - $it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS); + $it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - foreach ($files as $file) + //rollback settings + mkdir(PATH . 'cache/rollback'); + $update_failed = false; + + foreach ($files as $file) { - if ($file->isLink()) - { - file_put_contents( - str_replace("cache/kleeja-{$new_version}/", '' , $file->getPathname()) , - file_get_contents( $file->getPathname() ) - ); - unlink($file->getPathname()); - } - else if ($file->isDir()) - { + if ($file->isFile()) + { + $file_path = str_replace("cache/kleeja-{$new_version}/", '', $file->getPathname()); + + // same, no need to replace + if (file_exists($file_path) && md5_file($file_path) != md5_file($file->getPathname())) + { + continue; + } + + //backup for rollback + if (! file_put_contents( + 'cache/rollback/' . ltrim($file_path, '/'), + file_get_contents($file_path) + )) + { + $update_failed = true; + + break; + } + + //copy file + if (! file_put_contents( + $file_path, + file_get_contents($file->getPathname()) + )) + { + $update_failed = true; + + break; + } + } + elseif ($file->isDir()) + { // here is folder , when we finish update , we will delete all folders and files + //TODO if folder is new, then mkdir it. continue; } - else + else { - file_put_contents( - str_replace("cache/kleeja-{$new_version}/", '' , $file->getPathname()) , - file_get_contents( $file->getPathname() ) - ); - unlink($file->getPathname()); + // not file or folder ? } } - if (file_exists( $updateFiles = PATH . "cache/update_{$old_version}_to_{$new_version}.php")) + if ($update_failed) { - require_once $updateFiles; // we will include what we want to do in this file , and kleeja will done + //rollback to backup cache/rollback } + else + { + // we will include what we want to do in this file , and kleeja will done + if (file_exists($updateFiles = PATH . "cache/update_{$old_version}_to_{$new_version}.php")) + { + require_once $updateFiles; + } - // after we made success update , let's delete files and folders incache + // after we made success update , let's delete files and folders incache - // kleeja new version files - delete_plugin_folder(PATH . "cache/kleeja-{$new_version}"); + // kleeja new version files + kleeja_unlink(PATH . "cache/kleeja-{$new_version}"); - // delete old cache files - delete_cache('' , true); - - /** - * DDISPLAY SUCCESS MSG HERE , AND ALSO WE CAN INCLUDE SUCCESS MSG ON UPDATE FILE - * OR WE CAN INCLUDE UPDATE FILES IN GITHUB , AND DOWNLOAD IT IN CACHE FOLDER WHEN IT REQUEST - * AND DELETE AFTER WE FINISH ; - */ + // delete old cache files + delete_cache('', true); + /** + * DDISPLAY SUCCESS MSG HERE , AND ALSO WE CAN INCLUDE SUCCESS MSG ON UPDATE FILE + * OR WE CAN INCLUDE UPDATE FILES IN GITHUB , AND DOWNLOAD IT IN CACHE FOLDER WHEN IT REQUEST + * AND DELETE AFTER WE FINISH ; + */ + } } diff --git a/includes/functions.php b/includes/functions.php index ce9aaa7..8d43209 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -97,7 +97,7 @@ function get_ban() // if the request is an image // if ( - ( defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf')) ) + (defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf'))) || g('go', 'str', '') == 'queue' ) { @$SQL->close(); @@ -271,8 +271,8 @@ function fetch_remote_file($url, $save_in = false, $timeout = 20, $head_only = f { @ini_set('default_socket_timeout', $timeout); } - $allow_url_fopen = function_exists('ini_get') - ? strtolower(@ini_get('allow_url_fopen')) + $allow_url_fopen = function_exists('ini_get') + ? strtolower(@ini_get('allow_url_fopen')) : strtolower(@get_cfg_var('allow_url_fopen')); if (function_exists('curl_init')) @@ -302,7 +302,7 @@ function fetch_remote_file($url, $save_in = false, $timeout = 20, $head_only = f @curl_exec($ch); curl_close($ch); fclose($out); - } + } if ($head_only) { @@ -548,7 +548,7 @@ function delete_cache($name, $all=false) if (file_exists($path_to_cache . '/' . $name)) { - $del = kleeja_unlink ($path_to_cache . '/' . $name, true); + $del = kleeja_unlink($path_to_cache . '/' . $name, true); } } @@ -577,7 +577,32 @@ function kleeja_unlink($filePath, $cache_file = false) //99.9% who use this if (function_exists('unlink')) { - return unlink($filePath); + if (is_dir($filePath)) + { + $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); + $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + + foreach ($files as $file) + { + if ($file->isLink()) + { + unlink($file->getPathname()); + } + elseif ($file->isDir()) + { + rmdir($file->getPathname()); + } + else + { + unlink($file->getPathname()); + } + } + return rmdir($dir); + } + else + { + return unlink($filePath); + } } //5% only who use this //else if (function_exists('exec')) @@ -1301,12 +1326,12 @@ function klj_clean_old_files($from = 0) //delete from folder .. if (file_exists($row['folder'] . '/' . $row['name'])) { - @kleeja_unlink ($row['folder'] . '/' . $row['name']); + @kleeja_unlink($row['folder'] . '/' . $row['name']); } //delete thumb - if (file_exists($row['folder'] . '/thumbs/' . $row['name'] )) + if (file_exists($row['folder'] . '/thumbs/' . $row['name'])) { - @kleeja_unlink ($row['folder'] . '/thumbs/' . $row['name'] ); + @kleeja_unlink($row['folder'] . '/thumbs/' . $row['name']); } $ids[] = $row['id']; @@ -1717,11 +1742,11 @@ function parse_serve_rule($regex, $args, $is_unicode = false) foreach ($parsed_args as $arg_key => $arg_value) { - if ( preg_match('/^\$/', $arg_value)) + if (preg_match('/^\$/', $arg_value)) { $match_number = ltrim($arg_value, '$'); - if ( isset($matches[$match_number])) + if (isset($matches[$match_number])) { $_GET[$arg_key] = $matches[$match_number]; } diff --git a/includes/functions_adm.php b/includes/functions_adm.php index cd51fdb..f6298c8 100755 --- a/includes/functions_adm.php +++ b/includes/functions_adm.php @@ -18,6 +18,13 @@ if (! defined('IN_COMMON')) * Print cp error function handler * * For admin +* @param mixed $msg +* @param mixed $navigation +* @param mixed $title +* @param mixed $exit +* @param mixed $redirect +* @param mixed $rs +* @param mixed $style */ function kleeja_admin_err($msg, $navigation = true, $title='', $exit = true, $redirect = false, $rs = 3, $style = 'admin_err') { @@ -237,7 +244,7 @@ function build_search_query($search) global $SQL; - $search['filename'] = ! isset($search['filename']) ? '' : $search['filename']; + $search['filename'] = ! isset($search['filename']) ? '' : $search['filename']; $search['username'] = ! isset($search['username']) ? '' : $search['username']; $search['than'] = ! isset($search['than']) ? '' : $search['than']; $search['size'] = ! isset($search['size']) ? '' : $search['size']; @@ -249,8 +256,8 @@ function build_search_query($search) $search['ext'] = ! isset($search['ext']) ? '' : $search['ext']; $search['user_ip'] = ! isset($search['user_ip']) ? '' : $search['user_ip']; - $file_namee = $search['filename'] != '' ? 'AND (f.real_filename LIKE \'%' . $SQL->escape($search['filename']) . '%\' OR f.name LIKE \'%' . $SQL->escape($search['filename']) . '%\')' : ''; - $usernamee = $search['username'] != '' ? 'AND u.name LIKE \'%' . $SQL->escape($search['username']) . '%\'' : ''; + $file_namee = $search['filename'] != '' ? 'AND (f.real_filename LIKE \'%' . $SQL->escape($search['filename']) . '%\' OR f.name LIKE \'%' . $SQL->escape($search['filename']) . '%\')' : ''; + $usernamee = $search['username'] != '' ? 'AND u.name LIKE \'%' . $SQL->escape($search['username']) . '%\'' : ''; $size_than = ' f.size ' . ($search['than']!=1 ? '<=' : '>=') . (intval($search['size']) * 1024) . ' '; $ups_than = $search['ups'] != '' ? 'AND f.uploads ' . ($search['uthan']!=1 ? '<' : '>') . intval($search['ups']) . ' ' : ''; $rep_than = $search['rep'] != '' ? 'AND f.report ' . ($search['rthan']!=1 ? '<' : '>') . intval($search['rep']) . ' ' : ''; @@ -296,7 +303,7 @@ function sync_total_files($files = true, $start = false) $start = ! $start ? $min_id : $start; $end = $start + $batch_size; - //now lets get this step's files number + //now lets get this step's files number unset($v, $result); $query['SELECT'] = 'COUNT(f.id) as num_files'; @@ -322,7 +329,7 @@ function sync_total_files($files = true, $start = false) //make it zero, firstly if ($first_loop) { - $update_query['SET'] = ($files ? 'files' : 'imgs') . '= 0'; + $update_query['SET'] = ($files ? 'files' : 'imgs') . '= 0'; $SQL->build($update_query); } @@ -358,7 +365,7 @@ function get_actual_stats($name) } /** - * check wether a start box is hidden or not + * check wether a start box is hidden or not * @param string $name box name * @return bool */ @@ -386,31 +393,3 @@ function adm_is_start_box_hidden($name) return in_array($name, $boxes); } - -/** - * delete plugin folder - * @param string $dir plugin folder path - * @return void - */ -function delete_plugin_folder($dir) -{ - $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); - $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - - foreach ($files as $file) - { - if ($file->isLink()) - { - unlink($file->getPathname()); - } - elseif ($file->isDir()) - { - rmdir($file->getPathname()); - } - else - { - unlink($file->getPathname()); - } - } - rmdir($dir); -} From e4c67d59c1ced6a046906434b58fdc966c3c8c39 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Sun, 5 May 2019 20:18:48 +0300 Subject: [PATCH 03/27] chmod it --- includes/adm/update_kleeja.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index b6a59d9..ad63b44 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -112,6 +112,18 @@ if ($down_new_pack) continue; } + if(! is_writable($file_path)) + { + chmod($file_path, 0644); + + if( ! is_writable($file_path)) + { + //if a host uses restrictive file permissions (e.g. 400) for all user files, + //this could solve the problem. + chmod($file_path, 0644 & ~ umask()); + } + } + //backup for rollback if (! file_put_contents( 'cache/rollback/' . ltrim($file_path, '/'), From 2bb0571bf3354ddd9f815e468827438ae87b3aba Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Sun, 5 May 2019 20:22:26 +0300 Subject: [PATCH 04/27] maintenance mode --- includes/adm/update_kleeja.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index ad63b44..8794b36 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -100,6 +100,9 @@ if ($down_new_pack) mkdir(PATH . 'cache/rollback'); $update_failed = false; + //maintenance mode on + update_config('siteclose', 1); + foreach ($files as $file) { if ($file->isFile()) @@ -184,4 +187,7 @@ if ($down_new_pack) * AND DELETE AFTER WE FINISH ; */ } + + //maintenance mode off + update_config('siteclose', 0); } From 2978ac0ded7d99c32415faff5abcf9b6ecb42453 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Mon, 6 May 2019 02:30:37 +0300 Subject: [PATCH 05/27] last --- includes/adm/update_kleeja.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index 8794b36..055fe27 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -28,13 +28,13 @@ if (! ig('install_again')) exit; } -} // $_GET['install_again'] is set => reinstall kleeja => check if he is a developer +} else { - // please no . + // kleeja is up to date, unless your are a developer trying to make a point... if (! defined('DEV_STAGE')) { - kleeja_admin_err(':( NOOO!!'); + kleeja_admin_info('Kleeja is up to date!'); exit; } @@ -54,8 +54,17 @@ $kj_new_pack_link = 'https://github.com/kleeja-official/kleeja/archive/'; $old_version = KLEEJA_VERSION; $new_version = unserialize($config['new_version'])['version_number']; - // downloaded the last version to cache folder -$down_new_pack = fetch_remote_file($kj_new_pack_link . $new_version . '.zip', PATH . 'cache/kleeja.zip', 60, false, 10, true); + +if (! class_exists('ZipArchive')) +{ + //$error = $lang['NO_ZIP_ARCHIVE']; + $down_new_pack = false; +} +else +{ + // downloaded the last version to cache folder + $down_new_pack = fetch_remote_file($kj_new_pack_link . $new_version . '.zip', PATH . 'cache/kleeja.zip', 60, false, 10, true); +} if ($down_new_pack) { @@ -115,11 +124,11 @@ if ($down_new_pack) continue; } - if(! is_writable($file_path)) + if (! is_writable($file_path)) { chmod($file_path, 0644); - if( ! is_writable($file_path)) + if (! is_writable($file_path)) { //if a host uses restrictive file permissions (e.g. 400) for all user files, //this could solve the problem. From d2dc847f907af3c9579cf3f3d00fede6caac4f14 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Mon, 6 May 2019 23:45:24 +0200 Subject: [PATCH 06/27] Update update_kleeja.php --- includes/adm/update_kleeja.php | 80 ++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index 055fe27..8915515 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -13,7 +13,7 @@ if (! defined('IN_ADMIN')) exit(); } - +$old_version = KLEEJA_VERSION; $new_version = unserialize($config['new_version'])['version_number']; @@ -21,7 +21,7 @@ $new_version = unserialize($config['new_version'])['version_number']; if (! ig('install_again')) { // not reinstall , he want to update , => check if kleeja need or not - if (! version_compare(strtolower(KLEEJA_VERSION), strtolower($new_version), '<')) + if (! version_compare(strtolower($old_version), strtolower($new_version), '<')) { // kleeja doesn't need to update kleeja_admin_info('there is no update for your version', ADMIN_PATH); @@ -51,8 +51,6 @@ else $kj_new_pack_link = 'https://github.com/kleeja-official/kleeja/archive/'; -$old_version = KLEEJA_VERSION; -$new_version = unserialize($config['new_version'])['version_number']; if (! class_exists('ZipArchive')) @@ -101,12 +99,63 @@ if ($down_new_pack) kleeja_unlink(PATH . "cache/kleeja-{$new_version}/{$folderName}"); } + /** + * we will build rollback as zip file , and import the local version in it + */ + + $localVersion = PATH . 'cache/old_kj.zip'; + + if (file_exists($localVersion)) + { + kleeja_unlink($localVersion); + } + + $oldKjZip = new ZipArchive; + $oldKjZip->open($localVersion, ZipArchive::CREATE); + + $it = new RecursiveDirectoryIterator(PATH , RecursiveDirectoryIterator::SKIP_DOTS); + $pathFiles = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + + // we will not import all files , only what we want to update + foreach ($pathFiles as $pathFile) + { + // only files , i like the zip file becuse i don't need to create multi folders inside + if ($pathFile->isFile()) + { + if (strpos($pathFile->getPathname() , '../cache') !== false) + { + continue; + } + elseif (strpos($pathFile->getPathname() , '../plugins') !== false) + { + continue; + } + elseif (strpos($pathFile->getPathname() , '../styles') !== false) + { + continue; + } + elseif (strpos($pathFile->getPathname() , '../uploads') !== false) + { + continue; + }else + { + // it's make a folder with name (..) , we don't want it + $oldKjZip->addFromString(str_replace('../' , '' , $pathFile->getPathname() ) + , file_get_contents($pathFile->getPathname())); + } + } + } + $oldKjZip->close(); + + /** + * Now , we have a copy from old version , let's try to update it + */ + + // delete plugin folder function with some changes :) $it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - //rollback settings - mkdir(PATH . 'cache/rollback'); $update_failed = false; //maintenance mode on @@ -119,7 +168,7 @@ if ($down_new_pack) $file_path = str_replace("cache/kleeja-{$new_version}/", '', $file->getPathname()); // same, no need to replace - if (file_exists($file_path) && md5_file($file_path) != md5_file($file->getPathname())) + if (file_exists($file_path) && md5_file($file_path) == md5_file($file->getPathname())) { continue; } @@ -136,17 +185,6 @@ if ($down_new_pack) } } - //backup for rollback - if (! file_put_contents( - 'cache/rollback/' . ltrim($file_path, '/'), - file_get_contents($file_path) - )) - { - $update_failed = true; - - break; - } - //copy file if (! file_put_contents( $file_path, @@ -172,7 +210,11 @@ if ($down_new_pack) if ($update_failed) { - //rollback to backup cache/rollback + kleeja_admin_err('update filed '); + $zip = new ZipArchive; + $zip->open($localVersion); + $zip->extractTo(PATH); + $zip->close(); } else { From 0b238a32580416158a60616eac1759a83b5a45e3 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Wed, 8 May 2019 02:07:47 +0300 Subject: [PATCH 07/27] fixes --- includes/adm/update_kleeja.php | 56 +++--- includes/plugins.php | 10 +- install/includes/Plugins.php | 28 +++ install/includes/functions_install.php | 39 ++--- install/install.php | 38 +---- install/quick.php | 225 +++++++++++++++++++++++++ 6 files changed, 299 insertions(+), 97 deletions(-) create mode 100644 install/includes/Plugins.php create mode 100644 install/quick.php diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index 8915515..0da9443 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -14,7 +14,10 @@ if (! defined('IN_ADMIN')) } $old_version = KLEEJA_VERSION; -$new_version = unserialize($config['new_version'])['version_number']; +$new_version = unserialize($config['new_version']); +$new_version = empty($new_version['version_number']) + ? KLEEJA_VERSION + : $new_version['version_number']; // he can reinstall kleeja if he want by $_GET['install_again'] => for developers only @@ -24,7 +27,7 @@ if (! ig('install_again')) if (! version_compare(strtolower($old_version), strtolower($new_version), '<')) { // kleeja doesn't need to update - kleeja_admin_info('there is no update for your version', ADMIN_PATH); + kleeja_admin_info('there is no update for your version!', ADMIN_PATH); exit; } @@ -102,47 +105,36 @@ if ($down_new_pack) /** * we will build rollback as zip file , and import the local version in it */ - - $localVersion = PATH . 'cache/old_kj.zip'; - if (file_exists($localVersion)) - { - kleeja_unlink($localVersion); - } + $localVersion = PATH . 'cache/old_kj.zip'; - $oldKjZip = new ZipArchive; - $oldKjZip->open($localVersion, ZipArchive::CREATE); + if (file_exists($localVersion)) + { + kleeja_unlink($localVersion); + } - $it = new RecursiveDirectoryIterator(PATH , RecursiveDirectoryIterator::SKIP_DOTS); + $oldKjZip = new ZipArchive; + $oldKjZip->open($localVersion, ZipArchive::CREATE); + + $it = new RecursiveDirectoryIterator(PATH, RecursiveDirectoryIterator::SKIP_DOTS); $pathFiles = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); // we will not import all files , only what we want to update - foreach ($pathFiles as $pathFile) + foreach ($pathFiles as $pathFile) { // only files , i like the zip file becuse i don't need to create multi folders inside - if ($pathFile->isFile()) + if ($pathFile->isFile()) { - if (strpos($pathFile->getPathname() , '../cache') !== false) + if (preg_match('/^\.\.\/(plugins|styles|cache|uploads)/', $pathFile->getPathname())) { continue; } - elseif (strpos($pathFile->getPathname() , '../plugins') !== false) - { - continue; - } - elseif (strpos($pathFile->getPathname() , '../styles') !== false) - { - continue; - } - elseif (strpos($pathFile->getPathname() , '../uploads') !== false) - { - continue; - }else - { - // it's make a folder with name (..) , we don't want it - $oldKjZip->addFromString(str_replace('../' , '' , $pathFile->getPathname() ) - , file_get_contents($pathFile->getPathname())); - } + + // it's make a folder with name (..) , we don't want it + $oldKjZip->addFromString( + preg_replace('/^\.\.\//', '', $pathFile->getPathname()), + file_get_contents($pathFile->getPathname()) + ); } } $oldKjZip->close(); @@ -210,7 +202,7 @@ if ($down_new_pack) if ($update_failed) { - kleeja_admin_err('update filed '); + kleeja_admin_err('updating process has failed...'); $zip = new ZipArchive; $zip->open($localVersion); $zip->extractTo(PATH); diff --git a/includes/plugins.php b/includes/plugins.php index d0eec1d..233bc3a 100755 --- a/includes/plugins.php +++ b/includes/plugins.php @@ -36,7 +36,7 @@ class Plugins private $installed_plugins_info = []; - private $plugin_path = ''; + private $plugin_path = PATH . 'plugins'; private static $instance; @@ -55,7 +55,11 @@ class Plugins } - $this->plugin_path = PATH . KLEEJA_PLUGINS_FOLDER; + + if (defined('KLEEJA_PLUGINS_FOLDER')) + { + $this->plugin_path = PATH . KLEEJA_PLUGINS_FOLDER; + } // Get installed plugins $query = [ @@ -85,7 +89,7 @@ class Plugins { $dh = opendir($this->plugin_path); - while (false !== ($folder_name = readdir($dh))) + while ($dh !== false and false !== ($folder_name = readdir($dh))) { if (is_dir($this->plugin_path . '/' . $folder_name) && preg_match('/[a-z0-9_.]{3,}/', $folder_name)) { diff --git a/install/includes/Plugins.php b/install/includes/Plugins.php new file mode 100644 index 0000000..dabe8a1 --- /dev/null +++ b/install/includes/Plugins.php @@ -0,0 +1,28 @@ +', file_get_contents('style/' . $tplname)); ob_start(); @@ -95,34 +91,21 @@ function gettpl($tplname) /** * Export config */ -function do_config_export($srv, $usr, $pass, $nm, $prf, $fpath = '') +function do_config_export($srv, $usr, $pass, $nm, $prf) { - global $_path; - - if (! in_array($type, ['mysql', 'mysqli'])) - { - $type = 'mysql'; - } - $data = ''; + $written = false; - if (is_writable($_path)) + if (is_writable(PATH)) { - $fh = @fopen($_path . 'config.php', 'wb'); + $fh = @fopen(PATH . 'config.php', 'wb'); if ($fh) { diff --git a/install/install.php b/install/install.php index 9340db0..676a09e 100755 --- a/install/install.php +++ b/install/install.php @@ -23,6 +23,7 @@ if (file_exists($_path . 'config.php')) { include_once $_path . 'config.php'; } +include_once 'includes/plugins.php'; include_once $_path . 'includes/functions_display.php'; include_once $_path . 'includes/functions_alternative.php'; include_once $_path . 'includes/functions.php'; @@ -32,36 +33,6 @@ include_once $_path . 'includes/mysqli.php'; include_once 'includes/functions_install.php'; -/** - * @ignore an alias class for plugins class - */ -class Plugins -{ - private static $instance; - - /** - * @return Plugins - */ - public static function getInstance() - { - if (is_null(self::$instance)) - { - self::$instance = new self(); - } - return self::$instance; - } - - /** - * @return array - */ - public function run($name) - { - return []; - } -} - - - if (! ig('step')) { @@ -71,7 +42,6 @@ if (! ig('step')) exit; } - // // Kleeja must be safe .. // @@ -81,7 +51,7 @@ if (! empty($dbuser) && ! empty($dbname) && ! (ig('step') && in_array(g('step'), if (! empty($d)) { - header('Location: index.php'); + header('Location: ./index.php'); exit; } @@ -243,8 +213,8 @@ case 'data' : //connect .. for check $SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname); - include_once '../includes/usr.php'; - include_once '../includes/functions_alternative.php'; + include_once $_path . 'includes/usr.php'; + include_once $_path . 'includes/functions_alternative.php'; $usrcp = new usrcp; $user_salt = substr(kleeja_base64_encode(pack('H*', sha1(mt_rand()))), 0, 7); diff --git a/install/quick.php b/install/quick.php new file mode 100644 index 0000000..17ca3a6 --- /dev/null +++ b/install/quick.php @@ -0,0 +1,225 @@ +is_connected()) +{ + exit('Can not connect to database, please make sure the data in `config.php` is correct!'); +} + +if (! empty($SQL->mysql_version()) && version_compare($SQL->mysql_version(), MIN_MYSQL_VERSION, '<')) +{ + exit('The required MySQL version is `' . MIN_MYSQL_VERSION . '` and yours is `' . $SQL->mysql_version() . '`!'); +} + +foreach (['cache', 'uploads', 'uploads/thumbs'] as $folder) +{ + if (! is_writable(PATH . $folder)) + { + @chmod(PATH . $folder, 0755); + + if (! is_writable(PATH . $folder)) + { + exit('The folder `' . $folder . '` has to be writable!'); + } + } +} + + +//install +$SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname); + +include_once PATH . 'includes/usr.php'; +include_once PATH . 'includes/functions_alternative.php'; + +$usrcp = new usrcp; +$password = mt_rand(); +$user_salt = substr(kleeja_base64_encode(pack('H*', sha1(mt_rand()))), 0, 7); +$user_pass = $usrcp->kleeja_hash_password($password . $user_salt); +$user_name = $clean_name = 'admin'; +$user_mail = $config_sitemail = 'admin@example.com'; +$config_urls_type = 'id'; +$config_sitename = 'Yet Another Kleeja'; +$config_siteurl = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('install', '', dirname($_SERVER['PHP_SELF'])); +$config_time_zone = '3'; + +// Queries +include 'includes/install_sqls.php'; +include 'includes/default_values.php'; + +$SQL->query($install_sqls['ALTER_DATABASE_UTF']); + + +$err = 0; +$errors = ''; + +foreach ($install_sqls as $name => $sql_content) +{ + if ($name == 'DROP_TABLES' || $name == 'ALTER_DATABASE_UTF') + { + continue; + } + + if (! $SQL->query($sql_content)) + { + $errors .= implode(':', $SQL->get_error()) . '' . "\n___\n"; + echo $lang['INST_SQL_ERR'] . ' : ' . $name . '[basic]' . (CLI ? PHP_EOL : '
'); + $err++; + } +} + +if ($err == 0) +{ + //add configs + foreach ($config_values as $cn) + { + if (empty($cn[6])) + { + $cn[6] = 0; + } + + $sql = "INSERT INTO `{$dbprefix}config` (`name`, `value`, `option`, `display_order`, `type`, `plg_id`, `dynamic`) VALUES ('$cn[0]', '$cn[1]', '$cn[2]', '$cn[3]', '$cn[4]', '$cn[5]', '$cn[6]');"; + + if (! $SQL->query($sql)) + { + $errors .= implode(':', $SQL->get_error()) . '' . "\n___\n"; + echo $lang['INST_SQL_ERR'] . ' : [configs_values] ' . $cn . (CLI ? PHP_EOL : '
'); + $err++; + } + } + + //add groups configs + foreach ($config_values as $cn) + { + if ($cn[4] != 'groups' or ! $cn[4]) + { + continue; + } + + $itxt = ''; + + foreach ([1, 2, 3] as $im) + { + $itxt .= ($itxt == '' ? '' : ',') . "($im, '$cn[0]', '$cn[1]')"; + } + + $sql = "INSERT INTO `{$dbprefix}groups_data` (`group_id`, `name`, `value`) VALUES " . $itxt . ';'; + + if (! $SQL->query($sql)) + { + $errors .= implode(':', $SQL->get_error()) . '' . "\n___\n"; + echo $lang['INST_SQL_ERR'] . ' : [groups_configs_values] ' . $cn . (CLI ? PHP_EOL : '
'); + $err++; + } + } + + //add exts + foreach ($ext_values as $gid => $exts) + { + $itxt = ''; + + foreach ($exts as $t => $v) + { + $itxt .= ($itxt == '' ? '' : ',') . "('$t', $gid, $v)"; + } + + $sql = "INSERT INTO `{$dbprefix}groups_exts` (`ext`, `group_id`, `size`) VALUES " . $itxt . ';'; + + if (! $SQL->query($sql)) + { + $errors .= implode(':', $SQL->get_error()) . '' . "\n___\n"; + echo $lang['INST_SQL_ERR'] . ' : [ext_values] ' . $gid . (CLI ? PHP_EOL : '
'); + $err++; + } + } + + //add acls + foreach ($acls_values as $cn => $ct) + { + $it = 1; + $itxt = ''; + + foreach ($ct as $ctk) + { + $itxt .= ($itxt == '' ? '' : ',') . "('$cn', '$it', '$ctk')"; + $it++; + } + + + $sql = "INSERT INTO `{$dbprefix}groups_acl` (`acl_name`, `group_id`, `acl_can`) VALUES " . $itxt . ';'; + + if (! $SQL->query($sql)) + { + $errors .= implode(':', $SQL->get_error()) . '' . "\n___\n"; + echo $lang['INST_SQL_ERR'] . ' : [acl_values] ' . $cn . (CLI ? PHP_EOL : '
'); + $err++; + } + $it++; + } +} + + +if ($err > 0) +{ + echo CLI ? PHP_EOL : '
'; + echo 'We encountered a problem during installation, see the error log:'; + echo CLI ? PHP_EOL : '
'; + echo CLI ? '' : ''; +} +else +{ + echo CLI ? '' : ''; + echo 'Kleeja has been installed successfully, enjoy ...'; + echo CLI ? PHP_EOL : '

'; + echo 'Username: admin' . (CLI ? PHP_EOL : '
'); + echo 'Password: ' . $password; +} From e26157c5b166496979cdcdcafdf12ca608a62262 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Wed, 8 May 2019 03:36:51 +0300 Subject: [PATCH 08/27] fix --- includes/adm/p_check_update.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index b72b236..658c931 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -23,13 +23,18 @@ if ($current_smt == 'check'): //get data from kleeja github repo if (! ($version_data = $cache->get('kleeja_repo_version'))) { - $github_data = fetch_remote_file('https://raw.githubusercontent.com/awssat/kleeja/master/includes/version.php', false, 6); + $github_data = fetch_remote_file('https://api.github.com/repos/kleeja-official/kleeja/releases/latest', false, 60); if (! empty($github_data)) { - preg_match_all('/define\(\'KLEEJA_VERSION\',\s{1,4}\'([^\']+)\'\);/', $github_data, $matches, PREG_SET_ORDER, 0); - $version_data = trim(htmlspecialchars($matches[0][1])); - $cache->save('kleeja_repo_version', $version_data, 3600 * 2); + $latest_release = json_decode($github_data, true); + $version_data = ''; + + if (json_last_error() === JSON_ERROR_NONE) + { + $version_data = trim(htmlspecialchars($latest_release['tag_name'])); + $cache->save('kleeja_repo_version', $version_data, 3600 * 2); + } } } From 9471ffb3d2f959190053d978f5cfdbc7927d8b4b Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Wed, 8 May 2019 03:53:46 +0300 Subject: [PATCH 09/27] fixes --- includes/adm/update_kleeja.php | 8 +++++++- includes/functions.php | 23 ++--------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index 0da9443..61e9a40 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -149,6 +149,7 @@ if ($down_new_pack) $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); $update_failed = false; + $failed_files = []; //maintenance mode on update_config('siteclose', 1); @@ -184,6 +185,7 @@ if ($down_new_pack) )) { $update_failed = true; + array_push($failed_files, $file_path); break; } @@ -202,7 +204,11 @@ if ($down_new_pack) if ($update_failed) { - kleeja_admin_err('updating process has failed...'); + kleeja_admin_err( + 'updating process has failed...' . + (defined('DEV_STAGE') ? '[' . implode(', ', $failed_files) . ']' : '') + ); + $zip = new ZipArchive; $zip->open($localVersion); $zip->extractTo(PATH); diff --git a/includes/functions.php b/includes/functions.php index 8d43209..87faa2f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -579,16 +579,12 @@ function kleeja_unlink($filePath, $cache_file = false) { if (is_dir($filePath)) { - $it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS); + $it = new RecursiveDirectoryIterator($filePath, RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); foreach ($files as $file) { - if ($file->isLink()) - { - unlink($file->getPathname()); - } - elseif ($file->isDir()) + if ($file->isDir()) { rmdir($file->getPathname()); } @@ -604,21 +600,6 @@ function kleeja_unlink($filePath, $cache_file = false) return unlink($filePath); } } - //5% only who use this - //else if (function_exists('exec')) - //{ - // $out = array(); - // $return = null; - // exec('del ' . escapeshellarg(realpath($filepath)) . ' /q', $out, $return); - // return $return; - //} - //5% only who use this - //else if (function_exists('system')) - //{ - // $return = null; - // system ('del ' . escapeshellarg(realpath($filepath)) . ' /q', $return); - // return $return; - //} //just rename cache file if there is new thing elseif (function_exists('rename') && $cache_file) { From f94cb2e1bf68f5027209126a7fb9945a951d3d02 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Wed, 8 May 2019 04:18:06 +0300 Subject: [PATCH 10/27] fix --- includes/adm/update_kleeja.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index 61e9a40..ec04a71 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -19,6 +19,10 @@ $new_version = empty($new_version['version_number']) ? KLEEJA_VERSION : $new_version['version_number']; +// solutions for hosts running under suexec, add define('HAS_SUEXEC', true) to config.php. +define('K_FILE_CHMOD', defined('HAS_SUEXEC') ? (0644 & ~ umask()) : 0644); +define('K_DIR_CHMOD', defined('HAS_SUEXEC') ? (0755 & ~ umask()) : 0755); + // he can reinstall kleeja if he want by $_GET['install_again'] => for developers only if (! ig('install_again')) @@ -159,6 +163,7 @@ if ($down_new_pack) if ($file->isFile()) { $file_path = str_replace("cache/kleeja-{$new_version}/", '', $file->getPathname()); + $file_dir = str_replace("cache/kleeja-{$new_version}/", '', $file->getPath()); // same, no need to replace if (file_exists($file_path) && md5_file($file_path) == md5_file($file->getPathname())) @@ -166,23 +171,22 @@ if ($down_new_pack) continue; } + //no folder? + if(! file_exists($file_dir)) + { + mkdir($file_dir, K_DIR_CHMOD, true); + } + if (! is_writable($file_path)) { - chmod($file_path, 0644); - - if (! is_writable($file_path)) - { - //if a host uses restrictive file permissions (e.g. 400) for all user files, - //this could solve the problem. - chmod($file_path, 0644 & ~ umask()); - } + chmod($file_path, K_FILE_CHMOD); } //copy file - if (! file_put_contents( + if (file_put_contents( $file_path, file_get_contents($file->getPathname()) - )) + ) === false) { $update_failed = true; array_push($failed_files, $file_path); @@ -193,7 +197,7 @@ if ($down_new_pack) elseif ($file->isDir()) { // here is folder , when we finish update , we will delete all folders and files - //TODO if folder is new, then mkdir it. + mkdir($file_path, K_DIR_CHMOD, true); continue; } else @@ -204,6 +208,9 @@ if ($down_new_pack) if ($update_failed) { + //maintenance mode off + update_config('siteclose', 0); + kleeja_admin_err( 'updating process has failed...' . (defined('DEV_STAGE') ? '[' . implode(', ', $failed_files) . ']' : '') From 2a2199b8a8f296d0171ca415e49e904f38e563c8 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Wed, 8 May 2019 22:14:28 +0300 Subject: [PATCH 11/27] fixes --- includes/adm/update_kleeja.php | 109 ++++++++++++++++----------------- includes/functions.php | 2 +- includes/version.php | 2 +- 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php index ec04a71..4bddff8 100644 --- a/includes/adm/update_kleeja.php +++ b/includes/adm/update_kleeja.php @@ -13,6 +13,17 @@ if (! defined('IN_ADMIN')) exit(); } +/** + * TODO: + * - ajax + * - first get new kleeja version. (one request) + * - show [update] button. + * - update (one request). + * - after-update (one request) + */ + +set_time_limit(0); + $old_version = KLEEJA_VERSION; $new_version = unserialize($config['new_version']); $new_version = empty($new_version['version_number']) @@ -106,46 +117,16 @@ if ($down_new_pack) kleeja_unlink(PATH . "cache/kleeja-{$new_version}/{$folderName}"); } - /** - * we will build rollback as zip file , and import the local version in it - */ + # backup as zip file and import the local files in it to rollback later on failure + $backup_version = PATH . 'cache/backup.zip'; - $localVersion = PATH . 'cache/old_kj.zip'; - - if (file_exists($localVersion)) + if (file_exists($backup_version)) { - kleeja_unlink($localVersion); + kleeja_unlink($backup_version); } - $oldKjZip = new ZipArchive; - $oldKjZip->open($localVersion, ZipArchive::CREATE); - - $it = new RecursiveDirectoryIterator(PATH, RecursiveDirectoryIterator::SKIP_DOTS); - $pathFiles = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - - // we will not import all files , only what we want to update - foreach ($pathFiles as $pathFile) - { - // only files , i like the zip file becuse i don't need to create multi folders inside - if ($pathFile->isFile()) - { - if (preg_match('/^\.\.\/(plugins|styles|cache|uploads)/', $pathFile->getPathname())) - { - continue; - } - - // it's make a folder with name (..) , we don't want it - $oldKjZip->addFromString( - preg_replace('/^\.\.\//', '', $pathFile->getPathname()), - file_get_contents($pathFile->getPathname()) - ); - } - } - $oldKjZip->close(); - - /** - * Now , we have a copy from old version , let's try to update it - */ + $backup = new ZipArchive; + $backup->open($backup_version, ZipArchive::CREATE); // delete plugin folder function with some changes :) @@ -154,6 +135,7 @@ if ($down_new_pack) $update_failed = false; $failed_files = []; + $new_folders = []; //maintenance mode on update_config('siteclose', 1); @@ -175,6 +157,7 @@ if ($down_new_pack) if(! file_exists($file_dir)) { mkdir($file_dir, K_DIR_CHMOD, true); + array_push($new_folders, $file_dir); } if (! is_writable($file_path)) @@ -182,6 +165,12 @@ if ($down_new_pack) chmod($file_path, K_FILE_CHMOD); } + //back up current file + $backup->addFromString( + $file_path, + file_get_contents($file_path) + ); + //copy file if (file_put_contents( $file_path, @@ -197,7 +186,12 @@ if ($down_new_pack) elseif ($file->isDir()) { // here is folder , when we finish update , we will delete all folders and files - mkdir($file_path, K_DIR_CHMOD, true); + if (! file_exists($file_path)) + { + mkdir($file_path, K_DIR_CHMOD, true); + array_push($new_folders, $file_path); + } + continue; } else @@ -206,20 +200,28 @@ if ($down_new_pack) } } + $backup->close(); + if ($update_failed) { + //rollback to backup + $zip = new ZipArchive; + $zip->open($backup_version); + $zip->extractTo(PATH); + $zip->close(); + + foreach($new_folders as $folder) + { + kleeja_unlink($folder); + } + //maintenance mode off update_config('siteclose', 0); kleeja_admin_err( 'updating process has failed...' . - (defined('DEV_STAGE') ? '[' . implode(', ', $failed_files) . ']' : '') + (defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : '') ); - - $zip = new ZipArchive; - $zip->open($localVersion); - $zip->extractTo(PATH); - $zip->close(); } else { @@ -229,21 +231,18 @@ if ($down_new_pack) require_once $updateFiles; } - // after we made success update , let's delete files and folders incache + //maintenance mode off + update_config('siteclose', 0); - // kleeja new version files + // after a success update, delete files and folders in cache kleeja_unlink(PATH . "cache/kleeja-{$new_version}"); - - // delete old cache files delete_cache('', true); - /** - * DDISPLAY SUCCESS MSG HERE , AND ALSO WE CAN INCLUDE SUCCESS MSG ON UPDATE FILE - * OR WE CAN INCLUDE UPDATE FILES IN GITHUB , AND DOWNLOAD IT IN CACHE FOLDER WHEN IT REQUEST - * AND DELETE AFTER WE FINISH ; - */ + kleeja_info( + "Kleeja has been updated to {$new_version} successfully...", + '', + true, + '?cp=p_check_update' + ); } - - //maintenance mode off - update_config('siteclose', 0); } diff --git a/includes/functions.php b/includes/functions.php index 87faa2f..1aef259 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -593,7 +593,7 @@ function kleeja_unlink($filePath, $cache_file = false) unlink($file->getPathname()); } } - return rmdir($dir); + return rmdir($filePath); } else { diff --git a/includes/version.php b/includes/version.php index 4f52189..63de316 100755 --- a/includes/version.php +++ b/includes/version.php @@ -16,6 +16,6 @@ if (! defined('IN_COMMON')) -define('KLEEJA_VERSION', '3.0.2'); +define('KLEEJA_VERSION', '3.0.3'); define('KLEEJA_DB_VERSION', '9'); From 10c8f19e337849bbc90d1bb8f8b1ff1ae995c174 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Wed, 8 May 2019 23:28:18 +0200 Subject: [PATCH 12/27] fix error msg --- includes/adm/j_plugins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/adm/j_plugins.php b/includes/adm/j_plugins.php index 6690bb2..69440f4 100755 --- a/includes/adm/j_plugins.php +++ b/includes/adm/j_plugins.php @@ -617,7 +617,7 @@ switch ($case): } else { - kleeja_admin_err($lang['EXTRACT_ZIP_FAILED']); + kleeja_admin_err(sprintf($lang['EXTRACT_ZIP_FAILED'], KLEEJA_PLUGINS_FOLDER)); } } } From 3cb8a55db999444c5b2fb6745ba9d9ccc58273b0 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Fri, 10 May 2019 15:27:36 +0200 Subject: [PATCH 13/27] delete plugins langs --- lang/en/common.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lang/en/common.php b/lang/en/common.php index 5f48aca..e3347b0 100755 --- a/lang/en/common.php +++ b/lang/en/common.php @@ -288,4 +288,6 @@ return [ //3.0.3 'NOTIFICATIONS' => 'Notifications', 'KJ_TWEETS' => 'Kleeja Tweets' , + 'PLG_SUCSS_DEL' => 'the Folder of plugin "%s" is deleted successfuly !!' , + 'PLG_DEL_CONFIRM' => 'You will delete the plugin folder' , ]; From 5b4532a596170b9b6086b3518ef47e6558347b62 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Fri, 10 May 2019 15:29:16 +0200 Subject: [PATCH 14/27] delete plugins from server add delete plugin action --- includes/adm/j_plugins.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/includes/adm/j_plugins.php b/includes/adm/j_plugins.php index 69440f4..0e503d8 100755 --- a/includes/adm/j_plugins.php +++ b/includes/adm/j_plugins.php @@ -34,10 +34,11 @@ $plugin_enable_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&am $plugin_disable_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=disable&' . $GET_FORM_KEY . '&plg='; $plugin_download_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=download&' . $GET_FORM_KEY . '&plg='; $plugin_update_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=update&' . $GET_FORM_KEY . '&plg='; +$plugin_delete_folder_link = ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=delete_folder&' . $GET_FORM_KEY . '&plg='; //check _GET Csrf token -if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable' , 'download' , 'update'])) +if (! empty($case) && in_array($case, ['install', 'uninstall', 'enable', 'disable' , 'download' , 'update' , 'delete_folder'])) { if (! kleeja_check_form_key_get('PLUGINS_FORM_KEY')) { @@ -610,7 +611,7 @@ switch ($case): // download or update msg kleeja_admin_info( sprintf($lang[ig('update') ? 'PLUGIN_UPDATED' : 'PLUGIN_DOWNLOADED'], $download_plugin), - ADMIN_PATH . '?cp=' . basename(__file__, '.php') + ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=local' ); exit; @@ -656,11 +657,29 @@ switch ($case): if (is_dir($plugin_folder_name)) { - kleeja_unlink($plugin_folder_name); + delete_plugin_folder($plugin_folder_name); } redirect($plugin_download_link . $update_plugin . '&update' ); break; + case 'delete_folder': + + $plugin_folder = g('plg'); + + $plugin_folder_name = PATH . KLEEJA_PLUGINS_FOLDER . '/' . $plugin_folder; + + if (is_dir($plugin_folder_name)) + { + delete_plugin_folder($plugin_folder_name); + } + + kleeja_admin_info( + sprintf($lang['PLG_SUCSS_DEL'] , $plugin_folder), + ADMIN_PATH . '?cp=' . basename(__file__, '.php') . '&case=local' + ); + + break; + endswitch; From 4d7a02b890deb44e6b9d245dfc002ec25e9292f0 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Fri, 10 May 2019 15:31:43 +0200 Subject: [PATCH 15/27] add delete plugin btn --- admin/Masmak/admin_plugins.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/admin/Masmak/admin_plugins.html b/admin/Masmak/admin_plugins.html index bfcf248..8420bb7 100755 --- a/admin/Masmak/admin_plugins.html +++ b/admin/Masmak/admin_plugins.html @@ -98,6 +98,7 @@
{{name}}
+ @@ -196,4 +197,4 @@ - \ No newline at end of file + From ca300cbff1f20832d58e59dd8db73496f07bc595 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Fri, 10 May 2019 15:36:01 +0200 Subject: [PATCH 16/27] Update common.php --- lang/ar/common.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lang/ar/common.php b/lang/ar/common.php index a384579..ec22496 100755 --- a/lang/ar/common.php +++ b/lang/ar/common.php @@ -298,4 +298,6 @@ return [ //3.0.3 'NOTIFICATIONS' => 'تنبيهات', 'KJ_TWEETS' => 'تغريدات كليجا' , + 'PLG_SUCSS_DEL' => 'تم حذف مجلد الاضافة "%s" بنجاح!' , + 'PLG_DEL_CONFIRM' => 'سوف تقوم بحذف مجلد الاضافة' , ]; From b70e76664cfb26f45c6f2ab15464d9cb00304787 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Sun, 12 May 2019 03:08:45 +0300 Subject: [PATCH 17/27] moved to update page and make it better --- admin/Masmak/admin_check_update.html | 158 +++++++++++----- includes/adm/j_plugins.php | 4 +- includes/adm/p_check_update.php | 250 ++++++++++++++++++++++--- includes/adm/update_kleeja.php | 248 ------------------------ includes/common.php | 31 +-- includes/functions.php | 12 +- install/includes/functions_install.php | 39 ++-- install/quick.php | 17 +- lang/ar/acp.php | 26 +-- lang/en/acp.php | 9 +- 10 files changed, 407 insertions(+), 387 deletions(-) delete mode 100644 includes/adm/update_kleeja.php diff --git a/admin/Masmak/admin_check_update.html b/admin/Masmak/admin_check_update.html index 6634806..b759c5c 100755 --- a/admin/Masmak/admin_check_update.html +++ b/admin/Masmak/admin_check_update.html @@ -1,52 +1,126 @@ - - -
- +
+
+ {lang.LOADING} +
+
+ +
    +
  • +
    +
    +

    1

    Downloading latest Kleeja package... +
    + +
    +
    +
  • +
  • +
    +
    +

    2

    Create a backup container and extract the new package ... +
    + +
    +
    +
  • +
  • +
    +
    +

    3

    Updating to new version (files & database upgrade) ... +
    + +
    +
    +
  • + +
+ + + - - - - - - - -
    -
  • {lang.HOW_UPDATE_KLEEJA_STEP1}
  • -
  • {lang.HOW_UPDATE_KLEEJA_STEP2}
  • -
  • {lang.HOW_UPDATE_KLEEJA_STEP3} - -
  • -
- - - diff --git a/includes/adm/j_plugins.php b/includes/adm/j_plugins.php index 0e503d8..dffff94 100755 --- a/includes/adm/j_plugins.php +++ b/includes/adm/j_plugins.php @@ -657,7 +657,7 @@ switch ($case): if (is_dir($plugin_folder_name)) { - delete_plugin_folder($plugin_folder_name); + kleeja_unlink($plugin_folder_name); } redirect($plugin_download_link . $update_plugin . '&update' ); @@ -672,7 +672,7 @@ switch ($case): if (is_dir($plugin_folder_name)) { - delete_plugin_folder($plugin_folder_name); + kleeja_unlink($plugin_folder_name); } kleeja_admin_info( diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index 658c931..4a8d243 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -13,17 +13,36 @@ if (! defined('IN_ADMIN')) exit(); } +set_time_limit(0); + +$current_version = '3.0'; +$new_version = unserialize($config['new_version']); +$new_version = empty($new_version['version_number']) + ? KLEEJA_VERSION + : $new_version['version_number']; +$backup_archive_path = PATH . 'cache/backup.zip'; + +define('KLEEJA_VERSION_CHECK_LINK', 'https://api.github.com/repos/kleeja-official/kleeja/releases/latest'); +define('KLEEJA_LATEST_PACKAGE_LINK', 'https://github.com/kleeja-official/kleeja/archive/'); + $stylee = 'admin_check_update'; -$current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general')); +$current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general')); $update_link = $config['siteurl'] . 'install/update.php?lang=' . $config['language']; -//to prevent getting the url data for all cats -if ($current_smt == 'check'): +//only founders can do the upgrade process ... +if(in_array($current_smt, ['update1', 'update2', 'update3']) && intval($userinfo['founder']) !== 1) +{ + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); +} +//check latest version +if ($current_smt == 'check') +{ //get data from kleeja github repo if (! ($version_data = $cache->get('kleeja_repo_version'))) { - $github_data = fetch_remote_file('https://api.github.com/repos/kleeja-official/kleeja/releases/latest', false, 60); + $github_data = fetch_remote_file(KLEEJA_VERSION_CHECK_LINK, false, 100); if (! empty($github_data)) { @@ -47,16 +66,16 @@ if ($current_smt == 'check'): } else { - if (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '<')) + if (version_compare(strtolower($current_version), strtolower($version_data), '<')) { - $text = sprintf($lang['UPDATE_NOW_S'], KLEEJA_VERSION, strtolower($version_data)) . '

' . $lang['UPDATE_KLJ_NOW']; - $error = 1; + $text = sprintf($lang['UPDATE_NOW_S'], $current_version, strtolower($version_data)); + $error = 2; } - elseif (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '=')) + elseif (version_compare(strtolower($current_version), strtolower($version_data), '=')) { $text = $lang['U_LAST_VER_KLJ']; } - elseif (version_compare(strtolower(KLEEJA_VERSION), strtolower($version_data), '>')) + elseif (version_compare(strtolower($current_version), strtolower($version_data), '>')) { $text = $lang['U_USE_PRE_RE']; } @@ -77,14 +96,10 @@ if ($current_smt == 'check'): delete_cache('data_config'); $adminAjaxContent = $error . ':::' . $text; - -elseif ($current_smt == 'general'): - -// if(!$error) -// { - - - +} +// home of update page +elseif ($current_smt == 'general') +{ //To prevent expected error [ infinit loop ] if (ig('show_msg')) { @@ -103,18 +118,199 @@ elseif ($current_smt == 'general'): } } + $showMessage = ig('show_msg'); +} +//1. download latest kleeja version +elseif ($current_smt == 'update1') +{ + if (! class_exists('ZipArchive')) + { + $adminAjaxContent = '930:::' . $lang['NO_ZIP_ARCHIVE']; + } + elseif (! version_compare(strtolower($current_version), strtolower($new_version), '<')) + { + $adminAjaxContent = '940:::there is no update for your version!'; + } + else + { + // downloaded the last package to cache folder + fetch_remote_file(KLEEJA_LATEST_PACKAGE_LINK . $new_version . '.zip', PATH . "cache/kleeja-{$new_version}.zip", 60, false, 10, true); + if(file_exists(PATH . "cache/kleeja-{$new_version}.zip")) + { + $adminAjaxContent = '1:::'; + file_put_contents(PATH . 'cache/step1.done', time()); + } + else + { + $adminAjaxContent = '2:::We have encountered a problem while downloading the package ... '; + } + } +} +//2. extract new kleeja package, create backup zip file +elseif ($current_smt == 'update2') +{ + if(! file_exists(PATH . 'cache/step1.done')) + { + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); + } -// } + kleeja_unlink(PATH . 'cache/step1.done'); -$showMessage = ig('show_msg'); + // let's extract the zip to cache + $zip = new ZipArchive; + if ($zip->open(PATH . "cache/kleeja-{$new_version}.zip") == true) + { + $zip->extractTo(PATH . 'cache/'); + $zip->close(); + } -//end current_smt == general -endif; + // let's check if there any update files in install folder + $update_file = PATH . "cache/kleeja-{$new_version}/install/includes/update_files/{$old_version}_to_{$new_version}.php"; -//secondary menu -$go_menu = [ - 'general' => ['name'=>$lang['R_CHECK_UPDATE'], 'link'=> basename(ADMIN_PATH) . '?cp=p_check_update&smt=general', 'goto'=>'general', 'current'=> $current_smt == 'general'], - 'howto' => ['name'=>$lang['HOW_UPDATE_KLEEJA'], 'link'=> basename(ADMIN_PATH) . '?cp=p_check_update&smt=howto', 'goto'=>'howto', 'current'=> $current_smt == 'howto'], - 'site' => ['name'=>'Kleeja.com', 'link'=> 'http://www.kleeja.com', 'goto'=>'site', 'current'=> $current_smt == 'site'], -]; + if (file_exists($update_file)) + { + // move the update file from install folder to cache folder to include it later and delete install folder + // becuse if install folder is exists , it can make some problems if dev mode is not active + rename($update_file, PATH . "cache/update_{$old_version}_to_{$new_version}.php"); + } + + // skip some folders + foreach (['cache', 'plugins', 'uploads', 'styles', 'install'] as $folder_name) + { + kleeja_unlink(PATH . "cache/kleeja-{$new_version}/{$folder_name}"); + } + + if (file_exists($backup_archive_path)) + { + kleeja_unlink($backup_archive_path); + } + + file_put_contents(PATH . 'cache/step2.done', time()); + + $adminAjaxContent = '1:::'; +} +//3. update, or rollback on failure +elseif ($current_smt == 'update3') +{ + if(! file_exists(PATH . 'cache/step2.done')) + { + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); + } + + kleeja_unlink(PATH . 'cache/step2.done'); + + $backup = new ZipArchive; + if($backup->open($backup_archive_path, ZipArchive::CREATE) !== true) + { + + } + + // delete plugin folder function with some changes :) + $it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS); + $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); + + $update_failed = false; + $failed_files = $new_folders = []; + + //maintenance mode on + update_config('siteclose', 1); + + foreach ($files as $file) + { + if ($file->isFile()) + { + $file_path = str_replace("cache/kleeja-{$new_version}/", '', $file->getPathname()); + $file_dir = str_replace("cache/kleeja-{$new_version}/", '', $file->getPath()); + + // same, no need to replace + if (file_exists($file_path) && md5_file($file_path) == md5_file($file->getPathname())) + { + continue; + } + + //no folder? + if (! file_exists($file_dir)) + { + mkdir($file_dir, K_DIR_CHMOD, true); + array_push($new_folders, $file_dir); + } + + if (! is_writable($file_path)) + { + chmod($file_path, K_FILE_CHMOD); + } + + //back up current file + $backup->addFromString( + $file_path, + file_get_contents($file_path) + ); + + //copy file + if (file_put_contents( + $file_path, + file_get_contents($file->getPathname()) + ) === false) + { + $update_failed = true; + array_push($failed_files, $file_path); + + break; + } + } + elseif ($file->isDir()) + { + // here is folder , when we finish update , we will delete all folders and files + if (! file_exists($file_path)) + { + mkdir($file_path, K_DIR_CHMOD, true); + array_push($new_folders, $file_path); + } + + continue; + } + } + + $backup->close(); + + if ($update_failed) + { + //rollback to backup + $zip = new ZipArchive; + $zip->open($backup_archive_path); + $zip->extractTo(PATH); + $zip->close(); + + foreach ($new_folders as $folder) + { + kleeja_unlink($folder); + } + + //maintenance mode off + update_config('siteclose', 0); + + $adminAjaxContent = '1002:::updating process has failed...' . + (defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : ''); + } + else + { + // we will include what we want to do in this file , and kleeja will done + if (file_exists($db_update_file = PATH . "cache/update_{$old_version}_to_{$new_version}.php")) + { + require_once $db_update_file; + } + + //maintenance mode off + update_config('siteclose', 0); + + // after a success update, delete files and folders in cache + kleeja_unlink(PATH . "cache/kleeja-{$new_version}"); + delete_cache('', true); + + $adminAjaxContent = "1:::Kleeja has been updated to {$new_version} successfully..."; + } +} +//endif diff --git a/includes/adm/update_kleeja.php b/includes/adm/update_kleeja.php deleted file mode 100644 index 4bddff8..0000000 --- a/includes/adm/update_kleeja.php +++ /dev/null @@ -1,248 +0,0 @@ - for developers only -if (! ig('install_again')) -{ - // not reinstall , he want to update , => check if kleeja need or not - if (! version_compare(strtolower($old_version), strtolower($new_version), '<')) - { - // kleeja doesn't need to update - kleeja_admin_info('there is no update for your version!', ADMIN_PATH); - - exit; - } -} -else -{ - // kleeja is up to date, unless your are a developer trying to make a point... - if (! defined('DEV_STAGE')) - { - kleeja_admin_info('Kleeja is up to date!'); - - exit; - } -} - -/** - * we will download the last version from github and extract it in cache folder - * then scan the new version files , and put it to the PATH - * we don't need to create the folders again in PATH - * and if we have to update the DB or removing some old files , - * we can check if there any update file of this version from the new install folder - * EX : if file exists PATH . 'install/update/$old_version_$new_version.php': require_once the file - */ - -$kj_new_pack_link = 'https://github.com/kleeja-official/kleeja/archive/'; - - - -if (! class_exists('ZipArchive')) -{ - //$error = $lang['NO_ZIP_ARCHIVE']; - $down_new_pack = false; -} -else -{ - // downloaded the last version to cache folder - $down_new_pack = fetch_remote_file($kj_new_pack_link . $new_version . '.zip', PATH . 'cache/kleeja.zip', 60, false, 10, true); -} - -if ($down_new_pack) -{ - // let's extract the zip to cache - $zip = new ZipArchive; - - if ($zip->open(PATH . 'cache/kleeja.zip') == true) - { - $zip->extractTo(PATH . 'cache/'); - $zip->close(); - } - - // some folder don't need it - $no_need = [ - 'cache', // delete_cache() function - 'plugins', // kleeja now support plugins update - 'uploads', - 'styles', // kleeja will support style_update soon - 'install' // befor removing install folder , we will take what we want from it - ]; - - // let's check if there any update files in install folder - $update_file = PATH . "cache/kleeja-{$new_version}/install/includes/update_files/{$old_version}_to_{$new_version}.php"; - - if (file_exists($update_file)) - { - // move the update file from install folder to cache folder to include it later and delete install folder - // becuse if install folder is exists , it can make some problems if dev mode is not active - rename($update_file, PATH . "cache/update_{$old_version}_to_{$new_version}.php"); - } - - foreach ($no_need as $folderName) - { - kleeja_unlink(PATH . "cache/kleeja-{$new_version}/{$folderName}"); - } - - # backup as zip file and import the local files in it to rollback later on failure - $backup_version = PATH . 'cache/backup.zip'; - - if (file_exists($backup_version)) - { - kleeja_unlink($backup_version); - } - - $backup = new ZipArchive; - $backup->open($backup_version, ZipArchive::CREATE); - - - // delete plugin folder function with some changes :) - $it = new RecursiveDirectoryIterator(PATH . "cache/kleeja-{$new_version}/", RecursiveDirectoryIterator::SKIP_DOTS); - $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST); - - $update_failed = false; - $failed_files = []; - $new_folders = []; - - //maintenance mode on - update_config('siteclose', 1); - - foreach ($files as $file) - { - if ($file->isFile()) - { - $file_path = str_replace("cache/kleeja-{$new_version}/", '', $file->getPathname()); - $file_dir = str_replace("cache/kleeja-{$new_version}/", '', $file->getPath()); - - // same, no need to replace - if (file_exists($file_path) && md5_file($file_path) == md5_file($file->getPathname())) - { - continue; - } - - //no folder? - if(! file_exists($file_dir)) - { - mkdir($file_dir, K_DIR_CHMOD, true); - array_push($new_folders, $file_dir); - } - - if (! is_writable($file_path)) - { - chmod($file_path, K_FILE_CHMOD); - } - - //back up current file - $backup->addFromString( - $file_path, - file_get_contents($file_path) - ); - - //copy file - if (file_put_contents( - $file_path, - file_get_contents($file->getPathname()) - ) === false) - { - $update_failed = true; - array_push($failed_files, $file_path); - - break; - } - } - elseif ($file->isDir()) - { - // here is folder , when we finish update , we will delete all folders and files - if (! file_exists($file_path)) - { - mkdir($file_path, K_DIR_CHMOD, true); - array_push($new_folders, $file_path); - } - - continue; - } - else - { - // not file or folder ? - } - } - - $backup->close(); - - if ($update_failed) - { - //rollback to backup - $zip = new ZipArchive; - $zip->open($backup_version); - $zip->extractTo(PATH); - $zip->close(); - - foreach($new_folders as $folder) - { - kleeja_unlink($folder); - } - - //maintenance mode off - update_config('siteclose', 0); - - kleeja_admin_err( - 'updating process has failed...' . - (defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : '') - ); - } - else - { - // we will include what we want to do in this file , and kleeja will done - if (file_exists($updateFiles = PATH . "cache/update_{$old_version}_to_{$new_version}.php")) - { - require_once $updateFiles; - } - - //maintenance mode off - update_config('siteclose', 0); - - // after a success update, delete files and folders in cache - kleeja_unlink(PATH . "cache/kleeja-{$new_version}"); - delete_cache('', true); - - kleeja_info( - "Kleeja has been updated to {$new_version} successfully...", - '', - true, - '?cp=p_check_update' - ); - } -} diff --git a/includes/common.php b/includes/common.php index 6da6ab9..999ee7e 100755 --- a/includes/common.php +++ b/includes/common.php @@ -57,11 +57,15 @@ require_once PATH . KLEEJA_CONFIG_FILE; define('ADM_FILES_PATH', PATH . 'includes/adm'); //Report all errors, except notices -error_reporting( defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE); +error_reporting(defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE); /** * functions for start +* @param mixed $error_number +* @param mixed $error_string +* @param mixed $error_file +* @param mixed $error_line */ function kleeja_show_error($error_number, $error_string = '', $error_file = '', $error_line = '') { @@ -129,9 +133,9 @@ if (empty($dbname) || empty($dbuser)) exit; } -//include files .. & classes .. -$root_path = PATH; -// $db_type = isset($db_type) ? $db_type : 'mysqli'; +// solutions for hosts running under suexec, add define('HAS_SUEXEC', true) to config.php. +define('K_FILE_CHMOD', defined('HAS_SUEXEC') ? (0644 & ~umask()) : 0644); +define('K_DIR_CHMOD', defined('HAS_SUEXEC') ? (0755 & ~umask()) : 0755); include PATH . 'includes/functions_alternative.php'; include PATH . 'includes/version.php'; @@ -163,7 +167,7 @@ unset($dbpass); -$tpl = new kleeja_style; +$tpl = new kleeja_style; $usrcp = new usrcp; //then get caches @@ -310,10 +314,10 @@ if ( file_exists(PATH . 'install') && ! defined('IN_ADMIN') && ! defined('IN_LOGIN') && - ! defined('DEV_STAGE') && + ! defined('DEV_STAGE') && ! (defined('IN_GO') && in_array(g('go'), ['queue'])) && ! (defined('IN_UCP') && in_array(g('go'), ['captcha', 'login'])) - ) { +) { //Different message for admins! delete install folder kleeja_info((user_can('enter_acp') ? $lang['DELETE_INSTALL_FOLDER'] : $lang['WE_UPDATING_KLEEJA_NOW']), $lang['SITE_CLOSED']); } @@ -323,16 +327,16 @@ if ( $login_page = ''; if ( - $config['siteclose'] == '1' && - ! user_can('enter_acp') && - ! defined('IN_LOGIN') && - ! defined('IN_ADMIN') && + $config['siteclose'] == '1' && + ! user_can('enter_acp') && + ! defined('IN_LOGIN') && + ! defined('IN_ADMIN') && ! (defined('IN_GO') && in_array(g('go'), ['queue'])) && ! (defined('IN_UCP') && in_array(g('go'), ['captcha', 'login', 'register', 'logout'])) ) { //if download, images ? if ( - ( defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf')) ) + (defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf'))) || g('go', 'str', '') == 'queue' ) { @$SQL->close(); @@ -352,7 +356,8 @@ if ( //exceed total size if (($stat_sizes >= ($config['total_size'] *(1048576))) && ! defined('IN_LOGIN') && ! defined('IN_ADMIN')) -{// convert megabytes to bytes +{ + // convert megabytes to bytes // Send a 503 HTTP response code to prevent search bots from indexing the maintenace message header('HTTP/1.1 503 Service Temporarily Unavailable'); kleeja_info($lang['SIZES_EXCCEDED'], $lang['STOP_FOR_SIZE']); diff --git a/includes/functions.php b/includes/functions.php index 1aef259..9fdff49 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -22,7 +22,7 @@ if (! defined('IN_COMMON')) */ function kleeja_detecting_bots() { - global $SQL, $usrcp, $dbprefix, $config, $klj_session; + global $SQL, $dbprefix, $config; // get information .. $agent = $SQL->escape($_SERVER['HTTP_USER_AGENT']); @@ -1502,11 +1502,11 @@ function kleeja_log($text) return; } - $log_file = PATH . 'cache/kleeja_log.log'; - $l_c = @file_get_contents($log_file); - $fp = @fopen($log_file, 'w'); - @fwrite($fp, $text . ' [time : ' . date('H:i a, d-m-Y') . "] \r\n" . $l_c); - @fclose($fp); + file_put_contents( + PATH . 'cache/kleeja_log.log', + date_format(date_create(), 'Y-m-d h:i:s.ua') . ' | INFO | ' . $text . PHP_EOL, + FILE_APPEND | LOCK_EX + ); } diff --git a/install/includes/functions_install.php b/install/includes/functions_install.php index 145bc4c..539bf87 100755 --- a/install/includes/functions_install.php +++ b/install/includes/functions_install.php @@ -11,7 +11,7 @@ define('MIN_PHP_VERSION', '7.0'); define('MIN_MYSQL_VERSION', '4.2.2'); //version of latest changes at db -define ('LAST_DB_VERSION', '9'); +define('LAST_DB_VERSION', '9'); //set no errors define('MYSQL_NO_ERRORS', true); @@ -74,6 +74,7 @@ function getjquerylink() /** * Parsing installing templates +* @param mixed $tplname */ function gettpl($tplname) { @@ -90,6 +91,11 @@ function gettpl($tplname) /** * Export config +* @param mixed $srv +* @param mixed $usr +* @param mixed $pass +* @param mixed $nm +* @param mixed $prf */ function do_config_export($srv, $usr, $pass, $nm, $prf) { @@ -100,32 +106,22 @@ function do_config_export($srv, $usr, $pass, $nm, $prf) $data .= '$dbname = \'' . str_replace("'", "\'", $nm) . "'; // database name \n"; $data .= '$dbprefix = \'' . str_replace("'", "\'", $prf) . "'; // if you use prefix for tables , fill it \n"; - - $written = false; - - if (is_writable(PATH)) + if (file_put_contents(PATH . 'config.php', $data, LOCK_EX) !== false) { - $fh = @fopen(PATH . 'config.php', 'wb'); - - if ($fh) - { - fwrite($fh, $data); - fclose($fh); - - $written = true; - } + return true; } - if (! $written) + if (defined('CLI') && CLI) { - header('Content-Type: text/x-delimtext; name="config.php"'); - header('Content-disposition: attachment; filename=config.php'); - echo $data; - - exit; + return true; } - return true; + // + header('Content-Type: text/x-delimtext; name="config.php"'); + header('Content-disposition: attachment; filename=config.php'); + echo $data; + + exit; } @@ -140,6 +136,7 @@ function get_microtime() /** * Get config value from database directly, if not return false. +* @param mixed $name */ function inst_get_config($name) { diff --git a/install/quick.php b/install/quick.php index 17ca3a6..47f5792 100644 --- a/install/quick.php +++ b/install/quick.php @@ -30,6 +30,15 @@ include_once PATH . 'includes/mysqli.php'; include_once 'includes/functions_install.php'; +//cli options +$cli_options = []; + +if (CLI) +{ + $cli_options = getopt('', ['password::', 'link::']); +} + + if (file_exists(PATH . 'config.php')) { include_once PATH . 'config.php'; @@ -80,15 +89,17 @@ include_once PATH . 'includes/usr.php'; include_once PATH . 'includes/functions_alternative.php'; $usrcp = new usrcp; -$password = mt_rand(); +$password = ! empty($cli_options['password']) ? $cli_options['password'] : mt_rand(); $user_salt = substr(kleeja_base64_encode(pack('H*', sha1(mt_rand()))), 0, 7); $user_pass = $usrcp->kleeja_hash_password($password . $user_salt); $user_name = $clean_name = 'admin'; $user_mail = $config_sitemail = 'admin@example.com'; $config_urls_type = 'id'; $config_sitename = 'Yet Another Kleeja'; -$config_siteurl = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('install', '', dirname($_SERVER['PHP_SELF'])); -$config_time_zone = '3'; +$config_siteurl = ! empty($cli_options['link']) + ? $cli_options['link'] + : 'http://' . $_SERVER['HTTP_HOST'] . str_replace('install', '', dirname($_SERVER['PHP_SELF'])); +$config_time_zone = 'Asia/Buraydah'; // Queries include 'includes/install_sqls.php'; diff --git a/lang/ar/acp.php b/lang/ar/acp.php index 7239fe2..d348b18 100755 --- a/lang/ar/acp.php +++ b/lang/ar/acp.php @@ -123,9 +123,9 @@ return [ 'PLUGIN_EXISTS_BEFORE' => 'الاضافة هذه موجودة سابقاً بنفس الاصدار أو أعلى ولاتحتاج تحديث !', 'R_CHECK_UPDATE' => 'فحص عن تحديثات', 'ERROR_CHECK_VER' => 'خطأ: لا يمكن جلب معلومات عن آخر نسخة في هذه اللحظة، حاول مجدداً لاحقا!.', - 'UPDATE_KLJ_NOW' => 'يجب أن تقوم بتحديث نسختك إلى آخر نسخة الآن، قم بالذهاب لموقع كليجا لمعلومات أكثر .', + 'UPDATE_KLJ_NOW' => 'تحديث الآن!', 'U_LAST_VER_KLJ' => 'أنت تستخدم آخر نسخة من كليجا. شكراً لمتابعة نسختك بإستمرار.', - 'U_USE_PRE_RE' => 'أنت تستخدم نسخة تطويرية لم تصدر حتى الآن , اضغط هنا لإخبارنا بأي أخطاء برمجية وثغرات قد تقابلك.', + 'U_USE_PRE_RE' => 'أنت تستخدم نسخة تطويرية لم تصدر حتى الآن , اضغط هنا لإخبارنا بأي أخطاء برمجية وثغرات قد تقابلك.', 'STYLE_IS_DEFAULT' => 'استايل افتراضي', 'MAKE_AS_DEFAULT' => 'تعيينه افتراضي', 'STYLE_NOW_IS_DEFAULT' => 'تم تعيين الاستايل "%s" ستايل افتراضي', @@ -171,18 +171,10 @@ return [ 'ADD_HEADER_EXTRA' => 'هيدر إضافي', 'ADD_FOOTER_EXTRA' => 'فوتر إضافي', 'ADMIN_USING_IE6' => 'أنت تستخدم متصفح "انترنت اكسبلور قديم" هذا رغم انك صاحب موقع وتعرف اكثر ممايعرفه المستخدمون العاديون ! قم بترقية متصفحك او استخدم فيرفوكس الآن.', - - 'T_CLEANING_FILES_NOW' => 'جاري تنفيذ عملية حذف الملفات الخاملة حالياً على دفعات تفادياً للضغط ,وقت العملية يعتمد على عدد الملفات وحجمها ...', - - 'HOW_UPDATE_KLEEJA' => 'كيف تقوم بتحديث كليجا ؟', - 'HOW_UPDATE_KLEEJA_STEP1' => 'توجه الى موقع سكربت كليجا الرسمي Kleeja.com ثم توجه إلى صفحة التحميل وقم بتنزيل آخر تسخة صدرت من الاسكربت في حال توفر سكربت الترقية قم بتحميله', - 'HOW_UPDATE_KLEEJA_STEP2' => ' بعد ذلك قم بفك الضغط عن الملف الذي قمت بتحميله ثم رفعه الى موقعك لاستبدال الملفات القدييمة بالجديدة عدا ملف config.php.', - 'HOW_UPDATE_KLEEJA_STEP3' => 'بعد اتمام الخطوة السابقة بنجاح , قم بطلب العنوان التالي للتحديث قاعدة بيانـات الاسكربت:', - - 'DEPEND_ON_NO_STYLE_ERR' => 'هذا الستايل يعتمد على ستايل "%s" غير الموجود لديك ضمن الستايلات !.', - 'PLUGINS_REQ_NO_STYLE_ERR' => 'هذا الستايل يتطلب ان تكون الإضافة/الاضافات [ %s ] مثبتة لديك , ثبتها وحاول من جديد !.', - 'KLJ_VER_NO_STYLE_ERR' => 'هذا الستايل يتطلب على الاقل اصدار %s من كليجا .', - + 'T_CLEANING_FILES_NOW' => 'جاري تنفيذ عملية حذف الملفات الخاملة حالياً على دفعات تفادياً للضغط ,وقت العملية يعتمد على عدد الملفات وحجمها ...', + 'DEPEND_ON_NO_STYLE_ERR' => 'هذا الستايل يعتمد على ستايل "%s" غير الموجود لديك ضمن الستايلات !.', + 'PLUGINS_REQ_NO_STYLE_ERR' => 'هذا الستايل يتطلب ان تكون الإضافة/الاضافات [ %s ] مثبتة لديك , ثبتها وحاول من جديد !.', + 'KLJ_VER_NO_STYLE_ERR' => 'هذا الستايل يتطلب على الاقل اصدار %s من كليجا .', 'STYLE_DEPEND_ON' => 'يعتمد على ستايل', 'MESSAGE_NONE' => 'حتى الآن لا يوجد أي رسائل ..', 'KLEEJA_TEAM' => 'فريق تطوير كليجا', @@ -198,10 +190,8 @@ return [ 'ADM_UNWANTED_FILES' => 'يبدوا انك قمت بالترقية من نسخة سابقة وبسبب اختلاف اسماء بعض الملفات ستلاحظ وجود ازرار متكررة بلوحة التحكم .
لحل المشكلة قم بإزالة كافة الملفات في المسار "includes/adm" واعادة رفعها من جديد. ايضا قم بحذف ملف admin.php من المجلد الرئيسي اذا وجد.', 'HTML_URLS_ENABLED_NO_HTCC' => 'لقد قمت بتفعيل روابط الهتمل ولكنك نسيت أن تقوم بإعادة تسمية الملف htaccess.txt في مجلد كليجا الرئيسي ليصبح ".htaccess". اذا لم تفهم شيئاً من هذا الكلام قم بالسؤال في الدعم الفني لكليجا او قم بتعطيل روابط الهتمل .', - 'PLUGIN_CONFIRM_ADD' => 'انتبه, الاضافات هي تعديلات برمجية على السكربت و قد تكون ضارة أحياناً , لذا ان كنت غير متأكد من مصدر الإضافة ولم تقم بتحميلها من موقع كليجا فالافضل ان تراجع نفسك الآن . ', - - 'LOADING' => 'جاري التنفيذ', - + 'PLUGIN_CONFIRM_ADD' => 'انتبه, الاضافات هي تعديلات برمجية على السكربت و قد تكون ضارة أحياناً , لذا ان كنت غير متأكد من مصدر الإضافة ولم تقم بتحميلها من موقع كليجا فالافضل ان تراجع نفسك الآن . ', + 'LOADING' => 'جاري التنفيذ', 'WELCOME' => 'مرحباً', 'ENABLE_CAPTCHA' => 'تفعيل كود الامان بكليجا', 'NO_THUMB_FOLDER' => 'يبدو ان المصغرات مُفعلة لديك ولكن في نفس الوقت مجلد %s غير متوفر مما يمنع عملية انشاء المصغرات, قم بإنشاء المجلد.', diff --git a/lang/en/acp.php b/lang/en/acp.php index 60426f1..b226179 100755 --- a/lang/en/acp.php +++ b/lang/en/acp.php @@ -125,9 +125,9 @@ return [ 'PLUGIN_EXISTS_BEFORE' => 'This plugin exists before with same version or above, so no need to update it!.', 'R_CHECK_UPDATE' => 'Check for updates', 'ERROR_CHECK_VER' => 'Error: cannot get any update information at this moment , try again later !', - 'UPDATE_KLJ_NOW' => 'You Have to update your version now!. visit Kleeja.com for more information', + 'UPDATE_KLJ_NOW' => 'update now!', 'U_LAST_VER_KLJ' => 'You are using the latest version of Kleeja...', - 'U_USE_PRE_RE' => 'You are using a Pre-release version, Click here to report any bugs or exploits.', + 'U_USE_PRE_RE' => 'You are using a Pre-release version, Click here to report any bugs or exploits.', 'STYLE_IS_DEFAULT' => 'Default style', 'MAKE_AS_DEFAULT' => 'Set as default', @@ -174,12 +174,7 @@ return [ 'ADD_HEADER_EXTRA' => 'Extra Header', 'ADD_FOOTER_EXTRA' => 'Extra footer', 'ADMIN_USING_IE6' => 'You are using an outdated IE browser, Please update your browser or use FireFox now!', - 'T_CLEANING_FILES_NOW' => 'Deleting Un-downloaded files, The process could take a while depending on the size and number of the files.', - 'HOW_UPDATE_KLEEJA' => 'How to update Kleeja?', - 'HOW_UPDATE_KLEEJA_STEP1' => 'Visit the official website Kleeja.com then go to the Download page and download the latest version of the script, or download an upgrade copy if available.', - 'HOW_UPDATE_KLEEJA_STEP2' => 'Unzip the file and upload it to your website to replace the old files with the new ones Except config.php and uploads folder.', - 'HOW_UPDATE_KLEEJA_STEP3' => 'When done, go to the following URL to update the database.', 'DEPEND_ON_NO_STYLE_ERR' => 'This style is based on the "%s" style which you dont seem to have', 'PLUGINS_REQ_NO_STYLE_ERR' => 'This style requires the [ s% ] plugin(s), install it/them and try again.', 'KLJ_VER_NO_STYLE_ERR' => 'This style requires Kleeja version %s or above', From 4ff3debbf03abe031c794d2475e6710afe402eee Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Sun, 12 May 2019 04:15:11 +0300 Subject: [PATCH 18/27] fixes --- admin/Masmak/admin_check_update.html | 4 +- includes/adm/p_check_update.php | 43 ++++++++++++++++---- install/includes/default_values.php | 10 ++--- install/includes/functions_install.php | 5 ++- install/includes/update_files/1.7_to_2.0.php | 4 +- install/update.php | 12 +++--- lang/ar/acp.php | 4 ++ lang/en/acp.php | 22 ++++++---- 8 files changed, 71 insertions(+), 33 deletions(-) diff --git a/admin/Masmak/admin_check_update.html b/admin/Masmak/admin_check_update.html index b759c5c..e9cce73 100755 --- a/admin/Masmak/admin_check_update.html +++ b/admin/Masmak/admin_check_update.html @@ -102,7 +102,7 @@ function updateNow(step) { if(info[1].length > 0) { $('#update'+step+' .update-message').removeClass('d-none').addClass('d-block').text(info[1]); if(info[0] == 1) { - $('#update'+step+' .update-message').removeClass('alter-danger').addClass('alert-success'); + $('#update'+step+' .update-message').removeClass('alert-danger').addClass('alert-success'); } } @@ -117,7 +117,7 @@ function updateNow(step) { } }) .fail(function(data) { - $('#update'+step+' .update-status').text('error!'); + $('#update'+step+' .update-status').html(''); $('#update'+step+' .update-message').removeClass('d-none').addClass('d-block').html( (data.content ? data.content : (data.responseJSON ? data.responseJSON.content : '{lang.ERROR_TRY_AGAIN}')) ); diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index 4a8d243..3c623cd 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -127,9 +127,9 @@ elseif ($current_smt == 'update1') { $adminAjaxContent = '930:::' . $lang['NO_ZIP_ARCHIVE']; } - elseif (! version_compare(strtolower($current_version), strtolower($new_version), '<')) + elseif (! version_compare(strtolower($current_version), strtolower($new_version), '<=')) { - $adminAjaxContent = '940:::there is no update for your version!'; + $adminAjaxContent = '940:::' . $lang['U_LAST_VER_KLJ']; } else { @@ -142,7 +142,7 @@ elseif ($current_smt == 'update1') } else { - $adminAjaxContent = '2:::We have encountered a problem while downloading the package ... '; + $adminAjaxContent = '2:::' . $lang['UPDATE_ERR_FETCH_PACKAGE']; } } } @@ -205,7 +205,8 @@ elseif ($current_smt == 'update3') $backup = new ZipArchive; if($backup->open($backup_archive_path, ZipArchive::CREATE) !== true) { - + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['UPDATE_BACKUP_CREATE_FAILED']); } // delete plugin folder function with some changes :) @@ -292,7 +293,7 @@ elseif ($current_smt == 'update3') //maintenance mode off update_config('siteclose', 0); - $adminAjaxContent = '1002:::updating process has failed...' . + $adminAjaxContent = '1002:::' . $lang['UPDATE_PROCESS_FAILED'] (defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : ''); } else @@ -301,6 +302,34 @@ elseif ($current_smt == 'update3') if (file_exists($db_update_file = PATH . "cache/update_{$old_version}_to_{$new_version}.php")) { require_once $db_update_file; + + if($config['db_version'] < UPDATE_DB_VERSION) + { + $SQL->show_errors = false; + + if (isset($update_sqls) && sizeof($update_sqls) > 0) + { + foreach ($update_sqls as $name=>$sql_content) + { + $SQL->query($sql_content); + } + } + + if (isset($update_functions) && sizeof($update_functions) > 0) + { + foreach ($update_functions as $n) + { + if (is_callable($n)) + { + $n(); + } + } + } + + $SQL->query( + "UPDATE `{$dbprefix}config` SET `value` = '" . UPDATE_DB_VERSION . "' WHERE `name` = 'db_version'" + ); + } } //maintenance mode off @@ -308,9 +337,9 @@ elseif ($current_smt == 'update3') // after a success update, delete files and folders in cache kleeja_unlink(PATH . "cache/kleeja-{$new_version}"); + kleeja_unlink(PATH . "cache/kleeja-{$new_version}.zip"); delete_cache('', true); - $adminAjaxContent = "1:::Kleeja has been updated to {$new_version} successfully..."; + $adminAjaxContent = '1:::' . sprintf($lang['UPDATE_PROCESS_DONE'], $new_version); } } -//endif diff --git a/install/includes/default_values.php b/install/includes/default_values.php index b46d1dd..a573111 100755 --- a/install/includes/default_values.php +++ b/install/includes/default_values.php @@ -20,7 +20,7 @@ if (! defined('IN_COMMON')) $config_values = []; -// do it like this : +// do it like this : //$config_values = array('name', 'value', 'option', 'display_order', 'type', 'plg_id', 'dynamic'); // General settings @@ -45,7 +45,7 @@ $config_values[] = ['cookie_path', $cookie_data['cookie_path'], '', '15', 'advanced', 0, 0]; $config_values[] = ['cookie_secure', ($cookie_data['cookie_secure'] ? '1' : '0'), '\r\n ', '16', 'advanced', 0, 0]; -// Upload settings +// Upload settings $config_values[] = ['total_size', '10000000000', '', 17, 'upload', 0, 0]; $config_values[] = ['foldername', 'uploads', '', 18, 'upload', 0, 0]; $config_values[] = ['prefixname', '', '', 19, 'upload', 0, 0]; @@ -68,7 +68,7 @@ $config_values[] = ['filesnum_show', '1', '
diff --git a/install/style/check_all.html b/install/style/check_all.html index 630d487..1a714f8 100755 --- a/install/style/check_all.html +++ b/install/style/check_all.html @@ -8,32 +8,32 @@ {{endif}} - + {{if($GLOBALS['no_connection']): $GLOBALS['submit_disabled'] = true;}}

 {{echo $lang['INST_CONNCET_ERR']}}

{{endif}} - + {{if($GLOBALS['mysql_ver']): $GLOBALS['submit_disabled'] = true;}}

 {{echo sprintf($lang['INST_MYSQL_LESSMIN'], MIN_MYSQL_VERSION, $GLOBALS['mysql_ver'])}}

{{endif}} - {{if(!is_writable($_path . 'cache')) : $GLOBALS['submit_disabled'] = true;}} + {{if(!is_writable(PATH . 'cache')) : $GLOBALS['submit_disabled'] = true;}}

 [ cache ] : {{echo $lang['INST_NO_WRTABLE']}}

{{endif}} - - {{if(!is_writable($_path . 'uploads')) : $GLOBALS['submit_disabled'] = true;}} + + {{if(!is_writable(PATH . 'uploads')) : $GLOBALS['submit_disabled'] = true;}}

 [ uploads ] : {{echo $lang['INST_NO_WRTABLE']}}

{{endif}} - {{if(!is_writable($_path . 'uploads/thumbs')) : $GLOBALS['submit_disabled'] = true;}} + {{if(!is_writable(PATH . 'uploads/thumbs')) : $GLOBALS['submit_disabled'] = true;}}

 [ uploads/thumbs ] : {{echo $lang['INST_NO_WRTABLE']}}

@@ -51,10 +51,10 @@ {{else:}}
- + -
+ {{endif}} -
+
diff --git a/install/style/configs.html b/install/style/configs.html index e706ef8..a9fd344 100755 --- a/install/style/configs.html +++ b/install/style/configs.html @@ -5,17 +5,6 @@

!{{echo $lang['DB_INFO']}}

- diff --git a/install/style/header.html b/install/style/header.html index af67afa..8db7f58 100755 --- a/install/style/header.html +++ b/install/style/header.html @@ -23,7 +23,7 @@ var PATH_SPACER = 'style/images/spacer.gif'; {{if(((ig('step') && g('step') != 'language') && (strpos('index.php', $_SERVER['PHP_SELF'])=== false && ig('step'))) OR (ig('step') && g('step') == 'license' || g('step') == 'action_file') ):}}
{{echo $lang['DB_SERVER']}}
- - - {{foreach($GLOBALS['installed_plugins'] as $plugin):}} - - {{endforeach;}} - - - - {{foreach($GLOBALS['installed_plugins'] as $plugin):}} - - {{endforeach;}} - - - - {{foreach($GLOBALS['installed_plugins'] as $plugin):}} - - {{endforeach;}} - -
{{echo $lang['PLUGINS_NAME']}}{{echo $plugin['p_name']}}
{{echo $lang['PLUGINS_DES']}}{{echo $plugin['p_des']}}
{{echo $lang['PLUGINS_VER']}}{{echo $plugin['p_ver']}}
-
- - -
- -
-
\ No newline at end of file diff --git a/install/style/plugins_options.html b/install/style/plugins_options.html deleted file mode 100755 index a85c3f4..0000000 --- a/install/style/plugins_options.html +++ /dev/null @@ -1,38 +0,0 @@ -
-
- -
-

{{echo $lang['PLUGINS_KLEEJA'];}}

-

{{echo $lang['PLUGINS_BUILT_IN'];}}

- - - - {{foreach($GLOBALS['plugins'] as $plugin):}} - - {{endforeach;}} - - - - {{foreach($GLOBALS['plugins'] as $plugin):}} - - {{endforeach;}} - - - - {{foreach($GLOBALS['plugins'] as $plugin):}} - - {{endforeach;}} - - - - {{foreach($GLOBALS['plugins'] as $plugin):}} - - {{endforeach;}} - -
{{echo $lang['PLUGINS_NAME']}}{{echo $plugin['p_name']}}
{{echo $lang['PLUGINS_DES']}}{{echo $plugin['p_des']}}
{{echo $lang['PLUGINS_VER']}}{{echo $plugin['p_ver']}}
-
- -
- -
-
\ No newline at end of file diff --git a/install/style/style.css b/install/style/style.css index f34cff7..ee562ad 100755 --- a/install/style/style.css +++ b/install/style/style.css @@ -604,7 +604,7 @@ li.NoCheck { .ins_klj { -{{if($GLOBALS['IN_DEV']): echo " +{{if(defined('DEV_STAGE')): echo " width: 50px; height: 350px; position: fixed; @@ -612,4 +612,4 @@ li.NoCheck { left: 10px; background: url('style/images/dev_mode.gif') no-repeat left center; ";endif;}} -} \ No newline at end of file +} diff --git a/install/update.php b/install/update.php index ee0db7a..4194835 100755 --- a/install/update.php +++ b/install/update.php @@ -16,31 +16,28 @@ * include important files */ define('IN_COMMON', true); -$_path = '../'; -define('PATH', $_path); +define('STOP_PLUGINS', true); +define('PATH', '../'); -if (file_exists($_path . 'config.php')) +if (file_exists(PATH . 'config.php')) { - include_once $_path . 'config.php'; + include_once PATH . 'config.php'; } -include_once $_path . 'includes/functions.php'; -include_once $_path . 'includes/functions_alternative.php'; +include_once PATH . 'includes/plugins.php'; +include_once PATH . 'includes/functions.php'; +include_once PATH . 'includes/functions_alternative.php'; -include_once $_path . 'includes/mysqli.php'; +include_once PATH . 'includes/mysqli.php'; include_once 'includes/functions_install.php'; +include_once 'includes/update_schema.php'; -$order_update_files = [ - '1.7_to_2.0' => 9, - // filename => db_version -]; - $SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname); // -// Is current db is up-to-date ? +// fix missing db_version // $config['db_version'] = inst_get_config('db_version'); @@ -62,121 +59,69 @@ if (! ip('action_file_do')) } - /** * Navigation .. */ switch (g('step', 'str', 'action_file')) { default: -case 'action_file': - - if (ip('action_file_do')) - { - if (p('action_file_do', 'str', '') !== '') - { - echo ''; - } - } - else - { - //get fles - $s_path = 'includes/update_files'; - $dh = opendir($s_path); - $upfiles = []; - - while (($file = readdir($dh)) !== false) - { - if (substr($file, -3) == 'php') - { - $file = str_replace('.php', '', $file); - $db_ver = $order_update_files[$file]; - - // var_dump($db_ver); - - if ((empty($config['db_version']) || $db_ver > $config['db_version'])) - { - $upfiles[$db_ver] = $file; - } - } - } - @closedir($dh); - - ksort($upfiles); - - echo gettpl('update_list.html'); - } - -break; - case 'update_now': - if (! ig('action_file_do')) + $complete_update = true; + $update_msgs_arr = []; + $current_db_version = $config['db_version']; + + $all_db_updates = array_keys($update_schema); + + $available_db_updates = array_filter($all_db_updates, function ($v) use ($current_db_version) { + return $v > $current_db_version; + }); + + sort($available_db_updates); + + if (! sizeof($available_db_updates)) + { + $update_msgs_arr[] = '' . $lang['INST_UPDATE_CUR_VER_IS_UP'] . ''; + $complete_update = false; + } + + // + //is there any sqls + // + if ($complete_update) + { + //loop through available updates + foreach ($available_db_updates as $db_update_version) { - echo ''; + $SQL->show_errors = false; - exit(); - } - - if (ig('complet_up_func')) - { - define('C_U_F', true); - } - - $file_for_up = 'includes/update_files/' . preg_replace('/[^a-z0-9_\-\.]/i', '', g('action_file_do')) . '.php'; - - if (! file_exists($file_for_up)) - { - echo '' . $lang['INST_ERR_NO_SELECTED_UPFILE_GOOD'] . ' [ ' . $file_for_up . ' ]
'; - } - else - { - //get it - require $file_for_up; - $complete_update = true; - $update_msgs_arr = []; - - - if ($config['db_version'] >= UPDATE_DB_VERSION && ! defined('DEV_STAGE')) + //sqls + if (isset($update_schema[$db_update_version]['sql']) + && sizeof($update_schema[$db_update_version]['sql']) > 0) { - $update_msgs_arr[] = '' . $lang['INST_UPDATE_CUR_VER_IS_UP'] . ''; - $complete_update = false; - } + $err = ''; - // - //is there any sqls - // - if (($complete_update || (defined('DEV_STAGE')) && ! defined('C_U_F'))) - { - $SQL->show_errors = false; + $complete_update = true; - if (isset($update_sqls) && sizeof($update_sqls) > 0) + foreach ($update_schema[$db_update_version]['sql'] as $name=>$sql_content) { $err = ''; + $SQL->query($sql_content); + $err = $SQL->get_error(); - foreach ($update_sqls as $name=>$sql_content) + if (strpos($err[1], 'Duplicate') !== false || $err[0] == '1062' || $err[0] == '1060') { - $err = ''; - $SQL->query($sql_content); - $err = $SQL->get_error(); - - if (strpos($err[1], 'Duplicate') !== false || $err[0] == '1062' || $err[0] == '1060') - { - $update_msgs_arr[] = '' . $lang['INST_UPDATE_CUR_VER_IS_UP'] . ''; - $complete_update = false; - } + $complete_update = false; } } } - // - //is there any functions - // - if ($complete_update || defined('DEV_STAGE') || defined('C_U_F')) + //functions + if ($complete_update) { - if (isset($update_functions) && sizeof($update_functions) > 0) + if (isset($update_schema[$db_update_version]['functions']) && sizeof($update_schema[$db_update_version]['functions']) > 0) { - foreach ($update_functions as $n) + foreach ($update_schema[$db_update_version]['functions'] as $n) { if (is_callable($n)) { @@ -186,31 +131,13 @@ case 'update_now': } } - // - //is there any notes - // - $NOTES_CUP = false; - - if ($complete_update || defined('DEV_STAGE')) - { - if (isset($update_notes) && sizeof($update_notes) > 0) - { - $i =1; - $NOTES_CUP = []; - - foreach ($update_notes as $n) - { - $NOTES_CUP[$i] = $n; - ++$i; - } - } - - $sql = "UPDATE `{$dbprefix}config` SET `value` = '" . UPDATE_DB_VERSION . "' WHERE `name` = 'db_version'"; - $SQL->query($sql); - } - - echo gettpl('update_end.html'); + $sql = "UPDATE `{$dbprefix}config` SET `value` = '" . UPDATE_DB_VERSION . "' WHERE `name` = 'db_version'"; + $SQL->query($sql); } + } + + + echo gettpl('update_end.html'); break; } diff --git a/lang/ar/install.php b/lang/ar/install.php index 9867029..ade7856 100755 --- a/lang/ar/install.php +++ b/lang/ar/install.php @@ -37,7 +37,7 @@ return [ 'INST_FINISH_SQL' => 'تم تثبيت كليجا بنجاح', 'INST_NOTES' => 'ملاحظات التثبيت', 'INST_END' => 'معالج التثبيت انتهى، يجب الآن حذف مجلد INSTALL (الموقع لن يعمل في حال وجود المجلد)', - 'INST_NOTE_D' => 'أي ملاحظات أو مشاكل تتعلق بأداء كليجا، نرجوا التواصل مع مطوري كليجا!', + 'INST_NOTE_D' => 'أي ملاحظات أو مشاكل تتعلق بأداء كليجا، نرجو التبليغ عبر مركز الأخطاء', 'INST_FINISH_ERRSQL' => 'هناك مشكلة تعيق التثبيت، تأكد من حساب مستخدم القاعدة وحاول مجدداً او استفسر من مطوري كليجا', 'INST_KLEEJADEVELOPERS' => 'شكراً لإستخدامك كليجا ... مع أحلى و أطيب التمنيات .. من فريق عمل كليجا', 'SITENAME' => 'اسم الموقع', @@ -85,16 +85,10 @@ return [ 'FUNCTION_DISC_MUF' => 'دالة move_uploaded_file تستخدم لتحميل الملفات وهي اهم دالة في السكربت.', 'ADVICES_CHECK' => 'فحص متقدم (يمكن تثبيت كليجا بدون تحقق هذا الفحص , لكنه مجرد معلومات لك)', - 'ADVICES_REGISTER_GLOBALS' => 'خاصية register_globals مفعلة !
هذه الخاصية غير محبب تفعيلها ويفضل تعطيلها , ومع هذا فكليجا تحاول تعطيل أثارها برمجياً .', - 'ADVICES_MAGIC_QUOTES' => 'خاصية magic_quotes مفعله !
هذه الخاصية غير محبب تفعيلها ويفضل تعطيلها , ومع هذا فكليجا تحاول تعطيل أثارها برمجياً ..', + 'ZIPARCHIVE_LIB' => 'مكتبة ZipArchive غير متوفرة في خادمك !
هذه المكتبة مهمة لفك الإضافات والترقية لنسخ جديدة من كليجا!', //UPDATOR - 'INST_CHOOSE_UPDATE_FILE' => 'قم بإختيار التحديث المناسب لك ومن ثم تابع التحديث ..', - 'INST_ERR_NO_SELECTED_UPFILE_GOOD' => 'ملف التحديث غير مناسب أو أنه غير موجود من الأساس ! ..', - 'INST_UPDATE_CUR_VER_IS_UP' => 'نسختك الحالية محدثة لهذا التحديث المحدد.', - - 'INST_NOTES_UPDATE' => 'ملاحظات التحديث', - + 'INST_UPDATE_CUR_VER_IS_UP' => 'نسختك الحالية محدثة لآخر نسخة ... رائع!', 'INST_UPDATE_IS_FINISH' => 'معالج التحديث انتهى .. يجب الآن حذف مجلد INSTALL و متابعة عملك في كليجا .', diff --git a/lang/en/install.php b/lang/en/install.php index d1a5763..016af63 100755 --- a/lang/en/install.php +++ b/lang/en/install.php @@ -85,15 +85,10 @@ return [ 'FUNCTION_DISC_MUF' => 'The function move_uploaded_file is used to upload files and it\'s the most important function in the script.', 'ADVICES_CHECK' => 'Advanced check (Optional)', - 'ADVICES_REGISTER_GLOBALS' => 'register_globals function is enabled ..!
its recommended that you disable it.', - 'ADVICES_MAGIC_QUOTES' => 'magic_quotes function is enabled ..!
it is recommended that you disable it.', + 'ZIPARCHIVE_LIB' => 'ZipArchive Lib is not available..!
It is required to install plugins, styles and to upgrade to newer Kleeja versions!', //UPDATE - 'INST_CHOOSE_UPDATE_FILE' => 'Choose the appropriate update file', - 'INST_ERR_NO_SELECTED_UPFILE_GOOD' => 'Inappropriate update file, or it is missing!', - 'INST_UPDATE_CUR_VER_IS_UP' => 'Your current version is newer than this update.', - - 'INST_NOTES_UPDATE' => 'Update Notes', + 'INST_UPDATE_CUR_VER_IS_UP' => 'Your current version database is up-to-date ... hooray!', 'INST_UPDATE_IS_FINISH' => 'Installation completed! you can now delete the INSTALL directory...', @@ -112,6 +107,6 @@ return [ 'NO' => 'No', 'KLEEJA_TEAM_MSG_NAME' => 'Kleeja Development Team', - 'KLEEJA_TEAM_MSG_TEXT' => "Thank you for choosing Kleeja to empower your website,\n We really hope you enjoy the unique experience that Kleeja offers to you.\nDon't forget to visit http://kleeja.com for future updates.", + 'KLEEJA_TEAM_MSG_TEXT' => "Thank you for choosing Kleeja to empower your website,\n We really hope you enjoy the unique experience that Kleeja offers to you.\nDon't forget to visit http://kleeja.com for future updates, to report bugs/issues kindly visit our Issues page", ]; From 70ef359988cb12d67c2fb5b782ca5cadfa7a1bc0 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Mon, 13 May 2019 00:25:38 +0200 Subject: [PATCH 21/27] fix kj link --- lang/ar/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/ar/install.php b/lang/ar/install.php index ade7856..d2fe14b 100755 --- a/lang/ar/install.php +++ b/lang/ar/install.php @@ -101,7 +101,7 @@ return [ 'INST_WHAT_IS_KLEEJA_T' => 'ماهي كليجا ؟', 'INST_WHAT_IS_KLEEJA' => 'Kleeja تنطق عربياً "كليجا" ! وكتعريف مبسط "كليجا" سكربت رفع ملفات مجاني يأتي مع خصائص فريدة لمساعدة أصحاب المواقع بإمتلاك مركز تحميل قوي ويعتمد عليه , والحقيقة أن "كليجا" سكربت ضخم الامكانيات سهل الإدارة تم بناء نظام الحماية على مستوى عالي ويملك من الأنظمة المعقدة ما يؤمن لموقعك الحماية التامة بإذن الله !', 'INST_SPECIAL_KLEEJA' => 'من أهم مميزات كليجا !', - 'INST_WHAT_IS_KLEEJA_ONE' => '1. نظام أعضاء قوي تستطيع ربطه بأغلب السكربتات المستخدمة في المواقع الاجتماعية .
2. لوحة تحكم مذهلة ليس فقط للتحكم بالملفات ولكن للتحكم بكل صغيرة وكبيرة .
3. نظام الستايلات البسيط يجعلك تستطيع ان تصنع ستايلك بنفسك.
4. مع كليجا ونظام الإضافات البرمجية تستطيع أن تقوم بتركيب الكثير من الاضافات الرائعة .
5. ليس هذا فحسب بل كليجا تملك الكثير .. لتعرف أكثر رجاءاً قم بزيارة صفحه معلومات ومميزات .', + 'INST_WHAT_IS_KLEEJA_ONE' => '1. نظام أعضاء قوي تستطيع ربطه بأغلب السكربتات المستخدمة في المواقع الاجتماعية .
2. لوحة تحكم مذهلة ليس فقط للتحكم بالملفات ولكن للتحكم بكل صغيرة وكبيرة .
3. نظام الستايلات البسيط يجعلك تستطيع ان تصنع ستايلك بنفسك.
4. مع كليجا ونظام الإضافات البرمجية تستطيع أن تقوم بتركيب الكثير من الاضافات الرائعة .
5. ليس هذا فحسب بل كليجا تملك الكثير .. لتعرف أكثر رجاءاً قم بزيارة صفحه معلومات ومميزات .', 'YES' => 'نعم', 'NO' => 'لا', From 80c4ce358a7a36e3d769c3a9844aa5bd6f2add59 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Mon, 13 May 2019 00:26:21 +0200 Subject: [PATCH 22/27] fix kj link --- lang/en/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/install.php b/lang/en/install.php index 016af63..c9d308c 100755 --- a/lang/en/install.php +++ b/lang/en/install.php @@ -102,7 +102,7 @@ return [ 'INST_WHAT_IS_KLEEJA' => 'Keeja is a free, features rich, files and images upload system. Kleeja is developed to help webmasters to provide a decent files hosting service on their sites . Kleeja comes with a simple source code and powerful User system , also with easy template system so you can easily customize your styles ', 'INST_SPECIAL_KLEEJA' => 'Some Kleeja features .. !', - 'INST_WHAT_IS_KLEEJA_ONE' => 'Kleeja has a simple and powerful user system which can be easily integrated with many boards . Kleeja provide simple admin control panel that enables you to control over everything in your site . Also you can customize Kleeja\'s style and install a lot of add-ons .... more details in Kleeja site ', + 'INST_WHAT_IS_KLEEJA_ONE' => 'Kleeja has a simple and powerful user system which can be easily integrated with many boards . Kleeja provide simple admin control panel that enables you to control over everything in your site . Also you can customize Kleeja\'s style and install a lot of add-ons .... more details in Kleeja site ', 'YES' => 'Yes', 'NO' => 'No', From 44e829036c2e59466805449999113311497e93e3 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Mon, 13 May 2019 02:17:40 +0300 Subject: [PATCH 23/27] fixes --- admin/Masmak/admin_check_update.html | 23 +++++++--- includes/adm/p_check_update.php | 65 ++++++++++++++++++---------- lang/ar/acp.php | 1 + lang/en/acp.php | 2 +- 4 files changed, 60 insertions(+), 31 deletions(-) diff --git a/admin/Masmak/admin_check_update.html b/admin/Masmak/admin_check_update.html index 03cce26..f9ded86 100755 --- a/admin/Masmak/admin_check_update.html +++ b/admin/Masmak/admin_check_update.html @@ -5,11 +5,15 @@ -
-
- {lang.LOADING} +
+
+

+ {lang.LOADING} +

+
- +
+

    @@ -66,9 +70,14 @@ function checkVersion() { if(data.content) { var info = data.content.split(":::"); $('#updateInfo').addClass(info[0] != 0 ? 'alert-warning' : 'alert-info'); - $('#updateInfo div').html(info[1]); + $('#updateInfoStatus').html(info[1]); if(info[0] == 2) { + var message = info[1].split("::--x--::"); + $('#updateInfoStatus').html(message[0]); + $('#updateInfoHr').removeClass('d-none'); + $('#updateInfoMessage').removeClass('d-none').html('{lang.RELEASE_NOTE}:
    ' + + message[1].replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '
    ') + '
    ' + message[2].replace('T', ' ')); $('#updateButton').removeClass('d-none'); }
    @@ -88,13 +97,15 @@ function updateNow(step) { if(step == 1) { $('#updateButton').addClass('d-none'); $('#updateProcess').removeClass('d-none'); + $('#updateInfoHr').addClass('d-none'); + $('#updateInfoMessage').addClass('d-none') } $('#update'+step+' .update-status').html(''); $('#update'+step+'').removeClass('disabled'); $.ajax({ - url: './?cp=p_check_update&smt=update'+step+'&_ajax_=1', + url: './?cp=p_check_update&smt=update'+step+'&{GET_FORM_KEY}&_ajax_=1', dataType: 'json'}) .done(function (data) { if(data.content) { diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index ba87135..22fd0e6 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -21,19 +21,31 @@ $new_version = empty($new_version['version_number']) ? KLEEJA_VERSION : $new_version['version_number']; $backup_archive_path = PATH . 'cache/backup.zip'; +$GET_FORM_KEY = kleeja_add_form_key_get('UPDATER_FORM_KEY'); define('KLEEJA_VERSION_CHECK_LINK', 'https://api.github.com/repos/kleeja-official/kleeja/releases/latest'); -define('KLEEJA_LATEST_PACKAGE_LINK', 'https://github.com/kleeja-official/kleeja/archive/'); +define('KLEEJA_LATEST_PACKAGE_LINK', 'https://api.github.com/repos/kleeja-official/kleeja/zipball/'); $stylee = 'admin_check_update'; $current_smt = preg_replace('/[^a-z0-9_]/i', '', g('smt', 'str', 'general')); $update_link = $config['siteurl'] . 'install/update.php?lang=' . $config['language']; -//only founders can do the upgrade process ... -if(in_array($current_smt, ['update1', 'update2', 'update3']) && intval($userinfo['founder']) !== 1) + +if (in_array($current_smt, ['update1', 'update2', 'update3'])) { - header('HTTP/1.0 401 Unauthorized'); - kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); + //only founders can do the upgrade process ... + if (intval($userinfo['founder']) !== 1) + { + header('HTTP/1.0 401 Unauthorized'); + kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); + } + + if (! kleeja_check_form_key_get('UPDATER_FORM_KEY')) + { + header('HTTP/1.0 401 Unauthorized'); + + kleeja_admin_err($lang['INVALID_GET_KEY']); + } } //check latest version @@ -47,11 +59,15 @@ if ($current_smt == 'check') if (! empty($github_data)) { $latest_release = json_decode($github_data, true); - $version_data = ''; + $version_data = null; if (json_last_error() === JSON_ERROR_NONE) { - $version_data = trim(htmlspecialchars($latest_release['tag_name'])); + $version_data = [ + 'version' => trim(htmlspecialchars($latest_release['tag_name'])), + 'info' => trim(htmlspecialchars($latest_release['body'])), + 'date' => trim(htmlspecialchars($latest_release['created_at'])), + ]; $cache->save('kleeja_repo_version', $version_data, 3600 * 2); } } @@ -59,34 +75,35 @@ if ($current_smt == 'check') $error = 0; - if (empty($version_data)) + if (empty($version_data['version'])) { $text = $lang['ERROR_CHECK_VER']; $error = 1; } else { - if (version_compare(strtolower($current_version), strtolower($version_data), '<')) + if (version_compare(strtolower($current_version), strtolower($version_data['version']), '<')) { - $text = sprintf($lang['UPDATE_NOW_S'], $current_version, strtolower($version_data)); + $text = sprintf($lang['UPDATE_NOW_S'], $current_version, strtolower($version_data['version'])) . + '::--x--::' . $version_data['info'] . '::--x--::' . $version_data['date']; $error = 2; } - elseif (version_compare(strtolower($current_version), strtolower($version_data), '=')) + elseif (version_compare(strtolower($current_version), strtolower($version_data['version']), '=')) { $text = $lang['U_LAST_VER_KLJ']; } - elseif (version_compare(strtolower($current_version), strtolower($version_data), '>')) + elseif (version_compare(strtolower($current_version), strtolower($version_data['version']), '>')) { $text = $lang['U_USE_PRE_RE']; } else { - $text = $lang['ERROR_CHECK_VER'] . ' [code: ' . htmlspecialchars($version_data) . ']'; + $text = $lang['ERROR_CHECK_VER'] . ' [code: ' . htmlspecialchars($version_data['version']) . ']'; } } $data = [ - 'version_number' => $version_data, + 'version_number' => $version_data['version'], 'last_check' => time() ]; @@ -135,7 +152,8 @@ elseif ($current_smt == 'update1') { // downloaded the last package to cache folder fetch_remote_file(KLEEJA_LATEST_PACKAGE_LINK . $new_version . '.zip', PATH . "cache/kleeja-{$new_version}.zip", 60, false, 10, true); - if(file_exists(PATH . "cache/kleeja-{$new_version}.zip")) + + if (file_exists(PATH . "cache/kleeja-{$new_version}.zip")) { $adminAjaxContent = '1:::'; file_put_contents(PATH . 'cache/step1.done', time()); @@ -149,7 +167,7 @@ elseif ($current_smt == 'update1') //2. extract new kleeja package, create backup zip file elseif ($current_smt == 'update2') { - if(! file_exists(PATH . 'cache/step1.done')) + if (! file_exists(PATH . 'cache/step1.done')) { header('HTTP/1.0 401 Unauthorized'); kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); @@ -173,7 +191,7 @@ elseif ($current_smt == 'update2') { // move the update file from install folder to cache folder to include it later and delete install folder // becuse if install folder is exists , it can make some problems if dev mode is not active - rename($update_file, PATH . "cache/update_schema.php"); + rename($update_file, PATH . 'cache/update_schema.php'); } // skip some folders @@ -194,7 +212,7 @@ elseif ($current_smt == 'update2') //3. update, or rollback on failure elseif ($current_smt == 'update3') { - if(! file_exists(PATH . 'cache/step2.done')) + if (! file_exists(PATH . 'cache/step2.done')) { header('HTTP/1.0 401 Unauthorized'); kleeja_admin_err($lang['HV_NOT_PRVLG_ACCESS']); @@ -203,7 +221,8 @@ elseif ($current_smt == 'update3') kleeja_unlink(PATH . 'cache/step2.done'); $backup = new ZipArchive; - if($backup->open($backup_archive_path, ZipArchive::CREATE) !== true) + + if ($backup->open($backup_archive_path, ZipArchive::CREATE) !== true) { header('HTTP/1.0 401 Unauthorized'); kleeja_admin_err($lang['UPDATE_BACKUP_CREATE_FAILED']); @@ -293,13 +312,12 @@ elseif ($current_smt == 'update3') //maintenance mode off update_config('siteclose', 0); - $adminAjaxContent = '1002:::' . $lang['UPDATE_PROCESS_FAILED'] - (defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : ''); + $adminAjaxContent = '1002:::' . $lang['UPDATE_PROCESS_FAILED'](defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : ''); } else { // we will include what we want to do in this file , and kleeja will done - if (file_exists($db_update_file = PATH . "cache/update_schema.php")) + if (file_exists($db_update_file = PATH . 'cache/update_schema.php')) { require_once $db_update_file; @@ -311,9 +329,8 @@ elseif ($current_smt == 'update3') sort($available_db_updates); - if(sizeof($available_db_updates)) + if (sizeof($available_db_updates)) { - foreach ($available_db_updates as $db_update_version) { $SQL->show_errors = false; diff --git a/lang/ar/acp.php b/lang/ar/acp.php index 012fc80..247c623 100755 --- a/lang/ar/acp.php +++ b/lang/ar/acp.php @@ -280,4 +280,5 @@ return [ 'UPDATE_PROCESS_STEP1' => 'جلب حزمة آخر نسخة من كليجا...', 'UPDATE_PROCESS_STEP2' => 'إنشاء وعاء نسخة إحتياطية وفك حزمة آخر نسخة ...', 'UPDATE_PROCESS_STEP3' => 'الترقية للنسخة الجديدة (تحديث الملفات وقاعدة البيانات) ...', + 'RELEASE_NOTE' => 'معلومات الإصدار', ]; diff --git a/lang/en/acp.php b/lang/en/acp.php index b9f8dab..4cbcd7a 100755 --- a/lang/en/acp.php +++ b/lang/en/acp.php @@ -153,7 +153,6 @@ return [ 'COOKIE_NAME' => 'Cookie prefix', 'COOKIE_PATH' => 'Cookie path', 'COOKIE_SECURE' => 'Cookie secure', - //'ADMINISTRATORS' => 'Administrators', 'DELETEALLRES' => 'Delete all results', 'ADMIN_DELETE_FILES_OK' => 'File %s successfully deleted', 'ADMIN_DELETE_FILES_NOF' => 'No files to delete', @@ -283,4 +282,5 @@ return [ 'UPDATE_PROCESS_STEP1' => 'Fetching the package of latest version of Kleeja ...', 'UPDATE_PROCESS_STEP2' => 'Create a backup container and extract the new package ...', 'UPDATE_PROCESS_STEP3' => 'Updating to new version (files & database upgrade) ...', + 'RELEASE_NOTE' => 'Release Notes', ]; From 0123517473ea8d6f7ff47f89c08ae432869a2aad Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Mon, 13 May 2019 03:56:38 +0200 Subject: [PATCH 24/27] fix --- includes/adm/p_check_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index 22fd0e6..be84af8 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -312,7 +312,7 @@ elseif ($current_smt == 'update3') //maintenance mode off update_config('siteclose', 0); - $adminAjaxContent = '1002:::' . $lang['UPDATE_PROCESS_FAILED'](defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : ''); + $adminAjaxContent = '1002:::' . $lang['UPDATE_PROCESS_FAILED'] . (defined('DEV_STAGE') ? '[failed files: ' . implode(', ', $failed_files) . ']' : ''); } else { From c5420e6e1db490103ca6a7ee5c5232cc2143d8f0 Mon Sep 17 00:00:00 2001 From: Mitan Omar <22119228+MitanOmar@users.noreply.github.com> Date: Mon, 13 May 2019 04:34:13 +0200 Subject: [PATCH 25/27] fix update --- includes/adm/p_check_update.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index be84af8..3e4f960 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -151,7 +151,7 @@ elseif ($current_smt == 'update1') else { // downloaded the last package to cache folder - fetch_remote_file(KLEEJA_LATEST_PACKAGE_LINK . $new_version . '.zip', PATH . "cache/kleeja-{$new_version}.zip", 60, false, 10, true); + fetch_remote_file(KLEEJA_LATEST_PACKAGE_LINK . $new_version , PATH . "cache/kleeja-{$new_version}.zip", 60, false, 10, true); if (file_exists(PATH . "cache/kleeja-{$new_version}.zip")) { @@ -180,8 +180,15 @@ elseif ($current_smt == 'update2') if ($zip->open(PATH . "cache/kleeja-{$new_version}.zip") == true) { + // the name of folder after extracting it + // and we are sure that there is only one folder in the zip file + $ex_folder = trim($zip->getNameIndex(0), '/'); $zip->extractTo(PATH . 'cache/'); $zip->close(); + rename( + PATH . "cache/{$ex_folder}" , // the name of the folder after extract it + PATH . "cache/kleeja-{$new_version}" + ); } // let's check if there any update files in install folder From f1c23c24aaa7d333b38fbf8f568b1f909919ef4c Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Mon, 13 May 2019 20:43:35 +0300 Subject: [PATCH 26/27] fixes --- includes/adm/p_check_update.php | 29 ++++++++++++++++++++++------- includes/common.php | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/includes/adm/p_check_update.php b/includes/adm/p_check_update.php index 3e4f960..344b6e1 100755 --- a/includes/adm/p_check_update.php +++ b/includes/adm/p_check_update.php @@ -185,10 +185,18 @@ elseif ($current_smt == 'update2') $ex_folder = trim($zip->getNameIndex(0), '/'); $zip->extractTo(PATH . 'cache/'); $zip->close(); - rename( - PATH . "cache/{$ex_folder}" , // the name of the folder after extract it + if(rename( + PATH . "cache/{$ex_folder}", PATH . "cache/kleeja-{$new_version}" - ); + ) === false) + { + copy( + PATH . "cache/{$ex_folder}", + PATH . "cache/kleeja-{$new_version}" + ); + + kleeja_unlink(PATH . "cache/{$ex_folder}"); + } } // let's check if there any update files in install folder @@ -198,7 +206,10 @@ elseif ($current_smt == 'update2') { // move the update file from install folder to cache folder to include it later and delete install folder // becuse if install folder is exists , it can make some problems if dev mode is not active - rename($update_file, PATH . 'cache/update_schema.php'); + if(rename($update_file, PATH . 'cache/update_schema.php') === false) + { + copy($update_file, PATH . 'cache/update_schema.php'); + } } // skip some folders @@ -282,10 +293,14 @@ elseif ($current_smt == 'update3') file_get_contents($file->getPathname()) ) === false) { - $update_failed = true; - array_push($failed_files, $file_path); - break; + if (copy($file->getPathname(), $file_path) === false) + { + $update_failed = true; + array_push($failed_files, $file_path); + + break; + } } } elseif ($file->isDir()) diff --git a/includes/common.php b/includes/common.php index 999ee7e..57def01 100755 --- a/includes/common.php +++ b/includes/common.php @@ -37,7 +37,7 @@ if (! defined('PATH')) { define('__DIR__', dirname(__FILE__)); } - define('PATH', str_replace(DIRECTORY_SEPARATOR . 'includes', '', __DIR__) . DIRECTORY_SEPARATOR); + define('PATH', str_replace('/includes', '', __DIR__) . '/'); } //no config From 66d05acc9d80da9c408071f0bb68ae39d2108152 Mon Sep 17 00:00:00 2001 From: Abdulrahman Date: Tue, 14 May 2019 00:08:44 +0300 Subject: [PATCH 27/27] fix --- includes/version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/version.php b/includes/version.php index 2449241..49ec318 100755 --- a/includes/version.php +++ b/includes/version.php @@ -16,7 +16,7 @@ if (! defined('IN_COMMON')) -define('KLEEJA_VERSION', '3.0.3'); +define('KLEEJA_VERSION', '3.0.2'); define('KLEEJA_DB_VERSION', '9');