Software development techniques behind the magic user interface

Multi-Touch Developer Journal

Subscribe to Multi-Touch Developer Journal: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get Multi-Touch Developer Journal: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


Multi-Touch Authors: Ben Bradley, Qamar Qrsh, Suresh Sambandam, Jayaram Krishnaswamy, Kevin Benedict

Related Topics: Apache Web Server Journal

Apache Web Server: Article

The complete messaging gateway

Part 12 in our 'Linux for Peanuts' series and our server goes into production with Boa

(LinuxWorld) -- Boa: noun [Latin]

  1. Angry serpent that Steve Irwin (well-known crazed Aussie crocodile hunter featured on Animal Planet) drags from it's burrow to fondle and coo over.
  2. Article of apparel often sported by otherwise scantily clad ladies in photographs depicting [censored]
  3. A lean and mean Web server well suited to slower processors and minimal RAM.

Despite the obvious entertainment value in watching Mr. Irwin get bitten by a 17 foot-long snake, or in admiring (censored and link to .jpg removed), we turn our attention to the third definition: a Web server.

We have been busy setting up a Text Messaging Gateway for our Linux Network for Peanuts (see Part 9, Part 10, and Part 11) and let's take a moment to review what we have accomplished thus far:

We began by adapting a machine loaded with Debian (originally configured as an X terminal) by changing it's name and IP to something more descriptive of it's new role as a Text Messaging Gateway.

Next, we added a dial-up modem so that this machine can dial the TAP/IXO modems of alphanumeric paging services and those of digital cellular and PCS providers.

We installed and configured QuickPage to send messages using the Simple Network Paging Protocol (SNPP) and tested our QuickPage configuration with the command-line client.

Sendmail was installed, along with procmail and an old standby: Elm, as a Mail User Agent (MUA) so we could transmit messages to phones and pagers that are generated as e-mails.

Now, the time has come to install and configure a Web server and create a simple CGI-BIN e-mail form so that our Linux X terminal users (and users of other browser equipped workstations) can connect to the Text Messaging Gateway to send messages without complicated mail configurations or additional client software installed on their machines or the application server.

Step 1. Catch that snake!

Boa isn't the only Web server we could use -- Apache works well -- and I'm sure some of the others will too. I like Boa for this application, because my unscientific observations are that it runs more quickly on 486 and first-generation Pentiums with 8 to 16 megabytes of RAM. For small operations that average less than 30 or 40 messages per hour, why not use something inexpensive? This is Cheap and Easy Linux server-centric computing, after all.

You are an old hand at installing packages on a Debian system by now, so:

apt-get install boa

After grabbing the archives from Debian's server and installing the package, Apt reports that it is, "Starting HTTP server: Boa." This Linux sysadmin stuff is hard work, isn't it?

And I can see it all now, you lyin' dog! When you get home tonight:

Significant Other: "How'd it go at work today, honey?"

You (lying dog that you are): "Oh, you'll never believe it, babe. I had to set up this intranet Web server and I'm just wiped out."

SO: "You poor thing...here, you just make yourself comfortable, and I'll go pour you a tumbler full of your favorite beverage!"

Yeah, I got your Web server.

Step 2. Forms, I need forms, I tell you!

If you know how, you could write your own CGI-Bin application and create your own Web-based e-mail forms for message entry. For the rest of us, why bother? MIT did the hard work for us already and provides us with cgiemail, a "CGI program written in C for Unix...to take the input of WWW forms and convert it to an e-mail format..."

In short, the form (that Boa serves to our user's Web browsers) is converted to e-mail, and sendmail (with procmail's help) hands it off to QuickPage for delivery to pagers and cell phones, while placing a copy in /var/mail.

Let's get it quick!

apt-get install cgiemail

Whew! This is hard work!

Step 3. HTML 101

To keep things simple, we will only include two of our employees: Basil Buffoon from the personnel department and poor old Tom Smith from shipping. We want users to encounter a Web page that looks something like this when they point their browsers at the Gateway:


To write this page, change to the /var/www directory and with finest text editor known to mankind (Easy Editor), create a new file called index.html.

ee index.html

In this new file, type:

<HTML>
<HEAD>
<TITLE>ALPHABETIZED INDEX OF PAGERS</TITLE>
</HEAD>
<BODY BGCOLOR=#F0FFF0>
<FONT size=+6>
Welcome to our Text Messaging Gateway!
</FONT>
<BR>
<P>
<FONT size=+3>
Click on one of the links below to send a text message to:
<BR>
<P>
</font>
<FONT size=+2>
<UL>
<LI><A HREF="basilbuffoon-form.html" TARGET=_blank>Basil Buffoon's 
Alpha-Pager</A>
<LI><A HREF="tomsmith-form.html" TARGET=_blank>Tom Smith's PCS 
Phone</A>
</UL>
</FONT>
<BR>
</BODY>
</HTML>

Save your changes to index.html and test your handiwork by pointing a Web browser at the IP of your Text Messaging Gateway. Feel free to buy a book with a tutorial on writing Web pages if you think mine "sux." It works, and that is all I care about!

Step 4. Tom gets his very own page

