You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.5 KiB

  1. <?php
  2. chdir(dirname(__FILE__).'/..');
  3. include('vendor/autoload.php');
  4. register_shutdown_function('shutdown');
  5. // Load config file if present, otherwise use default
  6. if(file_exists(dirname(__FILE__).'/../config.php')) {
  7. require dirname(__FILE__).'/../config.php';
  8. } else {
  9. class Config {
  10. public static $cache = false;
  11. public static $admins = [];
  12. public static $base = '';
  13. }
  14. }
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. $router = new League\Route\RouteCollection;
  18. $templates = new League\Plates\Engine(dirname(__FILE__).'/../views');
  19. $router->addRoute('GET', '/', 'Main::index');
  20. $router->addRoute('GET', '/parse', 'Parse::parse');
  21. $router->addRoute('POST', '/parse', 'Parse::parse');
  22. $router->addRoute('POST', '/token', 'Token::token');
  23. $router->addRoute('GET', '/feeds', 'Feeds::find');
  24. $router->addRoute('POST', '/feeds', 'Feeds::find');
  25. $router->addRoute('GET', '/rels', 'Rels::fetch');
  26. $router->addRoute('POST', '/rels', 'Rels::fetch');
  27. $router->addRoute('GET', '/cert', 'Certbot::index');
  28. $router->addRoute('GET', '/cert/auth', 'Certbot::start_auth');
  29. $router->addRoute('GET', '/cert/logout', 'Certbot::logout');
  30. $router->addRoute('GET', '/cert/redirect', 'Certbot::redirect');
  31. $router->addRoute('POST', '/cert/save-challenge', 'Certbot::save_challenge');
  32. $router->addRoute('GET', '/.well-known/acme-challenge/{token}', 'Certbot::challenge');
  33. $dispatcher = $router->getDispatcher();
  34. $request = Request::createFromGlobals();
  35. try {
  36. $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
  37. $response->send();
  38. } catch(League\Route\Http\Exception\NotFoundException $e) {
  39. $response = new Response;
  40. $response->setStatusCode(404);
  41. $response->setContent("Not Found\n");
  42. $response->send();
  43. } catch(League\Route\Http\Exception\MethodNotAllowedException $e) {
  44. $response = new Response;
  45. $response->setStatusCode(405);
  46. $response->setContent("Method not allowed\n");
  47. $response->send();
  48. }
  49. function shutdown() {
  50. $error = error_get_last();
  51. if($error['type'] === E_ERROR) {
  52. header('HTTP/1.1 500 Server Error');
  53. header('X-PHP-Error-Type: '.$error['type']);
  54. header('X-PHP-Error-Message: '.$error['message']);
  55. header('Content-Type: application/json');
  56. echo json_encode([
  57. 'error' => 'internal_error',
  58. 'error_code' => 500,
  59. 'error_description' => $error['message'],
  60. 'debug' => 'Please file an issue with any information you have about what caused this error: https://github.com/aaronpk/XRay/issues'
  61. ]);
  62. die();
  63. }
  64. }