#!/bin/bash # (C)2009 DatuX - Released under GPL #voer asterisk commando uit via cli asterisk_cmd() { CMD="asterisk -r -x '$1'" VERIFYEXIT=0 sshtest return $? } asterisk_errorcheck() { DESCRIPTION1="check op fouten in logs.." CMD=" cat /var/log/asterisk/full | egrep '(WARNING|ERROR|abandoning)' | grep -v 'chan_misdn' | # voor het testen zonder isdn kaart grep -v 'app_queue.*fullname' | # dit field word dor asterisk genegeerd maar is nodig voor asterisk_gui grep -v 'Failed to write frame' | # gebeurd na opnemen voicemail grep -v 'Unable to write frame to channel' | # gebeurd bij meetme wel eens grep -v 'Channel .SIP/105-.* sent into invalid extension' | #ook voicemail grep -v 'No SMDI interfaces' | # res_smdi is nodig voor voicemail, maar klaagt over interfaces grep -v 'ast_expr2.fl:' | # asterisk_gui configureeerd FOLLOW_ME variabelle niet in extensions.conf grep -v 'app_fax is untested' | grep -v 'app_voicemail.c: maxsilence' " VERIFYNEGATIVE=".*" sshtest || exit 1 } #send a pjsua command pjsua_cmd() { echo "pjsua: Sending command '$1'" echo "$1" >> pjsua.in } #wait for specific pjsua output text LINES=1 pjsua_wait() { #DEBUG: asterisk_errorcheck COUNT=$TIMEOUT while true; do echo "pjsua: Waiting for '$1'..." if tail -n +"$LINES" pjsua.log | egrep -i "$1"; then echo "pjsua: Found '$1'"; LINES=`cat pjsua.log|wc -l` (( LINES++ )) return 0 fi (( COUNT-- )) if [ "$COUNT" == "0" ]; then echo "pjsua: Not found '$1'" LINES=`cat pjsua.log|wc -l` (( LINES++ )) return 1 fi pjsua_cmd "" sleep 1; done } #restart pjsua. use this to reset everything #WARNING: patch./pjsip/include/pjsua-lib/pjsua.h by setting PJSUA_MAX_ACC to 10000 ! pjsua_restart() { trap "kill -9 %1" 0 ####restart pjsua sip client killall -9 pjsua sleep 1 echo -n > pjsua.in echo -n > pjsua.log tail -s .1 -f pjsua.in | pjsua --app-log-level=3 $PJSUA_OPTS | egrep --line-buffered '(pjsua)' | tee pjsua.log & # tail -s .1 -f pjsua.in | pjsua --app-log-level=3 | tee pjsua.log & #wait for init pjsua_wait "initialized" || exit 1 } ## De pjsua_... zijn de VAGE lowlevel functies om met pjsua te communiceren. ## De sip_... functies zijn DUIDELIJKE wrappers om standaard dingen te doen, die je in testcases gebruikt. (bellen ophangen etc) #register new sip account sip_register() { info "sip: Registering $1@$IP (password test)" pjsua_cmd "+a" pjsua_cmd "sip:$1@$IP" pjsua_cmd "sip:$1@$IP" pjsua_cmd "*" pjsua_cmd "$1" pjsua_cmd "test" #password moet altijd 'test' zijn! if ! [ "$NOWAIT" ]; then pjsua_wait "$1@$IP.*registration success" return $? fi NOWAIT= return 0 } sip_call() { info "sip: Calling $1" pjsua_cmd "]" pjsua_cmd "m" pjsua_cmd "sip:$1@$IP" pjsua_wait "changed to CALLING" return $? } sip_waitanswer() { info "sip: Wait until call is answered" pjsua_wait "changed to CONFIRMED" return $? } sip_waithangup() { info "sip: Wait until call is ended" pjsua_wait "is DISCONNECTED" return $? } sip_hangup() { info "sip: Hang up all calls" pjsua_cmd "ha" sip_waithangup return $? } sip_answer() { info "sip: Answer call" OLDTIMEOUT=$TIMEOUT TIMEOUT=1 COUNT=10 #find the call.. while ! sip_waitanswer; do pjsua_cmd "]" pjsua_cmd "" pjsua_cmd "a" pjsua_cmd "200" sleep 1 (( COUNT-- )) [ "$COUNT" == 0 ] && return 1 done TIMEOUT=$OLDTIMEOUT return $? } sip_transfer() { info "sip: Transferring call to $1" pjsua_cmd "x" pjsua_cmd "sip:$1@$IP" pjsua_wait "transfered successfully" return $? } sip_hold() { info "sip: Holding call" pjsua_cmd "H" pjsua_wait "is suspended" return $? } sip_unhold() { info "sip: Un-hold call" pjsua_cmd "v" pjsua_wait "Media for call.*active" return $? } sip_dtmf() { #ALS DIT NIET WERKT, HEB JE EEN FIREWALL ISSUE MET SYN3 BAK - ZET FIREWALL HELEMAAL OPEN info "sip: Sending DTMF: $1" pjsua_cmd "#" pjsua_cmd "$1" sleep 2 # give asterisk time to react return $? } #6 seconds of sounds makesound() { #mplayer /usr/kde/3.5/share/sounds/KDE_Startup_3.ogg || exit 1 echo "MAKE SOUND!!!!" sleep 6 }