Category Archives: Hack

How to send an email alert using sendmail from Asterisk 1.4 when a call is made through Ooma

I have been using asterisk in conjunction with my Ooma voip device for some time now. My current configuration allows my family and I to place a call from anywhere there is an internet connection out through my ooma device. My family and extended family travel often and this is a great way to be able to still make local calls for free while being away.

While my family uses this setup, I often wondered the details of the calls made out through my Ooma device. Sure I could log into my.ooma.com or even check the asterisk call logs, but it wasnt as neat/tidy or as automated as I would have liked. I snooped around and discovered that Asterisk can run system commands when they are specified in the extensions.conf file!

I scoured the internet for instructions and realized the lack of a good guide for asterisk 1.4 when using sendmail (this guide should work for msmtp as well), so I thought i would share.

Below is my dialplan for sending an email alert when a call is placed through to my ooma device. This can be placed in any dialplan where you would like an email alert to be made to you, so the possibilities are endless!

Asterisk email alert

While many guides are written for use with the linux mail application which can allow for the subject and body to be specified by the command line, I was using sendmail which does not allow for the subject or body to be specified by command line (except using echo statements in a way which asterisk could not duplicate while running from a dialplan ig. (cat > text | echo xxx ; echo xxx ; | sendmail) etc.). Sendmail needs certain variables to be specified in a file, or by running the application and specifying it while it is running.

I found that asterisk would need to create the file dynamically and add the To:, Subject:, and Body text variables before Asterisk/Sendmail would send the customized email that I wanted sent.

*Note: For this to work, you must have sendmail already configured and able to send emails.

[ooma-out]
;make outgoing calls to ooma pstn
exten => _XXXX.,1,System(echo “To: putdestinationemail@here.com” > /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(echo “Subject: [PBX]: Outgoing call through Ooma” >> /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(echo “” >> /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(echo “User ${CALLERID(NUM)} has made an outgoing call through ooma to phone number ${EXTEN} on ${STRFTIME(%C%m%d%y%H%M)}” >> /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,System(sendmail -t -f putsendingemail@here.com < /opt/etc/init.d/calls)
exten => _XXXX.,n(done),NoOp()
exten => _XXXX.,n,Dial(SIP/${EXTEN}@pstn,20)
exten => _XXXX.,n,Hangup
exten => _XXXX.,n,Congestion

exten => _XXXX., is used instead of exten => s,n, because I wanted to have any number larger than 4 digits routed out through ooma, since my internal extensions are 4 digits long.
exten => _XXXX.,n,Dial(SIP/${EXTEN}@pstn,20) is my command to send the call out through ooma.

This configuration makes a file located in /opt/etc/init.d called “calls” containing:

To: putdestinationemail@here.com
Subject: [PBX]: Outgoing call through Ooma
User EXTENTIONCALLING has made an outgoing call through ooma to phone number NUMBERCALLED on DATE

The email is sent to the email specified in “putdestinationemail@here.com” from email address specified in putsendingemail@here.com

This dialplan can be customized to suit any email alert you may need to send when placed into any dialplan in the extensions.conf file, so have fun!

How to recover ssh access to your pogoplug when hbmgr.sh has been removed from startup

Recently, I was tinkering with my pogoplug running openpogo and decided to comment out the hbmgr.sh line in my rcS startup file. I soon learned that  hbmgr.sh is responsible for starting dropbear and connecting your pogoplug to the my.pogoplug.com service. Because telnet was disabled and dropbear was not starting, I realized I no longer had SSH access to my pogoplug, although I could see my programs like transmission and asterisk were starting up ok.

I freaked out for a moment as I believed there was no way to recover ssh access…until I thought about it some more. Below are the steps to recover SSH access to your pogoplug running openpogo if you somehow disabled hbmgr.sh on startup:

This procedure will work with pogoplugs running openpogo, not sure if it will work for units NOT running openpogo since openpogo searches the opt/etc/init.d directory on startup to start any other scripts on boot.

PREP:
-power off the pogoplug
-download a linux live distro. Any modern live distro will do, knoppix, slitaz, ubuntu, etc.
-burn distro to cd
-boot off linux live cd
-plug in HD from pogoplug into the computer now running linux

ACCESS the HD:

-mount hard drive (you might have to open up gparted to see what device your HD is coming up as)
-start terminal
-access your hd mount
-do an ls -a (this command shows hidden files on the directory you are in. If you do not use the -a command, you will only see the directories you shared out through pogoplug).
-go into the /.opt/etc/init.d directory
-nano or vi a new file called S70ssh with ROOT permissions (otherwise you will not be able to write the file)

Enter in this line in the new file:

/etc/init.d/hbmgr.sh start

-save and exit
-chmod 777 the S70ssh file for good measure

FINISHING:
-Power down the linux system
-Plug the HD back into the Pogoplug and power cycle the unit.

After the unit restarts, the script should have run and started hbmgr.sh. Remember to delete the script S70ssh and make sure the /etc/init.d/hbmgr.sh start line is enabled or entered back into the rcS startup file.