v-change-sys-api 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. status=$1
  14. # Includes
  15. source $HESTIA/func/main.sh
  16. source $HESTIA/conf/hestia.conf
  17. #----------------------------------------------------------#
  18. # Variable&Function #
  19. #----------------------------------------------------------#
  20. check_args '1' "$#" "STATUS"
  21. is_type_valid "enable,disable" "$status"
  22. # Perform verification if read-only mode is enabled
  23. check_hestia_demo_mode
  24. #----------------------------------------------------------#
  25. # Action #
  26. #----------------------------------------------------------#
  27. if [ "$status" = "enable" ]; then
  28. if [ $API = "no" ]; then
  29. if [ ! -f "$HESTIA/web/api/index.php" ]; then
  30. wget -q https://raw.githubusercontent.com/hestiacp/hestiacp/release/web/api/index.php -O $HESTIA/web/api/index.php
  31. else
  32. sed -i 's|die("Error: Disabled");|//die("Error: Disabled");|g' $HESTIA/web/api/index.php
  33. fi
  34. $HESTIA/bin/v-change-sys-config-value "API" "yes"
  35. fi
  36. else
  37. if [ $API = "yes" ]; then
  38. $HESTIA/bin/v-change-sys-config-value "API" "no"
  39. $HESTIA/bin/v-change-sys-config-value "API_ALLOWED_IP" ""
  40. sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
  41. fi
  42. fi
  43. #----------------------------------------------------------#
  44. # Logging #
  45. #----------------------------------------------------------#
  46. log_history "API status has been changed to $status" '' 'admin'
  47. log_event "$OK" "$ARGUMENTS"