Skip to content

Commit 4d865cc

Browse files
committed
Add + FIX some Colors.
1 parent 3f83c44 commit 4d865cc

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

nginx_proxy_manager_cli.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -439,22 +439,27 @@ generate_token() {
439439
expires=$(echo "$response" | jq -r '.expires')
440440

441441
## Debug
442-
echo "Request URL: $BASE_URL$API_ENDPOINT?expiry=$TOKEN_EXPIRY"
443-
echo "Request Body: {\"identity\":\"$API_USER\",\"secret\":\"$API_PASS\"}"
444-
echo "Response: $response"
442+
# echo "Request URL: $BASE_URL$API_ENDPOINT?expiry=$TOKEN_EXPIRY"
443+
# echo "Request Body: {\"identity\":\"$API_USER\",\"secret\":\"$API_PASS\"}"
444+
# echo "Response: $response"
445445
##
446446

447447
if [ "$token" != "null" ]; then
448448
echo "$token" > $TOKEN_FILE
449449
echo "$expires" > $EXPIRY_FILE
450450
echo "Token: $token"
451451
echo "Expiry: $expires"
452+
echo -e "\n ✅ ${COLOR_GREEN}The token is valid. Expiry: $expires${COLOR_RESET}"
452453
else
453454
echo -e " ${COLOR_RED}Error generating token.${COLOR_RESET}"
454-
echo -e " Check your [user] and [pass] and [IP]"
455+
echo -e " Check your credentials."
455456
exit 1
456457
fi
457458

459+
460+
}
461+
462+
renew_token_if_needed() {
458463
#CHECK_TOKEN=true
459464
if [ ! -f "$TOKEN_FILE" ] || [ ! -f "$EXPIRY_FILE" ]; then
460465
return 1
@@ -477,23 +482,22 @@ generate_token() {
477482

478483
# Validate the existing token
479484
validate_token() {
480-
481485
if [ ! -f "$TOKEN_FILE" ] || [ ! -f "$EXPIRY_FILE" ]; then
482486
echo -e "\n ⛔ ${COLOR_RED}No valid token found. Generating a new token...${COLOR_RESET}"
483487
generate_token
484488
fi
485489

486-
token=$(cat $TOKEN_FILE)
487490
expires=$(cat $EXPIRY_FILE)
488491
current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
489492

490493
if [[ "$current_time" < "$expires" ]]; then
491494
echo -e "${COLOR_GREEN}The token is valid. Expiry: $expires${COLOR_RESET}"
492-
# return 0
495+
# return 0
493496
else
494497
echo -e "${COLOR_RED}The token is invalid. Expiry: $expires${COLOR_RESET}"
498+
echo -e " 🔄 ${COLOR_GREEN}Processing NEW Token${COLOR_RESET}\n"
495499
generate_token
496-
# return 1
500+
# return 1
497501
fi
498502

499503
}
@@ -654,9 +658,11 @@ list_access() {
654658
-H "Authorization: Bearer $(cat $TOKEN_FILE)")
655659

656660
# Check if the response is a valid JSON array
657-
if echo " $RESPONSE" | jq -e 'type == "array"' > /dev/null; then
661+
if echo " $RESPONSE" | jq -e 'type == "array"' > /dev/null; then
658662
# Loop through and display the elements of the list
659-
echo " $RESPONSE" | jq -r '.[] | "\(.id): \(.name)"'
663+
echo -e "${COLOR_YELLOW}"
664+
echo " $RESPONSE" | jq -r '.[] | " \(.id): \(.name)"'
665+
echo -e "${COLOR_RESET}"
660666
else
661667
# In case of an error, check if there is an error message in the response
662668
if echo " $RESPONSE" | jq -e '.error // empty' > /dev/null; then

0 commit comments

Comments
 (0)