index.php 4.4 KB

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