35 lines
727 B
PHP
35 lines
727 B
PHP
<?php
|
|
include_once realpath(dirname(__DIR__, 2) . '/bootstrap/autoload.php');
|
|
|
|
$get = $_GET;
|
|
$post = $_POST;
|
|
|
|
function get_keys() {
|
|
$filename = realpath('./keys');
|
|
$keys = [];
|
|
if ($filename !== false) {
|
|
$keys = json_decode(trim(file_get_contents($filename)));
|
|
}
|
|
return $keys;
|
|
}
|
|
function validate_key($keys, $key) {
|
|
if (array_search($key, $keys) !== false) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
$keys = get_keys();
|
|
|
|
$key = $get['API_KEY'];
|
|
if (!validate_key($keys, $key)) {
|
|
throw new Exception('Error en la identificacion.');
|
|
}
|
|
|
|
$p = $get['page'] ?? $get['p'];
|
|
$a = $get['action'] ?? $get['a'];
|
|
if ($p == 'precios' and $a == 'importar') {
|
|
$data = json_decode($post['data']);
|
|
echo json_encode($data);
|
|
}
|