Skip to content

Commit 0933487

Browse files
author
Kristan Kenney
committed
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
1 parent 60353c1 commit 0933487

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

bin/v-change-sys-api

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ source $HESTIA/conf/hestia.conf
2525
#----------------------------------------------------------#
2626

2727
check_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
3131
check_hestia_demo_mode
@@ -36,7 +36,15 @@ check_hestia_demo_mode
3636

3737
if [ "$status" = "enable" ]; then
3838
if [ ! -f "$HESTIA/web/api/index.php" ]; then
39-
wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/release/web/api/index.php -O $HESTIA/web/api/index.php
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
47+
fi
4048
else
4149
sed -i 's|die("Error: Disabled");|//die("Error: Disabled");|g' $HESTIA/web/api/index.php
4250
sed -i 's|////|//|g' $HESTIA/web/api/index.php
@@ -45,12 +53,27 @@ if [ "$status" = "enable" ]; then
4553
else
4654
$HESTIA/bin/v-change-sys-config-value "API" "no"
4755
$HESTIA/bin/v-change-sys-config-value "API_ALLOWED_IP" ""
48-
sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
56+
if [ "$status" != "remove" ]; then
57+
sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
58+
fi
59+
fi
60+
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
4968
fi
5069

5170
#----------------------------------------------------------#
5271
# Logging #
5372
#----------------------------------------------------------#
5473

55-
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
5679
log_event "$OK" "$ARGUMENTS"

0 commit comments

Comments
 (0)