예제 #1
0
파일: init.php 프로젝트: geekypedia/aero
function fatal_handler()
{
    $error = error_get_last();
    if ($error !== NULL) {
        log_error($error);
        error_response(500, "There is some technical problem. Kindly contact the administrator.");
    }
}
예제 #2
0
function perform_list_operation()
{
    global $REQUIRED_IMAGE_OPERATION_ARGS, $am, $user;
    $operation = null;
    $missing_args = array();
    if (!array_key_exists('operation', $_GET)) {
        return error_response("Missing required argument: operation", RESPONSE_ERROR::ARGS);
    }
    $operation = $_GET['operation'];
    if (!array_key_exists($operation, $REQUIRED_IMAGE_OPERATION_ARGS)) {
        return error_response("Unsupported operation: " + $operation, RESPONSE_ERROR::ARGS);
    }
    $missing_args = check_required_args($operation);
    if (count($missing_args) > 0) {
        return error_response("Missing required arguments: " . join(", ", $missing_args), RESPONSE_ERROR::ARGS);
    }
    if ($am == null) {
        return error_response("Invalid AM provided", RESPONSE_ERROR::ARGS);
    }
    $am_url = $am[SR_ARGUMENT::SERVICE_URL];
    if ($operation == 'listimages') {
        $response = invoke_omni_function($am_url, $user, array('listimages'));
        $response = $response[1][$am_url];
        $output = am_response($response['code']['geni_code'], $response['value']);
    } else {
        if ($operation == 'createimage') {
            $response = invoke_omni_function($am_url, $user, array('createimage', $_GET['slice_name'], $_GET['image_name'], $_GET['public'], '--project', $_GET['project_name'], '-u', $_GET['sliver_id']));
            $response = $response[1];
        } else {
            if ($operation == 'deleteimage') {
                $urn = $_GET['image_urn'];
                $args = array('deleteimage', $urn);
                $response = invoke_omni_function($am_url, $user, $args);
                $response = $response[1][$am_url];
            }
        }
    }
    $code = $response['code']['geni_code'];
    if ($code == 0) {
        $output = am_response($code, $response['value']);
    } else {
        $output = error_response($response['output'], $code);
    }
    return $output;
}
예제 #3
0
if (isset($json_data["query"])) {
    $mysql_db = $conn_opts["database"];
    $sel_db = @mysql_select_db($mysql_db, $conn);
    if (!$sel_db) {
        error_response(3, "Failed to select DB " . $mysql_db);
        die;
    }
    $result = @mysql_query($json_data["query"], $conn);
    if (!$result) {
        if ($json_data["query"] == "SHOW DATABASES;") {
            // fix when missing permission to list databases
            header('Content-type: application/json');
            forceShowDbResponse($conn_opts["database"]);
            die;
        } else {
            error_response(mysql_errno($conn), mysql_error($conn));
            die;
        }
    }
    $fieldsInfo = getFieldsInfo($result, $mysql_db);
    /**
     * in case of processing query the response is streamed out instead of preparing whole bunch of data in memory
     */
    logToFile("RESPONSE:");
    header('Content-type: application/json');
    $responseBegin = '{"resultset": {"fields": ' . json_encode(getFieldsInfo($result, $mysql_db)) . ', "rows":[';
    echo $responseBegin;
    logToFile($responseBegin);
    streamResultRows($result);
    $responseEnd = ']}, "numRowsAffected": ' . json_encode(mysql_affected_rows($conn)) . ', "lastInsertId": ' . json_encode(mysql_insert_id($conn)) . '}';
    echo $responseEnd;
<?php

$vin_lookup_model = '../models/vin_lookup.php';
require $vin_lookup_model;
$vin = $_POST['vin_number'];
$response = error_response('El numero de bastidor es invalido');
if (isset($vin) && vin_number_is_valid($vin)) {
    $car_details = '';
    $vinlookup = new VinLookup();
    $car_details = $vinlookup->retrieve_car_details_with_vin_number($vin);
    //if !car_details  $response = error_response('error a recuperar el numero de bastidor desde la API');
    $response = json_encode(array('status' => 200, 'car_details' => $car_details));
}
echo $response;
function vin_number_is_valid($vin)
{
    $vin_is_valid = true;
    preg_match('/[ABCDEFGHLJKMNPRSTUVXYWZ0-9]{17}$/', $vin, $matches);
    //IOQÑ are not allowed
    $vin_is_valid = strlen($vin) == 17 && count($matches) > 0;
    return $vin_is_valid;
}
function error_response($error_description)
{
    $errors['server_answer'] = 'La pagina no responde, no existe o no contiene nada';
    $errors['error_description'] = $error_description;
    $response = json_encode(array('status' => 400, 'errors' => json_encode($errors)));
    return $response;
}
예제 #5
0
파일: contact.php 프로젝트: LyriD/tmp_m
}, 'message' => function ($value) {
    $value = trim($value);
    return strlen($value) ? $value : false;
}, 'phone' => function ($value) {
    return trim($value);
}];
$data = [];
foreach ($fields as $field => $validator) {
    $value = isset($_POST[$field]) ? $_POST[$field] : null;
    $data[$field] = $validator($value);
    if ($value === false) {
        error_response();
    }
}
if (!send_email($data)) {
    error_response();
}
success_response();
function error_response()
{
    header('Content-type: application/json');
    http_response_code(400);
    exit;
}
function success_response()
{
    header('Content-type: application/json');
    http_response_code(204);
    exit;
}
function send_email($data)