34 lines
1.6 KiB
Bash
34 lines
1.6 KiB
Bash
#!/bin/bash
|
|
|
|
#Enter your stwab.service-now.com Login Credentials here
|
|
USERNAME=''
|
|
PASSWORD=''
|
|
|
|
login(){
|
|
SESSION=$(curl --silent --cookie cookies.txt --cookie-jar cookies.txt "https://stwab.service-now.com/angular.do?sysparm_type=view_form.login&ni.nolog.user_password=true&remember_me=false&user_name=${USERNAME}&user_password=${PASSWORD}")
|
|
jq_script='if (.status == "success") then true else false end'
|
|
if echo $SESSION | jq -e "$jqscript" >/dev/null; then
|
|
echo "acquired Session: $(echo ${SESSION} | jq -r '.session_token')"
|
|
printf "Successfully logged in\n"
|
|
|
|
else
|
|
printf "failed to acquire session"
|
|
fi
|
|
printf "\n\n"
|
|
}
|
|
logout(){
|
|
curl --silent --cookie cookies.txt --cookie-jar cookies.txt 'https://stwab.service-now.com/logout.do?sysparm_goto_url=%2Favg' > /dev/null
|
|
printf "logging out\n"
|
|
}
|
|
|
|
query(){
|
|
API="https://stwab.service-now.com/api/now/sp/page?sys_id=a47424aa87955990097662480cbb358a&view=sp&id=form&table=u_customer_card"
|
|
KARTEN_NR=$(curl --cookie cookies.txt --cookie-jar cookies.txt --silent "${API}" --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:138.0) Gecko/20100101 Firefox/138.0' -H 'Accept: application/json' | jq -r '.result.containers[1].rows[0].columns[0].widgets[2].widget.data.f.display_value')
|
|
BALANCE=$(curl --cookie cookies.txt --cookie-jar cookies.txt --silent "${API}" --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:138.0) Gecko/20100101 Firefox/138.0' -H 'Accept: application/json' | jq -r '.result.containers[1].rows[0].columns[0].widgets[2].widget.data.f._fields.u_balance.currencyValue')
|
|
printf "Stadtwerkekarte $KARTEN_NR - Guthaben $BALANCE€"
|
|
}
|
|
|
|
login >&2
|
|
query
|
|
printf "\n" >&2
|
|
logout >&2
|