"btn btn-link", 'form.class' => "pull-right", 'title' => "Wczytaj ponownie listę dostępnych funkcji", 'data' => [ 'forceUpdate' => '1', ] ]); UI::tag('h1', [], 'Ant'); try { $taskList = $this->getAntUrlActionList(); // $featureID = V::get('featureID', '', $_GET); $primaryKey = V::get('primaryKey', '', $_GET, 'word'); $typeName = V::get('typeName', '', $_GET, 'word'); if (empty($typeName)) throw new Exception("Missing typeName"); if (empty($primaryKey)) throw new Exception("Missing primaryKey"); $parsedInfo = Core_AclHelper::parseTypeName($typeName); DBG::log($parsedInfo, '', "Ant parseTypeName({$typeName})"); $acl = ACL::getAclByNamespace("{$parsedInfo['url']}/{$parsedInfo['name']}"); $pkField = $acl->getPrimaryKeyField(); UI::startTag('ul'); foreach ($taskList as $path => $label) { echo UI::h('li', [], [ UI::h('a', [ 'class' => 'btn btn-md btn-link', 'href' => $this->getLink('ant', [ 'path' => $path, 'typeName' => $typeName, 'primaryKey' => $primaryKey, 'primaryKeyField' => $pkField ]) ], "Uruchom '{$label}'") ]); $tmpls = $this->getAntUrlActionTemplates($path); if (!empty($tmpls)) { foreach ($tmpls as $tmpl => $labelTmpl) { echo UI::h('div', [ 'style' => "padding-left: 50px" ], [ UI::h('a', [ 'href' => $this->getLink('ant', [ 'path' => $path, 'template' => $tmpl, 'typeName' => $typeName, 'primaryKey' => $primaryKey, 'primaryKeyField' => $pkField ]), // TODO: 'onclick' => 'return p5UI_runWPSAsyncJob(event, this)', 'class' => 'btn btn-sm btn-link', ], ' ' . $labelTmpl) ]); } } } UI::endTag('ul'); } catch (Exception $e) { UI::alert('danger', $e->getMessage()); DBG::log($e); } UI::endContainer(); UI::dol(); } public function outputAction() {// index.php?_route=UrlAction_Ant&_task=output & path={$path} & file={$file}"; $path = V::get('path', '', $_GET); if (!$path) throw new Exception("Missing Ant path!"); $file = V::get('file', '', $_GET); if (!$file) throw new Exception("Missing Ant file!"); // TODO: allow auth by token? throw new Exception("TODO: return output file '$file' from ant task '{$path}'"); } public function antAction() { UI::gora(); UI::startContainer(); try { $path = V::get('path', '', $_GET); if (!$path) throw new Exception("Missing Ant path!"); $typeName = V::get('typeName', '', $_GET); if (!$typeName) throw new Exception("Missing typeName"); $primaryKey = V::get('primaryKey', '', $_GET); if (!$primaryKey) throw new Exception("Missing primaryKey"); $pkField = V::get('primaryKeyField', '', $_GET); if (!$pkField) throw new Exception("Missing primaryKeyField"); // list($nsPrefix, $objectName) = explode(':', $typeName);// TODO: get wfs prefix from typeName $parsedInfo = Core_AclHelper::parseTypeName($typeName); DBG::log($parsedInfo, '', "Ant parseTypeName({$typeName})"); $nsPrefix = $parsedInfo['prefix']; $objectName = $parsedInfo['name']; $template = V::get('template', '', $_GET); $confirmAntfile = V::get('confirmAntfile', '', $_GET); $confirmAntfileTarget = V::get('confirmAntfileTarget', '', $_GET); // TODO: validate missing ... DBG::log($_GET, 'array', '$_GET'); DBG::log([ 'msg'=>'$path', '$path'=>$path]); DBG::log([ 'msg'=>'$primaryKey', '$primaryKey'=>$primaryKey]); DBG::log([ 'msg'=>'$typeName', '$typeName'=>$typeName]); $taskList = $this->getAntUrlActionList(); if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'"); echo UI::h('h3', [], [ "Druk", '
', UI::h('small', [], $taskList[$path]) ]); echo UI::h('hr'); $webRootUrl = Request::getPathUri() . "schema/ant-url_action/{$path}";// TODO: security - only for test $outputFunctionUrl = $this->getLink('output') . "&path={$path}&file="; $antFunctionUrl = $this->getLink('ant') . "&path={$path}&file={$file}&template={$template}&typeName={$typeName}&primaryKey={$primaryKey}&primaryKeyField={$pkField}"; // &confirmAntfile={$confirmAntfile}&confirmAntfileTarget={$confirmAntfileTarget} sdo confirmacji potrzebne - wzglednie przetwarzac z tresci output URL_TASK - ale potrzebne parametry analogiczne aby chodzily DBG::log([ 'msg'=>'$webRootUrl', '$webRootUrl'=>$webRootUrl]); DBG::log([ 'msg'=>'$outputFunctionUrl', '$outputFunctionUrl'=>$outputFunctionUrl]); $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$typeName}&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";// &REQUEST=GetFeature // $testUrl = Request::getPathUri() . "wfs-data.php" ;// &REQUEST=GetFeature $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH'])); $uniqID = date("Y-m-d-H_i_s") . substr(md5(time()), 0, 6);// TODO: uniq id for every request // $cmd = "{$this->pathUrlActions}/{$path}/do_build.sh"; $cmd = "cd {$this->pathUrlActions}/{$path} && ant -S"; // ant -silent, -S print nothing but task outputs and build failures // ant -D= use value for given property // ant -propertyfile load all properties from file with -D properties taking precedence // TODO: mv to build.properties file @see https://dzone.com/tutorials/java/ant/ant-properties-file.html // ant -propertyfile build.properties $cmd .= " -DoutputFunctionUrl='{$outputFunctionUrl}'"; $cmd .= " -DantFunctionUrl='{$antFunctionUrl}'"; if( strlen($confirmAntfile) > 0 ) $cmd .= " -DconfirmAntfile={$confirmAntfile}"; if( strlen($confirmAntfileTarget) > 0 ) $cmd .= " -DconfirmAntfileTarget={$confirmAntfileTarget}"; $cmd .= " -DwebRootUrl='{$webRootUrl}'"; // $cmd .= " -Durl='{$testUrl}'"; nie mozna tego uzywac, bo nadpisuje property w funkcji build_get_wfs.xml $cmd .= " -DpasswordBase64Basic=\"{$cryptedPass}\""; $cmd .= " -Duuid=\"{$uniqID}\""; $cmd .= " -Dphp_session_id=\"" . session_id() . "\""; $cmd .= " -Dxpath={$pkField}"; $cmd .= " -Dxpath_value={$primaryKey}"; $cmd .= " -Dtemplate={$template}"; $cmd .= " -Dapi_url=".Request::getPathUri()."wfs-data.php"; //potrzebuje ten parametr do dzialania w AMS itp $cmd .= " -DtypeName=\"{$typeName}\""; if ($template) $cmd .= " {$template} "; $cmd .= " 2>&1"; $pathCmd = []; $pathCmd[] = '/opt/local/bin/ant'; $pathCmd[] = '/bin'; $pathCmd[] = '/usr/bin'; $pathCmd[] = '/usr/local/bin'; $pathCmd[] = '/opt/local/bin'; $pathCmd[] = '/sbin'; $pathCmd[] = '/usr/sbin'; $pathCmd[] = '/opt/local/sbin/skrypty'; $pathCmd[] = '/opt/local/var/macports/software'; $pathCmd[] = '/Applications/Server.app/Contents/ServerRoot/usr/bin'; $pathCmd[] = '/Applications/Server.app/Contents/ServerRoot/usr/sbin'; $cmd = 'export PATH=' . implode(':', $pathCmd) . "\n" . 'JAVA_HOME="/usr/bin/java"' . "\n" . 'MAVEN_OPTS="-Xms256m -Xmx512m"' . "\n" . $cmd; $useShellExec = true; if (User::isAdmin()) { echo UI::h('details', [], [ UI::h('summary', [ 'style' => "padding:3px 8px;border:1px solid #ccc;background-color:#282c34;color:#de6b74;font-size:small" ], "DBG: command"), UI::h('div', [ 'style' => "padding:12px; background:#282c34;" ], [ UI::h('pre', [], $cmd), ]), ]); } if ($useShellExec) $out = shell_exec($cmd); else V::exec($cmd, $out, $ret); DBG::log([ 'msg'=>"cmd and returns({$ret})", 'output'=>$out, 'cmd'=>str_replace(APP_PATH_ROOT, 'SE', $cmd) ]); if (empty($out)) throw new Exception("Empty output"); if ($useShellExec) $out = explode("\n", $out); $outputType = 'HTML'; $html = []; $startRead = false; foreach ($out as $line) { if (!$startRead) { if ('OUTPUT__TYPE__XML' == $line) $outputType = 'XML'; if ('OUTPUT__TYPE__HTML' == $line) $outputType = 'HTML'; if ('OUTPUT__START' == $line) { $startRead = true; continue; } } else { if ('"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html); } } } catch (Exception $e) { UI::alert('danger', $e->getMessage()); DBG::log($e); } UI::endContainer(); UI::dol(); } }