Skip to content

Commit a073989

Browse files
committed
Fix bug in Quick install app when default template is used for php
Add v-list-default-php to know php version of default.tpl
1 parent ddaf8b9 commit a073989

File tree

3 files changed

+111
-8
lines changed

3 files changed

+111
-8
lines changed

bin/v-list-default-php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
# info: list default PHP version used by default.tpl
3+
# options: [FORMAT]
4+
#
5+
# example: v-list-default-php
6+
#
7+
# List the default version used by de the default template
8+
9+
#----------------------------------------------------------#
10+
# Variables & Functions #
11+
#----------------------------------------------------------#
12+
13+
# Argument definition
14+
format=${1-shell}
15+
16+
# Includes
17+
# shellcheck source=/etc/hestiacp/hestia.conf
18+
source /etc/hestiacp/hestia.conf
19+
# shellcheck source=/usr/local/hestia/func/main.sh
20+
source $HESTIA/func/main.sh
21+
# load config file
22+
source_conf "$HESTIA/conf/hestia.conf"
23+
24+
# JSON list function
25+
json_list() {
26+
i=1
27+
objects=$(echo "${versions[@]}" |wc -w)
28+
echo '['
29+
for version in "${versions[@]}"; do
30+
if [ "$i" -lt "$objects" ]; then
31+
echo -e "\t\"$version\","
32+
else
33+
echo -e "\t\"$version\""
34+
fi
35+
(( ++i))
36+
done
37+
echo "]"
38+
}
39+
40+
# SHELL list function
41+
shell_list() {
42+
echo "VERSION"
43+
echo "--------"
44+
for version in "${versions[@]}"; do
45+
echo "$version"
46+
done
47+
}
48+
49+
# PLAIN list function
50+
plain_list() {
51+
for version in "${versions[@]}"; do
52+
echo "$version"
53+
done
54+
}
55+
56+
# CSV list function
57+
csv_list() {
58+
echo "VERSION"
59+
for version in "${versions[@]}"; do
60+
echo "$version"
61+
done
62+
}
63+
64+
#----------------------------------------------------------#
65+
# Action #
66+
#----------------------------------------------------------#
67+
68+
declare -a versions;
69+
# List through /etc/php
70+
for version in /etc/php/*/fpm/pool.d/www.conf; do
71+
ver=$(echo "$version" | awk -F"/" '{ print $4 }');
72+
versions+=("$ver")
73+
done
74+
75+
# Listing data
76+
case $format in
77+
json) json_list ;;
78+
plain) plain_list ;;
79+
csv) csv_list ;;
80+
shell) shell_list ;;
81+
esac
82+
83+
#----------------------------------------------------------#
84+
# Hestia #
85+
#----------------------------------------------------------#
86+
87+
exit

web/inc/prevent_csrf.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ function prevent_post_csrf()
3232
{
3333
if (!empty($_SERVER['REQUEST_METHOD'])) {
3434
if ($_SERVER['REQUEST_METHOD']==='POST') {
35-
list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
36-
if(empty($port)){
35+
if(!empty($_SERVER["HTTP_HOST"])){
36+
list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
37+
if(empty($port)){
38+
$port = 443;
39+
}
40+
}else{
41+
$hostname = gethostname();
3742
$port = 443;
3843
}
3944
if (isset($_SERVER['HTTP_ORIGIN'])) {
@@ -56,10 +61,16 @@ function prevent_get_csrf()
5661
{
5762
if (!empty($_SERVER['REQUEST_METHOD'])) {
5863
if ($_SERVER['REQUEST_METHOD']==='GET') {
59-
list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
60-
if(empty($port)){
64+
if(!empty($_SERVER["HTTP_HOST"])){
65+
list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
66+
if(empty($port)){
67+
$port = 443;
68+
}
69+
}else{
70+
$hostname = gethostname();
6171
$port = 443;
6272
}
73+
6374
//list of possible entries route and these should never be blocked
6475
if (in_array($_SERVER['DOCUMENT_URI'], array('/list/user/index.php', '/login/index.php','/list/web/index.php','/list/dns/index.php','/list/mail/index.php','/list/db/index.php','/list/cron/index.php','/list/backup/index.php','/reset/index.php'))) {
6576
return true;

web/src/app/System/HestiaApp.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ public function run(string $cmd, $args, &$cmd_result=null): bool
2828
$cli_arguments = '';
2929
if (!empty($args) && is_array($args)) {
3030
foreach ($args as $arg) {
31+
var_dump($arg);
3132
$cli_arguments .= quoteshellarg((string)$arg) . ' ';
3233
}
3334
} else {
3435
$cli_arguments = quoteshellarg($args);
3536
}
36-
37+
3738
exec($cli_script . ' ' . $cli_arguments . ' 2>&1', $output, $exit_code);
3839

3940
$result['code'] = $exit_code;
@@ -194,9 +195,13 @@ public function databaseAdd(string $dbname, string $dbuser, string $dbpass, stri
194195
public function getCurrentBackendTemplate(string $domain){
195196
$status = $this->runUser('v-list-web-domain', [$domain, 'json'],$return_message);
196197
$version = $return_message -> json[$domain]['BACKEND'];
197-
$test= preg_match('/^.*PHP-([0-9])\_([0-9])/',$version, $match);
198-
return $match[1].'.'.$match[2];
199-
198+
if($version != "default"){
199+
$test= preg_match('/^.*PHP-([0-9])\_([0-9])/',$version, $match);
200+
return $match[1].'.'.$match[2];
201+
}else{
202+
$supported = $this -> run('v-list-sys-php', 'json', $result);
203+
return $this -> $supported -> json[0];
204+
}
200205
}
201206

202207
public function changeWebTemplate(string $domain, string $template)

0 commit comments

Comments
 (0)