Ant.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. // TODO: validate missing ...
  41. DBG::nicePrint($path, '$path');
  42. DBG::nicePrint($featureID, '$featureID');
  43. DBG::nicePrint($namespace, '$namespace');
  44. $taskList = $this->getAntUrlActionList();
  45. if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'");
  46. echo UI::h('hr');
  47. $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";
  48. $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
  49. $cmd = "cd {$this->pathUrlActions}{$path} && {$this->antBin} -S -Durl='{$testUrl}' -DpasswordBase64Basic='{$cryptedPass}' 2>&1";
  50. DBG::nicePrint(str_replace(APP_PATH_ROOT, 'SE', $cmd), 'command');
  51. V::exec($cmd, $out, $ret);
  52. DBG::nicePrint($out, 'output');
  53. $html = []; $startRead = false;
  54. foreach ($out as $line) {
  55. if (!$startRead) {
  56. if ('OUTPUT__START' == $line) {
  57. $startRead = true;
  58. continue;
  59. }
  60. } else {
  61. if ('<!DOCTYPE' == substr($line, 0, strlen('<!DOCTYPE'))) continue;
  62. if ('OUTPUT__END' == $line) {
  63. break;
  64. }
  65. $html[]= $line;
  66. }
  67. }
  68. echo UI::h('h3', [], "output:");
  69. if (empty($html)) UI::alert('danger', "Empty output!");
  70. echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
  71. } catch (Exception $e) {
  72. UI::alert('danger', $e->getMessage());
  73. DBG::log($e);
  74. }
  75. UI::dol();
  76. }
  77. }