Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- CREDENTIALS="admin:password"
- IP="192.168.1.1"
- SESSION_ID=""
- mode="$1"
- get_session_id()
- {
- local _attempts=5
- local _iter=1
- local _response="" local _session_id="" local _test_multiuser="" local _kickout_session_id=""
- while [ $_iter -le $_attempts ]; 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
- echo "$_session_id"
- return 0
- else
- _test_multiuser=$(echo "$_response" | grep -o 'top.location.href = "MNU_access_multiLogin2.htm"')
- if [ -n "$_test_multiuser" ]; then
- _kickout_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=$_kickout_session_id" >/dev/null
- fi
- fi
- sleep 1
- _iter=$(( $_iter + 1 ))
- done
- echo "Failed to get session ID!" 1>&2
- exit 1
- }
- set_mode()
- {
- local _mode_value="$1"
- local _response="$(curl -s -X POST -u $CREDENTIALS --data "led_settings=${_mode_value}" "http://${IP}/led_settings.cgi?id=${SESSION_ID}")"
- local _success=$(echo "$_response" | egrep -o "INPUT name=led_now type=hidden value=\"${_mode_value}\" ")
- if [ -z "$_success" ]; then
- echo "LED status change unsuccessful" 1>&2
- exit 1
- fi
- }
- case $mode in
- "off")
- SESSION_ID=$(get_session_id)
- set_mode "turn_off"
- ;;
- "blink")
- SESSION_ID=$(get_session_id)
- set_mode "en_blink"
- ;;
- "noblink")
- SESSION_ID=$(get_session_id)
- set_mode "dis_blink"
- ;;
- *)
- echo "USAGE: $0 <blink|noblink|off>"
- exit 1
- ;;
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement