--- /dev/null
+#!/bin/bash
+# modify next two line for your DSP-W215
+IP="192.168.1.183"
+PIN="215530"
+# do not modify after this line if you don't know what you are doing
+
+function usage {
+ echo -e "\nUsage: $(basename $0) [OPTION]"
+ echo -e "\nOPTION:"
+ echo -e "\t--getstate"
+ echo -e "\t--stop"
+ echo -e "\t--noise SoundType(1-6) Volume(0-100) Duration(??)"
+}
+
+function hash_hmac {
+ data="$1"
+ key="$2"
+ echo -n "$data" | openssl dgst "-md5" -hmac "$key" -binary | xxd -ps -u
+}
+
+contentType="Content-Type: text/xml; charset=utf-8"
+soapLogin="SOAPAction: \"http://purenetworks.com/HNAP1/Login\""
+
+#Get Login data
+
+head="<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
+end="</soap:Body></soap:Envelope>"
+
+message="<Login xmlns=\"http://purenetworks.com/HNAP1/\"><Action>request</Action><Username>admin</Username><LoginPassword></LoginPassword><Captcha/></Login>"
+loginrequest="$head$message$end"
+#echo "Login request: $loginrequest"
+
+#ret=`curl -s -X POST -H "$contentType" -H "$soapLogin" --data-binary "$loginrequest" http://$IP/HNAP1`
+ret=`curl -v -X POST -H "$contentType" -H "$soapLogin" --data-binary "$loginrequest" http://$IP/HNAP1`
+echo -e "Returned value: $ret"
+
+function getResult {
+ opt=`echo -n "$ret" | grep -Po "(?<=<$1>).*(?=</$1>)"`
+ echo -n "$opt"
+}
+
+#echo -e "Challenge: "
+#echo -e `getResult Challenge`
+
+challenge=`getResult Challenge`
+cookie="Cookie: uid=`getResult Cookie`"
+publickey="`getResult PublicKey`$PIN"
+privatekey=`hash_hmac "$challenge" "$publickey"`
+password=`hash_hmac "$challenge" "$privatekey"`
+timestamp=`date +%s`
+auth_str="$timestamp\"http://purenetworks.com/HNAP1/Login\""
+auth=`hash_hmac "$auth_str" "$privatekey"`
+hnap_auth="HNAP_AUTH: $auth $timestamp"
+
+message="<Login xmlns=\"http://purenetworks.com/HNAP1/\"><Action>login</Action><Username>admin</Username><LoginPassword>$password</LoginPassword><Captcha/></Login>"
+
+login="$head$message$end"
+echo "Login info: $login"
+
+#Get Login Result
+#ret=`curl -s -X POST -H "$contentType" -H "$soapLogin" -H "$hnap_auth" -H "$cookie" --data-binary "$login" http://$IP/HNAP1`
+ret=`curl -v -X POST -H "$contentType" -H "$soapLogin" -H "$hnap_auth" -H "$cookie" --data-binary "$login" http://$IP/HNAP1`
+echo -e "Returned value: $ret"
+
+echo -e "\nUsage: $(basename $0) [OPTION]"
+
+case "$1" in
+--getstate )
+ #Next 2 rows to modify query
+ method="GetSirenAlarmSettings"
+ message="<$method xmlns=\"http://purenetworks.com/HNAP1/\"><ModuleID>1</ModuleID>><Controller>1</Controller></$method>"
+
+ #Do not modify after this line
+ soapAction="SOAPAction: \"http://purenetworks.com/HNAP1/$method\""
+ authStr="$timestamp\"http://purenetworks.com/HNAP1/$method\""
+ auth=`hash_hmac "$authStr" "$privatekey"`
+ hnap_auth="HNAP_AUTH: $auth $timestamp"
+ data="$head$message$end"
+
+ #Get Device state from GetSocketSettings
+ #ret=`curl -s -X POST -H "$contentType" -H "$soapAction" -H "$hnap_auth" -H "$cookie" --data-binary "$data" http://$IP/HNAP1`
+ ret=`curl -v -X POST -H "$contentType" -H "$soapAction" -H "$hnap_auth" -H "$cookie" --data-binary "$data" http://$IP/HNAP1`
+ echo -e "Timestamp=$timestamp\tSOAPAction=$soapAction\tAuthStr=$authStr\tAUTH=$auth\tHNAP=$hnap_auth\tRET = $ret" #This line is for debug purpose
+ ;;
+--noise )
+ #Next 2 rows to modify query
+ method="SetSoundPlay"
+ message="<$method xmlns=\"http://purenetworks.com/HNAP1/\"><ModuleID>1</ModuleID><Controller>1</Controller><SoundType>$2</SoundType><Volume>$3</Volume><Duration>$4</Duration></$method>"
+
+ #Do not modify after this line
+ soapAction="SOAPAction: \"http://purenetworks.com/HNAP1/$method\""
+ authStr="$timestamp\"http://purenetworks.com/HNAP1/$method\""
+ auth=`hash_hmac "$authStr" "$privatekey"`
+ hnap_auth="HNAP_AUTH: $auth $timestamp"
+ data="$head$message$end"
+ echo -e "Sound data: $data"
+
+ #Get Device state from GetSocketSettings
+ #ret=`curl -s -X POST -H "$contentType" -H "$soapAction" -H "$hnap_auth" -H "$cookie" --data-binary "$data" http://$IP/HNAP1`
+ ret=`curl -v -X POST -H "$contentType" -H "$soapAction" -H "$hnap_auth" -H "$cookie" --data-binary "$data" http://$IP/HNAP1`
+ echo -e "Return value: $ret"
+ ;;
+--stop )
+ #Next 2 rows to modify query
+ method="SetAlarmDismissed"
+ message="<$method xmlns=\"http://purenetworks.com/HNAP1/\"><ModuleID>1</ModuleID><Controller>1</Controller></$method>"
+
+ #Do not modify after this line
+ soapAction="SOAPAction: \"http://purenetworks.com/HNAP1/$method\""
+ authStr="$timestamp\"http://purenetworks.com/HNAP1/$method\""
+ auth=`hash_hmac "$authStr" "$privatekey"`
+ hnap_auth="HNAP_AUTH: $auth $timestamp"
+ data="$head$message$end"
+ echo -e "Stop data: $data"
+
+ #Get Device state from GetSocketSettings
+ #ret=`curl -s -X POST -H "$contentType" -H "$soapAction" -H "$hnap_auth" -H "$cookie" --data-binary "$data" http://$IP/HNAP1`
+ ret=`curl -v -X POST -H "$contentType" -H "$soapAction" -H "$hnap_auth" -H "$cookie" --data-binary "$data" http://$IP/HNAP1`
+ ;;
+* )
+ usage
+ ;;
+esac