f5b 发表于 2015-03-27 15:16

OpenBSD的httpd web server显示来访者ip地址和浏览器信息的应用

OpenBSD的httpd web server显示来访者ip地址和浏览器信息的应用

在OpenBSD 5.7 beta上做的测试,应该适用于5.6之后的版本

看起来很简单,笔记放在这里保存:)

编辑脚本
# vi /var/www/cgi-bin/test

#!/bin/sh
echo "Content-type: text/plain"
echo
echo $REMOTE_ADDR
echo $HTTP_USER_AGENT

设置脚本可执行权限
# chmod 0555 /var/www/cgi-bin/test


# ldd /bin/sh
/bin/sh:
      Start            End            Type Open Ref GrpRef Name
      000019c10e34a000 000019c10e7cb000 dlib 1    0   0      /bin/sh

               
在chroot相应目录添加需要的程序               
# cp /bin/sh /var/www/bin/


确定程序可执行
# ls -l /var/www/bin/sh
-r-xr-xr-x1 rootdaemon480960 Mar 26 15:04 /var/www/bin/sh


添加恰当的http.conf
# cat /etc/httpd.conf


ext_addr="*"

server "default" {
      listen on $ext_addr port 80

      location "/cgi-bin/*" {
                fastcgi

                # The /cgi-bin directory is outside of the document root
                root "/"
      }

      root "/htdocs"
}


添加必须的启动项
# cat /etc/rc.conf.local
httpd_flags=""
slowcgi_flags=""

启动
# /etc/rc.d/slowcgi start
# /etc/rc.d/httpd start

任意浏览器访问服务器
http://A.A.A.A/cgi-bin/test

得到结果
B.B.B.B Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

参考
http://protoc.org/blog/2014/11/23/first-thoughts-on-the-new-openbsd-httpd-server/
http://en.wikibooks.org/wiki/Guide_to_Unix/BSD/OpenBSD/As_a_Webserver
https://www.ciscodude.net/2014/05/14/openbsd-5-dot-5-bgplg/
http://www.cgi101.com/book/ch3/text.html
https://snipt.net/bhubbard/display-visitors-ip-address-via-cgi/
http://www.perlmonks.org/?node_id=1110948
http://marc.info/?t=142737694500005&r=1&w=2
页: [1]
查看完整版本: OpenBSD的httpd web server显示来访者ip地址和浏览器信息的应用