Skip to content

Commit fa57c70

Browse files
committed
Web-Multiphp: Prevent removal of php backends with assigned webdomains
1 parent 3aa8bb4 commit fa57c70

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

web/edit/server/index.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
if(empty($backend_templates))
5151
$v_php_versions=[];
5252

53-
$v_php_versions = array_map(function($php_version) use ($backend_templates, $v_php_versions) {
53+
$backends_active = backendtpl_with_webdomains();
54+
$v_php_versions = array_map(function($php_version) use ($backend_templates, $backends_active) {
5455
// Mark installed php versions
5556

5657
if(stripos($php_version,'php') !== 0)
@@ -59,17 +60,29 @@
5960
$phpinfo = (object) [
6061
"name" => $php_version,
6162
"tpl" => strtoupper(str_replace('.', '_', $php_version)),
62-
"version" => str_ireplace('php-', '', $php_version)
63+
"version" => str_ireplace('php-', '', $php_version),
64+
"usedby" => [],
6365
];
6466

6567
if(in_array($phpinfo->tpl, $backend_templates)) {
6668
$phpinfo->installed = true;
6769
}
6870

69-
if(array_search($phpinfo->name, array_reverse($v_php_versions, true)) == array_key_last($v_php_versions)) {
71+
if (array_key_exists($phpinfo->tpl, $backends_active)) {
72+
// Prevent used php version to be removed
73+
if($phpinfo->installed)
74+
$phpinfo->protected = true;
75+
$phpinfo->usedby = $backends_active[$phpinfo->tpl];
76+
}
77+
78+
if ($phpinfo->name == DEFAULT_PHP_VERSION) {
7079
// Prevent default php version to be removed
7180
if($phpinfo->installed)
7281
$phpinfo->protected = true;
82+
83+
if (!empty($backends_active['default'])) {
84+
$phpinfo->usedby = array_merge_recursive($phpinfo->usedby,$backends_active['default'] );
85+
}
7386
}
7487

7588
return $phpinfo;

web/inc/main.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
define('HESTIA_CMD', '/usr/bin/sudo /usr/local/hestia/bin/');
66
define('JS_LATEST_UPDATE', '1491697868');
7+
define('DEFAULT_PHP_VERSION', 'php-7.3');
78

89
$i = 0;
910

@@ -373,3 +374,29 @@ function load_hestia_config() {
373374
$_SESSION[$key] = $value;
374375
}
375376
}
377+
378+
/**
379+
* Returns the list of all web domains from all users grouped by Backend Template used and owner
380+
*
381+
* @return array
382+
*/
383+
function backendtpl_with_webdomains() {
384+
exec (HESTIA_CMD . "v-list-users json", $output, $return_var);
385+
$users = json_decode(implode('', $output), true);
386+
unset($output);
387+
388+
$backend_list=[];
389+
foreach ($users as $user => $user_details) {
390+
exec (HESTIA_CMD . "v-list-web-domains ". escapeshellarg($user) . " json", $output, $return_var);
391+
$domains = json_decode(implode('', $output), true);
392+
unset($output);
393+
394+
foreach ($domains as $domain => $domain_details) {
395+
if (!empty($domain_details['BACKEND'])) {
396+
$backend = $domain_details['BACKEND'];
397+
$backend_list[$backend][$user][] = $domain;
398+
}
399+
}
400+
}
401+
return $backend_list;
402+
}

web/templates/admin/edit_server.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,19 @@
265265
<label for="<?=$php_version->name?>"><?=$php_version->name?></label>
266266
</td>
267267
</tr>
268+
<?php foreach($php_version->usedby as $wd_user => $wd_domains ): ?>
269+
<?php foreach($wd_domains as $wd_domain ): ?>
270+
<tr>
271+
<td class="vst-text" style="border: 1px lightgrey; padding:0 10px;">
272+
<span>
273+
<i class="fas fa-user"></i>
274+
<?=$wd_user;?>
275+
</span>
276+
<span class="optional" style="float:right"><?=$wd_domain;?></span>
277+
</td>
278+
</tr>
279+
<?php endforeach; ?>
280+
<?php endforeach; ?>
268281
<?php endforeach; ?>
269282
<?php endif; ?>
270283
</table>

0 commit comments

Comments
 (0)