Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- #--- zc-config.sh - Zero Client curl config
- #--- Commands: connect disconnect login zcreset
- #--- Usage: ./zc-config <CMD> <ADMIN?> <ZC> <PCoIP>
- CMD=$1
- ZC_USER=$2
- SLEEP=1
- timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; }
- #===================================
- #=== User handling / Status printing
- #===================================
- if [[ ${ZC_USER} == "admin" ]]
- then
- ZC_PASSWORD='AdminPassword'
- if [ -z ${3+x} ]; then ZC="no-ZC"; else ZC=${3}; fi
- if [ -z ${4+x} ]; then PCOIP="no-PCoIP"; else PCOIP=${4}; fi
- else
- ZC_PASSWORD=''
- if [ -z ${2+x} ]; then ZC="no-ZC"; else ZC=${2}; fi
- if [ -z ${3+x} ]; then PCOIP="no-PCoIP"; else PCOIP=${3}; fi
- fi
- if [ -z ${5+x} ];
- then
- echo
- read -p "[$CMD] ZC[$ZC] PCoIP[$PCOIP], Ctrl-C to back out now, Any button to continue" -n 1 -r
- echo
- fi
- #=============
- #=== Functions
- #=============
- #--- Login, save cookie to $ZC_COOKIE
- ZC_COOKIE=~/.zeroclient-cookie-${ZC}.txt
- zc_login(){
- timeout 10 curl -s 'https://'$(echo $ZC)'/cgi-bin/login' \
- --data 'password_value='$(echo $ZC_PASSWORD)'&idle_timeout=0' \
- --compressed \
- --insecure \
- -c ${ZC_COOKIE}
- LOGIN_CHECK=$(awk '/session_id/ && length($NF) > 30' ${ZC_COOKIE} | wc -l | awk '{printf "%d\n",$1}')
- if [[ ${LOGIN_CHECK} == 1 ]]
- then
- echo "Logged in"
- else
- echo "Login failed"
- exit 1
- fi
- }
- #--- Connect the Zeroclient to the $PCOIP host
- zc_connect(){
- curl 'https://'$(echo $ZC)'/cgi-bin/ajax/diagnostics/session_control?connect=' \
- -H 'Cookie: url_request=; session_id='$(awk "/session_id/ {print \$NF}" $(echo $ZC_COOKIE))'' \
- --compressed \
- --insecure
- }
- #--- Disconnnect the Zeroclient to the $PCOIP host
- zc_disconnect(){
- curl 'https://'$(echo $ZC)'/cgi-bin/ajax/diagnostics/session_control?disconnect=' \
- -H 'Cookie: url_request=; session_id='$(awk "/session_id/ {print \$NF}" $(echo $ZC_COOKIE))'' \
- --compressed \
- --insecure
- }
- #--- Powercycle the Zeroclient
- zc_zcreset(){
- curl 'https://'$(echo $ZC)'/cgi-bin/diagnostics/pcoip?reset=12345' \
- -H 'Cookie: url_request=; session_id='$(awk "/session_id/ {print \$NF}" $(echo $ZC_COOKIE))'' \
- --compressed \
- --insecure
- }
- #================
- #=== CMD handling
- #================
- if [[ $CMD == "login" ]]; then echo "#--- Login"; zc_login 2>&1 > ./ZC-${ZC}-login
- elif [[ $CMD == "connect" ]]; then echo "#--- Connect"; zc_connect 2>&1 | awk -F">" '/title/{gsub("</title","",$4); print $4}'
- elif [[ $CMD == "disconnect" ]]; then echo "#--- Disconnect"; zc_disconnect 2>&1 | awk -F">" '/title/{gsub("</title","",$4); print $4}'
- elif [[ $CMD == "zcreset" ]]; then echo "#--- ZC Reset"; zc_zcreset 2>&1 | awk -F">" '/title/{gsub("</title","",$4); print $4}'
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement