Commit 4bdd7ad97498c60fbdee03b7e0b4c78b08728551
1 parent
1baabd91
Exists in
master
and in
111 other branches
interim commit
Showing
1 changed file
with
45 additions
and
156 deletions
Show diff stats
php/classes/WebServer.php
... | ... | @@ -73,8 +73,8 @@ class WebResultMgr |
73 | 73 | class WebServer |
74 | 74 | { |
75 | 75 | private $isSoap = false; |
76 | - private $userID, $userPWD, $sessionID; | |
77 | - private $wsUserMgr; | |
76 | + private $userID, $userPWD, $sessionID, $IPclient; | |
77 | +// private $wsUserMgr; | |
78 | 78 | private $resultMgr; |
79 | 79 | private $dataFileName; |
80 | 80 | private $requestManager = null; |
... | ... | @@ -146,16 +146,7 @@ class WebServer |
146 | 146 | */ |
147 | 147 | private function getIPclient() |
148 | 148 | { |
149 | - if (getenv('REMOTE_ADDR')) { | |
150 | - $realIP = getenv('REMOTE_ADDR'); | |
151 | - } | |
152 | - else { | |
153 | - //get local IP | |
154 | - $command="hostname -i"; | |
155 | - $realIP = exec($command); | |
156 | - } | |
157 | - | |
158 | - return $realIP; | |
149 | + return $this->wsUserMgr->getIPClient(); | |
159 | 150 | } |
160 | 151 | |
161 | 152 | private function rrmdir($dir) |
... | ... | @@ -178,12 +169,10 @@ class WebServer |
178 | 169 | |
179 | 170 | protected function initUserMgr() |
180 | 171 | { |
181 | - if (isset($this->wsUserMgr)) | |
182 | - return array('success' => true); | |
183 | - | |
184 | - $this->wsUserMgr = new WSUserMgr(); | |
185 | - $this->wsUserMgr->init($this->userID, $this->userPWD, $this->sessionID, $this->isSoap); | |
172 | + $wsUserMgr = new WSUserMgr(); | |
173 | + $wsUserMgr->init($this->userID, $this->userPWD, $this->sessionID, $this->isSoap); | |
186 | 174 | |
175 | + $this->IPclient = $wsUserMgr->getIPClient(); | |
187 | 176 | return array('success' => true); |
188 | 177 | } |
189 | 178 | |
... | ... | @@ -406,7 +395,7 @@ class WebServer |
406 | 395 | $this->requestManager = new RequestManagerClass(); |
407 | 396 | |
408 | 397 | try { |
409 | - $plotResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, $requestObject); | |
398 | + $plotResult = $this->requestManager->runIHMRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PARAMS, $requestObject); | |
410 | 399 | } catch (Exception $e) { |
411 | 400 | $this->throwError("plotError", "Exeption detected : ".$e->getMessage()); |
412 | 401 | } |
... | ... | @@ -436,37 +425,12 @@ class WebServer |
436 | 425 | $this->requestManager = new RequestManagerClass(); |
437 | 426 | |
438 | 427 | try { |
439 | - $res = $this->requestManager->runWSRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSGETINFO, null, $id); | |
428 | + $res = $this->requestManager->runWSRequest($this->userID, 'unknown', FunctionTypeEnumClass::PROCESSGETINFO, null, $id); | |
440 | 429 | } catch (Exception $e) { |
441 | 430 | return array("error" => $e->getMessage()); |
442 | 431 | // $this->throwError("serverError", "Exeption detected : ".$e->getMessage()); |
443 | 432 | } |
444 | -// [success] => 1 | |
445 | -// [id] => process_t7ovpn_1520344095_13119 | |
446 | -// [name] => download_1520344108 | |
447 | -// [status] => done | |
448 | -// [jobType] => download | |
449 | -// [info] => imf | |
450 | -// [start] => 06-03-2018 13:48:15 | |
451 | -// [stop] => 06-03-2018 15:40:20 | |
452 | -// [folder] => DDEUQzrM_ | |
453 | -// [result] => result_EUQzrM | |
454 | -// [format] => unknown | |
455 | -// [compression] => 0 | |
456 | - | |
457 | -// [success] => 1 | |
458 | -// [id] => process_t7ovpn_1520344095_13119 | |
459 | -// [name] => download_1520344108 | |
460 | -// [status] => in_progress | |
461 | -// [jobType] => download | |
462 | -// [info] => imf | |
463 | -// [start] => 06-03-2018 13:48:15 | |
464 | -// [stop] => unknown | |
465 | -// [folder] => DDEUQzrM_ | |
466 | -// [result] => result_EUQzrM | |
467 | -// [format] => unknown | |
468 | -// [compression] => 0 | |
469 | - | |
433 | + | |
470 | 434 | if (!$res['success']) { |
471 | 435 | $this->throwError("processError","Cannot retrieve process $id info"); |
472 | 436 | } |
... | ... | @@ -478,20 +442,21 @@ class WebServer |
478 | 442 | if ($res['error']) { |
479 | 443 | $this->throwError("processError","Process $id error code"); |
480 | 444 | } |
481 | - | |
482 | - // $vars = $this->getVarsFromRunningPath($result['runningpath']); | |
483 | - | |
484 | -// if (!$vars['success']) { | |
485 | -// $this->throwError("processError","Process $id : cannot generate file name for result : ".$vars['message']); | |
486 | -// } | |
487 | -// | |
488 | -// $resultFile = glob($result['runningpath']."result_*"); | |
489 | -// | |
490 | -// $tempFilePath = $result['runningpath'].$resultFile.$vars['kernelExtension']; | |
491 | -// | |
492 | -// $outputFilePath = WSRESULT.$vars['dataFileName'].$vars['wsExtension']; | |
493 | - | |
494 | - return array('success' => true,'status' => $res['status']); //$this->finishDownloadRequest($id, $tempFilePath, $outputFilePath); | |
445 | + | |
446 | +// [success] => 1 | |
447 | +// [id] => process_jckrDz_1520873370_11632 | |
448 | +// [name] => download_1520873382 | |
449 | +// [status] => done | |
450 | +// [jobType] => download | |
451 | +// [info] => imf | |
452 | +// [start] => 12-03-2018 16:49:30 | |
453 | +// [stop] => 12-03-2018 16:51:49 | |
454 | +// [folder] => DDfqlbZr_ | |
455 | +// [result] => download_imf_1484352000_1494806400.txt | |
456 | +// [format] => | |
457 | +// [compression] => 0 | |
458 | + $this->cleanProcess($res['id']); | |
459 | + return array('success' => true, 'status' => $res['status'], 'dataFileURLs' => WSConfigClass::getUrl().$res['result']); | |
495 | 460 | } |
496 | 461 | |
497 | 462 | |
... | ... | @@ -543,27 +508,18 @@ class WebServer |
543 | 508 | { |
544 | 509 | $res = $this->init($data); |
545 | 510 | |
546 | - $resMgr = $this->initUserMgr(); | |
547 | - | |
548 | 511 | if (!$res['success']){ |
549 | 512 | $this->throwError("requestError", "Cannot parse request"); |
550 | 513 | } |
551 | 514 | |
515 | + $resMgr = $this->initUserMgr(); | |
516 | + | |
552 | 517 | $vars = $res['vars']; |
553 | 518 | |
554 | 519 | if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ |
555 | 520 | $this->throwError("requestError", "Requested time interval should be greater than 0"); |
556 | 521 | } |
557 | - | |
558 | - $dataFileName = $this->getDataFileName($vars); | |
559 | - | |
560 | - if ($dataFileName['success']) { | |
561 | - $this->dataFileName = $dataFileName['fileName']; | |
562 | - } | |
563 | - else { | |
564 | - $this->throwError("requestError", $dataFileName['message']); | |
565 | - } | |
566 | - | |
522 | + | |
567 | 523 | $paramId = array(); |
568 | 524 | array_push($paramId, $vars["parameterID"]); |
569 | 525 | |
... | ... | @@ -585,9 +541,7 @@ class WebServer |
585 | 541 | $res = $this->doDownloadRequest( |
586 | 542 | array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]), |
587 | 543 | array("params" => $paramId), |
588 | - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID), | |
589 | - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream), | |
590 | - $dataFileName); | |
544 | + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); | |
591 | 545 | |
592 | 546 | if ($res['success']) |
593 | 547 | return $res; |
... | ... | @@ -636,7 +590,6 @@ class WebServer |
636 | 590 | $orbParam = $orbitesParam['parameterID']; |
637 | 591 | } |
638 | 592 | else { |
639 | - //$orbParam = 'successEstfalse'; | |
640 | 593 | $this->throwError("requestError", $orbitesParam['message']); |
641 | 594 | } |
642 | 595 | |
... | ... | @@ -665,9 +618,7 @@ class WebServer |
665 | 618 | $res = $this->doDownloadRequest( |
666 | 619 | array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $vars["sampling"]), |
667 | 620 | array("params" => $paramId), |
668 | - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID), | |
669 | - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream), | |
670 | - $dataFileName); | |
621 | + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); | |
671 | 622 | |
672 | 623 | if ($res['success']) return $res; |
673 | 624 | |
... | ... | @@ -753,9 +704,7 @@ class WebServer |
753 | 704 | $res = $this->doDownloadRequest( |
754 | 705 | array("startTime" => $vars["startTime"], "stopTime" => $vars["stopTime"], "sampling" => $sampling), |
755 | 706 | array("params" => $paramId), |
756 | - array("userName" => $this->userID, "userPwd" => $this->userPWD, "sessionID" => $this->sessionID), | |
757 | - array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream), | |
758 | - $dataFileName); | |
707 | + array("format" => $vars["outputFormat"], "timeFormat"=> $timeFormat, "gzip"=>$gzip, "stream"=>$stream)); | |
759 | 708 | |
760 | 709 | if ($res['success']) return $res; |
761 | 710 | |
... | ... | @@ -837,10 +786,8 @@ class WebServer |
837 | 786 | 'compression' => $compression]; |
838 | 787 | } |
839 | 788 | |
840 | - protected function doDownloadRequest($interval,$paramList,$user,$formatInfo,$dataFileName) | |
789 | + protected function doDownloadRequest($interval, $paramList, $formatInfo) | |
841 | 790 | { |
842 | - $fileInfo = $this->getFormatInfo($formatInfo['format'], $formatInfo['timeFormat'], $formatInfo['gzip']); | |
843 | - | |
844 | 791 | if (!isset($this->paramLoader)) |
845 | 792 | $this->paramLoader = new IHMUserParamLoaderClass(); |
846 | 793 | |
... | ... | @@ -870,10 +817,9 @@ class WebServer |
870 | 817 | } |
871 | 818 | $param->paramid = "wsd_".$res['name']; |
872 | 819 | } |
873 | - else{ | |
820 | + else { | |
874 | 821 | $param->paramid = $paramId; |
875 | 822 | } |
876 | - | |
877 | 823 | $params[] = $param; |
878 | 824 | } |
879 | 825 | |
... | ... | @@ -882,16 +828,16 @@ class WebServer |
882 | 828 | "startDate" => $interval['startTime'], |
883 | 829 | "stopDate" => $interval['stopTime'], |
884 | 830 | "list" => $params, |
885 | - "fileformat" => 'ASCII', | |
886 | - "timeformat" => 'ISO08601', | |
887 | - "compression" => 0 | |
831 | + "fileformat" => $formatInfo['format'], | |
832 | + "timeformat" => $formatInfo['timeFormat'], | |
833 | + "compression" => $formatInfo['gzip'] | |
888 | 834 | ); |
889 | 835 | |
890 | 836 | if (!isset($this->requestManager)) |
891 | 837 | $this->requestManager = new RequestManagerClass(); |
892 | 838 | |
893 | 839 | try { |
894 | - $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PARAMS, WSConfigClass::DOWNLOAD, $obj); | |
840 | + $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PARAMS, WSConfigClass::DOWNLOAD, $obj); | |
895 | 841 | } catch (Exception $e) { |
896 | 842 | $this->throwError("executionError", "Exception detected : ".$e->getMessage()); |
897 | 843 | } |
... | ... | @@ -904,39 +850,25 @@ class WebServer |
904 | 850 | return ['success' => true, 'status' => 'in progress', 'id' => $downloadResult['id']]; |
905 | 851 | } elseif ($downloadResult['status'] == 'done') |
906 | 852 | { |
907 | - $resTempFilePath = USERWORKINGDIR.'/'.$downloadResult['folder'].'/'.$downloadResult['result'].$fileInfo['kernelExtension']; | |
908 | - $resOutputFilePath = WSRESULT.$this->dataFileName.$fileInfo['wsExtension']; | |
909 | - return $this->finishDownloadRequest($downloadResult['id'], $resTempFilePath, $resOutputFilePath); | |
853 | + $this->cleanProcess($downloadResult['id']); | |
854 | + return array('success' => true, 'status' => 'done', 'dataFileURLs' => WSConfigClass::getUrl().$downloadResult['result']); | |
910 | 855 | } else { |
911 | 856 | return ['success' => false, 'message' => 'Unknown status ' . $downloadResult['status']]; |
912 | 857 | } |
913 | 858 | } |
914 | 859 | |
915 | - private function finishDownloadRequest($id, $resTempFilePath, $resOutputFilePath) | |
860 | + private function cleanProcess($id) | |
916 | 861 | { |
917 | - if (!file_exists($resTempFilePath)) { | |
918 | - $this->throwError("serverError", "Cannot retrieve result file $resTempFilePath"); | |
919 | - } | |
920 | - | |
921 | - rename($resTempFilePath, $resOutputFilePath); | |
922 | - // chmod($resOutputFilePath, 0664); | |
923 | - | |
924 | - $outputURL = 'http://' . str_replace(BASE_PATH, $_SERVER['SERVER_NAME'] . APACHE_ALIAS, $resOutputFilePath); | |
925 | - | |
926 | - $obj = (object)array( | |
927 | - 'id' => $id | |
928 | - ); | |
862 | + $obj = (object)array('id' => $id); | |
929 | 863 | |
930 | 864 | if (!isset($this->requestManager)) |
931 | 865 | $this->requestManager = new RequestManagerClass(); |
932 | 866 | |
933 | -// try { | |
934 | -// $downloadResult = $this->requestManager->runIHMRequest($this->userID, $this->getIPclient(), FunctionTypeEnumClass::PROCESSDELETE, $obj); | |
935 | -// } catch (Exception $e) { | |
936 | -// error_log("Can not delete file $resOutputFilePath: $e"); | |
937 | -// } | |
938 | - | |
939 | - return array('success' => true, 'status' => 'done', 'dataFileURLs' => $outputURL); | |
867 | + try { | |
868 | + $downloadResult = $this->requestManager->runWSRequest($this->userID, $this->IPclient, FunctionTypeEnumClass::PROCESSDELETE, WSConfigClass::DOWNLOAD, $obj); | |
869 | + } catch (Exception $e) { | |
870 | + $this->throwError("cleanProcessError", $e->getMessage()); | |
871 | + } | |
940 | 872 | } |
941 | 873 | |
942 | 874 | protected function getDataFileName($vars, $multiParam = false) |
... | ... | @@ -966,48 +898,5 @@ class WebServer |
966 | 898 | return array('success' => false, 'message' => $message); |
967 | 899 | } |
968 | 900 | } |
969 | - | |
970 | - private function getVarsFromRunningPath($runningPath) | |
971 | - { | |
972 | - $filePath = $runningPath . "request_0.xml"; | |
973 | - | |
974 | - if (!file_exists($filePath)) { | |
975 | - return ['success' => false, 'message' => 'Failed to open request file']; | |
976 | - } | |
977 | - | |
978 | - $requestXml = new DOMDocument(); | |
979 | - $requestXml->load($filePath); | |
980 | - $fileFormat = $requestXml->getElementsByTagName('fileFormat')->item(0)->nodeValue; | |
981 | - $timeFormat = $requestXml->getElementsByTagName('timeFormat')->item(0)->nodeValue; | |
982 | - $gzip = 0; // todo $requestXml->getElementsByTagName('gzip')->item(0)->nodeValue; | |
983 | - | |
984 | - // get kernelExtension, wsExtension, fileFormat, timeFormat, compression: | |
985 | - $vars = $this->getFormatInfo($fileFormat, $timeFormat, $gzip); | |
986 | - | |
987 | - $vars['parameterID'] = $requestXml->getElementsByTagName('param')->item(0)->getAttribute('id'); | |
988 | - | |
989 | - $ddStart = $requestXml->getElementsByTagName('startTime')->item(0)->nodeValue; | |
990 | - $ddInterval = $requestXml->getElementsByTagName('timeInterval')->item(0)->nodeValue; | |
991 | - $vars['startTime'] = CommonClass::DDTimeToIso($ddStart); | |
992 | - $vars['stopTime'] = CommonClass::DDStartIntervalToStopIso($ddStart, $ddInterval); | |
993 | - | |
994 | - $sampling = $requestXml->getElementsByTagName('sampling')->item(0); | |
995 | - if (!is_null($sampling)) | |
996 | - $vars['sampling'] = $sampling->nodeValue; | |
997 | - | |
998 | - if (in_array(null, $vars, true)) { | |
999 | - return ['success' => false, | |
1000 | - 'message' => 'Can not create data file name - a value is missing in the request file']; | |
1001 | - } | |
1002 | - | |
1003 | - $dataFileName = $this->getDataFileName($vars, false); | |
1004 | - if (!$dataFileName['success']) { | |
1005 | - return $dataFileName; | |
1006 | - } | |
1007 | - $vars['dataFileName'] = $dataFileName['fileName']; | |
1008 | - $vars['success'] = true; | |
1009 | - | |
1010 | - return $vars; | |
1011 | - } | |
1012 | 901 | } |
1013 | 902 | ?> |
1014 | 903 | \ No newline at end of file |
... | ... |