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.

73 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('GET', '/cert', 'Certbot::index');
  27. $router->addRoute('GET', '/cert/auth', 'Certbot::start_auth');
  28. $router->addRoute('GET', '/cert/logout', 'Certbot::logout');
  29. $router->addRoute('GET', '/cert/redirect', 'Certbot::redirect');
  30. $router->addRoute('POST', '/cert/save-challenge', 'Certbot::save_challenge');
  31. $router->addRoute('GET', '/.well-known/acme-challenge/{token}', 'Certbot::challenge');
  32. $dispatcher = $router->getDispatcher();
  33. $request = Request::createFromGlobals();
  34. try {
  35. $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
  36. $response->send();
  37. } catch(League\Route\Http\Exception\NotFoundException $e) {
  38. $response = new Response;
  39. $response->setStatusCode(404);
  40. $response->setContent("Not Found\n");
  41. $response->send();
  42. } catch(League\Route\Http\Exception\MethodNotAllowedException $e) {
  43. $response = new Response;
  44. $response->setStatusCode(405);
  45. $response->setContent("Method not allowed\n");
  46. $response->send();
  47. }
  48. function shutdown() {
  49. $error = error_get_last();
  50. if($error['type'] === E_ERROR) {
  51. header('HTTP/1.1 500 Server Error');
  52. header('X-PHP-Error-Type: '.$error['type']);
  53. header('X-PHP-Error-Message: '.$error['message']);
  54. header('Content-Type: application/json');
  55. echo json_encode([
  56. 'error' => 'internal_error',
  57. 'error_code' => 500,
  58. 'error_description' => $error['message'],
  59. 'debug' => 'Please file an issue with any information you have about what caused this error: https://github.com/aaronpk/XRay/issues'
  60. ]);
  61. die();
  62. }
  63. }