Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- CREDENTIALS="admin:password"
- IP="192.168.1.1"
- attempts=5
- iter=1
- SESSION_ID=""
- while [ $iter -le 5 ]; do
- response=$(curl -s -u $CREDENTIALS http://{$IP}/LED_settings.htm)
- SESSION_ID=$(echo "$response" | grep -oP "(?<=led_settings.cgi\?id=)[0-9]+")
- if [ -n "$SESSION_ID" ]; then
- break
- else
- test_multiuser=$(echo "$response" | grep -o 'top.location.href = "MNU_access_multiLogin2.htm"')
- if [ -n "$test_multiuser" ]; then
- multi_session_id=$(curl -s -u $CREDENTIALS "http://${IP}/MNU_access_multiLogin2.htm" | grep -Po "(?<=multi_login.cgi\?id=)[0-9]+")
- curl -X POST --data "act=yes" -s -u $CREDENTIALS "http://${IP}/multi_login.cgi?id=$multi_session_id" >/dev/null
- fi
- fi
- sleep 1
- iter=$(( $iter + 1 ))
- done
- if [ -z "$SESSION_ID" ]; then
- echo "Failed to get session ID!" 1>&2
- exit 1
- fi
- mode="$1"
- if [ "$mode" = "off" ]; then
- response=$(curl -s -X POST -u $CREDENTIALS --data "led_settings=turn_off" "http://${IP}/led_settings.cgi?id=${SESSION_ID}")
- success=$(echo "$response" | egrep -o '<INPUT name=led_now type=hidden value="turn_off" >')
- if [ -z "$success" ]; then
- echo "LED status change unsuccessful" 1>&2
- exit 1
- fi
- elif [ "$mode" = "blink" ]; then
- response=$(curl -s -X POST -u $CREDENTIALS --data "led_settings=en_blink" "http://${IP}/led_settings.cgi?id=${SESSION_ID}")
- success=$(echo "$response" | egrep -o '<INPUT name=led_now type=hidden value="en_blink" >')
- if [ -z "$success" ]; then
- echo "LED status change unsuccessful" 1>&2
- exit 1
- fi
- elif [ "$mode" = "noblink" ]; then
- response=$(curl -s -X POST -u $CREDENTIALS --data "led_settings=dis_blink" "http://${IP}/led_settings.cgi?id=${SESSION_ID}")
- success=$(echo "$response" | egrep -o '<INPUT name=led_now type=hidden value="dis_blink" >')
- if [ -z "$success" ]; then
- echo "LED status change unsuccessful" 1>&2
- exit 1
- fi
- else
- echo "USAGE: $0 <off|blink|noblink>"
- exit 1
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement