Some recent projects for fun and work

I’ve had fun with a few personal and work-related VoIP projects lately. I’ll summarize them here, and if there’s any interest I’ll expand one or more of them into full how-to articles. 

speak2tweet
You may have heard about the Google/Twitter project called speak2tweet that was created over a weekend during the Egyptian protests, with the goal of allowing protesters whose Internet connectivity was cut to get their voices on to the web. Some folks on the PBX-in-a-Flash forum were talking about it and we realized it would not be hard to build, especially with the Tropo transcription service available to us.
Check out the first page of that thread for the dial-in numbers, and then try it out yourself. The code is posted on the forum for the first hack at it, which only does transcription. The current version includes links to the recordings, too, just like the original speak2tweet. I need to clean it up and post it. See and hear your spoken tweets at twitter.com/piafspeaktweet.
Fax
I have largely ignored fax over VoIP for a long time, because it’s not something I do. At PSU, we attach fax machines to analog lines; done. But recently, I was asked to assist with a quick-turnaround fax project: send a fax to 4,059 analog lines on campus, calls spaced one minute apart, and record the results, so that we can see how many fax machines are hooked up out there. Interesting. I tried Digium’s Free Fax for Asterisk module, but couldn’t get it to communicate. Next I built the soft-switch.org spandsp module, and told Asterisk to use it, and it worked right away. A Perl script using the excellent Asterisk::AMI module (referenced previously on this blog) drove the dialer, and standard Asterisk CDR with a few extra fields recorded the fax results. By the way, the faxes were sent in audio mode (not T.38) using SIP and G.711u over the Internet, and only 3 out of 4,059 calls failed.
FreeSWITCH revisited
Back when I wrote about using FreeSWITCH alongside Asterisk as a gateway to Google Voice, I determined that at some point I’d come back and dig into FreeSWITCH a little more just to understand it. I updated that article with a slightly better config, including lines that turn on comfort noise, which helps the FreeSWITCH-Asterisk bridge maintain synchronization on RTP. (See the FreeSWITCH wiki for more information on that.)

ssmtp to handle your PBX’s e-mail

Here’s a simple how-to for processing the mail your Asterisk server generates, without running a full mail-transfer agent (MTA) like sendmail or postfix.

First, two assertions:

  • You need to deal with mail, even if you aren’t using Asterisk’s voicemail-attached-to-e-mail feature, because your system daemons like cron are generating mail that you may want to read.
  • Running a mail daemon of any kind is a waste of resources when all you really want to do is get the mail off your Asterisk server to some other server for processing.

In the past, a Linux admin would enable sendmail, set the domain name and basically be done. Mail would work on port 25, everyone would accept everyone else’s mail, and life was good. Then spammers ruined our lives and we have to use strange ports, domain validation and a bunch of other things to make ourselves an official mail server. That’s too much work, especially for a box that’s supposed to be a PBX, not a mail system. And if you’re on a residential Internet connection, forget it–you’re probably in every blacklist.

Enter ssmtp, the simple SMTP sender. We’ll use it to send both Internet e-mail, such as might be produced by Asterisk’s voicemail system, and local root-type mail (e.g. cron alerts) through a legitimate SMTP server. It does not run as a system daemon, only on-demand when something on the server generates e-mail. And it’s simple to set up.

Setup

  • Get the source: http://packages.debian.org/source/sid/ssmtp . The file you want is the orig.tar.bz2 file.
  • tar jxvf ssmtp_(version).orig.tar.bz2 to expand it.
  • ./configure --enable-ssl (if the build fails later, yum install openssl-devel [CentOS/RedHat] to get the necessary SSL libraries)
  • make then make install, as root. On a fresh install, sample configurations are installed in /usr/local/etc/ssmtp/. The program is in /usr/local/sbin/.
  • Edit /usr/local/etc/ssmtp/ssmtp.conf. For a basic configuration that will send all locally-addressed mail to a single address, and Internet-addressed mail to the appropriate address, this is all you need:
    # The person who gets all mail for userids < 1000 root=mailbox@example.com # The place where the mail goes. The actual machine name is required # no MX records are consulted. Commonly mailhosts are named mail.domain.com mailhub=smtp.gmail.com:587 # The full hostname hostname=asteriskbox.example.com fromlineoverride=yes authuser=USERNAME authpass=PASSWORD useTLS=yes useSTARTTLS=yes authmethod=LOGIN 

    This example configuration, as you can guess, is for a Gmail account, and will also work with a Google Apps account. Since so many folks use Gmail, you could just cut and paste this, replacing the hostname and credentials with your own. If you are using a different SMTP server, adjust as necessary. With Gmail, the fromlineoverride won’t work–Gmail uses your Gmail address as the From. But it may work on other servers, especially if you are running your own mail server on a different box and send your mail to that.

  • Finally, get rid of sendmail and link to ssmtp in its place. yum erase sendmail will get rid of it from CentOS. Then ln -s /usr/local/sbin/ssmtp /usr/sbin/sendmail to trick your programs into believing sendmail is there, while ssmtp runs instead.

Test it out

You can install mailx with yum install mailx, then try both local mail and Internet mail:

mail root
mail youraddress@example.com

With mail, end your message by pressing Control-D.

Or you can use ssmtp directly: ssmtp root or sendmail root

Try sendmail -t and then fill out the header by typing to: address and so on.

Once you see that mail is moving, you’re done. If you encounter a problem, check /var/log/maillog.

More advanced

If you want to control where mail goes for individual local accounts, check out the revaliases file in /usr/local/etc/ssmtp/. Otherwise, all mail destined to local accounts with UID < 1000 will go to the mailbox specified in the root= line in the config.

Note

If you are using authenticated SMTP (as in the example config above), your ssmtp.conf file contains your SMTP password in plain text. If your box is secure and you are the only user of it, this may not matter. If other users are logging in to the box, and you don’t want them to be able to see the config, you can chmod 600 ssmtp.conf to make it readable only by root, then setuid root the ssmtp binary with chmod +s /usr/local/sbin/ssmtp .

References

Debian wiki on sSMTP