Ant.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. Lib::loadClass('UI');
  4. Lib::loadClass('DBG');
  5. Lib::loadClass('Request');
  6. Lib::loadClass('Crypt');
  7. Lib::loadClass('Route_Ant');
  8. class Route_UrlAction_Ant extends Route_Ant {// @doc @see Route_Ant
  9. public function defaultAction() {
  10. UI::gora();
  11. UI::tag('h1', [], 'Ant');
  12. try {
  13. $taskList = $this->getAntUrlActionList();
  14. DBG::nicePrint($taskList, 'ant-url_action');
  15. $featureID = V::get('featureID', '', $_GET);
  16. $typeName = V::get('typeName', '', $_GET);
  17. // TODO: validate missing ...
  18. UI::startTag('ul');
  19. foreach ($taskList as $path => $label) {
  20. $link = "index.php?_route=UrlAction_Ant&_task=ant&path={$path}&typeName={$typeName}&featureID={$featureID}";
  21. echo UI::h('li', [], [
  22. UI::h('a', ['href'=>$link], "Uruchom '{$label}'")
  23. ]);
  24. }
  25. UI::endTag('ul');
  26. } catch (Exception $e) {
  27. UI::alert('danger', $e->getMessage());
  28. DBG::log($e);
  29. }
  30. UI::dol();
  31. }
  32. public function outputAction() {// index.php?_route=UrlAction_Ant&_task=output & path={$path} & file={$file}";
  33. $path = V::get('path', '', $_GET);
  34. if (!$path) throw new Exception("Missing Ant path!");
  35. $file = V::get('file', '', $_GET);
  36. if (!$file) throw new Exception("Missing Ant file!");
  37. // TODO: allow auth by token?
  38. throw new Exception("TODO: return output file '$file' from ant task '{$path}'");
  39. }
  40. public function antAction() {
  41. UI::gora();
  42. try {
  43. echo UI::h('h1', [], "Ant action");
  44. $path = V::get('path', '', $_GET);
  45. if (!$path) throw new Exception("Missing Ant path!");
  46. $featureID = V::get('featureID', '', $_GET);
  47. $typeName = V::get('typeName', '', $_GET);
  48. $typeName_dot = explode(':', $typeName);// TODO: get wfs prefix from typeName
  49. // TODO: validate missing ...
  50. DBG::nicePrint($path, '$path');
  51. DBG::nicePrint($featureID, '$featureID');
  52. DBG::nicePrint($typeName, '$typeName');
  53. $taskList = $this->getAntUrlActionList();
  54. if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'");
  55. echo UI::h('hr');
  56. $webRootUrl = Request::getPathUri() . "schema/ant-url_action/{$path}";// TODO: security - only for test
  57. $outputFunctionUrl = Request::getPathUri() . "index.php?_route=UrlAction_Ant&_task=output&path={$path}&file=";
  58. DBG::nicePrint($webRootUrl, '$webRootUrl');
  59. DBG::nicePrint($outputFunctionUrl, '$outputFunctionUrl');
  60. $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=".$typeName."&SRSNAME=EPSG:3003&featureID=".$typeName_dot[1].".".$featureID ;
  61. $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
  62. $cmd = "cd {$this->pathUrlActions}{$path} && {$this->antBin} -S -DoutputFunctionUrl='{$outputFunctionUrl}' -DwebRootUrl='{$webRootUrl}' -Durl='{$testUrl}' -DpasswordBase64Basic='{$cryptedPass}' 2>&1";
  63. DBG::nicePrint(str_replace(APP_PATH_ROOT, 'SE', $cmd), 'command');
  64. V::exec($cmd, $out, $ret);
  65. DBG::nicePrint($out, 'output');
  66. $html = []; $startRead = false;
  67. foreach ($out as $line) {
  68. if (!$startRead) {
  69. if ('OUTPUT__START' == $line) {
  70. $startRead = true;
  71. continue;
  72. }
  73. } else {
  74. if ('<!DOCTYPE' == substr($line, 0, strlen('<!DOCTYPE'))) continue;
  75. if ('OUTPUT__END' == $line) {
  76. break;
  77. }
  78. $html[]= $line;
  79. }
  80. }
  81. echo UI::h('h3', [], "output:");
  82. if (empty($html)) UI::alert('danger', "Empty output!");
  83. echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
  84. } catch (Exception $e) {
  85. UI::alert('danger', $e->getMessage());
  86. DBG::log($e);
  87. }
  88. UI::dol();
  89. }
  90. }