82 lines
2.5 KiB
PHP
82 lines
2.5 KiB
PHP
<?php
|
|
if($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
|
http_response_code(405);
|
|
header('Content-Type: text/plain');
|
|
echo 'Unsupported request method.';
|
|
return;
|
|
}
|
|
|
|
$reqPath = '/' . trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
|
|
|
|
if($_SERVER['HTTP_HOST'] !== 'ip.flash.moe') {
|
|
$address = $_SERVER['REMOTE_ADDR'];
|
|
$version = (int)substr($_SERVER['HTTP_HOST'], 3, 1);
|
|
$packed = bin2hex(inet_pton($address));
|
|
|
|
if($reqPath === '/json') {
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Cache-Control: no-cache');
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
echo json_encode([
|
|
'a' => $address,
|
|
'h' => $packed,
|
|
'v' => $version,
|
|
]);
|
|
return;
|
|
}
|
|
|
|
if($reqPath === '/xml') {
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Cache-Control: no-cache');
|
|
header('Content-Type: application/xml; charset=utf-8');
|
|
$document = new DOMDocument('1.0', 'utf-8');
|
|
$root = $document->appendChild(new DOMElement('IPAddress'));
|
|
$root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
|
$root->setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
|
|
|
|
$root->setAttribute('version', $version);
|
|
$root->setAttribute('packed', $packed);
|
|
$root->appendChild(new DOMText($address));
|
|
|
|
echo $document->saveXML();
|
|
return;
|
|
}
|
|
|
|
if($reqPath === '/packed') {
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Cache-Control: no-cache');
|
|
header('Content-Type: text/plain');
|
|
echo $packed;
|
|
return;
|
|
}
|
|
|
|
if($reqPath === '/') {
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Cache-Control: no-cache');
|
|
header('Content-Type: text/plain');
|
|
echo $address;
|
|
return;
|
|
}
|
|
} else {
|
|
if($reqPath === '/style.css') {
|
|
header('Content-Type: text/css; charset=utf-8');
|
|
echo file_get_contents(__DIR__ . '/../style.css');
|
|
return;
|
|
}
|
|
|
|
if($reqPath === '/script.js') {
|
|
header('Content-Type: application/javascript; charset=utf-8');
|
|
echo file_get_contents(__DIR__ . '/../script.js');
|
|
return;
|
|
}
|
|
|
|
if($reqPath === '/') {
|
|
header('Content-Type: text/html; charset=utf-8');
|
|
echo file_get_contents(__DIR__ . '/../index.html');
|
|
return;
|
|
}
|
|
}
|
|
|
|
http_response_code(404);
|
|
header('Content-Type: text/plain');
|
|
echo 'Path not found.';
|