Powerful and easy to use cms to build websites, blogs or ecommerce stores.
HTML backendblogblog-engineblog-platformbloggingcmscontent-managementcontent-management-systemecommerceecommerce-platformno-codepage-builderphpphp-cmsphp7php8self-hostedshopping-cartweb-applicationwebsite-builder
Check file write permission step before downloading update zip step
givanzf0c53d86a911
diff --git a/admin/controller/tools/update.php b/admin/controller/tools/update.phpindex 2ff287f..aa80eb7 100755--- a/admin/controller/tools/update.php+++ b/admin/controller/tools/update.php@@ -31,7 +31,7 @@ use Vvveb\System\User\Admin;use function Vvveb\url;class Update extends Base {- private $steps = ['download', 'unzip', /*'backup',*/ 'copySystem',/* 'copyAdmin',*/ 'copyApp', 'copyInstall', 'copyCore', 'copyConfig', 'copyPublic', 'copyPublicAdmin', 'copyPublicMedia', 'setPermissions', 'cleanUp', 'clearCache', 'complete'];+ private $steps = ['checkPermissions', 'download', 'unzip', /*'backup',*/ 'copySystem', /* 'copyAdmin',*/ 'copyApp', 'copyInstall', 'copyCore', 'copyConfig', 'copyPublic', 'copyPublicAdmin', 'copyPublicMedia', 'setPermissions', 'cleanUp', 'clearCache', 'complete'];function __construct() {$this->update = new UpdateSys();@@ -151,6 +151,25 @@ class Update extends Base {return true;}+ function checkPermissions() {+ $result = false;++ try {+ $result = $this->update->checkPermissions();+ } catch (\Exception $e) {+ $this->view->errors[] = $e->getMessage();+ }++ if ($result === true) {+ $this->view->info[] = __('Permissions ok!');+ } else {+ $this->view->errors[] = sprintf(__('%s not writable!'), $result);+ return false;+ }++ return $result;+ }+function backup() {$result = false;@@ -188,11 +207,12 @@ class Update extends Base {}private function copy($method) {- $name = humanReadable(camelToUnderscore($method));+ $name = humanReadable(camelToUnderscore($method));$errorInstallMsg = sprintf(__('Error updating %s'), $name);$result = false;-+$method = "copy$method";+try {$result = $this->update->$method();} catch (\Exception $e) {@@ -207,7 +227,7 @@ class Update extends Base {return $result;}-+function copyCore() {return $this->copy('Core');}@@ -219,12 +239,14 @@ class Update extends Base {function copySystem() {//merge system and admin in one step so that the updater does not break if depends on older system code.$return = $this->copy('System');+if ($return) {$return = $this->copy('Admin');}-+return $return;}+/*function copyAdmin() {return $this->copy('Admin');@@ -330,28 +352,7 @@ class Update extends Base {return $this->index();}- function checkWriteAccess() {- $skip = ['install', 'locale', 'vendor', 'plugins', 'config'];- $unwritable = [];-- $dir = @opendir(DIR_ROOT);- while (false !== ($file = readdir($dir))) {- $full = DIR_ROOT . DS . $file;-- if (($file != '.') &&- ($file != '..') && !in_array($file, $skip)) {- if (is_dir($full) && ! is_writable($full)) {- $unwritable[] = $file;- }- }- }- if ($unwritable) {- $this->view->info[] = sprintf('Folders <b>%s</b> are not writable, update will not work properly', implode(', ', $unwritable));- }- }-- function index() {- $updateInfo = $this->checkWriteAccess();+ function index() {$updateInfo = $this->checkUpdates();$info = [diff --git a/public/js/admin/controller/update.js b/public/js/admin/controller/update.jsindex 9495a96..2272f27 100755--- a/public/js/admin/controller/update.js+++ b/public/js/admin/controller/update.js@@ -87,7 +87,7 @@ class UpdateController {}})*/.catch(error => {- let message = error.clone().text();+ let message = error.statusText ?? error.clone().text();if (typeof error.json === "function") {error.json().then(jsonError => {diff --git a/system/update.php b/system/update.phpindex 330d91c..3308546 100755--- a/system/update.php+++ b/system/update.php@@ -65,6 +65,48 @@ class Update {return [];}+ private function checkFolderPermissions($dir) {+ $skip = ['install', 'locale', 'vendor', 'plugins', 'config'];+ $unwritable = [];++ $handle = @opendir($dir);++ while (false !== ($file = readdir($handle))) {+ $full = $dir . DS . $file;++ if (($file != '.') &&+ ($file != '..') && ! in_array($file, $skip)) {+ if (is_dir($full)) {+ if (! is_writable($full)) {+ if (! @chmod($full, CHMOD_DIR)) {+ return $full;+ }+ }++ $result = $this->checkFolderPermissions($full);++ if ($result !== true) {+ return $result;+ }+ }+ //if (str_ends_with($full, '.php') && ! is_writable($full)) {+ if ((substr_compare($full,'.php', -4) === 0) && ! is_writable($full)) {+ if (! @chmod($full, CHMOD_FILE)) {+ return $full;+ }+ }+ }+ }++ return true;+ }++ function checkPermissions() {+ $check = $this->checkFolderPermissions(DIR_ROOT);++ return $check;+ }+static function backup() {$skipFolders = ['plugins', 'public', 'storage', 'install'];$backupFolder = DIR_BACKUP . 'update-' . V_VERSION . '-' . date('Y-m-d_H:i:s');@@ -107,24 +149,19 @@ class Update {if (! is_writable($dest)) {throw new \Exception(sprintf('Folder "%s" not writable!', $dest));}- rcopy($src, $dest, $skipFolders);- return true;+ return rcopy($src, $dest, $skipFolders);}function copyAdmin() {//$skipFolders = ['plugins', 'public', 'storage'];- $this->copyFolder($this->workDir . DS . 'admin', DIR_ROOT . DS . 'admin');-- return true;+ return $this->copyFolder($this->workDir . DS . 'admin', DIR_ROOT . DS . 'admin');}function copyApp() {ignore_user_abort(true);//$skipFolders = ['plugins', 'public', 'storage'];- $this->copyFolder($this->workDir . DS . 'app', DIR_ROOT . DS . 'app');-- return true;+ return $this->copyFolder($this->workDir . DS . 'app', DIR_ROOT . DS . 'app');}function copySystem() {