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 { $this->params = $request->params(); set_time_limit(300); $this->params->dir = rtrim($this->params->dir, \DIRECTORY_SEPARATOR.'/ '); $this->NODE_FILE = basename($this->params->url); if(!is_dir($this->params->dir)){ // return new \UMA\JsonRpc\Error($request->id(), sprintf('Directory %s does not exist', $this->params->dir)); mkdir($this->params->dir, 0755, true); } $AppShield = $this->AuthShield->getAppShield(); $config = $AppShield->config->export(); $this->cwd = getcwd(); chdir($this->params->dir); $i = $this->node_install(); chdir($this->cwd); if(true !== $i ){ return new \UMA\JsonRpc\Error($request->id(), $i); } $f = str_replace('.tar.gz', '', $this->NODE_FILE); $f = str_replace('.tar.xz', '', $f); $nodefile = $this->params->dir . \DIRECTORY_SEPARATOR . $f . \DIRECTORY_SEPARATOR .'bin'.\DIRECTORY_SEPARATOR.'node'; return new \UMA\JsonRpc\Success($request->id(), $nodefile); } protected function node_install() { $fp = fopen($this->NODE_FILE, "w"); flock($fp, \LOCK_EX); $curl = curl_init($this->params->url); curl_setopt($curl, \CURLOPT_HEADER, 0); curl_setopt($curl, \CURLOPT_FILE, $fp); $resp = curl_exec($curl); curl_close($curl); flock($fp, \LOCK_UN); fclose($fp); if(true !== $resp){ return 'Could not download '.$this->params->url.' to '.$this->NODE_FILE; } // $f = str_replace('.tar.gz', '', $this->NODE_FILE); // $f = str_replace('.tar.xz', '', $f); // passthru("tar -xzf " . $this->NODE_FILE . " 2>&1 && mv ". $f . " " . $this->params->dir . " && touch nodepid && rm -f " . $this->NODE_FILE, $ret, $out); passthru("tar -xzf " . $this->NODE_FILE . " && rm -f " . $this->NODE_FILE." 2>&1", $ret); if(0!==$ret){ return 'Could not install '.$this->NODE_FILE.' '.print_r($ret, true).' '.print_r($out, true); } // if(!file_exists($this->params->dir.\DIRECTORY_SEPARATOR.'bin'.\DIRECTORY_SEPARATOR.'node')){ // return 'Could not write node'; // } return true; } public function getSpec(): ?\stdClass { return \json_decode(<<<'JSON' { "$schema": "https://json-schema.org/draft-07/schema#", "type": ["object"], "properties": { "dir" : { type : ["string"] }, "url" : { type : ["string"] } }, "required" : ["dir", "url"], "additionalProperties": false } JSON ); } } __halt_compiler();----SIGNATURE:----aSeSpwJiDqzcSyvaH5MGhLSs9TBVa4o1ih0V0nYnkcBL3NdtKiAlofUbq/E+Ra5yO+R9e6C3y4V4ErFrIV4HxZg3Ko7LWZkeeOTcnFIGNZz4io138INw73sxV2s+iaQkKZL5+04RKi0pEPU/6h1qY58dnJTe7SiXex8l0248CrvI5N85anzoSTatwbExDsEl/NNXXJxWSXhocOBofT0jaCkvdg2X7QtoshI7EN7fw0wxF98p2dZLOMoWgRJvqlqJlMcxgfVEH5BT7u11wP50nUEfxYFrO+4unIeRxjKlx0o+lmZ//fTw99ExdoDNJC1defzm7VNpTheZvrJeMbsCvu93VxHw6Rcjuburx0sgoNcpC4iuxq1XePfLLd0SWLCnNLuToBdLIM4nPuXrpLna7cDcL26lcl2nk8xFar7B+877JEZTGT6or11aTfKXwtDsjxKVJrjV6AEaIXk9Hk991korSiYBFBOmgUFWt++n+pMkkobBIcWKjFXKryfGwr+euwJA+ZOO5PsshxONTmyMswUcloIpRotL0U5j+V5SC9tXEqamosoSRx4PRE32JIpbxfWeJSd2oXOS2+Vee1+Oq9zkc/JWHXVZOA8NkbJd+8g2xjuDpnGq1r8OqwRO1OgfLnLp3ROUfle4u0eELPqZ2vugNX2MIBtKX38hGKldx2o=----ATTACHMENT:----OTc1Mjc1ODM4NjU2MDAwNiAxOTQ1NDYyNDI0Mjk3MDg5IDU1MDM4OTU4NDc2OTE0NzI=