2013/1/7 7/23PM:察看CGIC官网http://www.boutell.com/cgic/#cgiPathTranslated,关于如何使用CGIC的内容如下:
- Are you using Visual C++ or Borland C++? Did you forget to add cgic.c to your project?
- Make sure you are using an ANSI C or C++ compiler. (All of the Windows compilers are ANSI C compliant.)
Since all CGI applications must perform certain initial tasks, such as parsing form data and examining environment variables, the cgic library provides its own main() function.When you write applications that use cgic, you will begin your own programs by writing acgiMain() function, which cgic will invoke when the initial cgi work has been successfully completed. Your program must also be sure to #include the file cgic.h.
总结:如果要使用CGIC库,只要将cgic.c cgic.h 文件添加到你的工程里,在使用到该CGIC库的文件头部写上如下定义就行。如果你的应用程序使用了CGIC库,要以cgiMain()函数作为你应用的主函数(类似c语言中的main()函数的地位。察看cgic.c程序文件,发现在本文件的main()函数中调用了cgiMain()函数,这也就是为什么你的应用要以cgiMain()作为主函数的原因
#include "cgic.h"
通过以上内容,分析:如果以Android为平台的boa服务器上有程序使用了CGIC库,满足上面‘总结’的描述即可使用CGIC库,这仅仅是猜测。下面以CGIC源代码附带的cgictest测试程序为例,验证上述猜想
7/40PM:在android源代码的external目录下创建cgictest目录
7/50PM:将CGIC源代码目录中的 cgic.c cgic.h cgictest.c文件拷贝到cgictest目录下
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/cgictest# cp /home/luosuo/Desktop/cgic205/cgic.c ./
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/cgictest# cp /home/luosuo/Desktop/cgic205/cgic.h ./
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/cgictest# cp /home/luosuo/Desktop/cgic205/cgictest.c ./
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/external/cgictest#
7/59PM:在cgictest目录下创建Android.mk文件,内容如下
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
#使用的源文件
LOCAL_SRC_FILES:=\
cgictest.c \
cgic.c \
cgic.h
LOCAL_CFLAGS:=-O2 -g
#LOCAL_CFLAGS+=-DLINUX
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
#生成的对像
LOCAL_MODULE:=Cgictest
include $(BUILD_EXECUTABLE)
8/04PM:编译Cgictest模块
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make Cgictest
8/07PM:编译完成,终端输出信息如下
build/core/Makefile:25: warning: overriding commands for target `out/target/product/mini210/system/lib/egl/egl.cfg'
build/core/base_rules.mk:524: warning: ignoring old commands for target `out/target/product/mini210/system/lib/egl/egl.cfg'
target thumb C: Cgictest <= external/cgictest/cgictest.c
target thumb C: Cgictest <= external/cgictest/cgic.c
target Executable: Cgictest (out/target/product/mini210/obj/EXECUTABLES/Cgictest_intermediates/LINKED/Cgictest)
target Symbolic: Cgictest (out/target/product/mini210/symbols/system/xbin/Cgictest)
target Strip: Cgictest (out/target/product/mini210/obj/EXECUTABLES/Cgictest_intermediates/Cgictest)
Install: out/target/product/mini210/system/xbin/Cgictest
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled#
8/09PM:将其拷贝到目标板的/etc/boa/www/cgi-bin目录下
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/out/target/product/mini210/system/xbin# adb push Cgictest /etc/boa/www/cgi-bin
604 KB/s (26564 bytes in 0.042s)
8/12PM:在目标板上直接运行Cgictest程序,执行指令及终端输出如下
/system/etc/boa/www/cgi-bin # ls
CGI_test_D
CGI_test_M
CGI_test_S
Cgictest
/system/etc/boa/www/cgi-bin # ./Cgictest
Content-type: text/html
<HTML><HEAD>
<TITLE>cgic test</TITLE></HEAD>
<BODY><H1>cgic test</H1>
<!-- 2.0: multipart/form-data is required for file uploads. --><form method="POST" enctype="multipart/form-data" action="">
<p>
Text Field containing Plaintext
<p>
<input type="text" name="name">Your Name
<p>
Multiple-Line Text Field
<p>
<textarea NAME="address" ROWS=4 COLS=40>
Default contents go here.
</textarea>
<p>
Checkbox
<p>
<input type="checkbox" name="hungry" checked>Hungry
<p>
Text Field containing a Numeric Value
<p>
<input type="text" name="temperature" value="98.6">
Blood Temperature (80.0-120.0)
<p>
Text Field containing an Integer Value
<p>
<input type="text" name="frogs" value="1">
Frogs Eaten
<p>
Single-SELECT
<br>
<select name="colors">
<option value="Red">Red
<option value="Green">Green
<option value="Blue">Blue
</select>
<br>
Multiple-SELECT
<br>
<select name="flavors" multiple>
<option value="pistachio">Pistachio
<option value="walnut">Walnut
<option value="creme">Creme
</select>
<p>Exclusive Radio Button Group: Age of Truck in Years
<input type="radio" name="age" value="1">1
<input type="radio" name="age" value="2">2
<input type="radio" name="age" value="3" checked>3
<input type="radio" name="age" value="4">4
<p>Nonexclusive Checkbox Group: Voting for Zero through Four Candidates
<input type="checkbox" name="vote" value="A">A
<input type="checkbox" name="vote" value="B">B
<input type="checkbox" name="vote" value="C">C
<input type="checkbox" name="vote" value="D">D
<p>File Upload:
<input type="file" name="file" value=""> (Select A Local File)
<p>
<p>Set a Cookie<p>
<input name="cname" value=""> Cookie Name
<input name="cvalue" value=""> Cookie Value<p>
<input type="submit" name="testcgic" value="Submit Request">
<input type="reset" value="Reset Request">
<p>Save the CGI Environment<p>
Pressing this button will submit the form, then save the CGI environment so that it can be replayed later by calling cgiReadEnvironment (in a debugger, for instance).<p>
<input type="submit" name="saveenvironment" value="Save Environment">
</form>
</BODY></HTML>
/system/etc/boa/www/cgi-bin #
8/16PM:浏览器测试,目标板的IP为:10.192.25.45
1,启动目标板的服务器
/system/etc/boa # ./boa
2,在PC机的浏览器地址栏输入:10.192.25.45/CSDN.NET.html,按Enter键
成功打开CSDN.NET.html页面内容
3,在PC机的浏览器地址栏输入:10.192.25.45/cgi-bin/CGI_test_M,按Enter键
OK,说明服务器的CGI功能没有问题
4,在PC机的浏览器地址栏输入:10.192.25.45/cgi-bin/Cgictest,按Enter键,浏览器显示如下
OK
8/31PM:填写页面内容后点击最后一行的 Save Environment按钮,页面显示如下
501 Not Implemented
POST to non-script is not supported in Boa.501 Not Implemented POST to non-script is not supported in Boa.问题的解决过程
百度/google搜索上述问题
在该网址中
无法POST的原因是boa是以nobody用户启动的,权限不够,将boa以root用户启动后,POST成功,文件上传正常。
8/49PM:我关掉boa服务
通过如下指令,查找boa进程号
/system/etc/boa # top -m 100
通过如下指令杀死boa进程
/system/etc/boa # kill 2559
修改boa.conf文件的User nobody 为 User 0,保存,启动boa服务器
/system/etc/boa # ./boa
8/58PM:在PC机的浏览器地址栏输入:10.192.25.45/CSDN.NET.html,按Enter键
失败
9/00PM:察看android进程信息,发现boa并没有在进程列表中
9/08PM:修改boa.conf文件的User 0 为 User nobody,保存,启动boa服务器
boa进程启动
9/10PM:杀死boa进程,修改boa.conf文件的User nobody 为 User root,保存,启动boa服务器
9/13PM:察看android进程信息,发现boa并没有在进程列表中
重新编译boa
将boa/src/boa.c文件中的
if (setuid(0) != -1) {
DIE("icky Linux kernel bug!");
}
注释掉,即
/*if (setuid(0) != -1) {
DIE("icky Linux kernel bug!");
}*/
9/21PM:编译boa
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled# make boa
9/22PM:编译完成,终端输出信息如下
target Executable: boa (out/target/product/mini210/obj/EXECUTABLES/boa_intermediates/LINKED/boa)
target Symbolic: boa (out/target/product/mini210/symbols/system/xbin/boa)
target Strip: boa (out/target/product/mini210/obj/EXECUTABLES/boa_intermediates/boa)
Install: out/target/product/mini210/system/xbin/boa
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled#
9/23PM:将boa拷贝到目标板中
root@ubuntu:/opt/FriendlyARM/mini210/android/android-4.0.3_r1_compiled/out/target/product/mini210/system/xbin# adb push boa /etc/boa
1672 KB/s (52320 bytes in 0.030s)
9/25PM:启动目标板boa服务器
9/26PM:察看android进程信息,发现boa在进程列表中
9/32PM:杀死boa进程,修改boa.conf文件的User root为 User 0,保存,启动boa服务器
1,在PC机的浏览器地址栏输入:10.192.25.45/CSDN.NET.html,按Enter键
成功打开CSDN.NET.html页面内容
3,在PC机的浏览器地址栏输入:10.192.25.45/cgi-bin/CGI_test_M,按Enter键
OK,说明服务器的CGI功能没有问题
4,在PC机的浏览器地址栏输入:10.192.25.45/cgi-bin/Cgictest,按Enter键,浏览器显示如下
OK
9/30PM:填写页面内容后点击最后一行的 Save Environment按钮,页面显示如下
501 Not Implemented
POST to non-script is not supported in Boa.
1,在PC机的浏览器地址栏输入:10.192.25.45/CSDN.NET.html,按Enter键
成功打开CSDN.NET.html页面内容
3,在PC机的浏览器地址栏输入:10.192.25.45/cgi-bin/CGI_test_M,按Enter键
OK,说明服务器的CGI功能没有问题
4,在PC机的浏览器地址栏输入:10.192.25.45/cgi-bin/Cgictest,按Enter键,浏览器显示如下
OK
9/36PM:填写页面内容,加载文件后点击最后一行的 Save Environment按钮,页面显示如下
501 Not Implemented
POST to non-script is not supported in Boa.
9/49PM:
小结:boa以root身份启动依然不能上传文件
今天起来有点晚,继续干活!!!!!
2014/1/8 11/19AM:
察看cgictest.c cgic.c源代码,发现cgic.test是将环境参数保存到/tmp/cgicsave.env文件中的,但是我的目标机并没有/tmp目录,于是在文件系统中创建了/tmp/cgicsave.env
11/28AM:不上传文件测试,此刻目标板IP为:10.192.22.153
OK
11/33AM:上传文件测试,此刻目标板IP为:10.192.22.153
OK
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
![哭](http://static.blog.csdn.net/xheditor/xheditor_emot/default/cry.gif)
!!!!!!!!!Read the fucking code!!!!!!!!
之前上传的文件有点小,再测试上传一7.**kb的文件试一试
11/41AM:上传一7,360bytes文件
OK