Commit 70880168fbc20582037d128994c0c519dff6b14a

Authored by Nathanael Jourdane
1 parent 47ef4864

Add rate limit only for Rest webservice, and also on GetOrbites and getDatasetData methods

php/classes/WebServer.php
... ... @@ -6,8 +6,6 @@
6 6 * @version $Id: WebServer.php 2968 2015-06-29 13:17:00Z natacha $
7 7 */
8 8  
9   -require_once '../config.php';
10   -
11 9 class WebResultMgr
12 10 {
13 11 private $resDOM;
... ... @@ -572,14 +570,6 @@ class WebServer
572 570  
573 571 $vars = $res['vars'];
574 572  
575   - if (!$vars["token"]) {
576   - return array('success' => false, 'message' => "E01\nAuthentication is required for this webservice.");
577   - }
578   -
579   - if($this->getNewToken()['token'] != $vars["token"]) {
580   - return array('success' => false, 'message' => "E02\nToken expired. Please authenticate again.");
581   - }
582   -
583 573 if ((strtotime($vars["stopTime"]) - strtotime($vars["startTime"])) < 0){
584 574 if ($this->isSoap) throw new SoapFault("request01","Start time must be higher than stop time");
585 575 else return array('success' => false, 'message' => "Start time must be higher than stop time");
... ...
php/rest/auth.php
1   -
2 1 <?php
3 2  
4 3 /**
5   - * @file getParameter.php
6   - * @brief REST interface for service getParameter
  4 + * @file getParameter.php
  5 + * @brief REST interface for service getParameter
7 6 *
8 7 *
9   - * @version $Id: $
  8 + * @version $Id: $
10 9 */
11 10  
12   - require_once '../config.php';
  11 +require_once '../config.php';
13 12  
14   - $amda_ws = new WebServer();
15   - $result = $amda_ws->getNewToken($_GET);
  13 +$amda_ws = new WebServer();
  14 +$result = $amda_ws->getNewToken($_GET);
16 15  
17   - if ($result['success']){
18   - echo $result['token'];
19   - }
20   - else {
21   - echo $result['message'];
22   - }
  16 +if ($result['success']) {
  17 + echo $result['token'];
  18 +} else {
  19 + echo $result['message'];
  20 +}
23 21  
24 22 ?>
25 23 \ No newline at end of file
... ...
php/rest/getDatasetData.php
1 1 <?php
2   -/**
3   -* @file getParameter.php
4   -* @brief REST interface for service getParameter
5   -*
6   -*
7   -* @version $Id: $
8   -*/
9   - ini_set("allow_url_fopen", true);
10   - require_once '../config.php';
11   -
12   - $amda_ws = new WebServer();
13   - $result = $amda_ws->getDataset($_GET);
14   -
15   - if ($result['success']){
16   - $file = str_replace("http://oberoi.cesr.fr/AMDA-WS/",BASE_PATH ,$result['dataFileURLs']);
17   -
18   - if ($file){
  2 +/**
  3 + * @file getParameter.php
  4 + * @brief REST interface for service getParameter
  5 + *
  6 + *
  7 + * @version $Id: $
  8 + */
  9 +ini_set("allow_url_fopen", true);
  10 +require_once '../config.php';
  11 +
  12 +$amda_ws = new WebServer();
  13 +
  14 +if (!$_GET["token"]) {
  15 + return array('success' => false, 'message' => "E01\nAuthentication is required for this webservice.");
  16 +}
  17 +if ($amda_ws->getNewToken()['token'] != $_GET["token"]) {
  18 + return array('success' => false, 'message' => "E02\nToken expired. Please authenticate again.");
  19 +}
  20 +
  21 +$result = $amda_ws->getDataset($_GET);
  22 +
  23 +if ($result['success']) {
  24 + $file = str_replace("http://oberoi.cesr.fr/AMDA-WS/", BASE_PATH, $result['dataFileURLs']);
  25 +
  26 + if ($file) {
19 27 // header('Content-type: text/xml');
20 28 // $contenu = file_get_contents($file);
21 29 // error_log($contenu,3,'/home/natacha/TMP/tmp.xml');
22 30 // echo $contenu;
23   -
24   -header('Content-type: text/xml');
25   -$doc = new DOMDocument();
26   -$doc->load($file);
27   -echo $doc->saveXML();
28   -
29   -
30   - }
31   - }
32   - else {
33   - $success = "false";
34   - echo '<?xml version="1.0" encoding="UTF-8"?><getParameterResponse>';
35   - echo '<success>'.$success.'</success>';
36   - echo '<message>'.$result['message'].'</message></getParameterResponse>';
  31 +
  32 + header('Content-type: text/xml');
  33 + $doc = new DOMDocument();
  34 + $doc->load($file);
  35 + echo $doc->saveXML();
  36 +
  37 +
37 38 }
  39 +} else {
  40 + $success = "false";
  41 + echo '<?xml version="1.0" encoding="UTF-8"?><getParameterResponse>';
  42 + echo '<success>' . $success . '</success>';
  43 + echo '<message>' . $result['message'] . '</message></getParameterResponse>';
  44 +}
38 45 ?>
... ...
php/rest/getOrbites.php
1 1 <?php
2   -
3   -/**
4   -* @file getParameter.php
5   -* @brief REST interface for service getParameter
6   -*
7   -*
8   -* @version $Id: $
9   -*/
10 2  
11   - require_once '../config.php';
  3 +/**
  4 + * @file getParameter.php
  5 + * @brief REST interface for service getParameter
  6 + *
  7 + *
  8 + * @version $Id: $
  9 + */
12 10  
13   - $amda_ws = new WebServer();
14   - $result = $amda_ws->getOrbites($_GET);
  11 +require_once '../config.php';
15 12  
16   - if ($result['success']){
17   - echo $result['dataFileURLs'];
18   - }
19   - else {
20   - echo $result['message'];
21   - }
  13 +$amda_ws = new WebServer();
  14 +
  15 +if (!$_GET["token"]) {
  16 + return array('success' => false, 'message' => "E01\nAuthentication is required for this webservice.");
  17 +}
  18 +if ($amda_ws->getNewToken()['token'] != $_GET["token"]) {
  19 + return array('success' => false, 'message' => "E02\nToken expired. Please authenticate again.");
  20 +}
  21 +
  22 +$result = $amda_ws->getOrbites($_GET);
  23 +
  24 +if ($result['success']) {
  25 + echo $result['dataFileURLs'];
  26 +} else {
  27 + echo $result['message'];
  28 +}
22 29  
23 30 ?>
24 31 \ No newline at end of file
... ...
php/rest/getParameter.php
1 1 <?php
2   -
3   -/**
4   -* @file getParameter.php
5   -* @brief REST interface for service getParameter
6   -*
7   -*
8   -* @version $Id: $
9   -*/
10 2  
11   - require_once '../config.php';
  3 +/**
  4 + * @file getParameter.php
  5 + * @brief REST interface for service getParameter
  6 + *
  7 + *
  8 + * @version $Id: $
  9 + */
12 10  
13   - $amda_ws = new WebServer();
14   - $result = $amda_ws->getParameter($_GET);
  11 +require_once '../config.php';
15 12  
16   - if ($result['success']){
17   - echo $result['dataFileURLs'];
18   - }
19   - else {
20   - echo $result['message'];
21   - }
  13 +$amda_ws = new WebServer();
  14 +
  15 +if (!$_GET["token"]) {
  16 + return array('success' => false, 'message' => "E01\nAuthentication is required for this webservice.");
  17 +}
  18 +if ($amda_ws->getNewToken()['token'] != $_GET["token"]) {
  19 + return array('success' => false, 'message' => "E02\nToken expired. Please authenticate again.");
  20 +}
  21 +
  22 +$result = $amda_ws->getParameter($_GET);
  23 +
  24 +if ($result['success']) {
  25 + echo $result['dataFileURLs'];
  26 +} else {
  27 + echo $result['message'];
  28 +}
22 29  
23 30 ?>
24 31 \ No newline at end of file
... ...