Question

Can you someone please point in me in a direction, sample code or an online resource to accomplish the following:

Requirement: I would like to write a simple IVR menu option that will run a script (Bash or Python). For example, phone the Asterisk machine and request to restart a service on another Linux box. The 'other Linux box' details would be hard coded to the IVR menu option and not needed to be supplied as part of the IVR interaction - just restart service X on box Y. I am little worried and unsure how one would secure this with a password (even if it is hard coded in version).

Background: I am an Asterisk newbie and installed it from the AsteriskNow distribution and I am still learning the product. The basic PBX functionality is working and is administered through FreePBX. Asterisk is not our main focus of development work but rather a tool in the toolbox. We mostly do .NET work but have Unix skills.

If possible I would not like to spend days learning the integrate details of Asterisk to get the job done...

Was it helpful?

Solution

The Asterisk AGI page holds links to applications in many programming languages. If you do mostly .NET, maybe nasterisk or the older MONO-TONE will help.

OTHER TIPS

Asterisk is not always waiting for user input. Only during the Background, WaitExten, Read commands. If you're using Playback(), Asterisk ignores any DTMF while it's playing the audio file.

You can replace Playback with Read() but you have to set the read timeout to a very low value or there will be a silence after every audio file you play with Read(). If you use Read() then you have to check the value input by the user to check for exit, something like this...

Instead of

exten => x,n,Playback(yourfile) 
exten => x,n,somethingelse...

you need

exten => x,n,Read(Exit,yourfile,1)
exten => x,n,GotoIf($["${Exit}" = "0"]?0,1) 
exten => x,n,somethingelse...

Will you set up Asterisk just for this or is it/will it be doing other stuff such as PBX, IVR, etc?

If you are doing other stuff with Asterisk, then set up a hidden extension (one not advertised on the IVR menu) which you can dial once you're connected; in this extension, you can check the caller id and compare it to your number, so that only you can execute the script (you can add some more security by asking for a PIN number, so you can rest easier if you can't find your phone).

Something like this:

exten => 9999,1,GotoIf($["${CALLERID(num)}" = "yournumber"]?4)
exten => 9999,2,Playback(sorry)
exten => 9999,3,Hangup
exten => 9999,4,Read(Pin,please-enter-pin,4)
exten => 9999,5,AGI(your-script)

In your-script you check the Pin variable and if it's valid, execute, otherwise exit without doing anything. This way you don't have to hardcode the pin inside the dialplan, which someone else may look at... if it's a trusted machine then you can validate the Pin right in the dialplan:

exten => 9999,5,GotoIf($["Pin" != "1234"]?2)
exten => 9999,6,AGI(your-script)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top