index.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // Get all user domains
  17. exec(HESTIA_CMD."v-list-web-domains ".escapeshellarg($user)." json", $output, $return_var);
  18. $user_domains = json_decode(implode('', $output), true);
  19. $user_domains = array_keys($user_domains);
  20. unset($output);
  21. // List domain
  22. $v_domain = $_GET['domain'];
  23. if (!in_array($v_domain, $user_domains)) {
  24. header("Location: /list/web/");
  25. exit;
  26. }
  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. if ($info['enabled'] != true) {
  37. $_SESSION['error_msg'] = sprintf(_('%s installer missing'), $app);
  38. } else {
  39. $installer = new \Hestia\WebApp\AppWizard($app_installer, $v_domain, $hestia);
  40. $GLOBALS['WebappInstaller'] = $installer;
  41. }
  42. } catch (Exception $e) {
  43. $_SESSION['error_msg'] = $e->getMessage();
  44. header('Location: /add/webapp/?domain=' . $v_domain);
  45. exit();
  46. }
  47. } else {
  48. $_SESSION['error_msg'] = sprintf(_('%s installer missing'), $app);
  49. }
  50. }
  51. // Check POST request
  52. if (!empty($_POST['ok']) && !empty($app)) {
  53. // Check token
  54. verify_csrf($_POST);
  55. if ($installer) {
  56. try {
  57. if (!$installer->execute($_POST)) {
  58. $result = $installer->getStatus();
  59. if (!empty($result)) {
  60. $_SESSION['error_msg'] = implode(PHP_EOL, $result);
  61. }
  62. } else {
  63. $_SESSION['ok_msg'] = sprintf(_('%s App was installed succesfully!'), htmlspecialchars($app));
  64. header('Location: /add/webapp/?domain=' . $v_domain);
  65. exit();
  66. }
  67. } catch (Exception $e) {
  68. $_SESSION['error_msg'] = $e->getMessage();
  69. header('Location: /add/webapp/?app='.rawurlencode($app).'&domain=' . $v_domain);
  70. exit();
  71. }
  72. }
  73. }
  74. if (!empty($installer)) {
  75. render_page($user, $TAB, 'setup_webapp');
  76. } else {
  77. $appInstallers = glob(__DIR__.'/../../src/app/WebApp/Installers/*/*.php');
  78. $v_web_apps = array();
  79. foreach ($appInstallers as $app) {
  80. $hestia = new \Hestia\System\HestiaApp();
  81. if (preg_match('/Installers\/([a-zA-Z][a-zA-Z0,9].*)\/([a-zA-Z][a-zA-Z0,9].*).php/', $app, $matches)) {
  82. if ($matches[1] != "Resources") {
  83. $app_installer_class = '\Hestia\WebApp\Installers\\'.$matches[1].'\\' . $matches[1] . 'Setup';
  84. $app_installer = new $app_installer_class($v_domain, $hestia);
  85. $v_web_apps[] = $app_installer -> info();
  86. }
  87. }
  88. }
  89. render_page($user, $TAB, 'list_webapps');
  90. }
  91. // Flush session messages
  92. unset($_SESSION['error_msg']);
  93. unset($_SESSION['ok_msg']);