| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- Lib::loadClass('RouteBase');
- Lib::loadClass('UI');
- Lib::loadClass('DBG');
- Lib::loadClass('Request');
- Lib::loadClass('Crypt');
- Lib::loadClass('Route_Ant');
- class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
- public function handleAuth() {
- if (!User::logged()) {
- User::authByRequest();
- }
- session_write_close();
- }
- public function defaultAction() {
- UI::gora();
- UI::menu();
- UI::startContainer();
- 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
- ]),
- 'class' => 'btn btn-sm btn-link',
- ], '<i class="glyphicon glyphicon-arrow-right"></i> ' . $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);
- // 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",
- '<br>',
- 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=";
- 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";
- $cmd .= " -DoutputFunctionUrl='{$outputFunctionUrl}'";
- $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 .= " -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 ($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 ('<!DOCTYPE' == substr($line, 0, strlen('<!DOCTYPE'))) continue;
- if ('OUTPUT__END' == $line) {
- break;
- }
- $html[]= $line;
- }
- }
- if (empty($html)) UI::alert('danger', "Empty output!");
- else {
- if ('XML' == $outputType) {
- echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
- } else if ('HTML' == $outputType) {
- echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
- }
- }
- } catch (Exception $e) {
- UI::alert('danger', $e->getMessage());
- DBG::log($e);
- }
- UI::endContainer();
- UI::dol();
- }
- }
|