diff --git a/Admin/Hooks/Web/Api.php b/Admin/Hooks/Web/Api.php new file mode 100644 index 0000000..34481cb --- /dev/null +++ b/Admin/Hooks/Web/Api.php @@ -0,0 +1,19 @@ + [ + 'callback' => ['\Modules\Admin\Controller\ApiController:cliEventCall'], + ], +]; diff --git a/Admin/Installer.php b/Admin/Installer.php index a60ddee..c04a373 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -28,6 +28,8 @@ use phpOMS\Message\Mail\SubmitType; use phpOMS\Module\InstallerAbstract; use phpOMS\Module\ModuleInfo; use phpOMS\System\File\PathException; +use phpOMS\System\OperatingSystem; +use phpOMS\System\SystemType; /** * Installer class. @@ -83,9 +85,13 @@ final class Installer extends InstallerAbstract SettingMapper::create()->execute(new Setting(0, SettingsEnum::PASSWORD_HISTORY, '3', '\\d+')); SettingMapper::create()->execute(new Setting(0, SettingsEnum::LOGGING_STATUS, '1', '[0-3]')); SettingMapper::create()->execute(new Setting(0, SettingsEnum::LOGGING_PATH, '')); + SettingMapper::create()->execute(new Setting(0, SettingsEnum::DEFAULT_ORGANIZATION, '1', '\\d+')); + SettingMapper::create()->execute(new Setting(0, SettingsEnum::LOGIN_STATUS, '1', '[0-3]')); + SettingMapper::create()->execute(new Setting(0, SettingsEnum::DEFAULT_LOCALIZATION, '1', '\\d+')); + SettingMapper::create()->execute(new Setting(0, SettingsEnum::MAIL_SERVER_ADDR, 'admin@karaka.email', "(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])", module: 'Admin')); SettingMapper::create()->execute(new Setting(0, SettingsEnum::MAIL_SERVER_TYPE, SubmitType::MAIL, module: 'Admin')); SettingMapper::create()->execute(new Setting(0, SettingsEnum::MAIL_SERVER_USER, '', module: 'Admin')); @@ -95,6 +101,21 @@ final class Installer extends InstallerAbstract SettingMapper::create()->execute(new Setting(0, SettingsEnum::MAIL_SERVER_KEYPASS, '', module: 'Admin')); SettingMapper::create()->execute(new Setting(0, SettingsEnum::MAIL_SERVER_TLS, (string) false, module: 'Admin')); + SettingMapper::create()->execute( + new Setting( + 0, + SettingsEnum::CLI_ACTIVE, + (string) ( + \stripos(\shell_exec( + (OperatingSystem::getSystem() === SystemType::WIN + ? 'php.exe' + : 'php' + ) .' cli.php -v' + ), 'Version:') !== false + ) + ) + ); + $l11n = Localization::fromLanguage('en'); LocalizationMapper::create()->execute($l11n); } diff --git a/Admin/Routes/Cli.php b/Admin/Routes/Cli.php index 141c721..fe63a28 100755 --- a/Admin/Routes/Cli.php +++ b/Admin/Routes/Cli.php @@ -3,7 +3,7 @@ use phpOMS\Router\RouteVerb; return [ - '^$' => [ + '^/* .*?$' => [ [ 'dest' => '\Modules\Admin\Controller\CliController:viewEmptyCommand', 'verb' => RouteVerb::ANY, diff --git a/Controller/ApiController.php b/Controller/ApiController.php index c4217bf..ea0f244 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -64,6 +64,8 @@ use phpOMS\Module\ModuleInfo; use phpOMS\Module\ModuleStatus; use phpOMS\System\File\Local\File; use phpOMS\System\MimeType; +use phpOMS\System\OperatingSystem; +use phpOMS\System\SystemType; use phpOMS\System\SystemUtils; use phpOMS\Uri\HttpUri; use phpOMS\Uri\UriFactory; @@ -1972,4 +1974,36 @@ final class ApiController extends Controller private function runUpdate(string $updateFile) : void { } + + /** + * Api method to make a call to the cli app + * + * @param mixed $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function cliEventCall(...$data) : void + { + $cliEventHandling = (bool) ($this->app->appSettings->get(null, SettingsEnum::CLI_ACTIVE)->content ?? false); + + if ($cliEventHandling) { + $count = \count($data); + + SystemUtils::runProc( + OperatingSystem::getSystem() === SystemType::WIN ? 'php.exe' : 'php', + \escapeshellarg(\realpath(__DIR__ . '/../../../cli.php')) . ' ' + . 'post:/admin/event' . ' ' + . '-g ' . \escapeshellarg($data[$count - 2]) . ' ' + . '-i ' . \escapeshellarg($data[$count - 1]) . ' ' + . '-d ' . \escapeshellarg(\json_encode($data)), + true + ); + } else { + $this->app->moduleManager->get('Workflow')->runWorkflowFromHook($data); + } + } } diff --git a/Controller/CliController.php b/Controller/CliController.php index ec681ba..2d4d245 100755 --- a/Controller/CliController.php +++ b/Controller/CliController.php @@ -49,7 +49,12 @@ final class CliController extends Controller public function viewEmptyCommand(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface { $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/Admin/Theme/Cli/empty-command'); + + if ($request->hasData('v')) { + $view->setTemplate('/Modules/Admin/Theme/Cli/version-command'); + } else { + $view->setTemplate('/Modules/Admin/Theme/Cli/empty-command'); + } return $view; } diff --git a/Theme/Cli/empty-command.tpl.php b/Theme/Cli/empty-command.tpl.php index d89e019..2d62f9a 100755 --- a/Theme/Cli/empty-command.tpl.php +++ b/Theme/Cli/empty-command.tpl.php @@ -1 +1 @@ -