35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
const INCLUDER = true;
|
|
require_once __DIR__ . '/lib.php';
|
|
|
|
$cli = strtolower(php_sapi_name()) === 'cli';
|
|
|
|
$headers = getallheaders();
|
|
$raw = file_get_contents('php://input');
|
|
|
|
$apikey = Config::apiKey();
|
|
|
|
$allowed = $headers['X-Api-Key'] === $apikey || $_GET['X-Api-Key'] === $apikey || $_POST['X-Api-Key'] === $apikey;
|
|
|
|
if ($allowed) {
|
|
try {
|
|
if ($_GET['type'] == 'uplink' && preg_match("!thethings\.network$!i", $headers["X-Tts-Domain"])) {
|
|
$process = new UplinkData($raw, $headers);
|
|
$process->write();
|
|
Logging::info('uplink', $headers, $raw);
|
|
} else {
|
|
db_logging($_GET['type'] ?? 'error', $raw, $headers);
|
|
Logging::info($_GET['type'] || 'error', $headers);
|
|
}
|
|
} catch (Throwable $e) {
|
|
error_log($e->getMessage() . ' - see also /tmp/track-error.log');
|
|
Logging::info('error', $e->getMessage(), $headers, $_GET, $_POST, json_decode($raw));
|
|
}
|
|
} else {
|
|
Logging::info('error', "Not allowed", $headers, $_GET, $_POST, json_decode($raw));
|
|
}
|
|
|
|
header("Content-Type: application/json", true, 200);
|
|
echo "true";
|
|
exit(0);
|