AuthShield = $AuthShield; $this->container=(null!==$container) ? $container : $AuthShield->getAppShield()->getContainer(); } public function auth(\UMA\JsonRpc\Request $request){ return 'admin' === $this->container->get('webfan.app.fsm.user')->getCurrentState()->getName(); } /** * {@inheritdoc} */ public function __invoke(\UMA\JsonRpc\Request $request): \UMA\JsonRpc\Response { $_dir = getcwd(); $time = time(); $params = $request->params(); $AppShield = $this->AuthShield->getAppShield(); $config = $AppShield->config; $wsdir = rtrim($config->wsdir, \DIRECTORY_SEPARATOR.'//\\ ').\DIRECTORY_SEPARATOR; $params->modules_dirname = preg_replace("/[^a-z0-9\-]/", "-", strtolower($params->modules_dirname)); $params->name = preg_replace("/[^A-Za-z0-9\-]/", "-", strtolower(str_replace(' ', '-',$params->name))); $params->jsglobal = preg_replace("/[^A-Za-z0-9\_]/", "_",str_replace(' ', '_',$params->jsglobal)); $params->title = trim(strip_tags($params->title), '\'" '); $params->lastbuild = 0; if(!preg_match("/\/[A-Za-z0-9\-\/]+\/[A-Za-z0-9\-\/]+\//",$params->jsbase)){ return new \UMA\JsonRpc\Error($request->id(), 'Invalid `jsbase` parameter!'); } if(!preg_match("/[A-Za-z0-9\-]+\.webfan\.de/",$params->workspace)){ return new \UMA\JsonRpc\Error($request->id(), 'Invalid `workspace` parameter!'); } if(is_dir($wsdir.'frdl-projects'.\DIRECTORY_SEPARATOR.$params->name)){ return new \UMA\JsonRpc\Error($request->id(), sprintf('`%s` already exists!', $params->name)); } if(!property_exists($params, 'intent') ){ $params->intent = []; } if(!is_array($params->intent)){ $params->intent = [$params->intent]; } $httpdocs = $_SERVER['DOCUMENT_ROOT'].\DIRECTORY_SEPARATOR.trim($params->ce_dir, \DIRECTORY_SEPARATOR.'//\\').\DIRECTORY_SEPARATOR; /* $params->ce_baseUrl = rtrim($params->ce_baseUrl, \DIRECTORY_SEPARATOR.'//\\').'/'; if(file_exists($httpdocs.'index.php') ){ return new \UMA\JsonRpc\Error($request->id(), sprintf('`%s` already exists! Remove this file first to install a project web-root here!', $httpdocs.'index.php')); } if(file_exists($httpdocs.'.htaccess') ){ return new \UMA\JsonRpc\Error($request->id(), sprintf('`%s` already exists! Remove this file first to install a project web-root here!', $httpdocs.'.htaccess')); } if(!is_dir($httpdocs)){ mkdir($httpdocs, 0755, true); } chmod($httpdocs, 0755); $check = 'installcheck '.$params->name.' '.$time.' '.sha1($httpdocs); $checkFile = $time.'.frdl-project-create-check'; file_put_contents($httpdocs.$checkFile, $check ); if(!file_exists($httpdocs.$checkFile )){ return new \UMA\JsonRpc\Error($request->id(), 'Could not create installcheck (in httpdocs directory)!'); } $_checkVal = file_get_contents($params->ce_baseUrl.$checkFile); if( $check != $_checkVal){ // return new \UMA\JsonRpc\Error($request->id(), 'Installcheck failed, Base-Url MUST refer to the httpdocs directory! '.$check); return new \UMA\JsonRpc\Error($request->id(), 'Installcheck failed, Base-Url MUST refer to the httpdocs directory! ['.$check.','.$_checkVal.']'); } // unlink($httpdocs.$checkFile); call_user_func(\frdlweb\Thread\ShutdownTasks::mutex(), function($file){ $glob = dirname($file).\DIRECTORY_SEPARATOR."*.frdl-project-create-check"; foreach(glob($glob) as $f){ unlink($f); } if(file_exists($file)){ unlink($file); } }, $httpdocs.$checkFile); */ chdir($wsdir); if(!is_dir($wsdir.'frdl-projects')){ mkdir('frdl-projects', 0755, true); } chdir('frdl-projects'); mkdir($params->name, 0755, true); chdir($params->name); $params->ce_dir = \webfan\hps\patch\Fs::getRelativePath(getcwd(), $httpdocs); $modules_dirname = $params->modules_dirname; $ce_dir = $params->ce_dir; $t = mt_rand(1000,9999).time().$this->container->get('.rand.str'); $name = 'acme/'.$params->name; $params->config = [ 'online' => 0, 'env' => 'dev', 'stage' => [ 'prod' => 'blue', 'dev' => 'green', ], 'theme' => [ 'vendor' => null, 'name' => null, ], 't' => $t, 'r' => $this->container->get('.rand.str'), 'lt' => [ 'created' => $time, 'compiled' => [0,0,0], // 0,blue,green 'deployed' => 0, ], ]; $params->hash = sha1(json_encode($params->config)); $dbConfigFile = getcwd() . \DIRECTORY_SEPARATOR.'config'.\DIRECTORY_SEPARATOR.'frdl'.\DIRECTORY_SEPARATOR.'frdlweb-cms-db'.\DIRECTORY_SEPARATOR.'db-config.php'; if(property_exists($params, 'database') && null !== $params->database){ //toDo: Test Database connection $dbConfig = (array)$params->database; $Tester = new \webfan\hps\patch\TestDatabaseConnection($dbConfig); if(!$Tester->valid() ){ chdir('../'); rmdir($params->name); return new \UMA\JsonRpc\Error($request->id(), 'Databases errors: ' .implode("\n", $Tester->errors())); } $export = var_export($dbConfig, true); $code = <<database); $parsedUrl = parse_url($p->ce_baseUrl); $_host = (isset($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']; $p->ce_baseUrl = str_replace([$parsedUrl['host'], $_host], ['${HOST}', '${HOST}'], $p->ce_baseUrl); $json = json_encode($p, \JSON_PRETTY_PRINT); if(!file_put_contents('frdl.project.json', $json )){ if(file_exists($dbConfigFile)){ unlink($dbConfigFile); } chdir('../'); rmdir($params->name); return new \UMA\JsonRpc\Error($request->id(), 'Could not create project!'); } if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'config'))mkdir('config', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'dist'))mkdir('dist', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'log'))mkdir('log', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'data'))mkdir('data', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'backup'))mkdir('backup', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'backup.restore'))mkdir('backup.restore', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'compiled'))mkdir('compiled', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.'themes'))mkdir('themes', 0755, true); if(!is_dir(getcwd() . \DIRECTORY_SEPARATOR.$params->modules_dirname))mkdir($params->modules_dirname, 0755, true); $composer= <<=7.2", "frdl/frdlweb-composer-installers" : "*", "frdl/web": "*" $requireDbString }, "extra": { "webfantize" : { "flavor" : "frdl-project", "oid" : "1.3.6.1.4.1.37553.8.1.8.8.11.1" }, "installer-types": ["frdl-theme", "frdl-module", "frdl-httpdocs", "frdl-public", "vendor", "frdl-extension"], "installer-paths": { "$modules_dirname/{\$vendor}.{\$name}/": ["type:frdl-module"], "frdl-extensions/{\$vendor}.{\$name}/": [ "type:frdl-extension"], "themes/{\$vendor}/{\$name}/": ["type:frdl-theme"], "$ce_dir{\$vendor}/{\$name}/": ["type:frdl-httpdocs"], "{\$webroot}/": ["type:frdl-public"], "vendor/frdlweb/{\$vendor}/{\$name}/": ["vendor:frdl", "vendor:frdlweb", "vendor:webfan", "vendor:webfan3"] } }, "config": { "preferred-install": "auto", "cache-files-ttl": 3600, "prepend-autoloader": true, "platform": { "php": "7.2.23" } }, "minimum-stability" : "dev", "autoload": { "psr-4": { "compiled\\\": "compiled\/" } } } JSONCODE; file_put_contents('composer.json', $composer ); chdir($wsdir); //return new \UMA\JsonRpc\Error($request->id(), 'Please try next version wich is coming soon!'); // return new \UMA\JsonRpc\Success($request->id(), true); $path = getcwd(); $outputfile = rtrim($path, \DIRECTORY_SEPARATOR). \DIRECTORY_SEPARATOR.'logs'. \DIRECTORY_SEPARATOR.'apc.rpc.composer.log'; if(!is_dir(dirname($outputfile))){ mkdir(dirname($outputfile), 0755, true); } if(!file_exists($outputfile)){ file_put_contents($outputfile, ''); } \webfan\hps\patch\Fs::filePrune($outputfile,1024 * 1024, true); $datum = date('c', time()); file_put_contents($outputfile, '@rpc>'.$request->method().' '.$datum, \FILE_APPEND/* | \LOCK_EX*/); $pidfile = tempnam(sys_get_temp_dir(), 'pid.rpc.'.$request->method()); //$cmd = sprintf('%s install --working-dir=%s --no-progress', 'COMPOSER_BIN="'.$config['COMPOSER_PATH'].'" '.(new \webfan\hps\patch\PhpBinFinder())->find().' '.$config['COMPOSER_PATH'], $path); // $cmd = sprintf('%s install --working-dir=%s --no-progress', $config['COMPOSER_PATH'], $path); $cmd = sprintf('%s create-project --working-dir=%s --no-progress', (new \webfan\hps\patch\PhpBinFinder())->find().' -d memory_limit=-1 '.$config['COMPOSER_PATH'], $path); set_time_limit(0); exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile)); $pid = file_get_contents($pidfile); return new \UMA\JsonRpc\Success($request->id(),[ 'pid' => $pid, 'logfile' => $outputfile, ]); } public function getSpec(): ?\stdClass { return \json_decode(<<<'JSON' { "$schema": "https://json-schema.org/draft-07/schema#", "type": ["object"], "properties": { "intent" : { type : ["string", "array"] }, "level" : { type : ["string"] }, "modules_dirname" : { type : ["string"] }, "name" : { type : ["string"] }, "title" : { type : ["string"] }, "jsbase" : { type : ["string"] }, "jsglobal" : { type : ["string"] }, "workspace" : { type : ["string"] }, "ce_baseUrl" : { type : ["string"] }, "ce_dir" : { type : ["string"] }, "database" : { type : ["object", "null"] } }, "required" : ["modules_dirname", "name", "title", "jsbase", "jsglobal", "workspace", "ce_baseUrl", "ce_dir"], "additionalProperties": false } JSON ); // } } __halt_compiler();----SIGNATURE:----VG47PeZNcwn/BC+5VVAWiYeNa0jkd6lCZbIOo3ODqh1xAn/VMewNX5H9wC7DiW7s1X3rUhhh/W4h2w8nW9gMLHpAT3tHqs/fsYgOaAeu1jqEoz71giy0LuUiBnazIkCtF8w4cS6o2Zi7X9QhTz8OX2Z46seMDlIYd6fhTh8rMVWBJsDp97mv5SUvky5vml8P7RykOD9zHXlvO2nTcrWd9iV5qbqD1U1LeQYYwH7Bm+wz7FdVqM2ID4qUI516H8TyOO1aLFyoR3BkPad/he4TsMK+MM7MKeljQHb3I2tWqo9oYgBJsiIV+pgj7L03+M2LmRh58bjMuNsrMbf2P1mnRk35egBozsIJrZtAtI4cmmOJszcnB29zhGoV/Ab8OAfLTZaZWC9pQdIc8HuKCvpEApE98Py4H2ViaecJCmBFy7+zsjnx/Qf8JyMBV6aNQQZueLykTlhOqMRWx9L6nfk0AHb1f2hOaOVdLxFzS0tq/WgoKwEb4xHs0QkywfZsYjDAaFlayr9A9KWHiSfVUFjCtKZ4221ZCkOQKd96Pq7iT04RCIFhvFmt8at5rsFpBEr0Tqr26lf5j/rx8UXpogItRFpgoO+5J527Bb52sLoyWGP1dNMWog+DumoOmnPWezTRQoFOt/fxQut09wjq6N9jMZHZO52cuKPp0b/bxxyMvw4=----ATTACHMENT:----NjUxMzQwNjAyMTc2MDE4NCAzNzAzNDY4MDUwNjY2ODY0IDQ5NDU4ODY4NjMzNTAwOQ==