index.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // Init
  3. error_reporting(NULL);
  4. ob_start();
  5. session_start();
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Check token
  8. if ((!isset($_GET['token'])) || ($_SESSION['token'] != $_GET['token'])) {
  9. header('location: /login/');
  10. exit();
  11. }
  12. // If the session has the same reset token as the current request prevent restarting again.
  13. // This happens when the server is restarted, the admin panel goes down and the browser reloads
  14. // the /restart/index.php page once the server goes online causing restart loop.
  15. $reset_token_dir = '/var/tmp/';
  16. if (isset($_GET['system_reset_token']) && is_numeric($_GET['system_reset_token'])) {
  17. clearstatcache();
  18. $reset_token_file = $reset_token_dir . 'hst_reset_' . $_GET['system_reset_token'];
  19. if (file_exists($reset_token_file)) {
  20. unlink($reset_token_file);
  21. sleep(5);
  22. header('location: /list/server/');
  23. exit();
  24. }
  25. if ($_SESSION['user'] == 'admin') {
  26. if (!empty($_GET['hostname'])) {
  27. touch($reset_token_file);
  28. $_SESSION['error_msg'] = 'The system is going down for reboot NOW!';
  29. touch($reset_token_file . '_persistent');
  30. exec(HESTIA_CMD . "v-restart-system yes", $output, $return_var);
  31. }
  32. unset($output);
  33. }
  34. }
  35. header("Location: /list/server/");
  36. exit();