A Web-Based Lunch Ordering System
I then placed the lunch.html file in the directory /home/httpd/html:
$ cp lunch.html /home/httpd/html
(This is the default location Apache looks for html files. It can be configured to look elsewhere.) Once you have done this, you can see what lunch.html looks like by browsing http://localhost/lunch.html using Netscape (or any browser).
Write the CGI script with Python, which is distributed with the Red Hat Linux distribution (see http://www.python.org/). After consulting the Python documentation, which also came with the system, my first script looked like the one shown in Listing 3. It is essentially a cannibalised version of an example found in the Python documentation. To make use of this script, you'll need to point the CGI script specified in the ACTION statement in the HTML file to this script instead. That is, change the cgi script specified in the ACTION statement from lunch.cgi to first.cgi.
I then copied first.cgi to the directory /home/httpd/cgi-bin:
$ cp first.cgi /home/httpd/cgi-bin
Essentially, I interrogated all the variables sent to the script by the form and printed it back out. All output printed will be displayed by the browser.
#----------------- 1 #!/usr/bin/env python 2 # first.cgi 3 import cgi # import the cgi module 4 5 print "Content-Type: text/plain\n\n" # necessary for the browser 6 7 lunchForm = cgi.FieldStorage() # retrieve the values 8 9 for name in lunchForm.keys(): 10 print "Key= " + name + " Value= " + lunchForm[name].value + " " 11 12 print "bye." #-------------When the Go button on the lunch.html page is clicked and the first.cgi script is activated, the output returned to the web browser looks like that shown in Figure 2.
You will notice that the keys found in the CGI script correspond to the variables I used in lunch.html.
Once I got this simple script working, I then expanded it to do what I wanted (see Listing 3). The Python code is quite straightforward and self-explanatory. It imports the CGI module, then calls the member function FieldStorage() of CGI. Whether the information is sent using the GET or POST method is hidden from you. That's how all the information sent by the web page is retrieved. The information can then be extracted by accessing lunchForm.
The body of the mail sent is then constructed via a series of writes to sendmail, a UNIX sendmail mail transfer agent. I decided to mail the lunch order to user lunch@localhost. An alias can be inserted in file /etc/aliases:
lunch: chai@localhost
where user chai@localhost is organising the orders. This way, if the lunch organiser gets changed, the file /etc/aliases needs to be changed and not the CGI script. (newaliases needs to be run for changes to /etc/aliases to take effect).
Easy, eh? Well, it could be much worse.
I then copied lunch.cgi to the directory /home/httpd/cgi-bin:
$ cp lunch.cgi /home/httpd/cgi-bin
I opened Netscape, typed in http://localhost/lunch.html as the URL, filled in the form, selected my order and clicked on “Go”.
Sometime later, an e-mail arrived outlining the order.
Here is what the received e-mail of the lunch order, sent by the CGI script, looks like:
>From nobody@localhost Wed Apr 26 11:01:50 2000<\n> Delivered-To: ccang@localhost Date: Wed, 26 Apr 2000 11:01:48 +1000 To: lunch@localhost From: chai <calcium@altavista.net> Subject: loi loi Sender: nobody@localhost SourceIP 194.118.1.1 calcium@altavista.net Wed Apr 26 11:01:01 GMT+1000 (EST) 2000 chai wants 1. L39 with Steamed rice. 2. NONE with NA rice. 3. NONE with NA rice. 4. NONE with NA rice.
Figure 3 shows what the web page looks like after the request has been sent.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Validate an E-Mail Address with PHP, the Right Way
- RSS Feeds
- Introduction to MapReduce with Hadoop on Linux
- Senior Perl Developer
- Weechat, Irssi's Little Brother
- Technical Support Rep
- Reply to comment | Linux Journal
3 hours 26 min ago - Reply to comment | Linux Journal
4 hours 12 min ago - Didn't read
4 hours 22 min ago - Reply to comment | Linux Journal
4 hours 27 min ago - Poul-Henning Kamp: welcome to
6 hours 37 min ago - This has already been done
6 hours 38 min ago - Reply to comment | Linux Journal
7 hours 23 min ago - Welcome to 1998
8 hours 12 min ago - notifier shortcomings
8 hours 36 min ago - heroku?
10 hours 12 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?






Comments
can you show us a web-based
can you show us a web-based gift shop system?