Advertisement
Guest User

zc-config.sh

a guest
Apr 30th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.69 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. #--- zc-config.sh - Zero Client curl config
  3. #--- Commands: connect disconnect login zcreset
  4. #---    Usage: ./zc-config <CMD> <ADMIN?> <ZC> <PCoIP>
  5. CMD=$1
  6. ZC_USER=$2
  7. SLEEP=1
  8. timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
  9.  
  10. #===================================
  11. #=== User handling / Status printing
  12. #===================================
  13. if [[ ${ZC_USER} == "admin" ]]
  14. then
  15.   ZC_PASSWORD='AdminPassword'
  16.   if [ -z ${3+x} ]; then ZC="no-ZC"; else ZC=${3}; fi
  17.   if [ -z ${4+x} ]; then PCOIP="no-PCoIP"; else PCOIP=${4}; fi
  18. else
  19.   ZC_PASSWORD=''
  20.   if [ -z ${2+x} ]; then ZC="no-ZC"; else ZC=${2}; fi
  21.   if [ -z ${3+x} ]; then PCOIP="no-PCoIP"; else PCOIP=${3}; fi
  22. fi
  23.  
  24. if [ -z ${5+x} ];
  25. then
  26.   echo
  27.   read -p "[$CMD] ZC[$ZC] PCoIP[$PCOIP], Ctrl-C to back out now, Any button to continue" -n 1 -r
  28.   echo
  29. fi
  30.  
  31. #=============
  32. #=== Functions
  33. #=============
  34. #--- Login, save cookie to $ZC_COOKIE
  35. ZC_COOKIE=~/.zeroclient-cookie-${ZC}.txt
  36. zc_login(){
  37. timeout 10 curl -s 'https://'$(echo $ZC)'/cgi-bin/login' \
  38. --data 'password_value='$(echo $ZC_PASSWORD)'&idle_timeout=0' \
  39. --compressed \
  40. --insecure \
  41. -c ${ZC_COOKIE}
  42. LOGIN_CHECK=$(awk '/session_id/ && length($NF) > 30' ${ZC_COOKIE} | wc -l | awk '{printf "%d\n",$1}')
  43. if [[ ${LOGIN_CHECK} == 1 ]]
  44. then
  45.   echo "Logged in"
  46. else
  47.   echo "Login failed"
  48.   exit 1
  49. fi
  50. }
  51.  
  52. #--- Connect the Zeroclient to the $PCOIP host
  53. zc_connect(){
  54. curl 'https://'$(echo $ZC)'/cgi-bin/ajax/diagnostics/session_control?connect=' \
  55. -H 'Cookie: url_request=; session_id='$(awk "/session_id/ {print \$NF}" $(echo $ZC_COOKIE))'' \
  56. --compressed \
  57. --insecure
  58. }
  59.  
  60. #--- Disconnnect the Zeroclient to the $PCOIP host
  61. zc_disconnect(){
  62. curl 'https://'$(echo $ZC)'/cgi-bin/ajax/diagnostics/session_control?disconnect=' \
  63. -H 'Cookie: url_request=; session_id='$(awk "/session_id/ {print \$NF}" $(echo $ZC_COOKIE))'' \
  64. --compressed \
  65. --insecure
  66. }
  67.  
  68. #--- Powercycle the Zeroclient
  69. zc_zcreset(){
  70. curl 'https://'$(echo $ZC)'/cgi-bin/diagnostics/pcoip?reset=12345' \
  71. -H 'Cookie: url_request=; session_id='$(awk "/session_id/ {print \$NF}" $(echo $ZC_COOKIE))'' \
  72. --compressed \
  73. --insecure
  74. }
  75.  
  76. #================
  77. #=== CMD handling
  78. #================
  79. if [[ $CMD == "login" ]];        then echo "#--- Login";      zc_login      2>&1 > ./ZC-${ZC}-login
  80. elif [[ $CMD == "connect" ]];    then echo "#--- Connect";    zc_connect    2>&1 | awk -F">" '/title/{gsub("</title","",$4); print $4}'
  81. elif [[ $CMD == "disconnect" ]]; then echo "#--- Disconnect"; zc_disconnect 2>&1 | awk -F">" '/title/{gsub("</title","",$4); print $4}'
  82. elif [[ $CMD == "zcreset" ]];    then echo "#--- ZC Reset";   zc_zcreset    2>&1 | awk -F">" '/title/{gsub("</title","",$4); print $4}'
  83. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement