v-check-api-key 1.1 KB

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