Introduction

Introduction

Have you ever been sitting around at work wishing you could execute a command on your home Linux system to get some information from it? I have, and I bet you could find lots of reasons why you would want to as well.

E-mail is simple yet powerful. But can it be used as a console to your home Linux system? You bet! I use it all the time. Why not just log in and execute commands in the traditional manner? Sure, I could do that, but that would be no fun and I would not be able say, "Try that with Windows NT!" (Another name we could have called our book.) Also, there are times when direct access to a system is not available. But if e-mail is available, then this will work for you. First, I'll tell you about how I arrived at developing the e-mail console; then I'll share how I did it.

My Disconnected System

If you're like me, at one time you probably connected to the Internet using a standard phone line and a local Internet service provider (ISP). I like my ISP, but they limit the number of hours I can be online each month and charge me big bucks when I go over that limit. I won't switch ISPs since they are, without a doubt, the best in my area. Because of this restriction to my online adventures , I pick and choose the times when my Linux system will be online fetching e-mail, downloading files, what have you. The problem I had with this situation was that I wanted access to my home system when I was at work. What I needed was a way to keep my home system offline until I needed it and then have it go online and stay that way until I told it to disconnect.

Some time ago I decided to make it so my system would periodically connect to the Internet and download e-mail from my ISP using a nifty program called Fetchmail. I wrote a few Perl scripts to automate and synchronize the connection requests from various applications, like SETI@Home and Fetchmail, which both need to connect to the Internet at various times. Plus, I needed to go online to surf around but not get disconnected when the Fetchmail utility was complete. Getting e-mail with Fetchmail allows me to spend as little connection time as possible getting and responding to e-mail. Why waste the connection time typing replies? The main goal of these scripts was to coordinate the connection and disconnection requests and to keep my system online when needed.

It then occurred to me that if I could send an e-mail to my system (which picked up e-mail once an hour ) and have that e-mail parsed somehow so that a command could be executed, I could make it so that I could tell my system to stay online or disconnect. Bingo! Now all I had to do was find that e-mail-parsing, command-executing dream utility. The solution was right under my keyboard.

Getting Connected

On a piece of paper beneath my keyboard I had written down some of the utilities I thought might be useful for dealing with my e-mail, and Procmail was one of them.

Procmail, as it turns out, is a very useful utility for performing searches on incoming e-mail and then performing some kind of action. I used Procmail to parse my incoming e-mail every 15 minutes (I lowered it from an hour to 15 minutes so I wouldn't have to wait so long to access my system) and execute the command that told my system to stay online after it was done fetching e-mail. This worked like a charm . I could send e-mail to my home system with a special subject like "CONNECT REMOTE" and my system would simply stay online after fetching and processing all the e-mail from my ISP. In my Procmail configuration file, a recipe file, I searched for this string and then executed the Perl script I had written to make it so my system stayed online. I could also tell it to disconnect. It then occurred to me that with a little more work, I could write a Procmail recipe and Perl script that would execute any arbitrary command I gave it. This was the coolest thing I had ever heard of, and my NT friends would be so jealous!

Locking It Down

Because anyone can send me an e-mail, I had to work out a protocol that would allow me and trusted friends, but no one else, to execute commands. I also needed to ensure that the results were returned securely, safe from snooping eyes. The solution to all of this lies with encryption and digital signatures found in another great utility, GnuPG (see Chapter 10 , Secure Your E-Mail with GPG).

The Project

Now that you know the story of how the e-mail console came to be, it's time to put together all the pieces and make a working system. You will be using the following utilities for this project:

·                 Fetchmail ” to get the mail

·                 Procmail ” to parse and execute the e-mail console script

·                 GnuPG ” to decrypt the e-mail and verify the authenticity of the sender

 



Multitool Linux. Practical Uses for Open Source Software
Multitool Linux: Practical Uses for Open Source Software
ISBN: 0201734206
EAN: 2147483647
Year: 2002
Pages: 257

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net