v-change-sys-api 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
  40. fi
  41. fi
  42. #----------------------------------------------------------#
  43. # Logging #
  44. #----------------------------------------------------------#
  45. log_history "API status has been changed to $status" '' 'admin'
  46. log_event "$OK" "$ARGUMENTS"