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.

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