Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1802239
  • 博文数量: 286
  • 博客积分: 3713
  • 博客等级: 少校
  • 技术积分: 2275
  • 用 户 组: 普通用户
  • 注册时间: 2012-01-11 09:47
个人简介

http://blog.chinaunix.net/uid/16979052.html

文章分类

全部博文(286)

文章存档

2018年(1)

2017年(16)

2016年(9)

2015年(17)

2014年(15)

2013年(112)

2012年(116)

分类: LINUX

2012-06-28 15:32:17

#!/bin/sh
# Simple little web server.
PORT=80
DOCROOT=/var/log

log () {
logger -t httpd "$@"
}

run_nc () {
nc -p $PORT -l -e $1 /dev/null 2>/dev/null &
}

header () {
echo "HTTP/1.0 $1 $2"
echo "Content-Type: $3"
echo
}

if [ -z "$HTTPD_STARTED" ]; then
[ -f /var/lib/httpd_stop ] && exit
HTTPD_STARTED=1
export HTTPD_STARTED
# daemonize
run_nc $0
exit
else
# start up the next listener process
[ -f /var/lib/httpd_stop ] || run_nc $0
fi

read GET page x y z
page="$(echo "$page" | sed 's/[^-.A-Za-z0-9_]//g')" # security; note no subdirs

# Reading the rest of the client's request is important; clients tend to get
# confused otherwise. Junk it all..
while read xx ; do
test "${xx}" || break
" && breakst "${xx}" = "
done

if [ -d "$DOCROOT/$page" ]; then
header 200 OK "text/html"
echo "Debian-installer logs and screenshots"
echo "Debian-installer logs and screenshots

    "
for file in $(cd "$DOCROOT/$page"; find -type f 2>/dev/null | sed 's/^\.\///' | sort); do
echo "
  • $file"
  • done
    echo " "
    elif [ -e "$DOCROOT/$page" ]; then
    if [ "${page%.ppm}" != "$page" ]; then
    header 200 "OK" "image/x-portable-pixmap"
    elif [ "${page%.png}" != "$page" ]; then
    header 200 "OK" "image/x-png"
    else
    header 200 "OK" "text/plain"
    fi

    if ! cat "$DOCROOT/$page" 2>/dev/null; then
    echo "error!"
    fi
    else
    header 404 "Not Found" "text/plain" 
    echo "File not found."
    fi

    阅读(1659) | 评论(0) | 转发(0) |
    0

    上一篇:nginx php cluster

    下一篇:kernel/gdt.c

    给主人留下些什么吧!~~