v-check-api-key 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. # info: check api key
  3. # options: KEY [IP]
  4. # labels:
  5. #
  6. # example: v-check-api-key random_key 127.0.0.1
  7. #
  8. # The function checks a key file in $HESTIA/data/keys/
  9. #----------------------------------------------------------#
  10. # Variable&Function #
  11. #----------------------------------------------------------#
  12. if [ -z "$1" ]; then
  13. echo "Error: key missmatch"
  14. exit 9
  15. fi
  16. key=$(basename $1)
  17. ip=${2-127.0.0.1}
  18. time_n_date=$(date +'%T %F')
  19. time=$(echo "$time_n_date" |cut -f 1 -d \ )
  20. date=$(echo "$time_n_date" |cut -f 2 -d \ )
  21. #----------------------------------------------------------#
  22. # Action #
  23. #----------------------------------------------------------#
  24. if [ ! -e $HESTIA/data/keys/$key ]; then
  25. echo "Error: key missmatch"
  26. echo "$date $time api $ip failed to login" >> $HESTIA/log/auth.log
  27. exit 9
  28. fi
  29. #----------------------------------------------------------#
  30. # Hestia #
  31. #----------------------------------------------------------#
  32. echo "$date $time api $ip successfully launched" >> $HESTIA/log/auth.log
  33. exit