Update nginx_proxy_manager_cli.sh

BUG fix EXPIRY check
This commit is contained in:
Erreur32 2024-07-10 18:39:05 +02:00 committed by GitHub
parent 2f5408c829
commit c3a0ee63b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -63,6 +63,7 @@ COLOR_ERROR="\e[41;1m" # Red for errors
# Definition variables TOKEN # Definition variables TOKEN
BASE_URL="http://$NGINX_IP:81/api" BASE_URL="http://$NGINX_IP:81/api"
API_ENDPOINT="/tokens" API_ENDPOINT="/tokens"
EXPIRY_FILE="expiry.txt"
# File storage token # File storage token
TOKEN_FILE="token.txt" TOKEN_FILE="token.txt"
@ -85,6 +86,7 @@ generate_token() {
if [ "$token" != "null" ]; then if [ "$token" != "null" ]; then
echo $token > $TOKEN_FILE echo $token > $TOKEN_FILE
echo $expires > $EXPIRY_FILE
echo "Token: $token" echo "Token: $token"
echo "Expiry: $expires" echo "Expiry: $expires"
else else
@ -95,11 +97,12 @@ generate_token() {
# Function to validate the token # Function to validate the token
validate_token() { validate_token() {
if [ ! -f "$TOKEN_FILE" ]; then if [ ! -f "$TOKEN_FILE" ] || [ ! -f "$EXPIRY_FILE" ]; then
return 1 return 1
fi fi
token=$(cat $TOKEN_FILE) token=$(cat $TOKEN_FILE)
expires=$(cat $EXPIRY_FILE)
current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ") current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
if [[ "$current_time" < "$expires" ]]; then if [[ "$current_time" < "$expires" ]]; then
@ -111,8 +114,8 @@ validate_token() {
fi fi
} }
# Check if Nginx is accessible # Check if Nginx is accessible // inprogress
check_nginx_access #check_nginx_access
# Check if the token file exists # Check if the token file exists
if ! validate_token; then if ! validate_token; then