Exemplo n.º 1
0
 /**
 * Returns a list of all stations according to the lang variable and what the API returns. Normally it will have these variables:
 * array[i] -> name
            -> locationX
            -> locationY
            -> standardname
 */
 private function getClosestStations($y, $x, $system)
 {
     include "config.php";
     //check if the stationslist hasn't been loaded yet and load the systems
     if (!isset($this->{$system})) {
         try {
             $args = array("system" => $system, "lang" => "NL");
             $this->{$system} = APICall::execute("stations", $args);
         } catch (Exception $e) {
             throw $e;
         }
     }
     $output = array();
     $stations = $this->{$system};
     //Loop and check if distance is smaller then the vicinity, you only want to get stations nearby
     foreach ($stations["station"] as $station) {
         $dist = $this->distance($x, $station["locationX"], $y, $station["locationY"]);
         if (!is_nan($dist) && $dist < $vicinity) {
             $station["distance"] = floor($dist * 1000);
             //in meters
             $output[sizeof($output)] = $station;
         }
     }
     $output = $this->removeDuplicates($output);
     return $output;
 }
Exemplo n.º 2
0
 public static function execute($functionname, $argumentarray = array())
 {
     //preconditions: we need a good functionname (probably one of the four defined in the iRail api, but let's not be racist). If we urlencode the functionname we're sure that no hacking will be possible (such as entering http://www.ihazhackedyourwebsitescript as a functionname)
     $functionname = urlencode($functionname);
     //url encode the argumentsarray so we have a good call to the API
     $arguments = "";
     //Set the GETs, &KEY1=VAL1&KEY2=VAL2...
     foreach ($argumentarray as $key => $val) {
         $arguments .= "&" . urlencode($key) . "=" . urlencode($val);
     }
     include "config.php";
     //Create final url to CALLAPI
     $url = $APIurl . $functionname . "/?format=json" . $arguments;
     //Now let's fire up the call to the api and return the result
     try {
         $json = json_decode(APICall::httpcall($url), true);
         if (isset($json["error"])) {
             //throw new Exception($json["message"]);
         }
         return $json;
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 3
0
 private static function fetchAllStationsFromDB($lang)
 {
     APICall::connectToDB();
     $station = array();
     try {
         $lang = mysql_real_escape_string(strtoupper($lang));
         $query = "SELECT `ID`,`X`, `Y`, `STD`,`{$lang}` FROM stations WHERE `ID` LIKE 'BE.NMBS.%' ORDER BY `{$lang}`";
         $result = mysql_query($query) or die("Could not get stationslist from DB");
         $i = 0;
         while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
             $station[$i] = new Station();
             $station[$i]->id = $line["ID"];
             $station[$i]->locationX = $line["X"];
             $station[$i]->locationY = $line["Y"];
             if ($line[$lang] != "") {
                 $station[$i]->name = $line[$lang];
             } else {
                 $station[$i]->name = $line["STD"];
             }
             $station[$i]->standardname = $line["STD"];
             $i++;
         }
     } catch (Exception $e) {
         throw new Exception("Error reading from the database.", 3);
     }
     return $station;
 }
Exemplo n.º 4
0
/* Copyright (C) 2010, 2011 by iRail vzw/asbl */
/*

 This file is part of iRail.

 iRail is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 iRail is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with iRail.  If not, see <http://www.gnu.org/licenses/>.

 http://project.irail.be - http://irail.be

 source available at http://github.com/Tuinslak/iRail
*/
/**
 * This is the API request handler
 */
include_once "requests/StationsRequest.php";
include_once "APICall.php";
date_default_timezone_set("Europe/Brussels");
$call = new APICall("stations");
$call->executeCall();
 public static function getUnifiedAPICalls($cycleID, $onlyErrornousCalls = false)
 {
     $errornousFilter = $onlyErrornousCalls ? 'AND IFNULL(ds.error_code_id,f.error_code_id) IS NOT NULL' : '';
     $rows = MySQLRunner::execute("SELECT ds.session_id, ds.request_index, ds.user_ip FROM kalturadw_ds.ds_incomplete_api_calls ds, kalturadw.dwh_fact_incomplete_api_calls f " . "WHERE ds.session_id = f.session_id " . "AND ds.request_index = f.request_index " . "AND ds.user_ip = f.user_ip " . "AND ds.cycle_id=? " . "AND IFNULL(ds.api_call_date_id, f.api_call_date_id) IS NOT NULL " . "AND IFNULL(ds.duration_msecs, f.duration_msecs) IS NOT NULL {$onlyErrornousCalls}", array(0 => $cycleID));
     $res = array();
     foreach ($rows as $row) {
         $res[] = APICall::CreateAPICallByID($row["session_id"], $row["request_index"], $row["user_ip"]);
     }
     return $res;
 }
Exemplo n.º 6
0
 protected function logRequest()
 {
     $r = $this->request;
     parent::writeLog($_SERVER['HTTP_USER_AGENT'], $r->getFrom(), $r->getTo(), "none (connections)", $_SERVER['REMOTE_ADDR']);
 }
Exemplo n.º 7
0
 protected function writeLog($ua, $from, $to, $err, $ip)
 {
     // get time + date in rfc2822 format
     date_default_timezone_set('Europe/Brussels');
     $now = date('D, d M Y H:i:s');
     if ($from == "") {
         $from = "EMPTY";
     }
     if ($to == "") {
         $to = "EMPTY";
     }
     if ($ua == "") {
         $ua = "-";
     }
     APICall::connectToDB();
     $from = mysql_real_escape_string($from);
     $to = mysql_real_escape_string($to);
     $err = mysql_real_escape_string($err);
     $ip = mysql_real_escape_string($ip);
     $ua = mysql_real_escape_string($ua);
     // insert in db
     try {
         include "../includes/dbConfig.php";
         $query = "INSERT INTO {$api_table} ({$api_c2}, {$api_c3}, {$api_c4}, {$api_c5}, {$api_c6}, {$api_c7}, {$api_c8}) VALUES('{$now}', '{$ua}', '{$from}', '{$to}', '{$err}', '{$ip}', '{$api_server_name}')";
         $result = mysql_query($query);
     } catch (Exception $e) {
         echo "Error writing to the database.";
     }
 }
Exemplo n.º 8
0
 /**
  * @param $lang
  * @return array
  * @throws Exception
  */
 private static function fetchAllStationsFromDB($lang)
 {
     if ($lang == "EN") {
         $lang = "STD";
     }
     APICall::connectToDB();
     mysql_query("SET NAMES utf8");
     $station = [];
     try {
         $lang = mysql_real_escape_string(strtoupper($lang));
         $query = "SELECT `ID`,`X`, `Y`, `STD`,`{$lang}` FROM mivb ORDER BY `{$lang}`";
         $result = mysql_query($query) || die("Could not get stationslist from DB");
         $i = 0;
         while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
             $station[$i] = new Station();
             $station[$i]->id = $line["ID"];
             $station[$i]->locationX = $line["X"];
             $station[$i]->locationY = $line["Y"];
             $station[$i]->name = $line[$lang];
             $station[$i]->standardname = $line["STD"];
             $i++;
         }
     } catch (Exception $e) {
         throw new Exception("Error reading from the database.", 300);
     }
     return $station;
 }
 private function getFileApiIncompleteCalls($file)
 {
     $requestStarts = array();
     $requestEnds = array();
     $lines = file($file);
     foreach ($lines as $line) {
         if (!APICall::ignoredLine($line) && APICall::validLine($line)) {
             $id = APICall::getLineID($line);
             if (strpos($line, 'request_start') > -1) {
                 if (array_key_exists($id, $requestEnds)) {
                     unset($requestEnds[$id]);
                     continue;
                 }
                 $requestStarts[$id] = APICall::CreateAPICallByLine($line);
             } else {
                 if (strpos($line, 'request_end') > -1) {
                     if (array_key_exists($id, $requestStarts)) {
                         unset($requestStarts[$id]);
                         continue;
                     }
                     $requestEnds[$id] = APICall::CreateAPICallByLine($line);
                 }
             }
         }
     }
     return array_merge($requestStarts, $requestEnds);
 }
