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(); $params = $request->params(); $AppShield = $this->AuthShield->getAppShield(); $config = $AppShield->config->export(); if(!isset($config['COMPOSER_PATH'])){ return new \UMA\JsonRpc\Error($request->id(), 'Composer is not setup correctly'); } if(!property_exists($params, 'dir')){ return new \UMA\JsonRpc\Error($request->id(), 'No `dir` specified'); } $path = str_replace('//', '/', $params->dir); $path = str_replace('/', \DIRECTORY_SEPARATOR, $path); $path = str_replace('composer.json', '', $path); $original_path=$path; if(!is_dir($path)){ $path = $config['wsdir'] . $original_path; } if(!is_dir($path)){ $path = $config['wsdir'] . \DIRECTORY_SEPARATOR . $original_path; } if(!is_dir($path)){ $path = $config['wsdir'] . 'frdl-projects' . $original_path; } if(!is_dir($path)){ $path = $config['wsdir'] . 'frdl-projects' . \DIRECTORY_SEPARATOR . $original_path; } if(!is_dir($path)){ return new \UMA\JsonRpc\Error($request->id(), '`dir` does not exist'); } chdir($path); $composer = json_decode(file_get_contents('composer.json')); if(!isset($composer->config))$composer->config=new \stdclass; if(!isset($composer->config->platform))$composer->config->platform=new \stdclass; $composer->config->platform->php = \PHP_VERSION; $composer->{'minimum-stability'} = 'dev'; //if(isset($composer->{'minimum-stability'}))unset($composer->{'minimum-stability'}); file_put_contents('composer.json', json_encode($composer, \JSON_PRETTY_PRINT)); $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*/); // --optimize-autoloader $pidfile = tempnam(sys_get_temp_dir(), 'pid.rpc.'.$request->method()); if(!property_exists($params, 'package')){ //exec(sprintf('%s update --working-dir=%s --no-progress 2>&1 ', $config['COMPOSER_PATH'], $path), $out, $status); $cmd = sprintf('%s update --working-dir=%s --no-progress', (new \webfan\hps\patch\PhpBinFinder())->find().' -d memory_limit=-1 '.$config['COMPOSER_PATH'], $path); }else{ //exec(sprintf('%s update %s --with-dependencies --working-dir=%s --no-progress 2>&1 ', $config['COMPOSER_PATH'], $params->package, $path), $out, $status); $cmd = sprintf('%s update %s --with-dependencies --working-dir=%s --no-progress 2>&1 ', (new \webfan\hps\patch\PhpBinFinder())->find().' -d memory_limit=-1 '.$config['COMPOSER_PATH'], $params->package, $path); } // set_time_limit(0); exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile)); $pid = file_get_contents($pidfile); unlink($pidfile); return new \UMA\JsonRpc\Success($request->id(),[ 'pid' => intval($pid), 'logfile' => $outputfile, ]); } public function getSpec(): ?\stdClass { return \json_decode(<<<'JSON' { "$schema": "https://json-schema.org/draft-07/schema#", "type": ["object"], "properties": { "dir" : { type : ["string"] }, "package" : { type : ["string"] } }, "required" : ["dir"], "additionalProperties": false } JSON ); } } __halt_compiler();----SIGNATURE:----flrD8UQUA/Ebha1mVT/SjpGNPgR4CGE1xhdycRcU9ZBItwZ9G7GO9ihAQDoUZoF64X5nmSE8wnV+SG4W0O2nPnHqv84cgU2ar1QAZdUZ/HSrjmr2MaYgrnTwVnj1BQmCHobv7jaTJht6OOBY/9PjX+jaXRj5KWp85dfn7/VvTKmtzfHrJB/JAk/AG+WIVANLVlGcrQs2fMQI0YDCfwb0sy5VYiaAq0s8sltW3DQBqxELzRk5QysbVdfW+dOVACozb4/gUYH1Oqgl9Xm8iHb+84mEt9tHXns9s52Z3b3780Kla4GrOJJXWvloIhjBZXjY2iReAA7eWVsfOlEYZZn/Tpn/JX1Dxo19OVgZViFFAe5r5QvVkx891ebpGlkddM+f/TCkrfdJXfgOxKfwdOE/ipKkBAINosATdyXGVnC2uG5jiUZub3Qpyc+SMHlEf0enoiiL815R8gK6QdvomfEte55UfOqqYfRF0pFynJwdxA9l3FKp/RatqWxHphHOGimnomTJmdh+RMOi4t3Hvu4EFXMH0CF7YLb/lJwh7+CPDNq1b1yqPkd9zrytk3nuTYsZ+kW0/ceAk4DJI1AO3a2KOYqg6hPJ+JnfoZpP+TjmR8Ym5+5Dyw9WFMqSvu7YeK8xRhi6950UadlNQZ/kb7jLjDV+qYIKmfPD0TLL+VkLqCk=----ATTACHMENT:----OTY4OTgwNzYzNTEzMjU5MSA5MDYwNzM4MDc2NDQ1MDE3IDI5NjY2MDYyNTcyMDMzMzY=