From e1d998d91e9934d44bf1a4782342b35565399053 Mon Sep 17 00:00:00 2001 From: Cyber Date: Fri, 26 Jul 2024 13:06:41 +0000 Subject: [PATCH] fix: disable notifs if api key is invalid or not found --- notify.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/notify.sh b/notify.sh index 697a22f..695dfb5 100755 --- a/notify.sh +++ b/notify.sh @@ -1,6 +1,18 @@ API_HOST="https://api.ssh.surf" API_KEY=$(cat .api-key) +if [ ! $API_KEY ]; then + notif "API key not found. Please re-run \`/enable-expire-notifs\`" + exit 1 +fi + +hello=$(curl -w %{http_code} -sH "x-ssh-auth: $API_KEY" $API_HOST/hello -o /dev/null) + +if [[ hello -ne 200 ]]; then + notif "API key not valid. Please re-run \`/enable-expire-notifs\`" + exit 1 +fi + notif "Hello, your container at SSH.SURF has hit its expire date, if not extended before 6PM EST the container will be removed automatically. Use /extend to gain another 7 days." date=$(curl -sH "x-ssh-auth: $API_KEY" $API_HOST/time | grep -o '"expireDate":"[^"]*' | grep -o '[^"]*$')