index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  55. header('location: /login/');
  56. exit();
  57. }
  58. if ($installer) {
  59. try{
  60. if (!$installer->execute($_POST)){
  61. $result = $installer->getStatus();
  62. if(!empty($result))
  63. $_SESSION['error_msg'] = implode(PHP_EOL, $result);
  64. } else {
  65. $_SESSION['ok_msg'] = sprintf(_('%s App was installed succesfully!'),htmlspecialchars($app));
  66. header('Location: /add/webapp/?domain=' . $v_domain);
  67. exit();
  68. }
  69. } catch (Exception $e) {
  70. $_SESSION['error_msg'] = $e->getMessage();
  71. header('Location: /add/webapp/?app='.rawurlencode($app).'&domain=' . $v_domain);
  72. exit();
  73. }
  74. }
  75. }
  76. if(!empty($installer)) {
  77. render_page($user, $TAB, 'setup_webapp');
  78. } else {
  79. $appInstallers = glob(__DIR__.'/../../src/app/WebApp/Installers/*/*.php');
  80. $v_web_apps = array();
  81. foreach($appInstallers as $app){
  82. $hestia = new \Hestia\System\HestiaApp();
  83. if( preg_match('/Installers\/([a-zA-Z][a-zA-Z0,9].*)\/([a-zA-Z][a-zA-Z0,9].*).php/', $app, $matches)){
  84. if ($matches[1] != "Resources"){
  85. $app_installer_class = '\Hestia\WebApp\Installers\\'.$matches[1].'\\' . $matches[1] . 'Setup';
  86. $app_installer = new $app_installer_class($v_domain, $hestia);
  87. $v_web_apps[] = $app_installer -> info();
  88. }
  89. }
  90. }
  91. render_page($user, $TAB, 'list_webapps');
  92. }
  93. // Flush session messages
  94. unset($_SESSION['error_msg']);
  95. unset($_SESSION['ok_msg']);