index.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // Check GET request
  24. if (!empty($_GET['app'])) {
  25. $app = basename($_GET['app']);
  26. $hestia = new \Hestia\System\HestiaApp();
  27. $app_installer_class = '\Hestia\WebApp\Installers\\'.$app.'\\' . $app . 'Setup';
  28. if (class_exists($app_installer_class)) {
  29. try {
  30. $app_installer = new $app_installer_class($v_domain, $hestia);
  31. $info = $app_installer -> info();
  32. if ($info['enabled'] != true) {
  33. $_SESSION['error_msg'] = sprintf(_('%s installer missing'), $app);
  34. } else {
  35. $installer = new \Hestia\WebApp\AppWizard($app_installer, $v_domain, $hestia);
  36. $GLOBALS['WebappInstaller'] = $installer;
  37. }
  38. } catch (Exception $e) {
  39. $_SESSION['error_msg'] = $e->getMessage();
  40. header('Location: /add/webapp/?domain=' . $v_domain);
  41. exit();
  42. }
  43. } else {
  44. $_SESSION['error_msg'] = sprintf(_('%s installer missing'), $app);
  45. }
  46. }
  47. // Check POST request
  48. if (!empty($_POST['ok']) && !empty($app)) {
  49. // Check token
  50. verify_csrf($_POST);
  51. if ($installer) {
  52. try {
  53. if (!$installer->execute($_POST)) {
  54. $result = $installer->getStatus();
  55. if (!empty($result)) {
  56. $_SESSION['error_msg'] = implode(PHP_EOL, $result);
  57. }
  58. } else {
  59. $_SESSION['ok_msg'] = sprintf(_('%s App was installed succesfully!'), htmlspecialchars($app));
  60. header('Location: /add/webapp/?domain=' . $v_domain);
  61. exit();
  62. }
  63. } catch (Exception $e) {
  64. $_SESSION['error_msg'] = $e->getMessage();
  65. header('Location: /add/webapp/?app='.rawurlencode($app).'&domain=' . $v_domain);
  66. exit();
  67. }
  68. }
  69. }
  70. if (!empty($installer)) {
  71. render_page($user, $TAB, 'setup_webapp');
  72. } else {
  73. $appInstallers = glob(__DIR__.'/../../src/app/WebApp/Installers/*/*.php');
  74. $v_web_apps = array();
  75. foreach ($appInstallers as $app) {
  76. $hestia = new \Hestia\System\HestiaApp();
  77. if (preg_match('/Installers\/([a-zA-Z][a-zA-Z0,9].*)\/([a-zA-Z][a-zA-Z0,9].*).php/', $app, $matches)) {
  78. if ($matches[1] != "Resources") {
  79. $app_installer_class = '\Hestia\WebApp\Installers\\'.$matches[1].'\\' . $matches[1] . 'Setup';
  80. $app_installer = new $app_installer_class($v_domain, $hestia);
  81. $v_web_apps[] = $app_installer -> info();
  82. }
  83. }
  84. }
  85. render_page($user, $TAB, 'list_webapps');
  86. }
  87. // Flush session messages
  88. unset($_SESSION['error_msg']);
  89. unset($_SESSION['ok_msg']);