Procházet zdrojové kódy

Minor changes to v-change-sys-api

Ensure API file is installed correctly
Improve error handling
Add remove argument to remove disable API (reinstalls latest bits when enabled)
Use system specified release branch when fetching API file for install
Updated logging
Kristan Kenney před 5 roky
rodič
revize
0933487dbe
1 změnil soubory, kde provedl 27 přidání a 4 odebrání
  1. 27 4
      bin/v-change-sys-api

+ 27 - 4
bin/v-change-sys-api

@@ -25,7 +25,7 @@ source $HESTIA/conf/hestia.conf
 #----------------------------------------------------------#
 
 check_args '1' "$#" "STATUS"
-is_type_valid "enable,disable" "$status"
+is_type_valid "enable,disable,remove" "$status"
 
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
@@ -36,7 +36,15 @@ check_hestia_demo_mode
 
 if [ "$status" = "enable" ]; then
     if [ ! -f "$HESTIA/web/api/index.php" ]; then
-        wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/release/web/api/index.php -O $HESTIA/web/api/index.php
+        wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/$RELEASE_BRANCH/web/api/index.php -O $HESTIA/web/api/index.php
+        check_api_download=$(cat $HESTIA/web/api/index.php)
+        if [ -z "$HESTIA/web/api/index.php" ]; then
+            # Throw error message to user
+            echo "ERROR: API installation failed."
+            # Remove empty file created by wget output
+            rm -f "$HESTIA/web/api/index.php"
+            exit 1
+        fi
     else
         sed -i 's|die("Error: Disabled");|//die("Error: Disabled");|g' $HESTIA/web/api/index.php
         sed -i 's|////|//|g' $HESTIA/web/api/index.php
@@ -45,12 +53,27 @@ if [ "$status" = "enable" ]; then
 else
     $HESTIA/bin/v-change-sys-config-value "API" "no"
     $HESTIA/bin/v-change-sys-config-value "API_ALLOWED_IP" ""
-    sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
+    if [ "$status" != "remove" ]; then
+        sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
+    fi
+fi
+
+if [ "$status" = "remove" ]; then
+    if [ ! -f "$HESTIA/web/api/index.php" ]; then
+        echo "ERROR: API is not installed."
+        exit 1
+    else
+        rm -f "$HESTIA/web/api/index.php"
+    fi
 fi
 
 #----------------------------------------------------------#
 #                       Logging                            #
 #----------------------------------------------------------#
 
-log_history "API status has been changed to $status" '' 'admin'
+if [ "$status" = "enable" ] || [ "$status" = "disable" ]; then
+    log_history "API status has been changed to $status" '' 'admin'
+else
+    log_history "API has been disabled and removed" '' 'admin'
+fi
 log_event "$OK" "$ARGUMENTS"