• 博客访问: 3916016
  • 博文数量: 23
  • 博客积分: 731
  • 博客等级: 军士长
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-25 17:53
  • 认证徽章:
个人简介

技术宅,开源软件爱好者 虚拟机,编译器,编辑器,MCU IP,数据结构,操作系统,TCP/IP协议

文章分类

全部博文(23)

文章存档

2015年(1)

2014年(2)

2013年(2)

2011年(4)

2010年(14)

微信关注

IT168企业级官微



微信号:IT168qiye



系统架构师大会



微信号:SACC2013

订阅
热词专题

分类: LINUX

1. BusyBox httpd CGI scripts


The http daemon expects that CGI script is in subdirectory cgi-bin under main web directory set by options -h (default /www and CGI in /www/cgi-bin). CGI script must have permision for execute (min mode 700).

1.1. CGI


Standard set of Comon Gateway Interface environment variable are :

CONTENT_TYPE=application/x-www-form-urlencoded
GATEWAY_INTERFACE=CGI/1.1
REMOTE_ADDR=192.168.1.180
QUERY_STRING=Zbr=1234567&SrceMB=&ime=jhkjhlkh+klhlkjhlk+%A9%D0%C6%AE%C6%AE&prezime=&sektor=OP
REMOTE_PORT=2292
CONTENT_LENGTH=128
REQUEST_URI=/cgi-bin/test
SERVER_SOFTWARE=busybox httpd/1.35 6-Oct-2004
PATH=/bin:/sbin:/usr/bin:/usr/sbin
HTTP_REFERER=http://192.168.1.1/index1.html
SERVER_PROTOCOL=HTTP/1.0
PATH_INFO=
REQUEST_METHOD=POST
PWD=/www/cgi-bin
SERVER_PORT=80
SCRIPT_NAME=/cgi-bin/test
REMOTE_USER=[http basic auth username]

/cgi-bin/test

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<HTML><HEAD><TITLE>Sample CGI Output</TITLE></HEAD>"
echo "<BODY>"
echo "<pre>"
env
echo "</pre>"
echo "</BODY></HTML>"

Environment variables are set up and the script is invoked with pipes for stdin/stdout.

1.2. HTML Forms


If a post is being done the script is fed the POST data in addition to setting the QUERY_STRING variable (for GETs or POSTs).

Prefered way to do forms in CGI is POST.

1.2.1. POST

Example how to use POST in form.

/www/form-post.html

<html>
<head>
<title>CGI Test</title>
</head>

<body>
<form name="form1" method="post" action="/cgi-bin/test-post">
  <p>Text field
    <input name="Text_Field" type="text" id="Text_Field">
  </p>
  <p>Radio button  </p>
  <p>
    <input name="Radio_Button" type="radio" value="1"> 1
  </p>
  <p>
    <input name="Radio_Button" type="radio" value="2"> 2
  </p>
  <p>
    <input name="Radio_Button" type="radio" value="3"> 3
  </p>
  <p>Some text </p>
  <p>
    <textarea name="Text_Area" id="Text_Area"></textarea>
  </p>
  <p>&nbsp;</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Reset" value="Reset">
  </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html>

/www/cgi-bin/test-post

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<HTML><HEAD><TITLE>Sample CGI Output</TITLE></HEAD>"
echo "<BODY>"
echo "<pre>"
echo "Environment variables"
echo ""
env
echo ""
echo "========================================================="
echo ""
echo "Form variables :"
echo ""
read QUERY_STRING
eval $(echo "$QUERY_STRING"|awk -F'&' '{for(i=1;i<=NF;i++){print $i}}')
tmp=`httpd -d $Text_Field`
echo "Text_Field=$tmp"
tmp=`httpd -d $Radio_Button`
echo "Radio_Button=$tmp"
tmp=`httpd -d $Text_Area`
echo "Text_Area=$tmp"
echo "</pre>"
echo "</BODY></HTML>"

1.2.2. GET


Text area fields (and any other field that may contain \n are very hard to menage).

Example how to use GET in form.

/www/form-get.html

<html>
<head>
<title>CGI Test</title>
</head>

<body>
<form name="form1" method="get" action="/cgi-bin/test-get">
  <p>Text field
    <input name="Text_Field" type="text" id="Text_Field">
  </p>
  <p>Radio button  </p>
  <p>
    <input name="Radio_Button" type="radio" value="1"> 1
  </p>
  <p>
    <input name="Radio_Button" type="radio" value="2"> 2
  </p>
  <p>
    <input name="Radio_Button" type="radio" value="3"> 3
  </p>
  <p>&nbsp;</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Reset" value="Reset">
  </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</form>
</body>
</html>

/www/cgi-bin/test-get

#!/bin/sh
echo "Content-type: text/html"
echo ""
echo "<HTML><HEAD><TITLE>Sample CGI Output</TITLE></HEAD>"
echo "<BODY>"
echo "<pre>"
echo "Environment variables"
echo ""
env
echo ""
echo "========================================================="
echo ""
echo "Form variables :"
echo ""
eval $(echo "$QUERY_STRING"|awk -F'&' '{for(i=1;i<=NF;i++){print $i}}')
tmp=`httpd -d $Text_Field`
echo "Text_Field=$tmp"
tmp=`httpd -d $Radio_Button`
echo "Radio_Button=$tmp"
echo "</pre>"
echo "</BODY></HTML>"

OpenWrtDocs/httpd CGI scripts (dernière édition le 2006-09-18 21:55:07 par phat_bastard)

Almost all of these pages are editable, create an account and click the edit (Edit) button at the top of the page.

    * Page immuable

EffacerLeCache (mémorisé dans le cache le 2007-05-23 17:56:13)

Ou essayez l'une de ces actions : Attach File, Despam, Pages similaires, Carte locale du site, Ma page, Pages des paquets, Render As Docbook, Spell Check, Abonner un utilisateur

    * MoinMoin Powered
    * Python Powered
    * Valid HTML 4.01




阅读(3029502) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册