Advertisement
Guest User

pin_E5186

a guest
Apr 15th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.36 KB | None | 0 0
  1. #!/bin/sh
  2. #ustawienie IP routera oraz pinu
  3. modIPAdr="192.168.0.8"
  4. nr_pin="1234"
  5.  
  6. ISACTIVE="$(ping -c 1 -W 1 $modIPAdr | grep received | cut -d ',' -f2 | cut -d 'p' -f1)"
  7. if [ "$ISACTIVE" = " 1 " ]; then
  8.     tmp="$(curl -s -X GET http://$modIPAdr/api/webserver/SesTokInfo)"
  9.  
  10.     sid=$(echo "$tmp" | grep SesInfo | cut -d '>' -f2 | cut -d '<' -f1)
  11.     sid="Cookie: $sid"
  12.  
  13.     tok=$(echo "$tmp" | grep TokInfo | cut -d '>' -f2 | cut -d '<' -f1)
  14.     tok="__RequestVerificationToken: $tok"
  15.    
  16.     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)"
  17.     if [ "x$SIMSTATE" = "x260" ]; then
  18.         #tymczasowy plik nagłówkowy
  19.         headers=$(mktemp)
  20.  
  21.         #pobranie poczatkowego tokena oraz ID sesji i zapisanie do zmiennych
  22.         tmp="$(curl -s -X GET http://$modIPAdr/api/webserver/SesTokInfo)"
  23.  
  24.         sid=$(echo "$tmp" | grep SesInfo | cut -d '>' -f2 | cut -d '<' -f1)
  25.         sid="Cookie: $sid"
  26.  
  27.         tok=$(echo "$tmp" | grep TokInfo | cut -d '>' -f2 | cut -d '<' -f1)
  28.         tok="__RequestVerificationToken: $tok"
  29.  
  30.         #zalogowanie się na dane admin:admin (base64: YWRtaW4=) i zapisanie nagłówków
  31.         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"
  32.        
  33.         #echo "$tmp"
  34.         tmp=$(awk '{ sub("\r$", ""); print }' "$headers")
  35.  
  36.         #wyciągnięcie z nagłówków nowego tokena i ID sesji
  37.         tok=$(echo "$tmp" | grep __RequestVerificationTokenone | cut -d ':' -f2)
  38.         tok="__RequestVerificationToken: $tok"
  39.  
  40.         sid=$(echo "$tmp" | grep Cookie | cut -d ':' -f2 | cut -d ';' -f1)
  41.         sid="Cookie: $sid"
  42.  
  43.         #wpisanie pinu do routera
  44.         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"
  45.  
  46.         tmp=$(awk '{ sub("\r$", ""); print }' "$headers")
  47.  
  48.         #wyciągnięcie z nagłówków nowego tokena i ID sesji
  49.         tok=$(echo "$tmp" | grep __RequestVerificationToken | cut -d ':' -f2)
  50.         tok="__RequestVerificationToken: $tok"
  51.  
  52.         #wylogowanie się
  53.         curl -X POST -d "<request><Logout>1</Logout></request>" http://$modIPAdr/api/user/logout -H "$sid" -H "$tok" -H "Content-Type: text/xml"
  54.  
  55.         rm $headers
  56.        
  57.     fi
  58. fi
  59.  
  60. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement