forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-change-sys-api
More file actions
executable file
·79 lines (68 loc) · 2.54 KB
/
v-change-sys-api
File metadata and controls
executable file
·79 lines (68 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# info: Enable / Disable API access
# options: STATUS
# labels: hestia
#
# example: v-change-sys-api enable
# # Enable API
#
# example: v-change-sys-api disable
# # Disable API
#
# Enabled / Disable API
status=$1
# Includes
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# shellcheck source=/usr/local/hestia/conf/hestia.conf
source $HESTIA/conf/hestia.conf
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
check_args '1' "$#" "STATUS"
is_type_valid "enable,disable,remove" "$status"
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
if [ "$status" = "enable" ]; then
if [ ! -f "$HESTIA/web/api/index.php" ]; then
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
fi
$HESTIA/bin/v-change-sys-config-value "API" "yes"
else
$HESTIA/bin/v-change-sys-config-value "API" "no"
$HESTIA/bin/v-change-sys-config-value "API_ALLOWED_IP" ""
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 #
#----------------------------------------------------------#
if [ "$status" = "enable" ]; then
$BIN/v-log-action "system" "Warning" "System" "System API access enabled."
else
$BIN/v-log-action "system" "Info" "System" "System API access disabled."
fi
log_event "$OK" "$ARGUMENTS"