index.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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($v_domain, $hestia);
  39. $info = $app_installer->info();
  40. foreach ($php_versions as $version) {
  41. if (in_array($version, $info["php_support"])) {
  42. $supported = true;
  43. $supported_versions[] = $version;
  44. }
  45. }
  46. if ($supported) {
  47. $info["enabled"] = true;
  48. } else {
  49. $info["enabled"] = false;
  50. $_SESSION["error_msg"] = sprintf(
  51. _("Unable to install %s, %s is not available"),
  52. $app,
  53. "PHP-" . end($info["php_support"]),
  54. );
  55. }
  56. if ($info["enabled"] == true) {
  57. $installer = new \Hestia\WebApp\AppWizard($app_installer, $v_domain, $hestia);
  58. $GLOBALS["WebappInstaller"] = $installer;
  59. }
  60. } catch (Exception $e) {
  61. $_SESSION["error_msg"] = $e->getMessage();
  62. header("Location: /add/webapp/?domain=" . $v_domain);
  63. exit();
  64. }
  65. } else {
  66. $_SESSION["error_msg"] = sprintf(_("%s installer missing"), $app);
  67. }
  68. }
  69. // Check POST request
  70. if (!empty($_POST["ok"]) && !empty($app)) {
  71. // Check token
  72. verify_csrf($_POST);
  73. if ($installer) {
  74. try {
  75. if (!$installer->execute($_POST)) {
  76. $result = $installer->getStatus();
  77. if (!empty($result)) {
  78. $_SESSION["error_msg"] = implode(PHP_EOL, $result);
  79. }
  80. } else {
  81. $_SESSION["ok_msg"] = sprintf(
  82. _("%s App was installed successfully!"),
  83. htmlspecialchars($app),
  84. );
  85. header("Location: /add/webapp/?domain=" . $v_domain);
  86. exit();
  87. }
  88. } catch (Exception $e) {
  89. $_SESSION["error_msg"] = $e->getMessage();
  90. header("Location: /add/webapp/?app=" . rawurlencode($app) . "&domain=" . $v_domain);
  91. exit();
  92. }
  93. }
  94. }
  95. if (!empty($installer)) {
  96. render_page($user, $TAB, "setup_webapp");
  97. } else {
  98. $appInstallers = glob(__DIR__ . "/../../src/app/WebApp/Installers/*/*.php");
  99. $v_web_apps = [];
  100. foreach ($appInstallers as $app) {
  101. $hestia = new \Hestia\System\HestiaApp();
  102. if (
  103. preg_match(
  104. "/Installers\/([a-zA-Z][a-zA-Z0,9].*)\/([a-zA-Z][a-zA-Z0,9].*).php/",
  105. $app,
  106. $matches,
  107. )
  108. ) {
  109. if ($matches[1] != "Resources") {
  110. $app_installer_class =
  111. "\Hestia\WebApp\Installers\\" . $matches[1] . "\\" . $matches[1] . "Setup";
  112. $app_installer = new $app_installer_class($v_domain, $hestia);
  113. $appInstallerInfo = $app_installer->info();
  114. $supported = false;
  115. $supported_versions = [];
  116. foreach ($php_versions as $version) {
  117. if (in_array($version, $appInstallerInfo["php_support"])) {
  118. $supported = true;
  119. $supported_versions[] = $version;
  120. }
  121. }
  122. if ($supported) {
  123. $appInstallerInfo["enabled"] = true;
  124. } else {
  125. $appInstallerInfo["enabled"] = false;
  126. }
  127. $v_web_apps[] = $appInstallerInfo;
  128. }
  129. }
  130. }
  131. render_page($user, $TAB, "list_webapps");
  132. }
  133. // Flush session messages
  134. unset($_SESSION["error_msg"]);
  135. unset($_SESSION["ok_msg"]);