So does Basil, and so does everyone else you listed in index.html. Fire up the world's finest text editor (why, Easy Editor, of course) and create tomsmith-form.html

ee tomsmith-form.html

In that file, type the following:

<HTML>
<HEAD>
<TITLE>TOMSMITH-FORM</TITLE>
</HEAD>
<BODY>
<H1><FONT size=+6>Send a message to Tom Smith's PCS 
phone:</FONT></H1>
<FORM METHOD="POST" 
ACTION="http://192.168.1.2/cgi-bin/cgiemail/templates/tomsmith-template">
<BR>
Message Body: <INPUT TYPE="text" NAME="messagebody" SIZE="65" 
MAXLENGTH="100"><P>
<INPUT TYPE="submit" value="Send Page">
</FORM> 
</BODY>
</HTML>

Save your changes, and repeat, only this time for Basil Buffoon:

ee basilbuffoon-form.html

Note the changes between the two example forms so that you can extrapolate to meet your own needs:

<HTML>
<HEAD>
<TITLE>BASILBUFFOON-FORM</TITLE>
</HEAD>
<BODY>
<H1><FONT size=+6>Send a message to Basil Buffoon's 
Alpha-Pager:</FONT></H1>
<FORM METHOD="POST" 
ACTION="http://192.168.1.2/cgi-bin/cgiemail/templates/basilbuffoon-template">
<BR>
Message Body: <INPUT TYPE="text" NAME="messagebody" SIZE="65" 
MAXLENGTH="100"><P>
<INPUT TYPE="submit" value="Send Page">
</FORM> 
</BODY>
</HTML>

By "clicking" on the link to Tom Smith at our "Welcome Page" (index.html) we should be taken to:

Step 5. The missing link

Well, we have a "Welcome Page" named index.html that displays in our user's Web browsers, and we can enter text messages but they still don't go anywhere yet. For the next task, let's create a link in /var/www that points to the directory where cgiemail is installed on this Debian system. Make sure you are in the /var/www directory and use the ln utility to create a "symlink" like so:

ln -s /usr/lib/cgi-bin cgi-bin

By running ls -l you should see:

lrwxrwxrwx   1 root root   16 Jan 27 21:02 cgi-bin -> /usr/lib/cgi-bin
-rw-r--r--   1 root root  360 Jan 27 20:52 basilbuffoon-form.html
-rw-r--r--   1 root root  463 Jan 27 20:50 index.html
-rw-r--r--   1 root root  366 Jan 27 20:51 tomsmith-form.html

See the "man pages" (man ls and man ln) for information on these utilities.

Step 6. Make a "templates" directory

Cgiemail uses "templates" for each e-mail address to which you want to send messages. Since each alphapager and phone you add to this system has it's own address, it helps keep everything neat and tidy to create a subdirectory to store them: /var/www/templates. Make the directory with mkdir.

mkdir /var/www/templates

Change to that new directory, and with a text editor (oh, I don't care which one you use, but I'm going to use Easy Editor) create tomsmith-template and basilbuffoon-template as follows:

ee tomsmith-template

Here is the content of Tom's file:

To: [email protected]
From:Our Company
Message Body: [messagebody]

After saving the file, create Basil's:

ee basilbuffoon-template

Type this:

To: [email protected]
From:Our Company
Message Body: [messagebody]

Step 7. Turn this puppy up for production use!

Add each of your remaining users to index.html following the same format we used for Basil and Tom in Step 3, above.

To save time creating the username-form.html files, you can use the cp command to create a new form and then edit the resulting form for each new user. Same for the templates you create in /var/www/templates.

In other words:

cp tomsmith-form.html janedoe-form.html

Use a text editor to make the minor changes required for "Jane Doe."

Having created templates, the final piece is in place and by pointing Netscape or other browser at our Text Messaging Gateway, users see:

By "clicking" on a link, they are taken to:

They enter their message for transmission:

As soon as they "click" on Send Page they see a "Success Page:."

Now, that wasn't so very difficult, was it?

What did we do?

We combined the capabilities of several relatively small applications to create a service for our Network for Peanuts that doesn't exist as a single application. A fundamental principle of Linux/Unix system administration: Boa-->cgiemail-->sendmail-->procmail-->QuickPage.

We used the dog out of Debian's Apt utility, and every bit of software used was installed with apt-get install package-name.

We saved a bundle by not spending money for both Windows and a proprietary application that would also require a more powerful (and expensive) computer to provide this service.

What didn't we do?

We didn't write elegant HTML that makes for pretty Web pages. You are encouraged to read a book and apply that knowledge to clean up the example HTML provided in this article. I also encourage you to spend some time at MIT's cgiemail site to learn how to create templates and forms more suited to your particular needs.

We also didn't create a Text Messaging Gateway suitable for the 'net. This modest project is intended for use on a LAN, behind a firewall, and you are warned!

That is enough for today, and for Text Messaging. Maybe 13 is an unlucky number. That's the next installment in our series and we will be tearing into another service for our Linux Network for Peanuts that used up most of my good luck!

More Stories By Colin Mattoon

When not buried under his real job in commercial two-way radio system design and sales, Colin Mattoon is a part-time Linux system administrator at Northwest Communications in Lewiston, ID.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.