Building a SIP spam rejecter with linphonec

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Building a SIP spam rejecter with linphonec

Andrew Benham
Every so often the phone spammers get a new block of numbers (024 7668
xxxx has just started up).  As my home phone is on a SIP service, it's
time to get creative - I fancy building a SIP spam rejecter.

Plan is to run something on a Raspberry Pi to read the CLID.  If it's a
normal call do nothing, and the phones here will ring as usual.  But if
the number pattern is in a naughty list, answer the call, play SIT and
possibly a voice message, then terminate the call.  Just rejecting the
call is no good, because the other phones will still ring as they're
registered with the SIP server individually.

The Raspberry Pi runs Raspian, and I have linphonec v3.12.0 installed
which I can automate with an Expect script.
Essentially I want to check the caller id, and if bad do:
   answer
   play a wav file (SIT followed by a voice message)
   terminate

linphonec's help text says I can play a wav file, but I get an error
when I try.  Alternatively I can answer the call, then pause the call
which causes 'music on hold' to be played.  The help text says I can
define the 'music on hold', but defining a wav file adds that audio to
an internal list of audio clips which seem to be selected at random -
maybe 1 time in 6 it plays my defined wav file.

Am I trying to do the impossible ?  I can't see where the other 'music
on hold' clips are defined.  Ideally I'd like to be able to select
different wav files for different classes of bad calls, but doing it
with one wav file as 'music on hold' would be OK.

This is what I have at the moment as a first try.  Works nicely, but it
seldom plays my desired SIT audio file.

-------------------------

#!/usr/bin/expect

log_user 0

spawn /usr/bin/linphonec
expect "linphonec>"
send "soundcard use files\r"
expect "linphonec>"
send "play /home/adsb/call_guardian/sit-tone-8000.wav\r"
expect "linphonec>"

set timeout -1

proc handle_call {number id} {
        send_user "Call $id from $number\n"
        if [string match $number {02476680123}] {
                exp_send "answer $id\r"
                expect "Connected."
                exp_send "pause\r"
                sleep 5
                exp_send "terminate\r"
                expect "Call ended"
        }
        return
}

expect {
        -re "Receiving new incoming call from \"(.*)\".*, assigned id (\\d)"
        {
          handle_call $expect_out(1,string) $expect_out(2,string)
          exp_continue
        }
}

-------------------------

I'm getting suggestions to use Asterisk instead, but that seems much
more complicated than a 40 line Expect script...

--
Andrew Benham     Southgate, London N14, United Kingdom

The gates in my computer are AND OR and NOT, not "Bill"


_______________________________________________
Linphone-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/linphone-users

signature.asc (673 bytes) Download Attachment