Просмотр исходного кода

WebApp: Installers expect a clean web domain root, show warning when files are already present

Robert Zollner 6 лет назад
Родитель
Сommit
5aee92ae0b
2 измененных файлов с 37 добавлено и 5 удалено
  1. 23 3
      web/src/app/WebApp/AppWizard.php
  2. 14 2
      web/templates/admin/setup_webapp.html

+ 23 - 3
web/src/app/WebApp/AppWizard.php

@@ -14,9 +14,9 @@ class AppWizard {
 
 
     private $database_config = [
     private $database_config = [
         'database_create' => ['type'=>'boolean', 'value'=>false],
         'database_create' => ['type'=>'boolean', 'value'=>false],
-        'database_name' => 'text',
-        'database_user' => 'text',
-        'database_password' => 'password',
+        'database_name' => ['type'=>'text', 'placeholder' => 'auto'],
+        'database_user' => ['type'=>'text', 'placeholder' => 'auto'],
+        'database_password' => ['type'=>'password', 'placeholder' => 'auto'],
     ];
     ];
 
 
     public function __construct(InstallerInterface $app, string $domain, HestiaApp $context)
     public function __construct(InstallerInterface $app, string $domain, HestiaApp $context)
@@ -36,6 +36,26 @@ class AppWizard {
         return $this->errors;
         return $this->errors;
     }
     }
 
 
+    public function isDomainRootClean()
+    {
+        $this->appcontext->runUser('v-run-cli-cmd', [ "ls", $this->appsetup->getDocRoot() ], $status);
+        if($status->code !== 0) {
+            throw new \Exception("Cannot list domain files");
+        }
+
+        $files = $status->raw;
+        if( count($files) > 2) {
+            return false;
+        }
+
+        foreach($files as $file) {
+            if ( !in_array($file,['index.html','robots.txt']) ) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     public function formNs()
     public function formNs()
     {
     {
         return $this->formNamespace;
         return $this->formNamespace;

+ 14 - 2
web/templates/admin/setup_webapp.html

@@ -36,6 +36,15 @@
         <form id="vstobjects" method="POST" name="v_setup_webapp" style="padding-top:0px;" >
         <form id="vstobjects" method="POST" name="v_setup_webapp" style="padding-top:0px;" >
             <input type="hidden" name="token" value="<?=$_SESSION['token']?>" />
             <input type="hidden" name="token" value="<?=$_SESSION['token']?>" />
             <input type="hidden" name="ok" value="true" />
             <input type="hidden" name="ok" value="true" />
+
+            <?php if( !$WebappInstaller->isDomainRootClean()): ?>
+                <span class="alert alert-info alert-with-icon">
+                    <i class="fas fa-info"></i>
+                    <?=__('Data loss warning!<br>Your web domain already has files uploaded, the installer will overwrite your files and/or the installation might fail.<br/><br/> Please use the installer only for empty web domains')?>
+                </span>
+                <br/>
+            <?php endif ?>
+
             <div class="app-form" >
             <div class="app-form" >
                 <?php foreach ($WebappInstaller->getOptions() as $form_name => $form_control):?>
                 <?php foreach ($WebappInstaller->getOptions() as $form_name => $form_control):?>
                     <?php
                     <?php
@@ -43,13 +52,16 @@
                         $f_type = $form_control;
                         $f_type = $form_control;
                         $f_value = '';
                         $f_value = '';
                         $f_label = ucwords(str_replace(['.','_'], ' ', $form_name));
                         $f_label = ucwords(str_replace(['.','_'], ' ', $form_name));
+                        $f_placeholder = '';
                         if (is_array($form_control)) {
                         if (is_array($form_control)) {
                             $f_type = (!empty($form_control['type']))?$form_control['type']:'text';
                             $f_type = (!empty($form_control['type']))?$form_control['type']:'text';
                             $f_value = (!empty($form_control['value']))?$form_control['value']:'';
                             $f_value = (!empty($form_control['value']))?$form_control['value']:'';
+                            $f_placeholder = (!empty($form_control['placeholder']))?$form_control['placeholder']:'';
                         }
                         }
 
 
                         $f_value = htmlentities($f_value);
                         $f_value = htmlentities($f_value);
                         $f_label = htmlentities($f_label);
                         $f_label = htmlentities($f_label);
+                        $f_placeholder = htmlentities($f_placeholder);
                     ?>
                     ?>
                     <div class="form-group">
                     <div class="form-group">
                         <label style="padding-bottom: 2px;" for="<?=$f_name?>"><?=$f_label?>
                         <label style="padding-bottom: 2px;" for="<?=$f_name?>"><?=$f_label?>
@@ -70,11 +82,11 @@
                         <?php elseif (in_array($f_type, ['boolean'])):?>
                         <?php elseif (in_array($f_type, ['boolean'])):?>
                         <p>
                         <p>
                             <?php $checked = (!empty($f_value))?'checked':''?>
                             <?php $checked = (!empty($f_value))?'checked':''?>
-                          <input style="width:auto;" type="checkbox" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" <?=$checked?> value="true">
+                            <input style="width:auto;" type="checkbox" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" <?=$checked?> value="true">
                         </p>
                         </p>
                         <?php else:?>
                         <?php else:?>
                           <p style="margin-top:0;"></p>
                           <p style="margin-top:0;"></p>
-                            <input type="text" size="20" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" value="<?=$f_value?>">
+                            <input type="text" size="20" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" placeholder="<?=$f_placeholder?>" value="<?=$f_value?>">
                           </p>
                           </p>
                         <?php endif?>
                         <?php endif?>
                     </div>
                     </div>