1+ #! /bin/bash
2+ # info: Enable / Disable API access
3+ # options: STATUS
4+ # labels: hestia
5+ #
6+ # example: v-change-sys-api enable
7+ # # Enable API
8+ #
9+ # example: v-change-sys-api disable
10+ # # Disable API
11+ #
12+ # Enabled / Disable API
13+
14+
15+ status=$1
16+
17+ # Includes
18+ source $HESTIA /func/main.sh
19+ source $HESTIA /conf/hestia.conf
20+
21+ # ----------------------------------------------------------#
22+ # Variable&Function #
23+ # ----------------------------------------------------------#
24+
25+ check_args ' 1' " $# " " STATUS"
26+ is_type_valid " enable,disable" " $status "
27+
28+ # Perform verification if read-only mode is enabled
29+ check_hestia_demo_mode
30+
31+ # ----------------------------------------------------------#
32+ # Action #
33+ # ----------------------------------------------------------#
34+
35+ if [ " $status " = " enable" ]; then
36+ if [ $API = " no" ]; then
37+ if [ ! -f " $HESTIA /web/api/index.php" ]; then
38+ wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/release/web/api/index.php -O $HESTIA /web/api/index.php
39+ else
40+ sed -i ' s|die("Error: Disabled");|//die("Error: Disabled");|g' $HESTIA /web/api/index.php
41+ fi
42+ $HESTIA /bin/v-change-sys-config-value " API" " yes"
43+ fi
44+ else
45+ if [ $API = " yes" ]; then
46+ $HESTIA /bin/v-change-sys-config-value " API" " no"
47+ $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
49+ fi
50+ fi
51+
52+ # ----------------------------------------------------------#
53+ # Logging #
54+ # ----------------------------------------------------------#
55+
56+ log_history " API status has been changed to $status " ' ' ' admin'
57+ log_event " $OK " " $ARGUMENTS "
0 commit comments