tags = $procedure->getTags(); } if(method_exists($procedure,'getExternalDocs') ){ $method->externalDocs = $procedure->getExternalDocs(); } if(method_exists($procedure,'getDeprecated') ){ $method->deprecated = $procedure->getDeprecated(); } if(method_exists($procedure,'getErrors') ){ $method->errors = $procedure->getErrors(); } if(method_exists($procedure,'getParamStructure') ){ //"by-name" | "by-position" | "either" $method->paramStructure = $procedure->getParamStructure(); } if(method_exists($procedure,'getServers') ){ $method->servers = $procedure->getServers(); } } $procedure = $this->server->getContainer()->get($serviceId); $method = new \stdclass; $method->name = $method_name; // $method->params = $procedure->getSpec(); if($procedure instanceof MethodDiscoverableInterface){ $method->params = $procedure->getParametersSpec(); $method->result = $procedure->getResultSpec(); if($procedure->getSummary()){ $method->summary = $procedure->getSummary(); } if($procedure->getDescription()){ $method->description = $procedure->getDescription(); } $examples = $procedure->getExamples(); if($examples){ $method->examples = $examples; } $links = $procedure->getLinks(); if($links){ $method->links = $links; } $procedure->discover($this); */ class frdl_project_create_2 implements ProcedureInterface { protected $AuthShield; protected $container; public function __construct(\Webfan\App\Rpc\AuthShield $AuthShield, \Psr\Container\ContainerInterface $container = null){ $this->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)); } $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); } $check = 'installcheck '.$params->name.' '.$time.' '.sha1($httpdocs); $checkFile = $time.'.frdl-project-create-check'; if(!file_put_contents($httpdocs.$checkFile, $check )){ return new \UMA\JsonRpc\Error($request->id(), 'Could not create installcheck (in httpdocs directory)!'); } $_checkVal = file_get_contents($params->ce_baseUrl.$checkFile); // 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); 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!'); } chdir($wsdir); if(!is_dir($wsdir.'frdl-projects')){ mkdir('frdl-projects', 0755, true); } chdir('frdl-projects'); mkdir($params->name, 0755, true); chdir($params->name); $projectDirectory = getcwd(); $params->ce_dir = \webfan\hps\patch\Fs::getRelativePath($projectDirectory, $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); $json = json_encode($p); 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!'); } mkdir('config', 0755, true); mkdir('dist', 0755, true); mkdir('web', 0755, true); mkdir('log', 0755, true); mkdir('data', 0755, true); mkdir('backup', 0755, true); mkdir('backup.restore', 0755, true); mkdir('compiled', 0755, true); mkdir('compiled.blue', 0755, true); mkdir('compiled.green', 0755, true); mkdir('themes', 0755, true); mkdir($params->modules_dirname, 0755, true); /* $composer= <<=7.2", "oomphinc/composer-installers-extender" : "1.1.2", "frdl/web": "*" $requireDbString }, "extra": { "installer-types": ["frdl-theme", "frdl-module", "frdl-httpdocs", "vendor"], "installer-paths": { "$modules_dirname/{\$vendor}.{\$name}/": ["type:frdl-module"], "themes/{\$vendor}/{\$name}/": ["type:frdl-theme"], "$ce_dir{\$vendor}/{\$name}/": ["type:frdl-httpdocs"], "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" } }, "autoload": { "psr-4": { "compiled\\\": "compiled\/" } } } JSONCODE; file_put_contents('composer.json', $composer ); */ //php composer.phar create-project doctrine/orm path "2.2.*" $outputfile = rtrim($projectDirectory, \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 create-project --working-dir=%s --no-progress', $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, ]); 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); } public function getParametersSpec(): ?array { return []; } public function getExamples(): ?array { return []; } public function getLinks(): ?array { return []; } public function getSummary(): ?string { return 'Method as specified in https://spec.open-rpc.org/'; } public function getDescription(): ?string { return "Returns an OpenRPC schema as a description of this service"; } /** * {@inheritdoc} */ public function discover(MethodDiscoverableInterface $DiscoverMethod) : void { } public function getResultSpec(): ?\stdClass { return \json_decode(' { "schema": "https://raw.githubusercontent.com/open-rpc/meta-schema/master/schema.json", "name" : "OpenRPC Document" } ' ); } public function getSpec(): ?\stdClass { return \json_decode(<<<'JSON' { "$schema": "https://json-schema.org/draft-07/schema#", "type": ["object"], "definitions": { "frdlwebTemplatePackage": { "enum": [ "frdl/project", "frdl/module", "frdl/theme", "frdl/httpdocs", "frdl/extension" ] }, "stringList": { "type": "array", "items": { "type": "string" }, "uniqueItems": true, "default": [] } }, "properties": { "template": { "anyOf": [ { "$ref": "#/definitions/frdlwebTemplatePackage" }, { "type": "array", "items": { "$ref": "#/definitions/frdlwebTemplatePackage" }, "minItems": 1, "uniqueItems": true } ] }, "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" : ["template", "modules_dirname", "name", "title", "jsbase", "jsglobal", "workspace", "ce_baseUrl", "ce_dir"], "additionalProperties": false } JSON ); // } } __halt_compiler();----SIGNATURE:----Zos2GfO4vYDXJt/obCacQcCaAUXO2m2BaDK9MENQIeNc5kCyhg7d5ZeoFqZmXbi0tp7RBDZU3FkLrDPNN3HABFaw1eoLo4eSbwO0FYuCm7sibscxh4x9J2st8Xw01MQY3XrXBXO+HnBRmkBByjBLTYLR4ddq6RRuZJwVTc82AO3QMJFVJAwFsycyKBQR4vXdyd2nt9SkVyeyyDUscb6mLwtaqJ+aLn2m866MwcpKTfdaQ2/fSVWxctTJWieOMRo3jPTJwSuRrofXWLMJNCbnUmX99CIbVTDO9J5qeNKIRmV54BZige/WA8PKxFSS9Xbc2k6msiNGbWI8lpVwTg/3ypZ8SArxGT2UEeXszcqv3sFas5Q8Or5TcXjvx1IQeHXK/pR/35CDz46X8Wh2ySkurUyXFMPjhE5zXuRpN+//2BAdp0dlwDHwTECfHK77f7TUbfr8Oe+9vm9MfdxtT1hcl+YeUfHuP/f45TIXqlPPn9FJ9rNk8Hr6EcqX16Q+5zIyghNfuQ7q1yxih0QWugu6Clfd6ZGvf+qh1y6yxRSiOdj83K4UR0IlyJ1u52HZPgMPOUn4LDniy/pxJS3uAUfbK6kREVZDvfxmGZbzYDtWRsMKXK1RbFtQx/qpXrdmZxWyT7X6vtv0eNeUP+bR7sen1wOJojJqPAKEvasY67sQYZw=----ATTACHMENT:----NDA4MTUwMTM4MzQxMzgxMyAzMDAzMzQyNzc1NDIxMzk5IDYwOTk2MjUxNTk4MDUxNTc=