Processing Form Data in Shell CGI Scripts
2015-05-21 16:26
387 查看
Processing Form Data in Shell CGI Scripts
Important: Versions before 11/06/1997 have a security bug.If you downloaded this program before that date, download thecurrent version, and substitute all your copies with this one.This page presents a little program that will help you processing formdata in a CGI shell script. If you're unfamiliar with Perl and don'twant to write a bulky C program just for a small CGI job, shell scriptCGI programming may be an option. You receive the
form values straightinto your shell environment (the names prefixed with "FORM_"), whereyou can then access them just like other shell variables.
I have a different page with the same title, where I present ashell script to do the same jobof extracting form data and feeding it to your script. However,this C program is much
faster and easier to use.
Features
Handles both GET and POST methods transparently.Also accepts assignments on the command line (great for testing).
If the extra pathname features assignments (like
/A=trash), it is processed as well.
Handles '+' (replaced by space) and '%XX' sequences.
Exports all found variables to the shell environment.
Can also handle multiline "Textarea" input fields.
Installation
Installation is simple. Just download the C code,proccgi.c, and compile it. Compilationshouldn't be a problem on any system. Copy the resulting executableproccgito a location
of your choice, where it isaccessible to your CGI scripts.
Usage
All you have to do in your shell script is to calleval "`proccgi $*`"
In some cases, you might need to give the full pathname if it's notfound automatically. After this call, you have everything in your shell.
Be careful to quote the call to proccgi, else shell expansion willtake place, potentially opening security leaks.
Example
This is a very simple example of an automatic software-by-email program.You can fill in your email address and a file name which is thenautomatically mailed to you.Do not, I repeat, do notinstall this piece of code. It would be a major security leak.
The Form
<form action="http://our-server/cgi-stuff/mailer" method="post"> <dl> <dt> Your Email <dd> <input name="email" size="50"> <dt> Filename <dd> <input name="file" size="50"> </dl> <input type="submit" value="Submit"> </form>
The Script
(Install this script in the location you used above in the form'saction field.)#!/bin/sh eval "`procgi $*`" mail $FORM_email < $FORM_file cat - << \END echo Content-type: text/plain echo echo done. END
As you can see, after the call to
proccgi, theemail address from the form is stored in the shell variable $FORM_email,and the file name is in $FORM_file.
Download
Once again, here's a link to downloadproccgi.c.
The script may be freely used and distributed at no charge provided that thecopyright notice remains at its top.
Frank Pilhofer<fp -AT- fpx.de>Back to the Homepage
Last modified: Fri Aug 29 15:34:33 1997
相关文章推荐
- Processing Form Data in Shell CGI Scripts[转]
- Using shell scripts for CGI in lighttpd
- spring in action 4 7.2 Processing multipart form data
- 翻译-In-Stream Big Data Processing 流式大数据处理
- How to Use the BASH "for" Loop in Shell Scripts
- Reshape Data Form in R
- Spark SQL Relational Data Processing in Spark (学习笔记)
- iOS-Assertion failure in -[AFStreamingMultipartFormData appendPartWithHeaders:body:]
- 4.Data Types in the mongo Shell-官方文档摘录
- android向服务器上传multipart/form-data文件(upload using multipart post using httpclient in android)
- MongoDB - The mongo Shell, Data Types in the mongo Shell
- Sending of multipart/form-data of request in Qt
- iOS 之Assertion failure in -[AFStreamingMultipartFormData appendPartWithHeaders:body:]
- 翻译-In-Stream Big Data Processing 流式大数据处理
- Data Structure Binary Tree: Level order traversal in spiral form
- 翻译-In-Stream Big Data Processing 流式大数据处理
- servlet: org.apache.tomcat.util.http.fileupload.FileUploadException: Processing of multipart/form-data request failed
- Processing of multipart/form-data request failed. Stream ended unexpectedly
- bdd 启动 data processing进程报错 Can't locate LWP.pm in @INC
- 【原创】如何在DataFormWebPart中嵌入自定义控件[How to embeded custom control in DFWP]