From 189a6f4f94ff13b25c24d8b31863ebd7692ede76 Mon Sep 17 00:00:00 2001 From: Elena.Budnik Date: Tue, 9 Apr 2019 12:47:09 +0200 Subject: [PATCH] coorect timie --- php/WebServices/WebServer.php | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- php/rest/getDataset.php | 9 ++++++++- php/rest/getOrbites.php | 7 +++++++ php/rest/getParameter.php | 7 +++++++ 4 files changed, 95 insertions(+), 39 deletions(-) diff --git a/php/WebServices/WebServer.php b/php/WebServices/WebServer.php index 7e497bc..51acf66 100644 --- a/php/WebServices/WebServer.php +++ b/php/WebServices/WebServer.php @@ -286,17 +286,6 @@ class WebServer $this->throwError("deleteProcessError", $e->getMessage()); } } - -/* -* generate AUTH token for access to REST services -*/ - public function getNewToken() - { - // generate token from timeStamp and some salt - $newToken = md5(1321 * (int)( time() / WSConfigClass::$timeLimitQuery)); - - return array('success' => true, 'token' => $newToken); - } private function excludePrivateNodes($locParamSrc, $locParamDst) { @@ -325,8 +314,24 @@ class WebServer $this->throwError('workspaceError', 'Cannot save Amda Local DataBase Parameters description file'.$this->userID); } + private function checkInputTime($startTime, $stopTime) + { + if ($stopTime <= $startTime ) + $this->throwError("requestError", "Requested time interval should be greater than 0"); + } + /************************** WEB SERVICES **************************************/ - +/* +* generate AUTH token for access to REST services +*/ + public function getNewToken() + { + // generate token from timeStamp and some salt + $newToken = md5(1321 * (int)( time() / WSConfigClass::$timeLimitQuery)); + + return array('success' => true, 'token' => $newToken); + } + /* * public data only : user impex */ @@ -390,18 +395,25 @@ class WebServer $this->initUserMgr(); $vars = $res['vars']; - - if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ - $this->throwError("requestError", "Requested time interval should be greater than 0"); + + if (is_numeric($vars["startTime"])) { + $this->checkInputTime($vars["startTime"],$vars["stopTime"]); + $vars["startTime"] = date("Y-m-d\TH:i:s", $vars["startTime"]); + $vars["stopTime"] = date("Y-m-d\TH:i:s", $vars["stopTime"]); + } + else { + $this->checkInputTime(strtotime($vars["startTime"]),strtotime($vars["stopTime"])); } - $paramId = array(); - array_push($paramId, $vars["parameterID"]); - - if (!$vars["timeFormat"]) + if (!$vars["timeFormat"]) { $timeFormat = "ISO8601"; - else + } + else { $timeFormat = $vars["timeFormat"]; + } + + $paramId = array(); + array_push($paramId, $vars["parameterID"]); if (!$vars["gzip"]) $gzip = 0; @@ -465,11 +477,23 @@ class WebServer $this->initUserMgr(); $vars = $res['vars']; - - if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ - $this->throwError("requestError", "Requested time interval should be greater than 0"); - } + if (is_numeric($vars["startTime"])) { + $this->checkInputTime($vars["startTime"],$vars["stopTime"]); + $vars["startTime"] = date("Y-m-d\TH:i:s", $vars["startTime"]); + $vars["stopTime"] = date("Y-m-d\TH:i:s", $vars["stopTime"]); + } + else { + $this->checkInputTime(strtotime($vars["startTime"]),strtotime($vars["stopTime"])); + } + + if (!$vars["timeFormat"]) { + $timeFormat = "ISO8601"; + } + else { + $timeFormat = $vars["timeFormat"]; + } + $dataSetDom = $this->getDatasetInfo($vars['datasetID']); $params = $dataSetDom->getElementsByTagName("parameter"); @@ -506,11 +530,6 @@ class WebServer $sampling = $vars["sampling"]; } - if (!$vars["timeFormat"]) - $timeFormat = "ISO8601"; - else - $timeFormat = $vars["timeFormat"]; - if (!$vars["gzip"]) $gzip = 0; else @@ -642,11 +661,23 @@ class WebServer $this->initUserMgr(); $vars = $res['vars']; - - if (strtotime($vars["stopTime"]) <= strtotime($vars["startTime"])){ - $this->throwError("requestError", "Requested time interval should be greater than 0"); + + if (is_numeric($vars["startTime"])) { + $this->checkInputTime($vars["startTime"],$vars["stopTime"]); + $vars["startTime"] = date("Y-m-d\TH:i:s", $vars["startTime"]); + $vars["stopTime"] = date("Y-m-d\TH:i:s", $vars["stopTime"]); + } + else { + $this->checkInputTime(strtotime($vars["startTime"]),strtotime($vars["stopTime"])); + } + + if (!$vars["timeFormat"]) { + $timeFormat = "ISO8601"; + } + else { + $timeFormat = $vars["timeFormat"]; } - + $spacecraft = $vars["spacecraft"]; $coordinateSystem = $vars["coordinateSystem"]; @@ -667,11 +698,6 @@ class WebServer $paramId = array(); array_push($paramId, $orbitParam['parameterID']); - if (!$vars["timeFormat"]) - $timeFormat = "ISO8601"; - else - $timeFormat = $vars["timeFormat"]; - if (!$vars["gzip"]) $gzip = 0; else @@ -705,6 +731,15 @@ class WebServer $vars = $res['vars']; $mission = $vars["missionID"]; + if (is_numeric($vars["startTime"])) { + $this->checkInputTime($vars["startTime"],$vars["stopTime"]); + $vars["startTime"] = date("Y-m-d\TH:i:s", $vars["startTime"]); + $vars["stopTime"] = date("Y-m-d\TH:i:s", $vars["stopTime"]); + } + else { + $this->checkInputTime(strtotime($vars["startTime"]),strtotime($vars["stopTime"])); + } + $resultFilePrefix = strtolower(__FUNCTION__)."_".$mission."_".date("YmdHms",strtotime($vars["startTime"]))."_".date("YmdHms",strtotime($vars["stopTime"])); if ($this->userID != "impex") diff --git a/php/rest/getDataset.php b/php/rest/getDataset.php index fba5bba..53d1803 100644 --- a/php/rest/getDataset.php +++ b/php/rest/getDataset.php @@ -41,7 +41,14 @@ $result = array('success' => false, 'message' => "Authentication is required for this webservice."); exit(json_encode($result)); } - + + if ($_GET['startTime'] && strpos($_GET['startTime'], ' ') !== false) + { + $result = array('success' => false, + 'message' => "Check that there is no + (plus) character in your time definition. + is a special character and should be encoded by %2B"); + exit(json_encode($result)); + } + $amda_ws = new WebServer(); if ($amda_ws->getNewToken()['token'] != $_GET["token"]) diff --git a/php/rest/getOrbites.php b/php/rest/getOrbites.php index 4f3e6da..7d8a383 100644 --- a/php/rest/getOrbites.php +++ b/php/rest/getOrbites.php @@ -52,6 +52,13 @@ exit(json_encode($result)); } + if ($_GET['startTime'] && strpos($_GET['startTime'], ' ') !== false) + { + $result = array('success' => false, + 'message' => "Check that there is no + (plus) character in your time definition. + is a special character and should be encoded by %2B"); + exit(json_encode($result)); + } + $amda_ws = new WebServer(); if ($amda_ws->getNewToken()['token'] != $_GET["token"]) diff --git a/php/rest/getParameter.php b/php/rest/getParameter.php index c09632b..9d5a148 100644 --- a/php/rest/getParameter.php +++ b/php/rest/getParameter.php @@ -42,6 +42,13 @@ $result = array('success' => false, 'message' => "Authentication is required for this webservice."); exit(json_encode($result)); } + + if ($_GET['startTime'] && strpos($_GET['startTime'], ' ') !== false) + { + $result = array('success' => false, + 'message' => "Check that there is no + (plus) character in your time definition. + is a special character and should be encoded by %2B"); + exit(json_encode($result)); + } $amda_ws = new WebServer(); -- libgit2 0.21.2