Пример #1
0
$filePath = "./CINEMA.xml";
//Gestione degli errori
if ($_SERVER['REQUEST_METHOD'] != "GET") {
    sendHTTPError($Errore[405], "Il metodo utilizzato non e' di tipo GET");
}
if ($URL_key and $URL_comp and $URL_value) {
    //...ne verifico la correttezza semantica(funzione definita nel file funzioni.php)
    if (correttezzaConfronti($comparazioniValide, $URL_key, $URL_comp) == FALSE) {
        sendHTTPError($Errore[406], "Comparazione al di fuori delle specifiche");
    }
} else {
    if (!$URL_key and !$URL_comp and !$URL_value) {
        $XPath_query = '/locations/location';
        //restituisco il database intero come da protocollo
    } else {
        sendHTTPError($Errore[406], "Parametro non settato");
    }
}
//Genero la query Xpath
if (!$URL_key and !$URL_comp and !$URL_value) {
    $XPath_query = '/locations/location';
} else {
    if ($URL_comp == 'contains') {
        if ($URL_key == 'id') {
            $URL_key = '@' . $URL_key;
        }
        $upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ";
        $lower = "abcdefghijklmnopqrstuvwxyzæøå";
        $XPath_query = '/locations/location[contains(translate(' . $URL_key . ',"' . $upper . '","' . $lower . '"),"' . $URL_value . '")]';
    } else {
        if ($URL_comp == 'ncontains') {
Пример #2
0
$lat1 = $_GET["lat1"];
$long1 = $_GET["long1"];
$lat2 = $_GET["lat2"];
$long2 = $_GET["long2"];
$lat1 = trim($lat1);
$lat2 = trim($lat2);
$long1 = trim($long1);
$long2 = trim($long2);
//Gestione degli errori
if (!$lat1 or !$lat2 or !$long1 or !$long2) {
    sendHTTPError($Errore[406], 'Uno o piu parametri assenti');
}
if (is_numeric($lat1) == FALSE or is_numeric($lat2) == FALSE or is_numeric($long1) == FALSE or is_numeric($long2) == FALSE) {
    sendHTTPError($Errore[406], 'Uno o piu parametri non sono numeri');
}
//Verifico che lat e long siano rispettino gli standard reali
if (90 >= $lat1 and $lat1 >= -90 and 90 >= $lat2 and $lat2 >= -90 and 180 >= $long1 and $long1 >= -180 and 180 >= $long2 and $long2 >= -180) {
    //Calcolo la distanza
    $diff_long = $long1 - $long2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($diff_long));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    $distanzainkm = $miles * 1.609344;
    $distanzainm = $distanzainkm * 1000;
    //Mando il risultato
    sendHTTPResult("Content-type: text/plain", $distanzainm);
    //echo $distanzainm;
} else {
    sendHTTPError($Errore[406], 'Valori al di fuori del range massimo (-90/90 per lat e -180/180 per long)');
}
Пример #3
0
<?php

//Margherita Donnici
require_once '../funzioni.php';
//Prendo i valori dall'url
$orario1 = $_GET["orario1"];
//'Mon, Tue, Thu, Wed, Fri, Sat, Sun: 2105-0130';
$orario2 = $_GET["orario2"];
// '2012-02-02: 2135-2136';
//Gestione degli errori
if (!$orario1 or !$orario2) {
    sendHTTPError($Errore[406], 'Parametri assenti');
}
$arrayorario1 = explode('.', $orario1);
// Divido la stringa degli orari della struttura in un array di stringhe con in ogni posizione un set di orari
$arrayorario2 = explode(':', $orario2);
// Divido la stringa dell'orario ricercato in un array con il giorno in posizione 0 e l'intervallo di orari in posizione 1
$pattern = "/^[0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2}\$/";
//Creo una espressione regolare che corrisponde alla data nel formato richiesto dal rpotocollo
//Se il giorno ricercato è nella forma yyyy-mm-dd lo converto
if (preg_match($pattern, $arrayorario2[0])) {
    // Conversione data => giorno settimanale
    //Trovo il gioprno della settimana con la funzione date che restituisce una stringa formattata secondo la
    //stringa formato passata come paramentro, in questo caso D usando il timestamp passato egualmente come parametro
    $data = explode('-', $arrayorario2[0]);
    // $data[0] = anno, $data[1]=mese, $data[2]=giorno
    $h = mktime(0, 0, 0, $data[1], $data[2], $data[0]);
    //Creo un timestamp con la data ricercata
    $w = date("D", $h);
    $arrayorario2[0] = $w;
}
Пример #4
0
function curl_request($url, $accept)
{
    //Ricevo l'arrey con gli header della risposta
    $arrey_headers = get_headers($url, 1);
    //Salvo il Content-Type della risposta
    $content = $arrey_headers["Content-Type"];
    //Richiesta CURL
    if (!function_exists('curl_init')) {
        die('Sorry cURL is not installed!');
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    // Include header in result? (0 = yes, 1 = no)
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: text/turtle, text/csv, application/json,  application/xml"));
    // Should cURL return or print out the data? (true = return, false = print)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    //Genero nome random per il file temporaneo
    $nomefiletemp = random_string(5);
    //Creo un file temporaneo dove salvare il risultato
    $ourFileHandle = fopen($nomefiletemp . ".txt", 'w+') or die("can't open file");
    fwrite($ourFileHandle, $output);
    fclose($ourFileHandle);
    //Leggo il Content-type della risposta e se necessario converto
    switch ($content) {
        case "application/json":
            $xml = json2xml($nomefiletemp . ".txt");
            break;
        case "text/csv":
            $xml = csv2xml($nomefiletemp . ".txt");
            break;
        case "text/turtle":
            $xml = turtle2xml($nomefiletemp . ".txt");
            break;
        case "application/xml":
            $xml = $output;
            break;
            //Errore
        //Errore
        case "text/plain":
            sendHTTPError($output, 'Sorgente errore --> aggregatore');
            break;
        default:
            unlink($nomefiletemp . ".txt");
            sendHTTPError('Attenzione', 'Formato ricevuto non accettato, Sorgente errore --> aggregatore');
            break;
    }
    //remove temp file
    unlink($nomefiletemp . ".txt");
    //Genero nome random per il file temporaneo
    $nomefiletemp2 = random_string(5);
    //Creo file temporaneo con la risposta convertita in formato XML
    $ourFileHandle2 = fopen($nomefiletemp2 . ".xml", 'w+') or die("can't open file");
    fwrite($ourFileHandle2, $xml);
    fclose($ourFileHandle2);
    //Converto nel formato richiesto dal narratore
    switch ($accept) {
        case "application/json":
            $result = xml2json($nomefiletemp2 . ".xml");
            break;
        case "text/csv":
            $result = xml2csv($nomefiletemp2 . ".xml");
            break;
        case "text/turtle":
            $result = turtle2xml($nomefiletemp2 . ".xml");
            break;
        case "application/xml":
            $result = $xml;
            break;
        default:
            unlink($nomefiletemp2 . ".xml");
            sendHTTPError('Attenzione', 'Formato richiesto non accettato');
            break;
    }
    //remove temp file
    unlink($nomefiletemp2 . ".xml");
    return $result;
}
Пример #5
0
require_once '../funzioni.php';
require_once '../conversioni/CONVERSIONI_NEW.php';
//Prendo i valori dall'url
$strinput = strtolower($_GET['s']);
$strinput = trim($strinput);
$idagg = strtolower($_GET['aggr_id']);
$idagg = trim($idagg);
//Leggo l'accept header del narratore
$arrayHead = apache_request_headers();
$accept = $arrayHead["Accept"];
//Gestione degli errori
if (!$idagg or !$strinput) {
    sendHTTPError($Errore[406], 'Parametro/i assente/i');
}
//Richiamo la funzione per ricercare l'url dell'aggregatore
$urlaggr = get_aggr_url($idagg);
//Se non esiste rispondo con un errore
if ($urlaggr == NULL) {
    sendHTTPError($Errore[404], 'Aggregatore non trovato');
}
//Custom: se nel narratore viene effettuata una ricerca vuota, restituisco tutto il database
if ($strinput == '*') {
    $url = $urlaggr;
    $xml_result = curl_request($url, $accept);
    sendHTTPResult("Content-type: " . $accept . "; charset=utf-8", $xml_result);
} else {
    $url = $urlaggr . "/name/contains/" . $strinput;
    $xml_result = curl_request($url, $accept);
    //Mando il risultato
    sendHTTPResult("Content-type: " . $accept . "; charset=utf-8", $xml_result);
}
Пример #6
0
            error_log("Caugth {$e} with status code " . $e->getCode() . "which should not happen! Check the code at " . $e->getFile() . ":" . $e->getLine());
            /* no break here - falling back to Internal Server Error */
        /* no break here - falling back to Internal Server Error */
        default:
            $r = new \PKIX\OCSP\InternalErrorResponse();
            break;
    }
    $r->respond();
} catch (\PKIX\ASN1\HTTPException $e) {
    logException($e);
    $c = $e->getCode();
    if ($c < 100 || $c > 599) {
        error_log(get_class($e) . " called with non HTTP error code {$c}! " . "Check the code at " . $e->getFile() . ":" . $e->getLine());
        $c = \PKIX\ASN1\HTTP_INTERNAL_SERVER_ERROR;
    }
    sendHTTPError($c);
} catch (\OCSPServer\Exception $e) {
    logException($e);
    switch ($e->getCode()) {
        case OCSPSERVER_ERR_NOTEXIST:
            $r = new \PKIX\OCSP\InternalErrorResponse();
            break;
        case OCSPSERVER_ERR_NOT_FOUND:
            $r = new \PKIX\OCSP\UnauthorizedResponse();
            break;
        default:
            error_log(get_class($e) . " caught with unexpected code " . $e->getCode() . "! " . "Check the code at " . $e->getFile() . ":" . $e->getLine());
            $r = new \PKIX\OCSP\InternalErrorResponse();
            break;
    }
    $r->respond();