RemoteController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. require_once(dirname(__FILE__)."/../../../Tools/controllers/TransformerController.php");
  3. class RemoteController
  4. {
  5. public static function Run ($type = "", $files = array())
  6. {
  7. $remoteCtrl = new RemoteController();
  8. $remoteCtrl->getOptions();
  9. if ($type == "") {
  10. return $remoteCtrl->options;
  11. }
  12. if (!in_array($type, array_keys($remoteCtrl->options))) {
  13. return "Falscher Aufruf";
  14. }
  15. return $remoteCtrl->getDetails($type, $files);
  16. }
  17. private $config;
  18. private $info;
  19. private $paths;
  20. private $options;
  21. private function __construct ()
  22. {
  23. $this->config = parse_ini_file(dirname(__FILE__) . "/../../../../GAPS.ini");
  24. $this->info = json_decode(file_get_contents($this->config['XML'] . "\\info\\info.json"), true);
  25. $this->paths = array(
  26. 'Tasks' => dirname(__FILE__) . "/../../../..",
  27. 'Starter' => $this->config['STARTER'] . "\\Batch",
  28. 'Transformer' => $this->config['PORTAL'] . "\\System\\Models",
  29. 'Impromptu' => $this->config['PORTAL'] . "\\System\\IQD",
  30. 'Powerplay' => $this->config['PORTAL'] . "\\System\\Report",
  31. 'Portal' => $this->config['XML'],
  32. 'Logs' => dirname(__FILE__) . "/../../../../logs",
  33. 'Prot' => $this->config['PORTAL'] . "\\System\\Prot"
  34. );
  35. if (isset($this->config['PROT'])) {
  36. $this->paths['Prot'] = $this->config['PROT'];
  37. }
  38. }
  39. public function getOptions ()
  40. {
  41. $this->options = array(
  42. 'Tasks' => $this->getFilenames($this->paths['Tasks'], "*.bat", false),
  43. 'Starter' => $this->getFilenames($this->paths['Starter'], "*.bat"),
  44. 'Transformer' => $this->getFilenames($this->paths['Transformer'], "*.pyi"),
  45. 'Impromptu' => $this->getFilenames($this->paths['Impromptu'], "*.imr"),
  46. 'Powerplay' => $this->getFilenames($this->paths['Powerplay'] , "*.ppr"),
  47. 'Portal' => $this->getFilenames($this->paths['Portal'], "*.xml"),
  48. 'Logs' => $this->getFilenames($this->paths['Logs'], "*"),
  49. 'Prot' => $this->getFilenames($this->paths['Prot'], "*.log")
  50. );
  51. }
  52. private function removePath (&$value, $key, $path)
  53. {
  54. $value = utf8_encode(str_replace($path . "\\", "", $value));
  55. }
  56. private function getFilenames ($path, $filter, $recursive = true, $isSubdir = false)
  57. {
  58. $path = realpath($path);
  59. $result = glob($path . "\\" . $filter);
  60. if ($recursive) {
  61. foreach(glob($path . "\\*", GLOB_ONLYDIR) as $subdir) {
  62. if ($subdir != $path && substr($subdir, -1) != ".") {
  63. $result = array_merge($result, $this->getFilenames($subdir, $filter, $recursive, true));
  64. }
  65. }
  66. }
  67. if (!$isSubdir) {
  68. array_walk($result, array($this, 'removePath'), $path);
  69. }
  70. return $result;
  71. }
  72. public function getDetails ($type, $files)
  73. {
  74. $result = array();
  75. foreach ($files as $file) {
  76. $fullname = realpath($this->paths[$type] . "\\" . $file);
  77. if (!file_exists($fullname)) {
  78. continue;
  79. }
  80. $fileinfo = $this->getFileInfo($fullname);
  81. $fileinfo = call_user_func(array($this, "getDetails" . $type), $fileinfo);
  82. $result[$file] = $fileinfo;
  83. }
  84. return $result;
  85. }
  86. private function getFileInfo ($filename)
  87. {
  88. $result = array(
  89. 'filename' => $filename,
  90. 'exists' => file_exists($filename)
  91. );
  92. if ($result['exists']) {
  93. $result['size'] = filesize($filename);
  94. $result['modified'] = date('d.m.Y H:i', filemtime($filename));
  95. $result['days'] = $this->dateDiff(filemtime($filename));
  96. } else {
  97. $result['size'] = 0;
  98. $result['modified'] = "fehlt";
  99. $result['days'] = 0;
  100. }
  101. return $result;
  102. }
  103. private function getDetailsTasks ($fileinfo)
  104. {
  105. $info['contents'] = explode("\r\n", file_get_contents($fileinfo['filename']));
  106. return $info;
  107. }
  108. private function getDetailsStarter ($fileinfo)
  109. {
  110. $info['contents'] = explode("\r\n", file_get_contents($fileinfo['filename']));
  111. return $info;
  112. }
  113. private function getDetailsImpromptu ($fileinfo)
  114. {
  115. $filename = substr($fileinfo['filename'], 0, -3);
  116. $ext = array('csv', 'ims', 'iqd');
  117. foreach($ext as $e) {
  118. $fileinfo[$e] = $this->getFileInfo($filename . $e);
  119. }
  120. if ($fileinfo['iqd']['exists']) {
  121. $fileinfo['iqd']['newer'] = filemtime($fileinfo['filename']) <= filemtime($fileinfo['iqd']['filename']) + 20;
  122. }
  123. return $fileinfo;
  124. }
  125. private function getDetailsTransformer ($fileinfo)
  126. {
  127. $fileinfo['cube'] = TransformerController::GetCubeName($fileinfo['filename']);
  128. $fileinfo['mdc'] = $this->getFileInfo(realpath($this->config['PORTAL'] . "\\System\\Cube_out") . "\\" . $fileinfo['cube'] . ".mdc");
  129. return $fileinfo;
  130. }
  131. private function getDetailsPowerplay ($fileinfo)
  132. {
  133. $filename = substr($fileinfo['filename'], 0, -3);
  134. $ext = array('ppx', 'gif', 'pdf', 'csv', 'xls');
  135. foreach($ext as $e) {
  136. $fileinfo[$e] = $this->getFileInfo($filename . $e);
  137. }
  138. return $fileinfo;
  139. }
  140. private function getDetailsPortal ($fileinfo)
  141. {
  142. $filename = strtolower(basename($fileinfo['filename']));
  143. $users = array('*' => '');
  144. $structure = array('*' => '');
  145. $email = array('*' => '');
  146. $cube = array('*' => '');
  147. foreach ($this->info['versand'] as $e) {
  148. if (strtolower($e['Datei']) == $filename) {
  149. $users[$e['Benutzer']] = 1;
  150. $structure[$e['Struktur']] = 1;
  151. $email[$e['Empfaenger']] = 1;
  152. $cube[$e['Cube']] = 1;
  153. }
  154. }
  155. $fileinfo['type'] = (count($users) == 1) ? "Portal" : "Versand";
  156. if ($fileinfo['type'] == "Portal") {
  157. foreach ($this->info['reports'] as $e) {
  158. if (strtolower($e['Datei']) == $filename) {
  159. $users[$e['Benutzer']] = 1;
  160. $structure[$e['Struktur']] = 1;
  161. $cube[$e['Cube']] = 1;
  162. }
  163. }
  164. }
  165. $fileinfo['users'] = array_keys($users);
  166. $fileinfo['structure'] = array_keys($structure);
  167. $fileinfo['email'] = array_keys($email);
  168. $fileinfo['cube'] = array_keys($cube);
  169. sort($fileinfo['users']);
  170. sort($fileinfo['structure']);
  171. sort($fileinfo['email']);
  172. sort($fileinfo['cube']);
  173. return $fileinfo;
  174. }
  175. private function dateDiff ($timestamp, $now = "now")
  176. {
  177. return round((strtotime($now) - strtotime($timestamp)) / (24 * 60 * 60));
  178. }
  179. }