Skip to content

Commit 5aee92a

Browse files
committed
WebApp: Installers expect a clean web domain root, show warning when files are already present
1 parent 8a34530 commit 5aee92a

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

web/src/app/WebApp/AppWizard.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class AppWizard {
1414

1515
private $database_config = [
1616
'database_create' => ['type'=>'boolean', 'value'=>false],
17-
'database_name' => 'text',
18-
'database_user' => 'text',
19-
'database_password' => 'password',
17+
'database_name' => ['type'=>'text', 'placeholder' => 'auto'],
18+
'database_user' => ['type'=>'text', 'placeholder' => 'auto'],
19+
'database_password' => ['type'=>'password', 'placeholder' => 'auto'],
2020
];
2121

2222
public function __construct(InstallerInterface $app, string $domain, HestiaApp $context)
@@ -36,6 +36,26 @@ public function getStatus()
3636
return $this->errors;
3737
}
3838

39+
public function isDomainRootClean()
40+
{
41+
$this->appcontext->runUser('v-run-cli-cmd', [ "ls", $this->appsetup->getDocRoot() ], $status);
42+
if($status->code !== 0) {
43+
throw new \Exception("Cannot list domain files");
44+
}
45+
46+
$files = $status->raw;
47+
if( count($files) > 2) {
48+
return false;
49+
}
50+
51+
foreach($files as $file) {
52+
if ( !in_array($file,['index.html','robots.txt']) ) {
53+
return false;
54+
}
55+
}
56+
return true;
57+
}
58+
3959
public function formNs()
4060
{
4161
return $this->formNamespace;

web/templates/admin/setup_webapp.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,32 @@
3636
<form id="vstobjects" method="POST" name="v_setup_webapp" style="padding-top:0px;" >
3737
<input type="hidden" name="token" value="<?=$_SESSION['token']?>" />
3838
<input type="hidden" name="ok" value="true" />
39+
40+
<?php if( !$WebappInstaller->isDomainRootClean()): ?>
41+
<span class="alert alert-info alert-with-icon">
42+
<i class="fas fa-info"></i>
43+
<?=__('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')?>
44+
</span>
45+
<br/>
46+
<?php endif ?>
47+
3948
<div class="app-form" >
4049
<?php foreach ($WebappInstaller->getOptions() as $form_name => $form_control):?>
4150
<?php
4251
$f_name = $WebappInstaller->formNs() . '_' . $form_name;
4352
$f_type = $form_control;
4453
$f_value = '';
4554
$f_label = ucwords(str_replace(['.','_'], ' ', $form_name));
55+
$f_placeholder = '';
4656
if (is_array($form_control)) {
4757
$f_type = (!empty($form_control['type']))?$form_control['type']:'text';
4858
$f_value = (!empty($form_control['value']))?$form_control['value']:'';
59+
$f_placeholder = (!empty($form_control['placeholder']))?$form_control['placeholder']:'';
4960
}
5061

5162
$f_value = htmlentities($f_value);
5263
$f_label = htmlentities($f_label);
64+
$f_placeholder = htmlentities($f_placeholder);
5365
?>
5466
<div class="form-group">
5567
<label style="padding-bottom: 2px;" for="<?=$f_name?>"><?=$f_label?>
@@ -70,11 +82,11 @@
7082
<?php elseif (in_array($f_type, ['boolean'])):?>
7183
<p>
7284
<?php $checked = (!empty($f_value))?'checked':''?>
73-
<input style="width:auto;" type="checkbox" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" <?=$checked?> value="true">
85+
<input style="width:auto;" type="checkbox" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" <?=$checked?> value="true">
7486
</p>
7587
<?php else:?>
7688
<p style="margin-top:0;"></p>
77-
<input type="text" size="20" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" value="<?=$f_value?>">
89+
<input type="text" size="20" class="vst-input" name="<?=$f_name?>" id="<?=$f_name?>" placeholder="<?=$f_placeholder?>" value="<?=$f_value?>">
7890
</p>
7991
<?php endif?>
8092
</div>

0 commit comments

Comments
 (0)