v-delete-sys-api-ip 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # info: delete ip adresss from allowed ip list api
  3. # options: IP
  4. #
  5. # example: v-delete-sys-api-ip 1.1.1.1
  6. #----------------------------------------------------------#
  7. # Variables & Functions #
  8. #----------------------------------------------------------#
  9. ip46=${1// /}
  10. # Includes
  11. # shellcheck source=/etc/hestiacp/hestia.conf
  12. source /etc/hestiacp/hestia.conf
  13. # shellcheck source=/usr/local/hestia/func/main.sh
  14. source $HESTIA/func/main.sh
  15. # shellcheck source=/usr/local/hestia/func/ip.sh
  16. source $HESTIA/func/ip.sh
  17. # load config file
  18. source_conf "$HESTIA/conf/hestia.conf"
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. check_args '1' "$#" 'IP'
  23. is_format_valid 'ip46'
  24. # Perform verification if read-only mode is enabled
  25. check_hestia_demo_mode
  26. #----------------------------------------------------------#
  27. # Action #
  28. #----------------------------------------------------------#
  29. new_list=''
  30. set -f # avoid globbing (expansion of *).
  31. array=(${API_ALLOWED_IP//,/ })
  32. for i in "${!array[@]}"; do
  33. if [ "${array[i]}" != "$ip46" ]; then
  34. if [ "$new_list" = '' ]; then
  35. new_list="${array[i]}"
  36. else
  37. new_list="$new_list,${array[i]}"
  38. fi
  39. fi
  40. done
  41. $BIN/v-change-sys-config-value 'API_ALLOWED_IP' "$new_list"
  42. # Logging
  43. $BIN/v-log-action "system" "Warning" "System" "Removed IP address added from Allowed IP API (IP: $ip46)"
  44. log_event "$OK" "$ARGUMENTS"