Added files

This commit is contained in:
Holger Sielaff
2025-06-28 16:23:47 +02:00
parent 21a2714401
commit e2eeeaefcd
8 changed files with 328 additions and 0 deletions

34
api.php Normal file
View File

@@ -0,0 +1,34 @@
<?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);