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 { $params = $request->params(); if(function_exists('exec')){ exec('which composer',$out_wich_composer, $status_wich_composer); }else{ return new \UMA\JsonRpc\Error($request->id(), 'Function exec is not available'); } if(!$status_wich_composer){ // return new \UMA\JsonRpc\Error($request->id(), 'An global Composer installation is available already'); } if(isset($params->path) && !is_dir($params->path)){ mkdir($params->path, 0775, true); } if(!isset($params->path) || !is_dir($params->path) || !is_writable($params->path) ){ return new \UMA\JsonRpc\Error($request->id(), 'Path '.((!isset($params->path)) ? '' : $params->path).' is not writable!'); } $installerFilename = rtrim($params->path, \DIRECTORY_SEPARATOR.' ').\DIRECTORY_SEPARATOR."composer-installer.php"; chdir(dirname($installerFilename)); $composer_installer_content = file_get_contents('https://getcomposer.org/installer'); file_put_contents($installerFilename, $composer_installer_content); exec(sprintf('%s %s %s 2>&1', (new \webfan\hps\patch\PhpBinFinder())->find(), $installerFilename, '--install-dir='.dirname($installerFilename).' --filename=composer.phar'), $out, $status); if($status){ return new \UMA\JsonRpc\Error($request->id(), implode("\n", $out)); } unlink($installerFilename); return new \UMA\JsonRpc\Success($request->id(), $out); /* $composer_installer_content = file_get_contents('https://getcomposer.org/installer'); // $find = array('#!/usr/bin/env php', 'exit(','print'); $find = array('#!/usr/bin/env php', 'exit(', '$error = sprintf(\'', '$error = sprintf($', 'printf($format, $text);'); //$replace = array('', 'return(','//print'); $replace = array('', 'return(', '//$error = sprintf(\'', '//$error = sprintf($', '//printf($format, $text);'); $new_composer_installer_content = str_replace($find,$replace, $composer_installer_content); file_put_contents($installerFilename, $new_composer_installer_content); $argv = array( '--install-dir='.dirname($installerFilename), '--filename=composer.phar', // '--version=1.0.0-alpha8' ); $target_file = dirname($installerFilename).\DIRECTORY_SEPARATOR."composer.phar"; // try{ ob_start(); error_reporting(\E_PARSE | \E_USER_ERROR); $result = require $installerFilename; $c = ob_get_contents(); if(!file_exists($target_file)){ return new \UMA\JsonRpc\Error($request->id(), sprintf('Error creating %s', $target_file)); } $AppShield = $this->AuthShield->getAppShield(); $config = $AppShield->config->export(); $config['COMPOSER_PATH'] = $target_file; $AppShield->setConfig($config, true, true); //}catch(\Exception $e){ // return new \UMA\JsonRpc\Error($request->id(), $e->getMessage()); //} unlink($installerFilename); return new \UMA\JsonRpc\Success($request->id(), [$result, $c]); */ /* function install($file){ $argv = array( // '--install-dir=../', // '--filename=composer.phar', // '--version=1.0.0-alpha8' ); include_once($file); } $installerFilename = "composer-installer.php"; $composer_installer_content = file_get_contents('https://getcomposer.org/installer'); $find = array('#!/usr/bin/env php', 'exit(','print'); $replace = array('', 'return(','//print'); $new_composer_installer_content = str_replace($find,$replace, $composer_installer_content); file_put_contents($installerFilename, $new_composer_installer_content); $return = install($installerFilename); */ } public function getSpec(): ?\stdClass { return \json_decode(<<<'JSON' { "$schema": "https://json-schema.org/draft-07/schema#", "type": ["object"], "properties": { "path" : { type : ["string"] } }, "required" : ["path"], "additionalProperties": true } JSON ); } } __halt_compiler();----SIGNATURE:----CsakR6N3lPfD4v/hhhYaUCdz5H1RPNL2v1Fr3QlvXboQuuLVHKxLXrBaotEupGHapip3r1qEFV/wbohlK9Xoqp3M2Hrqhys69OwuSdF2eJyx6EanrKiMjljPhIWHHOMJoNHX8d5yVs7m/JkNC4ESy1qv82cxykEg1bYzKriSwSWga69qtBGcdRvSZbWiGfcEKx/XMc1ifn7r1+nzvzKZTv+NDkTpFouZPLzSFMjTfJn8SiQz1QSEzePRgpR0KoAZt4CMb5XsyGaBYJoH/k+xXukJOTJ/ziZyC5hCE0qkVWxJmr6nsasqcOubjDEhno7ixAK3bDQ5WBPEL4x/qtzLmk84Wzn5dpaxPAbeVKOdobdMC3OaChYDP41BxpShrDIZK2+oZBq/1s/Y4z+aLYNpSULhesGYYBjQPqRctqAKEac2VB7BqZXej7te5sWSr5oJrWPsJuL/+ZoqQoEcFsAuBGW0+mIlfTJLwxM7b01eXdZOYvczavUVXODKt14m1NsX655XYuIDa8s33x+0VQTg/RuhrLviLrpP3bgjS7+w80QhEgGA/Ynvfnqyybf+Mu266hKLVcZSQB55GGjD3JVuMZgpzOsIVeAD7Rq6TGAXeeHvxnoNi8O+KVUstHFPfxOSE3721LN+8TEOfD43BGBBldDvAdXC5QXiapjkc5NyhUE=----ATTACHMENT:----NzU1OTIyNzM5NDcyMjIwNCA5NTc3MzExMDMwMTM2MTA3IDE2NTM4Nzg5MzU5OTQxNDg=