move pstab to td-ps, improve td-gnuplot
[hband-tools.git] / crawler-bin / arubacloud-balance
blob00aa62f4444489a3e755ee8179bc87cd4b4adfc7
1 #!/bin/bash
2 # Depends: pup, jq, curl
4 set -u
5 Login=$1
6 Password=$2
9 login_url=https://ugyfel.arubacloud.hu/Login.aspx
10 login_response=`curl -iSs "$login_url"`
11 login_header=`echo "$login_response" | sed -e 's/\r//; /^\r\?$/q'`
12 login_page=`echo "$login_response" | sed -e '1,/^\r\?$/d'`
14 cookies=`echo "$login_header" | grep -Eo '^Set-Cookie:[^;]+' | cut -f2- -d: | tr "\n" ";"`
16 declare -A fields
17 IFS=$'\n'
18 for field in `echo "$login_page" | pup "form#form1 input[type=hidden] json{}" | jq -r '.[] | [.name, .value] | join(" ")'`
20 name=${field%% *}
21 value=${field#* }
22 fields[$name]=$value
23 done
24 IFS=$'\n\t\ '
26 fields["ctl00_ContentPlaceHolder1_ctl00_tooltipUsername_ClientState"]=''
27 fields["ctl00\$ContentPlaceHolder1\$ctl00\$txtUserName"]=$Login
28 fields["ctl00\$ContentPlaceHolder1\$ctl00\$txtPassword"]=$Password
29 fields["ctl00\$ContentPlaceHolder1\$ctl00\$btnLogIn"]="Bejelentkezés"
31 post_data=''
33 for name in "${!fields[@]}"
35 value=${fields[$name]}
36 value=`echo -n "$value" | url_encode`
37 post_data="$post_data${post_data:+&}$name=$value"
38 done
39 set -u
42 home_page=`curl -sS -L "$login_url" -H "Cookie: $cookies" -d "$post_data"`
43 credit=`echo "$home_page" | pup '#ContentPlaceHolder1_ctl00_ucCredit_lblAmount text{}'`
45 if [ -z "$credit" ]
46 then
47 exit 1
48 else
49 echo "$credit"