1 | #!/bin/bash |
---|
2 | # (C)2009 DatuX - Released under GPL |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | #voer asterisk commando uit via cli |
---|
7 | asterisk_cmd() |
---|
8 | { |
---|
9 | CMD="asterisk -r -x '$1'" |
---|
10 | VERIFYEXIT=0 |
---|
11 | sshtest |
---|
12 | return $? |
---|
13 | } |
---|
14 | |
---|
15 | asterisk_errorcheck() |
---|
16 | { |
---|
17 | DESCRIPTION1="check op fouten in logs.." |
---|
18 | CMD=" |
---|
19 | cat /var/log/asterisk/full | |
---|
20 | egrep '(WARNING|ERROR|abandoning)' | |
---|
21 | grep -v 'chan_misdn' | # voor het testen zonder isdn kaart |
---|
22 | grep -v 'app_queue.*fullname' | # dit field word dor asterisk genegeerd maar is nodig voor asterisk_gui |
---|
23 | grep -v 'Failed to write frame' | # gebeurd na opnemen voicemail |
---|
24 | grep -v 'Unable to write frame to channel' | # gebeurd bij meetme wel eens |
---|
25 | grep -v 'Channel .SIP/105-.* sent into invalid extension' | #ook voicemail |
---|
26 | grep -v 'No SMDI interfaces' | # res_smdi is nodig voor voicemail, maar klaagt over interfaces |
---|
27 | grep -v 'ast_expr2.fl:' | # asterisk_gui configureeerd FOLLOW_ME variabelle niet in extensions.conf |
---|
28 | grep -v 'app_fax is untested' | |
---|
29 | grep -v 'app_voicemail.c: maxsilence' |
---|
30 | |
---|
31 | " |
---|
32 | VERIFYNEGATIVE=".*" |
---|
33 | sshtest || exit 1 |
---|
34 | } |
---|
35 | |
---|
36 | #send a pjsua command |
---|
37 | pjsua_cmd() |
---|
38 | { |
---|
39 | echo "pjsua: Sending command '$1'" |
---|
40 | echo "$1" >> pjsua.in |
---|
41 | } |
---|
42 | |
---|
43 | #wait for specific pjsua output text |
---|
44 | LINES=1 |
---|
45 | pjsua_wait() |
---|
46 | { |
---|
47 | #DEBUG: |
---|
48 | asterisk_errorcheck |
---|
49 | |
---|
50 | COUNT=$TIMEOUT |
---|
51 | while true; do |
---|
52 | echo "pjsua: Waiting for '$1'..." |
---|
53 | if tail -n +"$LINES" pjsua.log | egrep -i "$1"; then |
---|
54 | echo "pjsua: Found '$1'"; |
---|
55 | LINES=`cat pjsua.log|wc -l` |
---|
56 | (( LINES++ )) |
---|
57 | return 0 |
---|
58 | fi |
---|
59 | (( COUNT-- )) |
---|
60 | if [ "$COUNT" == "0" ]; then |
---|
61 | echo "pjsua: Not found '$1'" |
---|
62 | LINES=`cat pjsua.log|wc -l` |
---|
63 | (( LINES++ )) |
---|
64 | return 1 |
---|
65 | fi |
---|
66 | pjsua_cmd "" |
---|
67 | sleep 1; |
---|
68 | done |
---|
69 | } |
---|
70 | |
---|
71 | #restart pjsua. use this to reset everything |
---|
72 | #WARNING: patch./pjsip/include/pjsua-lib/pjsua.h by setting PJSUA_MAX_ACC to 10000 ! |
---|
73 | pjsua_restart() |
---|
74 | { |
---|
75 | trap "kill -9 %1" 0 |
---|
76 | |
---|
77 | ####restart pjsua sip client |
---|
78 | killall -9 pjsua |
---|
79 | sleep 1 |
---|
80 | echo -n > pjsua.in |
---|
81 | echo -n > pjsua.log |
---|
82 | |
---|
83 | tail -s .1 -f pjsua.in | pjsua --app-log-level=3 $PJSUA_OPTS | egrep --line-buffered '(pjsua)' | tee pjsua.log & |
---|
84 | # tail -s .1 -f pjsua.in | pjsua --app-log-level=3 | tee pjsua.log & |
---|
85 | |
---|
86 | #wait for init |
---|
87 | pjsua_wait "initialized" || exit 1 |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | ## De pjsua_... zijn de VAGE lowlevel functies om met pjsua te communiceren. |
---|
92 | ## De sip_... functies zijn DUIDELIJKE wrappers om standaard dingen te doen, die je in testcases gebruikt. (bellen ophangen etc) |
---|
93 | |
---|
94 | #register new sip account |
---|
95 | sip_register() |
---|
96 | { |
---|
97 | info "sip: Registering $1@$IP (password test)" |
---|
98 | pjsua_cmd "+a" |
---|
99 | pjsua_cmd "sip:$1@$IP" |
---|
100 | pjsua_cmd "sip:$1@$IP" |
---|
101 | pjsua_cmd "*" |
---|
102 | pjsua_cmd "$1" |
---|
103 | pjsua_cmd "test" #password moet altijd 'test' zijn! |
---|
104 | |
---|
105 | if ! [ "$NOWAIT" ]; then |
---|
106 | pjsua_wait "$1@$IP.*registration success" |
---|
107 | return $? |
---|
108 | fi |
---|
109 | NOWAIT= |
---|
110 | return 0 |
---|
111 | } |
---|
112 | |
---|
113 | sip_call() |
---|
114 | { |
---|
115 | info "sip: Calling $1" |
---|
116 | pjsua_cmd "]" |
---|
117 | pjsua_cmd "m" |
---|
118 | pjsua_cmd "sip:$1@$IP" |
---|
119 | |
---|
120 | pjsua_wait "changed to CALLING" |
---|
121 | return $? |
---|
122 | } |
---|
123 | |
---|
124 | sip_waitanswer() |
---|
125 | { |
---|
126 | info "sip: Wait until call is answered" |
---|
127 | pjsua_wait "changed to CONFIRMED" |
---|
128 | return $? |
---|
129 | } |
---|
130 | |
---|
131 | sip_waithangup() |
---|
132 | { |
---|
133 | info "sip: Wait until call is ended" |
---|
134 | pjsua_wait "is DISCONNECTED" |
---|
135 | return $? |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | sip_hangup() |
---|
140 | { |
---|
141 | info "sip: Hang up all calls" |
---|
142 | pjsua_cmd "ha" |
---|
143 | sip_waithangup |
---|
144 | return $? |
---|
145 | } |
---|
146 | |
---|
147 | sip_answer() |
---|
148 | { |
---|
149 | info "sip: Answer call" |
---|
150 | OLDTIMEOUT=$TIMEOUT |
---|
151 | TIMEOUT=1 |
---|
152 | COUNT=10 |
---|
153 | #find the call.. |
---|
154 | while ! sip_waitanswer; do |
---|
155 | pjsua_cmd "]" |
---|
156 | pjsua_cmd "" |
---|
157 | pjsua_cmd "a" |
---|
158 | pjsua_cmd "200" |
---|
159 | sleep 1 |
---|
160 | (( COUNT-- )) |
---|
161 | [ "$COUNT" == 0 ] && return 1 |
---|
162 | done |
---|
163 | |
---|
164 | TIMEOUT=$OLDTIMEOUT |
---|
165 | |
---|
166 | return $? |
---|
167 | } |
---|
168 | |
---|
169 | sip_transfer() |
---|
170 | { |
---|
171 | info "sip: Transferring call to $1" |
---|
172 | pjsua_cmd "x" |
---|
173 | pjsua_cmd "sip:$1@$IP" |
---|
174 | pjsua_wait "transfered successfully" |
---|
175 | return $? |
---|
176 | } |
---|
177 | |
---|
178 | sip_hold() |
---|
179 | { |
---|
180 | info "sip: Holding call" |
---|
181 | pjsua_cmd "H" |
---|
182 | pjsua_wait "is suspended" |
---|
183 | return $? |
---|
184 | } |
---|
185 | |
---|
186 | sip_unhold() |
---|
187 | { |
---|
188 | info "sip: Un-hold call" |
---|
189 | pjsua_cmd "v" |
---|
190 | pjsua_wait "Media for call.*active" |
---|
191 | return $? |
---|
192 | } |
---|
193 | |
---|
194 | sip_dtmf() |
---|
195 | { |
---|
196 | #ALS DIT NIET WERKT, HEB JE EEN FIREWALL ISSUE MET SYN3 BAK - ZET FIREWALL HELEMAAL OPEN |
---|
197 | info "sip: Sending DTMF: $1" |
---|
198 | pjsua_cmd "#" |
---|
199 | pjsua_cmd "$1" |
---|
200 | sleep 2 # give asterisk time to react |
---|
201 | return $? |
---|
202 | } |
---|
203 | |
---|
204 | #6 seconds of sounds |
---|
205 | makesound() |
---|
206 | { |
---|
207 | #mplayer /usr/kde/3.5/share/sounds/KDE_Startup_3.ogg || exit 1 |
---|
208 | echo "MAKE SOUND!!!!" |
---|
209 | sleep 6 |
---|
210 | } |
---|
211 | |
---|