Added files
This commit is contained in:
34
api.php
Normal file
34
api.php
Normal 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);
|
||||
Reference in New Issue
Block a user