Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #ustawienie IP routera oraz pinu
- modIPAdr="192.168.0.8"
- nr_pin="1234"
- ISACTIVE="$(ping -c 1 -W 1 $modIPAdr | grep received | cut -d ',' -f2 | cut -d 'p' -f1)"
- if [ "$ISACTIVE" = " 1 " ]; then
- tmp="$(curl -s -X GET http://$modIPAdr/api/webserver/SesTokInfo)"
- sid=$(echo "$tmp" | grep SesInfo | cut -d '>' -f2 | cut -d '<' -f1)
- sid="Cookie: $sid"
- tok=$(echo "$tmp" | grep TokInfo | cut -d '>' -f2 | cut -d '<' -f1)
- tok="__RequestVerificationToken: $tok"
- SIMSTATE="$(curl -X GET http://$modIPAdr/api/monitoring/converged-status -H "$sid" -H "$tok" -H "Content-Type: text/xml" | grep SimState | cut -d '>' -f2 | cut -d '<' -f1)"
- if [ "x$SIMSTATE" = "x260" ]; then
- #tymczasowy plik nagłówkowy
- headers=$(mktemp)
- #pobranie poczatkowego tokena oraz ID sesji i zapisanie do zmiennych
- tmp="$(curl -s -X GET http://$modIPAdr/api/webserver/SesTokInfo)"
- sid=$(echo "$tmp" | grep SesInfo | cut -d '>' -f2 | cut -d '<' -f1)
- sid="Cookie: $sid"
- tok=$(echo "$tmp" | grep TokInfo | cut -d '>' -f2 | cut -d '<' -f1)
- tok="__RequestVerificationToken: $tok"
- #zalogowanie się na dane admin:admin (base64: YWRtaW4=) i zapisanie nagłówków
- curl -D "$headers" -X POST -d "<request><Username>admin</Username><Password>YWRtaW4=</Password>" http://$modIPAdr/api/user/login -H "$sid" -H "$tok" -H "Content-Type: text/xml"
- #echo "$tmp"
- tmp=$(awk '{ sub("\r$", ""); print }' "$headers")
- #wyciągnięcie z nagłówków nowego tokena i ID sesji
- tok=$(echo "$tmp" | grep __RequestVerificationTokenone | cut -d ':' -f2)
- tok="__RequestVerificationToken: $tok"
- sid=$(echo "$tmp" | grep Cookie | cut -d ':' -f2 | cut -d ';' -f1)
- sid="Cookie: $sid"
- #wpisanie pinu do routera
- curl -D "$headers" -X POST -d "<request><OperateType>0</OperateType><CurrentPin>$nr_pin</CurrentPin><NewPin></NewPin><PukCode></PukCode></request>" http://$modIPAdr/api/pin/operate -H "$sid" -H "$tok" -H "Content-Type: text/xml"
- tmp=$(awk '{ sub("\r$", ""); print }' "$headers")
- #wyciągnięcie z nagłówków nowego tokena i ID sesji
- tok=$(echo "$tmp" | grep __RequestVerificationToken | cut -d ':' -f2)
- tok="__RequestVerificationToken: $tok"
- #wylogowanie się
- curl -X POST -d "<request><Logout>1</Logout></request>" http://$modIPAdr/api/user/logout -H "$sid" -H "$tok" -H "Content-Type: text/xml"
- rm $headers
- fi
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement