WebOrbiton
v1.0.1

AtheraStudio Database

69 lines · 2.2 KB
  1. <?php
  2. declare(strict_types=1);
  3. ​
  4. namespace Athera;
  5. ​
  6. defined('ATHERA') || exit;
  7. ​
  8. final class App
  9. {
  10. public static function run(): void
  11. {
  12. ini_set('zlib.output_compression', '0');
  13. if (function_exists('header_remove')) header_remove('X-Powered-By');
  14. Http::noCache();
  15. try {
  16. Config::boot();
  17. } catch (\Throwable $e) {
  18. self::plain(500, 'AtheraStudio Database: ' . $e->getMessage());
  19. return;
  20. }
  21. try {
  22. self::route();
  23. } catch (\Throwable $e) {
  24. Security::log(['ev' => 'error', 'error' => mb_substr($e->getMessage() . ' @ ' . basename($e->getFile()) . ':' . $e->getLine(), 0, 500)]);
  25. if (!headers_sent()) self::plain(500, 'Internal error');
  26. }
  27. }
  28. ​
  29. private static function route(): void
  30. {
  31. if (!Security::ipAllowed()) {
  32. Security::log(['ev' => 'ip_denied', 'path' => mb_substr((string)($_SERVER['REQUEST_URI'] ?? ''), 0, 200)]);
  33. self::plain(403, 'Forbidden');
  34. return;
  35. }
  36. if (Config::bool('REQUIRE_HTTPS') && !Http::https()) {
  37. if (($_SERVER['REQUEST_METHOD'] ?? '') === 'GET' && !isset($_GET['api'])) {
  38. header('Location: ' . preg_replace('/^http:/', 'https:', Http::origin()) . Http::basePath(), true, 301);
  39. return;
  40. }
  41. self::plain(403, 'HTTPS required');
  42. return;
  43. }
  44. $path = (string)parse_url((string)($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH);
  45. $base = Http::basePath();
  46. if ($path !== '' && $path . '/' === $base && empty($_GET)) {
  47. header('Location: ' . $base, true, 301);
  48. return;
  49. }
  50. if (isset($_GET['unlock'])) {
  51. Page::unlock((string)$_GET['unlock']);
  52. return;
  53. }
  54. if (isset($_GET['api'])) {
  55. Api::handle((string)$_GET['api']);
  56. return;
  57. }
  58. Page::render();
  59. }
  60. ​
  61. public static function plain(int $code, string $text): void
  62. {
  63. http_response_code($code);
  64. Http::securityHeaders(false);
  65. header('Content-Type: text/plain; charset=utf-8');
  66. echo $text;
  67. }
  68. }
  69. ​