index.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. ob_start();
  4. $TAB = "WEB";
  5. // Main include
  6. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  7. require_once $_SERVER["DOCUMENT_ROOT"] . "/src/init.php";
  8. // Check domain argument
  9. if (empty($_GET["domain"])) {
  10. header("Location: /list/web/");
  11. exit();
  12. }
  13. // Edit as someone else?
  14. if ($_SESSION["user"] == "admin" && !empty($_GET["user"])) {
  15. $user = quoteshellarg($_GET["user"]);
  16. }
  17. // Check if domain belongs to the user
  18. $v_domain = $_GET["domain"];
  19. exec(
  20. HESTIA_CMD . "v-list-web-domain " . $user . " " . quoteshellarg($v_domain) . " json",
  21. $output,
  22. $return_var,
  23. );
  24. if ($return_var > 0) {
  25. check_return_code_redirect($return_var, $output, "/list/web/");
  26. }
  27. unset($output);
  28. exec(HESTIA_CMD . "v-list-sys-php json", $output, $return_var);
  29. $php_versions = json_decode(implode("", $output), true);
  30. unset($output);
  31. // Check GET request
  32. if (!empty($_GET["app"])) {
  33. $app = basename($_GET["app"]);
  34. $hestia = new \Hestia\System\HestiaApp();
  35. $app_installer_class = "\Hestia\WebApp\Installers\\" . $app . "\\" . $app . "Setup";
  36. if (class_exists($app_installer_class)) {
  37. try {
  38. $app_installer = new $app_installer_class($hestia);
  39. $info = $app_installer->getInfo();
  40. if (!$info->isInstallable()) {
  41. $_SESSION["error_msg"] = sprintf(
  42. _("Unable to install %s, required php version is not available."),
  43. $app,
  44. );
  45. } else {
  46. $installer = new \Hestia\WebApp\AppWizard($app_installer, $v_domain, $hestia);
  47. $GLOBALS["WebappInstaller"] = $installer;
  48. }
  49. } catch (Exception $e) {
  50. $_SESSION["error_msg"] = $e->getMessage();
  51. header("Location: /add/webapp/?domain=" . $v_domain);
  52. exit();
  53. }
  54. } else {
  55. $_SESSION["error_msg"] = sprintf(_("%s installer missing."), $app);
  56. }
  57. }
  58. // Check POST request
  59. if (!empty($_POST["ok"]) && !empty($app)) {
  60. // Check token
  61. verify_csrf($_POST);
  62. if ($installer) {
  63. try {
  64. $installer->execute($_POST);
  65. $_SESSION["ok_msg"] = sprintf(_("%s installed successfully."), htmlspecialchars($app));
  66. header("Location: /add/webapp/?domain=" . $v_domain);
  67. exit();
  68. } catch (Exception $e) {
  69. $_SESSION["error_msg"] = $e->getMessage();
  70. header("Location: /add/webapp/?app=" . rawurlencode($app) . "&domain=" . $v_domain);
  71. exit();
  72. }
  73. }
  74. }
  75. if (!empty($installer)) {
  76. render_page($user, $TAB, "setup_webapp");
  77. } else {
  78. $hestia = new \Hestia\System\HestiaApp();
  79. $appInstallers = glob(__DIR__ . "/../../src/app/WebApp/Installers/*/*.php");
  80. $v_web_apps = [];
  81. foreach ($appInstallers as $app) {
  82. $pattern = "/Installers\/([a-zA-Z][a-zA-Z0,9].*)\/([a-zA-Z][a-zA-Z0,9].*)Setup\.php/";
  83. $class = "\Hestia\WebApp\Installers\%s\%sSetup";
  84. if (preg_match($pattern, $app, $matches)) {
  85. $app_installer_class = sprintf($class, $matches[1], $matches[1]);
  86. $v_web_apps[] = (new $app_installer_class($hestia))->getInfo();
  87. }
  88. }
  89. render_page($user, $TAB, "list_webapps");
  90. }
  91. // Flush session messages
  92. unset($_SESSION["error_msg"]);
  93. unset($_SESSION["ok_msg"]);