Ant.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. $namespace = V::get('namespace', '', $_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}&namespace={$namespace}&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 antAction() {
  33. UI::gora();
  34. try {
  35. echo UI::h('h1', [], "Ant action");
  36. $path = V::get('path', '', $_GET);
  37. if (!$path) throw new Exception("Missing Ant path!");
  38. $featureID = V::get('featureID', '', $_GET);
  39. $namespace = V::get('namespace', '', $_GET);
  40. $namespace_dot = explode(':', $namespace);
  41. // TODO: validate missing ...
  42. DBG::nicePrint($path, '$path');
  43. DBG::nicePrint($featureID, '$featureID');
  44. DBG::nicePrint($namespace, '$namespace');
  45. $taskList = $this->getAntUrlActionList();
  46. if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'");
  47. echo UI::h('hr');
  48. // $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=p5_default_db:TEST_PERMS&SRSNAME=EPSG:3003&featureID=TEST_PERMS.63";
  49. $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=".$namespace."&SRSNAME=EPSG:3003&featureID=".$namespace_dot[1].".".$featureID ;
  50. $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
  51. $cmd = "cd {$this->pathUrlActions}{$path} && {$this->antBin} -S -Durl='{$testUrl}' -DpasswordBase64Basic='{$cryptedPass}' 2>&1";
  52. DBG::nicePrint(str_replace(APP_PATH_ROOT, 'SE', $cmd), 'command');
  53. V::exec($cmd, $out, $ret);
  54. DBG::nicePrint($out, 'output');
  55. $html = []; $startRead = false;
  56. foreach ($out as $line) {
  57. if (!$startRead) {
  58. if ('OUTPUT__START' == $line) {
  59. $startRead = true;
  60. continue;
  61. }
  62. } else {
  63. if ('<!DOCTYPE' == substr($line, 0, strlen('<!DOCTYPE'))) continue;
  64. if ('OUTPUT__END' == $line) {
  65. break;
  66. }
  67. $html[]= $line;
  68. }
  69. }
  70. echo UI::h('h3', [], "output:");
  71. if (empty($html)) UI::alert('danger', "Empty output!");
  72. echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
  73. } catch (Exception $e) {
  74. UI::alert('danger', $e->getMessage());
  75. DBG::log($e);
  76. }
  77. UI::dol();
  78. }
  79. }