Exemplo n.º 10
0
 /**
  * @param $ua
  * @param $from
  * @param $to
  * @param $err
  * @param $ip
  * @throws Exception
  */
 protected function writeLog($ua, $from, $to, $err, $ip)
 {
     // get time + date in rfc2822 format
     date_default_timezone_set('Europe/Brussels');
     $now = date('D, d M Y H:i:s');
     if ($from == "") {
         $from = "EMPTY";
     }
     if ($to == "") {
         $to = "EMPTY";
     }
     if ($ua == "") {
         $ua = "-";
     }
     APICall::connectToDB();
     $from = mysql_real_escape_string($from);
     $to = mysql_real_escape_string($to);
     $err = mysql_real_escape_string($err);
     $ip = mysql_real_escape_string($ip);
     $ua = mysql_real_escape_string($ua);
     // insert in db
     try {
         $dotenv = new Dotenv(dirname(__DIR__));
         $dotenv->load();
         $query = "\n              INSERT INTO {$api_table} ({$api_c2}, {$api_c3}, {$api_c4}, {$api_c5}, {$api_c6}, {$api_c7}, {$api_c8})\n              VALUES('{$now}', '{$ua}', '{$from}', '{$to}', '{$err}', '{$ip}', '" . $_ENV['apiServerName'] . "')";
         $result = mysql_query($query);
     } catch (Exception $e) {
         echo "Error writing to the database.";
     }
 }