Преглед изворни кода

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
Jaap Marcus пре 3 година
родитељ
комит
a073989099
3 измењених фајлова са 111 додато и 8 уклоњено
  1. 87 0
      bin/v-list-default-php
  2. 15 4
      web/inc/prevent_csrf.php
  3. 9 4
      web/src/app/System/HestiaApp.php

+ 87 - 0
bin/v-list-default-php

@@ -0,0 +1,87 @@
+#!/bin/bash
+# info: list default PHP version used by default.tpl
+# options: [FORMAT]
+#
+# example: v-list-default-php
+#
+# List the default version used by de the default template
+
+#----------------------------------------------------------#
+#                Variables & Functions                     #
+#----------------------------------------------------------#
+
+# Argument definition
+format=${1-shell}
+
+# Includes
+# shellcheck source=/etc/hestiacp/hestia.conf
+source /etc/hestiacp/hestia.conf
+# shellcheck source=/usr/local/hestia/func/main.sh
+source $HESTIA/func/main.sh
+# load config file
+source_conf "$HESTIA/conf/hestia.conf"
+
+# JSON list function
+json_list() {
+    i=1
+    objects=$(echo "${versions[@]}" |wc -w)
+    echo '['
+    for version in "${versions[@]}"; do
+        if [ "$i" -lt "$objects" ]; then
+            echo -e  "\t\"$version\","
+        else
+            echo -e  "\t\"$version\""
+        fi
+        (( ++i))
+    done
+    echo "]"
+}
+
+# SHELL list function
+shell_list() {
+    echo "VERSION"
+    echo "--------"
+    for version in "${versions[@]}"; do
+        echo "$version"
+    done
+}
+
+# PLAIN list function
+plain_list() {
+    for version in "${versions[@]}"; do
+        echo "$version"
+    done
+}
+
+# CSV list function
+csv_list() {
+    echo "VERSION"
+    for version in "${versions[@]}"; do
+        echo "$version"
+    done
+}
+
+#----------------------------------------------------------#
+#                       Action                             #
+#----------------------------------------------------------#
+
+declare -a versions;
+# List through /etc/php
+for version in /etc/php/*/fpm/pool.d/www.conf; do
+    ver=$(echo "$version" | awk -F"/" '{ print $4 }');
+    versions+=("$ver")
+done
+
+# Listing data
+case $format in
+    json)   json_list ;;
+    plain)  plain_list ;;
+    csv)    csv_list ;;
+    shell)  shell_list ;;
+esac
+
+#----------------------------------------------------------#
+#                       Hestia                             #
+#----------------------------------------------------------#
+
+exit

+ 15 - 4
web/inc/prevent_csrf.php

@@ -32,8 +32,13 @@
     {
         if (!empty($_SERVER['REQUEST_METHOD'])) {
             if ($_SERVER['REQUEST_METHOD']==='POST') {
-                list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
-                if(empty($port)){
+                if(!empty($_SERVER["HTTP_HOST"])){
+                    list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
+                    if(empty($port)){
+                        $port = 443;
+                    }
+                }else{
+                    $hostname = gethostname();
                     $port = 443;
                 }
                 if (isset($_SERVER['HTTP_ORIGIN'])) {
@@ -56,10 +61,16 @@
     {
         if (!empty($_SERVER['REQUEST_METHOD'])) {
             if ($_SERVER['REQUEST_METHOD']==='GET') {
-                list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
-                if(empty($port)){
+                if(!empty($_SERVER["HTTP_HOST"])){
+                    list($hostname, $port) = explode(':', $_SERVER["HTTP_HOST"].":");
+                    if(empty($port)){
+                        $port = 443;
+                    }
+                }else{
+                    $hostname = gethostname();
                     $port = 443;
                 }
+                
                 //list of possible entries route and these should never be blocked
                 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'))) {
                     return true;

+ 9 - 4
web/src/app/System/HestiaApp.php

@@ -28,12 +28,13 @@ class HestiaApp
         $cli_arguments = '';
         if (!empty($args) && is_array($args)) {
             foreach ($args as $arg) {
+                var_dump($arg);
                 $cli_arguments .= quoteshellarg((string)$arg) . ' ';
             }
         } else {
             $cli_arguments = quoteshellarg($args);
         }
-
+        
         exec($cli_script . ' ' . $cli_arguments . ' 2>&1', $output, $exit_code);
 
         $result['code'] = $exit_code;
@@ -194,9 +195,13 @@ class HestiaApp
     public function getCurrentBackendTemplate(string $domain){
         $status = $this->runUser('v-list-web-domain', [$domain, 'json'],$return_message);
         $version = $return_message -> json[$domain]['BACKEND'];
-        $test= preg_match('/^.*PHP-([0-9])\_([0-9])/',$version, $match);
-        return $match[1].'.'.$match[2];
-                
+        if($version != "default"){
+            $test= preg_match('/^.*PHP-([0-9])\_([0-9])/',$version, $match);
+            return $match[1].'.'.$match[2];   
+        }else{
+            $supported = $this -> run('v-list-sys-php', 'json', $result);
+            return $this -> $supported -> json[0];
+        }                
     }
     
     public function changeWebTemplate(string $domain, string $template)