| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/bin/bash
- # info: check api key
- # options: KEY [IP]
- # labels:
- #
- # example: v-check-api-key random_key 127.0.0.1
- #
- # The function checks a key file in $HESTIA/data/keys/
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- [[ -z $HESTIA ]] && HESTIA="/usr/local/hestia"
- source $HESTIA/func/main.sh
- new_timestamp
- abort_missmatch() {
- echo "Error: key missmatch"
- echo "$date $time api $ip failed to login" >> $HESTIA/log/auth.log
- exit $E_PASSWORD
- }
- ip=${2-127.0.0.1}
- time_n_date=$(date +'%T %F')
- time=$(echo "$time_n_date" |cut -f 1 -d \ )
- date=$(echo "$time_n_date" |cut -f 2 -d \ )
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- key="$(basename "$1")"
- # Exit if Key is unset or to short
- [[ -z $key || ${#key} -lt 16 ]] && abort_missmatch
- # Key file must exist
- maybe_key_path="$(readlink -e "${HESTIA}/data/keys/${key}")"
- [[ -z $maybe_key_path ]] && abort_missmatch
- # Key file cannot be the key store
- [[ $maybe_key_path == "${HESTIA}/data/keys" ]] && abort_missmatch
- # Key file must be in the key store
- [[ $maybe_key_path == "${HESTIA}/data/keys/"* ]] || abort_missmatch
- #----------------------------------------------------------#
- # Hestia #
- #----------------------------------------------------------#
- echo "$date $time api $ip successfully launched" >> $HESTIA/log/auth.log
- exit
|