From a0a99de862c2711904416e0ae7a73858f3354b7b Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 15:24:25 +0300 Subject: [PATCH 1/8] version fix --- bootstrap/secure.php | 2 +- .../console/controllers/KernelController.php | 8 +++--- kernel/helpers/Files.php | 28 +++++++++++++++++-- kernel/helpers/Version.php | 16 +++++++++++ kernel/services/KernelService.php | 11 ++++++-- kernel/services/ModuleService.php | 6 +++- 6 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 kernel/helpers/Version.php diff --git a/bootstrap/secure.php b/bootstrap/secure.php index a8baf09..b57765e 100644 --- a/bootstrap/secure.php +++ b/bootstrap/secure.php @@ -1,7 +1,7 @@ 'email_code', // login_password, email_code + 'web_auth_type' => 'login_password', // login_password, email_code 'token_type' => 'hash', // random_bytes, md5, crypt, hash, JWT 'token_expired_time' => "+30 days", // +1 day ]; diff --git a/kernel/console/controllers/KernelController.php b/kernel/console/controllers/KernelController.php index 13efa75..e6a3a2a 100644 --- a/kernel/console/controllers/KernelController.php +++ b/kernel/console/controllers/KernelController.php @@ -27,7 +27,7 @@ class KernelController extends ConsoleController if (file_exists(ROOT_DIR . $this->argv['path'])) { $tmpKernelDirFull = RESOURCES_DIR . '/tmp/ad/kernel/kernel'; - $this->files->copy_folder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull); + $this->files->copyKernelFolder(ROOT_DIR . $this->argv['path'], $tmpKernelDirFull); $this->out->r("Ядро скопировано во временную папку", 'green'); } else { $this->out->r("Ядро не найдено", 'red'); @@ -35,7 +35,7 @@ class KernelController extends ConsoleController if (file_exists(ROOT_DIR . '/bootstrap')) { $tmpBootstrapDirFull = RESOURCES_DIR . '/tmp/ad/kernel/bootstrap'; - $this->files->copy_folder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull); + $this->files->copyKernelFolder(ROOT_DIR . '/bootstrap', $tmpBootstrapDirFull); $this->out->r("/bootstrap скопирован во временную папку", 'green'); } else { $this->out->r("/bootstrap не найден", 'red'); @@ -99,11 +99,11 @@ class KernelController extends ConsoleController $zip->extractTo($tmpKernelDirFull); $zip->close(); $this->files->recursiveRemoveKernelDir(); - $this->files->copy_folder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel"); + $this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel"); if (isset($this->argv['bootstrap'])) { $this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap'); - $this->files->copy_folder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); + $this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); copy($tmpKernelDirFull . '/bootstrap.php' , ROOT_DIR . '/bootstrap.php'); } diff --git a/kernel/helpers/Files.php b/kernel/helpers/Files.php index e05a3a1..5f6daf7 100644 --- a/kernel/helpers/Files.php +++ b/kernel/helpers/Files.php @@ -7,11 +7,33 @@ use ZipArchive; class Files { - public function copy_folder($d1, $d2): void + public function copy_folder($d1, $d2, int $permissions = 0774, bool $recursive = true): void { if (is_dir($d1)) { if (!file_exists($d2)){ - $_d2 = mkdir($d2, permissions: 0774, recursive: true); + $_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive); + if (!$_d2) { + return; + } + } + + $d = dir($d1); + while (false !== ($entry = $d->read())) { + if ($entry != '.' && $entry != '..') { + $this->copy_folder("$d1/$entry", "$d2/$entry"); + } + } + $d->close(); + } else { + copy($d1, $d2); + } + } + + public function copyKernelFolder($d1, $d2, int $permissions = 0774, bool $recursive = true): void + { + if (is_dir($d1)) { + if (!file_exists($d2)){ + $_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive); if (!$_d2) { return; } @@ -20,7 +42,7 @@ class Files $d = dir($d1); while (false !== ($entry = $d->read())) { if ($entry != '.' && $entry != '..' && $entry != 'app_modules') { - $this->copy_folder("$d1/$entry", "$d2/$entry"); + $this->copyKernelFolder("$d1/$entry", "$d2/$entry"); } } $d->close(); diff --git a/kernel/helpers/Version.php b/kernel/helpers/Version.php new file mode 100644 index 0000000..3380436 --- /dev/null +++ b/kernel/helpers/Version.php @@ -0,0 +1,16 @@ + intval($version) * 100, + 2 => intval($version) * 10, + 3 => intval($version), + }; + } +} \ No newline at end of file diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index 3caf8ec..2eebee9 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -6,6 +6,7 @@ use kernel\helpers\Debug; use kernel\helpers\Files; use kernel\helpers\Manifest; use kernel\helpers\RESTClient; +use kernel\helpers\Version; use kernel\Request; use ZipArchive; @@ -42,8 +43,12 @@ class KernelService $modules_info = json_decode($modules_info->getBody()->getContents(), true); $kernel_info = $this->getKernelInfo(); + + $kernelVersion = Version::getIntVersionByString($kernel_info['version']); + foreach ($modules_info as $mod) { - if ($mod['slug'] === $kernel_info['slug'] && $mod['version'] === $kernel_info['version']) { + $modVersion = Version::getIntVersionByString($mod['version']); + if ($mod['slug'] === $kernel_info['slug'] && $modVersion <= $kernelVersion) { return true; } } @@ -66,12 +71,12 @@ class KernelService $zip->extractTo($tmpKernelDirFull); $zip->close(); $this->files->recursiveRemoveKernelDir(); - $this->files->copy_folder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel"); + $this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel"); foreach ($files as $file) { if ($file === 'bootstrap') { $this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap'); - $this->files->copy_folder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); + $this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); } copy($tmpKernelDirFull . $file , ROOT_DIR . '/' . $file); } diff --git a/kernel/services/ModuleService.php b/kernel/services/ModuleService.php index 7beb721..3d769fa 100644 --- a/kernel/services/ModuleService.php +++ b/kernel/services/ModuleService.php @@ -9,6 +9,7 @@ use kernel\helpers\Debug; use kernel\helpers\Files; use kernel\helpers\Manifest; use kernel\helpers\RESTClient; +use kernel\helpers\Version; use kernel\models\Option; use ZipArchive; @@ -449,8 +450,11 @@ class ModuleService $modules_info = json_decode($modules_info->getBody()->getContents(), true); $mod_info = $this->getModuleInfoBySlug($slug); + + $currentVersion = Version::getIntVersionByString($mod_info['version']); foreach ($modules_info as $mod) { - if ($mod['slug'] === $mod_info['slug'] && $mod['version'] === $mod_info['version']) { + $modVersion = Version::getIntVersionByString($mod['version']); + if ($mod['slug'] === $mod_info['slug'] && $modVersion <= $currentVersion) { return true; } } From 0d98ec7cde73670633ee564390e019140506fe66 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 16:15:03 +0300 Subject: [PATCH 2/8] copy folder fix --- kernel/controllers/ModuleController.php | 4 ---- kernel/helpers/Files.php | 10 ++++++++-- kernel/manifest.json | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/kernel/controllers/ModuleController.php b/kernel/controllers/ModuleController.php index e0fc983..8ce4d4e 100644 --- a/kernel/controllers/ModuleController.php +++ b/kernel/controllers/ModuleController.php @@ -6,13 +6,9 @@ use DirectoryIterator; use JetBrains\PhpStorm\NoReturn; use Josantonius\Session\Facades\Session; use kernel\AdminController; -use kernel\EntityRelation; use kernel\helpers\Debug; use kernel\models\Option; -use kernel\modules\module_shop_client\services\ModuleShopClientService; -use kernel\modules\user\service\UserService; use kernel\Request; -use kernel\services\MigrationService; use kernel\services\ModuleService; class ModuleController extends AdminController diff --git a/kernel/helpers/Files.php b/kernel/helpers/Files.php index 5f6daf7..ef154e7 100644 --- a/kernel/helpers/Files.php +++ b/kernel/helpers/Files.php @@ -7,11 +7,13 @@ use ZipArchive; class Files { - public function copy_folder($d1, $d2, int $permissions = 0774, bool $recursive = true): void + public function copy_folder($d1, $d2, int $permissions = 0775, bool $recursive = true): void { if (is_dir($d1)) { if (!file_exists($d2)){ + $old_mask = umask(0); $_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive); + umask($old_mask); if (!$_d2) { return; } @@ -26,14 +28,17 @@ class Files $d->close(); } else { copy($d1, $d2); + chmod($d2, permissions: $permissions); } } - public function copyKernelFolder($d1, $d2, int $permissions = 0774, bool $recursive = true): void + public function copyKernelFolder($d1, $d2, int $permissions = 0773, bool $recursive = true): void { if (is_dir($d1)) { if (!file_exists($d2)){ + $old_mask = umask(0); $_d2 = mkdir($d2, permissions: $permissions, recursive: $recursive); + umask($old_mask); if (!$_d2) { return; } @@ -48,6 +53,7 @@ class Files $d->close(); } else { copy($d1, $d2); + chmod($d2, permissions: $permissions); } } diff --git a/kernel/manifest.json b/kernel/manifest.json index 3cccfd0..65282d4 100644 --- a/kernel/manifest.json +++ b/kernel/manifest.json @@ -1,6 +1,6 @@ { "name": "Kernel", - "version": "0.1", + "version": "0.2", "author": "ITGuild", "slug": "kernel", "type": "kernel", From bcf8b6621b8cbd1007fa18bd462a9ecedcf69e75 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 16:32:51 +0300 Subject: [PATCH 3/8] some fix --- kernel/helpers/Files.php | 2 +- .../controllers/ModuleShopClientController.php | 1 - kernel/services/KernelService.php | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/helpers/Files.php b/kernel/helpers/Files.php index ef154e7..2360dd7 100644 --- a/kernel/helpers/Files.php +++ b/kernel/helpers/Files.php @@ -32,7 +32,7 @@ class Files } } - public function copyKernelFolder($d1, $d2, int $permissions = 0773, bool $recursive = true): void + public function copyKernelFolder($d1, $d2, int $permissions = 0775, bool $recursive = true): void { if (is_dir($d1)) { if (!file_exists($d2)){ diff --git a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php index 3612132..5ad60cd 100644 --- a/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php +++ b/kernel/modules/module_shop_client/controllers/ModuleShopClientController.php @@ -124,7 +124,6 @@ class ModuleShopClientController extends AdminController #[NoReturn] public function actionKernelUpdate(): void { - $request = new Request(); $modules_info = RESTClient::request($_ENV['MODULE_SHOP_URL'] . '/api/module_shop/gb_slug'); $modules_info = json_decode($modules_info->getBody()->getContents(), true); diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index 2eebee9..2523b14 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -74,7 +74,9 @@ class KernelService $this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel"); foreach ($files as $file) { + Debug::prn($file); if ($file === 'bootstrap') { + Debug::prn(123); $this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap'); $this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); } @@ -83,6 +85,7 @@ class KernelService $this->files->recursiveRemoveDir($tmpKernelDirFull); unlink(ROOT_DIR . $path); + Debug::dd("update kernel success"); return true; } From 798c6875472a8bc35b6723f20ae733b6bbe3ccb0 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 16:38:08 +0300 Subject: [PATCH 4/8] fix --- kernel/manifest.json | 2 +- kernel/modules/module_shop_client/views/kernel_update.php | 2 +- kernel/services/KernelService.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/manifest.json b/kernel/manifest.json index 65282d4..3cccfd0 100644 --- a/kernel/manifest.json +++ b/kernel/manifest.json @@ -1,6 +1,6 @@ { "name": "Kernel", - "version": "0.2", + "version": "0.1", "author": "ITGuild", "slug": "kernel", "type": "kernel", diff --git a/kernel/modules/module_shop_client/views/kernel_update.php b/kernel/modules/module_shop_client/views/kernel_update.php index 0bbe204..ca520f4 100644 --- a/kernel/modules/module_shop_client/views/kernel_update.php +++ b/kernel/modules/module_shop_client/views/kernel_update.php @@ -15,7 +15,7 @@ $form->field(\itguild\forms\inputs\Select::class, "files[]", [ ]) ->setLabel("Дополнительные файлы") ->setOptions([ - '.env.example' => '.env.example', + 'env.example' => 'env.example', 'bootstrap.php' => 'bootstrap', 'composer.json' => 'composer.json', ]) diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index 2523b14..d6b8d3a 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -75,7 +75,7 @@ class KernelService foreach ($files as $file) { Debug::prn($file); - if ($file === 'bootstrap') { + if ($file === 'bootstrap.php') { Debug::prn(123); $this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap'); $this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); From d74a30f33e8517d4f2d474bd0126039d2f02afe1 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 16:43:32 +0300 Subject: [PATCH 5/8] some --- .env.example | 2 +- kernel/services/KernelService.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index ffddf4b..e54c0b7 100644 --- a/.env.example +++ b/.env.example @@ -20,4 +20,4 @@ MAIL_SMTP_PASSWORD=somepassword MODULE_SHOP_URL='http://igfs.loc' MODULE_SHOP_TOKEN='your token' -SECRET_KEY='' \ No newline at end of file +SECRET_KEY='key' \ No newline at end of file diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index d6b8d3a..1d09273 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -81,6 +81,7 @@ class KernelService $this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); } copy($tmpKernelDirFull . $file , ROOT_DIR . '/' . $file); + chmod(ROOT_DIR . '/' . $file, 0775); } $this->files->recursiveRemoveDir($tmpKernelDirFull); From 5d671d03d2e41032313924fd3174db1c6169937e Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 16:43:53 +0300 Subject: [PATCH 6/8] some --- .env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env.example b/.env.example index e54c0b7..ffddf4b 100644 --- a/.env.example +++ b/.env.example @@ -20,4 +20,4 @@ MAIL_SMTP_PASSWORD=somepassword MODULE_SHOP_URL='http://igfs.loc' MODULE_SHOP_TOKEN='your token' -SECRET_KEY='key' \ No newline at end of file +SECRET_KEY='' \ No newline at end of file From 57d2f202553cf180d92905d267a22d9554e2d00b Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 16:48:32 +0300 Subject: [PATCH 7/8] some --- kernel/services/KernelService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index 1d09273..0441ba5 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -80,6 +80,11 @@ class KernelService $this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap'); $this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); } + if ($file === 'env.example') { + copy($tmpKernelDirFull . $file , ROOT_DIR . '/.' . $file); + chmod(ROOT_DIR . '/.' . $file, 0775); + continue; + } copy($tmpKernelDirFull . $file , ROOT_DIR . '/' . $file); chmod(ROOT_DIR . '/' . $file, 0775); } From 1cf2dc3d86ecff354dbb0ea559316ba605acfee3 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 18 Dec 2024 16:52:09 +0300 Subject: [PATCH 8/8] fix kernel update --- kernel/manifest.json | 2 +- kernel/services/KernelService.php | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/manifest.json b/kernel/manifest.json index 3cccfd0..6521135 100644 --- a/kernel/manifest.json +++ b/kernel/manifest.json @@ -1,6 +1,6 @@ { "name": "Kernel", - "version": "0.1", + "version": "0.1.1", "author": "ITGuild", "slug": "kernel", "type": "kernel", diff --git a/kernel/services/KernelService.php b/kernel/services/KernelService.php index 0441ba5..28c42fc 100644 --- a/kernel/services/KernelService.php +++ b/kernel/services/KernelService.php @@ -74,9 +74,7 @@ class KernelService $this->files->copyKernelFolder($tmpKernelDirFull . 'kernel' , ROOT_DIR . "/kernel"); foreach ($files as $file) { - Debug::prn($file); if ($file === 'bootstrap.php') { - Debug::prn(123); $this->files->recursiveRemoveDir(ROOT_DIR . '/bootstrap'); $this->files->copyKernelFolder($tmpKernelDirFull . 'bootstrap' , ROOT_DIR . '/bootstrap'); } @@ -91,7 +89,6 @@ class KernelService $this->files->recursiveRemoveDir($tmpKernelDirFull); unlink(ROOT_DIR . $path); - Debug::dd("update kernel success"); return true; }