index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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(HESTIA_CMD."v-list-web-domain ".$user." ".quoteshellarg($v_domain)." json", $output, $return_var);
  20. if ($return_var > 0) {
  21. check_return_code_redirect($return_var, $output, '/list/web/');
  22. }
  23. unset($output);
  24. exec(HESTIA_CMD."v-list-sys-php json", $output, $return_var);
  25. $php_versions = json_decode(implode('', $output), true);
  26. unset($output);
  27. // Check GET request
  28. if (!empty($_GET['app'])) {
  29. $app = basename($_GET['app']);
  30. $hestia = new \Hestia\System\HestiaApp();
  31. $app_installer_class = '\Hestia\WebApp\Installers\\'.$app.'\\' . $app . 'Setup';
  32. if (class_exists($app_installer_class)) {
  33. try {
  34. $app_installer = new $app_installer_class($v_domain, $hestia);
  35. $info = $app_installer -> info();
  36. foreach ($php_versions as $version) {
  37. if (in_array($version, $info['php_support'])) {
  38. $supported = true;
  39. $supported_versions[] = $version;
  40. }
  41. }
  42. if ($supported) {
  43. $info['enabled'] = true;
  44. } else {
  45. $info['enabled'] = false;
  46. $_SESSION['error_msg'] = sprintf(_('Unable to install %s, %s is not available'), $app, 'PHP-'.end($info['php_support']));
  47. }
  48. if ($info['enabled'] == true) {
  49. $installer = new \Hestia\WebApp\AppWizard($app_installer, $v_domain, $hestia);
  50. $GLOBALS['WebappInstaller'] = $installer;
  51. }
  52. } catch (Exception $e) {
  53. $_SESSION['error_msg'] = $e->getMessage();
  54. header('Location: /add/webapp/?domain=' . $v_domain);
  55. exit();
  56. }
  57. } else {
  58. $_SESSION['error_msg'] = sprintf(_('%s installer missing'), $app);
  59. }
  60. }
  61. // Check POST request
  62. if (!empty($_POST['ok']) && !empty($app)) {
  63. // Check token
  64. verify_csrf($_POST);
  65. if ($installer) {
  66. try {
  67. if (!$installer->execute($_POST)) {
  68. $result = $installer->getStatus();
  69. if (!empty($result)) {
  70. $_SESSION['error_msg'] = implode(PHP_EOL, $result);
  71. }
  72. } else {
  73. $_SESSION['ok_msg'] = sprintf(_('%s App was installed succesfully!'), htmlspecialchars($app));
  74. header('Location: /add/webapp/?domain=' . $v_domain);
  75. exit();
  76. }
  77. } catch (Exception $e) {
  78. $_SESSION['error_msg'] = $e->getMessage();
  79. header('Location: /add/webapp/?app='.rawurlencode($app).'&domain=' . $v_domain);
  80. exit();
  81. }
  82. }
  83. }
  84. if (!empty($installer)) {
  85. render_page($user, $TAB, 'setup_webapp');
  86. } else {
  87. $appInstallers = glob(__DIR__.'/../../src/app/WebApp/Installers/*/*.php');
  88. $v_web_apps = array();
  89. foreach ($appInstallers as $app) {
  90. $hestia = new \Hestia\System\HestiaApp();
  91. if (preg_match('/Installers\/([a-zA-Z][a-zA-Z0,9].*)\/([a-zA-Z][a-zA-Z0,9].*).php/', $app, $matches)) {
  92. if ($matches[1] != "Resources") {
  93. $app_installer_class = '\Hestia\WebApp\Installers\\'.$matches[1].'\\' . $matches[1] . 'Setup';
  94. $app_installer = new $app_installer_class($v_domain, $hestia);
  95. $appInstallerInfo = $app_installer -> info();
  96. $supported = false;
  97. $supported_versions = array();
  98. foreach ($php_versions as $version) {
  99. if (in_array($version, $appInstallerInfo['php_support'])) {
  100. $supported = true;
  101. $supported_versions[] = $version;
  102. }
  103. }
  104. if ($supported) {
  105. $appInstallerInfo['enabled'] = true;
  106. } else {
  107. $appInstallerInfo['enabled'] = false;
  108. }
  109. $v_web_apps[] = $appInstallerInfo;
  110. }
  111. }
  112. }
  113. render_page($user, $TAB, 'list_webapps');
  114. }
  115. // Flush session messages
  116. unset($_SESSION['error_msg']);
  117. unset($_SESSION['ok_msg']);