by Peter Lavin
December 22, 2011
I’ve used OpenWrt (Kamikaze 7.09) installed on a Linksys WRT54GL (v 1.1) router for a few years. When I initially installed OpenWrt I made changes to the dnsmasq.conf file configuring bogus domains, setting up text records for machines on my LAN and other such things. OpenWrt works so well that after a while you tend to forget about it.
When I realized that I could programme the button on the face of my router I couldn’t resist taking another look at OpenWrt. What to do with the button though? There’s no point in making it a reboot button- you never have to reboot an OpenWrt router. Toggle the wi-fi? I don’t think so.
Instead, I decided to send the logs by email. One click on the face of my router and a few moments later my phone is telling me I’ve got ‘OpenWrt Logs’.
This article is geared towards Kamikaze 7.09 on a Linksys WRT54GL router. However, the ssmtp package is available for all versions of Kamikaze and for Backfire so what’s described here may well be more widely applicable.
ssmtp is a minimalist sendmail clone ideal for use on embedded systems. You can find out more about it from the command line of your router by using ipkg info ssmtp. You should see something similar to the following:
Package: ssmtp Version: 2.61-2 Depends: libopenssl Provides: Status: install user installed Section: net Architecture: mipsel maintainer: OpenWrt Developers Team <email@example.com> MD5Sum: 8bd9deb9af9e1d5a0ab82512a87c8fef Size: 12727 Filename: ./ssmtp_2.61-2_mipsel.ipk Source: /data/release/packages/packages/net/ssmtp Description: A minimal and secure mail sender A secure, effective and simple way of getting mail off a system to your mail hub. It contains no suid-binaries or other dangerous things - no mail spool to poke around in, and no daemons running in the background. mail is simply forwarded to the configured mailhost. Extremely easy configuration.
The ssmtp package requires libopenssl. To find out more about this package use ipkg info libopenssl. Note that the file size is 472517. Check that there is space available by going to the command line and using the df command.
Issuing the command ipkg install ssmtp will install the ssmtp package and the libopenssl package.
After installation you can find the ssmtp configuration file, ssmtp.conf, in the /etc/ssmtp directory. Change or add the configuration options shown below:
mailhub=smtp.gmail.com:465 AuthUser= *firstname.lastname@example.org AuthPass= *secret* FromLineOverride=YES UseTLS=YES
In this case, the GMail mail server is being used. Add values appropriate to your circumstances. Setting FromLineOverride to YES is optional.
After changing the ssmtp configuration file, test that the ssmtp command functions properly. To do this, first add the following file to the /etc directory naming it email:
To: *email@example.com Subject: OpenWrt Logs From: *firstname.lastname@example.org Log Files
Add appropriate values for the sender and recipient. Leave an empty line after the From: line so that the body of the email is separated from the sender line.
Test sending an email by navigating to the /etc directory and issuing the command ssmtp -vvv `email@example.com` < email. Use the -vvv option for verbose output-you’ll see every phase of the SMTP transaction.
If you are not successful then an error message is displayed and a dead.letter is created in the home directory. With verbose output set, you’ll see the SMTP response code 250 which indicates success but check your email account to make sure that the message was received.
Now that ssmtp is installed and working, you can begin coding the router’s button.
Now that you can send log files at the press of a button you should know what they’re telling you. dnsmasq uses the syslog facility and writes a circular log to memory. This log is read using the logread utility.
Find below sample log entries related to sending an email:
... Dec 22 17:05:24 OpenWrt mail.info sSMTP: Creating SSL connection to host Dec 22 17:05:25 OpenWrt mail.info sSMTP: SSL connection using RC4-SHA Dec 22 17:05:29 OpenWrt mail.info sSMTP: Sent mail for firstname.lastname@example.org (221 2.0.0 closing connection h9sm18368679qac.13) uid=0 username=root outbytes=13989 Dec 22 17:17:39 OpenWrt syslog.info -- MARK --
The meaning of the fields is as follows:
Records with the message – MARK – are “heartbeats” sent every twenty minutes, indicating that logging is still active.