https://ant.apache.org/manual/Tasks/exec.html */ class Route_Ant extends RouteBase { public $pathTools = APP_PATH_SCHEMA . "/ant-tool/"; public $pathUrlActions = APP_PATH_SCHEMA . "/ant-url_action/"; public $antBin = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant'; public function defaultAction() { UI::gora(); UI::tag('h1', [], 'Ant'); try { $taskList = $this->getAntToolList(); DBG::nicePrint($taskList, 'ant-tool'); $featureID = V::get('featureID', '', $_GET); $namespace = V::get('namespace', '', $_GET); UI::startTag('ul'); foreach ($taskList as $path => $label) { $link = "index.php?_route=Ant&_task=ant&path={$path}"; echo UI::h('li', [], [ UI::h('a', ['href'=>$link], "Uruchom '{$label}'") ]); } UI::endTag('ul'); } catch (Exception $e) { UI::alert('danger', $e->getMessage()); DBG::log($e); } UI::dol(); } public function antAction() { UI::gora(); try { $path = V::get('path', '', $_GET); if (!$path) throw new Exception("Missing Ant path!"); $taskList = $this->getAntToolList(); if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'"); $cmd = "cd {$this->pathTools}{$path} && {$this->antBin} 2>&1";// wymaga java jdk V::exec($cmd, $out, $ret); } catch (Exception $e) { UI::alert('danger', $e->getMessage()); DBG::log($e); } UI::dol(); } public function execAntTool($antTask) { $antList = $this->getAntToolList(); if (!array_key_exists($antTask, $antList)) throw new Exception("ant task not found", 404); throw new Exception("TODO: run ant task '{$antTask}'", 501); } //todo headery xml itp - aby szly z anta do tej funkcji i wysylane byly przez php // /SE/ant.php?antTask=$ jakas nazwa z ant_tool //ant ogolne // public function getAntUrlActionList() { V::exec("ls -1 {$this->pathUrlActions}*/*/build.xml", $out, $ret); $taskList = array(); foreach ($out as $line) { try { if ($this->pathUrlActions != substr($line, 0, strlen($this->pathUrlActions))) throw new Exception("Wrong line prefix '{$line}' - skip"); if ('/build.xml' != substr($line, -1 * strlen('/build.xml'))) throw new Exception("Wrong line suffix '{$line}' - expected '/build.xml' - skip"); } catch (Exception $e) { UI::alert('warning', $e->getMessage()); continue; } $line = substr($line, strlen($this->pathUrlActions)); $name = substr($line, 0, -1 * strlen('/build.xml')); $taskList[$name] = $name;// TODO: $name => $description (read from build.xml file first xml tag ) } return $taskList; } public function getAntToolList() { V::exec("ls -1 {$this->pathTools}*/build.xml", $out, $ret); $taskList = array(); foreach ($out as $line) { try { if ($this->pathTools != substr($line, 0, strlen($this->pathTools))) throw new Exception("Wrong line prefix '{$line}' - skip"); if ('/build.xml' != substr($line, -1 * strlen('/build.xml'))) throw new Exception("Wrong line suffix '{$line}' - expected '/build.xml' - skip"); } catch (Exception $e) { UI::alert('warning', $e->getMessage()); continue; } $line = substr($line, strlen($this->pathTools)); $name = substr($line, 0, -1 * strlen('/build.xml')); $taskList[$name] = $name;// TODO: $name => $description (read from build.xml file first xml tag ) } return $taskList; } public function generatePdfAction() {// TODO: OLD TEST $antPath = V::get('ditaPath', '', $_GET); $idKoresp = V::get('idKoresp', 0, $_POST, 'int'); $doExecute = V::get('doExecute', '', $_POST); $antList = $this->getAntToolList(); if (!array_key_exists($antPath, $antList)) throw new Exception("dita path not found", 404); UI::gora(); UI::startContainer(); try { UI::tag('h1', [], "Dita: '{$antList[$antPath]}'"); UI::startTag('form', ['action'=>"", 'method'=>"POST", 'class'=>'form-inline']); UI::tag('input', ['type'=>'number', 'value'=>$idKoresp, 'class'=>'form-control', 'style'=>'max-width:200px']); UI::tag('input', ['type'=>'hidden', 'name'=>'doExecute', 'value'=>'1']); UI::tag('input', ['type'=>"submit", 'value'=>"Wykonaj", 'class'=>'btn btn-primary']); UI::endTag('form'); if ($doExecute) { // if ($idKoresp <= 0) throw new Exception("Bad Request - missing id koresp"); if ($idKoresp <= 0) UI::alert('danger', "Missing id koresp - using default file"); if ($idKoresp > 0) UI::alert('warning', "TODO: generate xml file for id koresp = {$idKoresp}"); $execPath = APP_PATH_SCHEMA . DS . 'ant' . DS . $antPath; $ant = APP_PATH_WWW . DS . 'stuff' . DS . 'dita-ot-2.3.3' . DS . 'bin' . DS . 'ant'; $cmd = "cd {$execPath} && {$ant} 2>&1";// wymaga java jdk V::exec($cmd, $out, $ret); DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__); } throw new Exception("TODO: F." . __FUNCTION__ . " . L." . __LINE__); } catch (Exception $e) { UI::alert('danger', $e->getMessage()); } UI::endContainer(); UI::dol(); } public function reinstallAction() { UI::gora(); UI::tag('h1', [], 'Reinstall Dita Open Toolkit 2.3.3'); $stuffPath = APP_PATH_WWW . DS . 'stuff'; // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && rm dita-ot-2.3.3.zip || echo PASSED"; // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && wget https://github.com/dita-ot/dita-ot/releases/download/2.3.3/dita-ot-2.3.3.zip -O dita-ot-2.3.3.zip "; // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && rm dita-ot-2.3.3 || echo PASSED"; // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff && unzip dita-ot-2.3.3.zip || echo PASSED"; // $cmd[]['rsh']="cd /Library/Server/Web/Data/Sites/Default/SE/stuff/dita-ot-2.3.3 && ./startcmd.sh || echo PASSED"; $wget = "/opt/local/bin/wget"; $unzip = "/usr/bin/unzip"; // $testCmd = "which unzip"; // V::exec($testCmd, $out, $ret); // DBG::_(true, true, "testCmd: {$testCmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__); // $testCmd = "which wget"; // V::exec($testCmd, $out, $ret); // DBG::_(true, true, "testCmd: {$testCmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__); $cmd = "cd {$stuffPath} ; [ -f dita-ot-2.3.3.zip ] && rm dita-ot-2.3.3.zip"; V::exec($cmd, $out, $ret); DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__); $cmd = "cd {$stuffPath} ; {$wget} https://github.com/dita-ot/dita-ot/releases/download/2.3.3/dita-ot-2.3.3.zip -O dita-ot-2.3.3.zip"; V::exec($cmd, $out, $ret); DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__); $cmd = "cd {$stuffPath} [ -f dita-ot-2.3.3.zip ] && rm dita-ot-2.3.3.zip {$wget} https://github.com/dita-ot/dita-ot/releases/download/2.3.3/dita-ot-2.3.3.zip -O dita-ot-2.3.3.zip [ -d dita-ot-2.3.3 ] && rm -rf dita-ot-2.3.3 {$unzip} dita-ot-2.3.3.zip "; V::exec($cmd, $out, $ret); DBG::_(true, true, "cmd: {$cmd} (return: {$ret})", $out, __CLASS__, __FUNCTION__, __LINE__); } }