Ant.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. $primaryKey = V::get('primaryKey', '', $_GET);
  47. $xpath = V::get('xpath', '', $_GET);
  48. $typeName = V::get('typeName', '', $_GET);
  49. list($nsPrefix, $objectName) = explode(':', $typeName);// TODO: get wfs prefix from typeName
  50. // TODO: validate missing ...
  51. DBG::log([ 'msg'=>'$path', '$path'=>$path]);
  52. DBG::log([ 'msg'=>'$primaryKey', '$primaryKey'=>$primaryKey]);
  53. DBG::log([ 'msg'=>'$typeName', '$typeName'=>$typeName]);
  54. $taskList = $this->getAntUrlActionList();
  55. if (!array_key_exists($path, $taskList)) throw new Exception("Ant path not exists! '{$path}'");
  56. echo UI::h('hr');
  57. $webRootUrl = Request::getPathUri() . "schema/ant-url_action/{$path}";// TODO: security - only for test
  58. $outputFunctionUrl = Request::getPathUri() . "index.php?_route=UrlAction_Ant&_task=output&path={$path}&file=";
  59. DBG::log([ 'msg'=>'$webRootUrl', '$webRootUrl'=>$webRootUrl]);
  60. DBG::log([ 'msg'=>'$outputFunctionUrl', '$outputFunctionUrl'=>$outputFunctionUrl]);
  61. $testUrl = Request::getPathUri() . "wfs-data.php/default_db/?SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=".$typeName."&SRSNAME=EPSG:3003&featureID={$objectName}.{$primaryKey}";
  62. $cryptedPass = base64_encode(User::getLogin() . ":" . Crypt::decrypt($_SESSION['ADM_PASS_HASH']));
  63. // $cmd = "cd {$this->pathUrlActions}{$path} && {$this->antBin} -DoutputFunctionUrl='{$outputFunctionUrl}' -DwebRootUrl='{$webRootUrl}' -Durl='{$testUrl}' -DpasswordBase64Basic=\"{$cryptedPass}\" -Duuid=\"".session_id()."\" -Dxpath=".$xpath." -Dxpath_value=".$primaryKey." -DtypeName=\"".$typeName."\" 2>&1";
  64. $cmd = "{$this->pathUrlActions}{$path}/do_build.sh -DoutputFunctionUrl='{$outputFunctionUrl}' -DwebRootUrl='{$webRootUrl}' -Durl='{$testUrl}' -DpasswordBase64Basic=\"{$cryptedPass}\" -Duuid=\"".session_id()."\" -Dxpath=".$xpath." -Dxpath_value=".$primaryKey." -DtypeName=\"".$typeName."\" ";
  65. DBG::log([ 'msg'=>"cmd", 'cmd'=>str_replace(APP_PATH_ROOT, 'SE', $cmd) ]);
  66. //V::exec($cmd, $out, $ret); to nie dziala prawidlowo
  67. V::shell_exec();
  68. DBG::log([ 'msg'=>"cmd and returns({$ret})", 'output'=>$out ]);
  69. $html = []; $startRead = false;
  70. foreach ($out as $line) {
  71. if (!$startRead) {
  72. if ('OUTPUT__START' == $line) {
  73. $startRead = true;
  74. continue;
  75. }
  76. } else {
  77. if ('<!DOCTYPE' == substr($line, 0, strlen('<!DOCTYPE'))) continue;
  78. if ('OUTPUT__END' == $line) {
  79. break;
  80. }
  81. $html[]= $line;
  82. }
  83. }
  84. echo UI::h('h3', [], "output:");
  85. if (empty($html)) UI::alert('danger', "Empty output!");
  86. // echo UI::h('pre', [], htmlspecialchars(implode("\n", $html)));
  87. echo UI::h('div', ['class'=>"container", 'style'=>"padding:12px; border:1px solid #ddd"], $html);
  88. } catch (Exception $e) {
  89. UI::alert('danger', $e->getMessage());
  90. DBG::log($e);
  91. }
  92. UI::dol();
  93. }
  94. }