@@ -25,7 +25,7 @@ source $HESTIA/conf/hestia.conf
2525# ----------------------------------------------------------#
2626
2727check_args ' 1' " $# " " STATUS"
28- is_type_valid " enable,disable" " $status "
28+ is_type_valid " enable,disable,remove " " $status "
2929
3030# Perform verification if read-only mode is enabled
3131check_hestia_demo_mode
@@ -35,25 +35,45 @@ check_hestia_demo_mode
3535# ----------------------------------------------------------#
3636
3737if [ " $status " = " enable" ]; then
38- if [ $API = " no" ]; then
39- if [ ! -f " $HESTIA /web/api/index.php" ]; then
40- wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/release/web/api/index.php -O $HESTIA /web/api/index.php
41- else
42- sed -i ' s|die("Error: Disabled");|//die("Error: Disabled");|g' $HESTIA /web/api/index.php
38+ if [ ! -f " $HESTIA /web/api/index.php" ]; then
39+ wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/$RELEASE_BRANCH /web/api/index.php -O $HESTIA /web/api/index.php
40+ check_api_download=$( cat $HESTIA /web/api/index.php)
41+ if [ -z " $HESTIA /web/api/index.php" ]; then
42+ # Throw error message to user
43+ echo " ERROR: API installation failed."
44+ # Remove empty file created by wget output
45+ rm -f " $HESTIA /web/api/index.php"
46+ exit 1
4347 fi
44- $HESTIA /bin/v-change-sys-config-value " API" " yes"
48+ else
49+ sed -i ' s|die("Error: Disabled");|//die("Error: Disabled");|g' $HESTIA /web/api/index.php
50+ sed -i ' s|////|//|g' $HESTIA /web/api/index.php
4551 fi
52+ $HESTIA /bin/v-change-sys-config-value " API" " yes"
4653else
47- if [ $API = " yes " ] ; then
48- $HESTIA /bin/v-change-sys-config-value " API " " no "
49- $HESTIA /bin/v-change-sys-config-value " API_ALLOWED_IP " " "
54+ $HESTIA /bin/v-change-sys-config-value " API " " no "
55+ $HESTIA /bin/v-change-sys-config-value " API_ALLOWED_IP " " "
56+ if [ " $status " != " remove " ] ; then
5057 sed -i ' s|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA /web/api/index.php
5158 fi
5259fi
5360
61+ if [ " $status " = " remove" ]; then
62+ if [ ! -f " $HESTIA /web/api/index.php" ]; then
63+ echo " ERROR: API is not installed."
64+ exit 1
65+ else
66+ rm -f " $HESTIA /web/api/index.php"
67+ fi
68+ fi
69+
5470# ----------------------------------------------------------#
5571# Logging #
5672# ----------------------------------------------------------#
5773
58- log_history " API status has been changed to $status " ' ' ' admin'
74+ if [ " $status " = " enable" ] || [ " $status " = " disable" ]; then
75+ log_history " API status has been changed to $status " ' ' ' admin'
76+ else
77+ log_history " API has been disabled and removed" ' ' ' admin'
78+ fi
5979log_event " $OK " " $ARGUMENTS "
0 commit comments