27.10.08

A WebServer built with 100 lines of BASH

Piotr Gabryjeluk: 100 lines of BASH script that simply rock!: "Screenshot Tour


#!/bin/bash

function debug {
local severity="$1"
shift
local message="$@"

echo -n "`date -u`" 1>&2
echo -ne '\t' 1>&2
echo -n "$severity" 1>&2
echo -ne '\t' 1>&2
echo "$message" 1>&2
}

function fix_path {
echo -n "$1" | head -n 1 | sed 's|^[/.-]*||' | sed 's|/\.*|/|g'
}

function serve_dir {
local dir="`fix_path "$1"`"
if [ "$dir" = "" ]; then
dir="./"
fi
echo 'HTTP/1.1 200 OK'
echo 'Content-type: text/html;charset=UTF-8'
echo
echo LISTING "$dir"
echo '
'
ls -p "$dir" | sed -e 's|^\(.*\)$|\1
|'
}

function serve_file {
echo 'HTTP/1.1 200 OK'
echo 'Content-type: application/x-download-this'
echo
local file="`fix_path "$1"`"
debug INFO serving file "$file"
cat "$file"
}

function process {
local url="`gawk '{print $2}' | head -n 1`"
case "$url" in
*/)
debug INFO Processing "$url" as dir
serve_dir "$url"
break
;;
*)
debug INFO Processing "$url" as file
serve_file "$url"
;;
esac
}

function serve {
local port="$1"
local sin="$2"
local sout="$3"

while debug INFO Running nc; do

nc -l -p "$port" < "$sin" > "$sout" &
pid="$!"

debug INFO Server PID: "$pid"

trap cleanup SIGINT
head -n 1 "$sout" | process > "$sin"
trap - SIGINT

debug INFO Killing nc

kill "$pid"
done

debug INFO Quiting server
}

function cleanup {
debug INFO Caught signal, quitting...
rm -Rf "$tmp_dir"
exit
}

tmp_dir="`mktemp -d -t http_server.XXXXXXXXXX`"
sin="$tmp_dir"/in
sout="$tmp_dir"/out
pid=0
port="$1"

mkfifo "$sin"
mkfifo "$sout"

debug INFO Starting server on port "$port"
serve "$port" "$sin" "$sout"
cleanup

26.10.08

The Linux and Unix Menagerie: Using Mkfifo For Monitoring And Enhanced User Activity Logging

The Linux and Unix Menagerie: Using Mkfifo For Monitoring And Enhanced User Activity Logging

20.10.08

.htaccess trick shows Development CSS file only to Developer

.htaccess trick shows Development CSS file only to Developer: ".htaccess trick to show Alternate CSS file based on IPThis past week I was making changes to my sites apache.css file for a site-redesign. I wanted to make changes to the .css file that only I could see, so that my regular traffic and site-visitors would still see the old version. I quickly came up with an elegant solution using the incredibly powerful .htaccess and mod_rewrite that worked so well I wanted to share it with all you great and interesting people :)"

11.10.08

Simple Wordpress Security Tips

Simple ways to protect your blog from malicious activity.

read more | digg story

Rare and Obscure Penetration Testing Tools

List of mainly obscure security software geared more for the master pentester. These are mostly for unix, bsd, and mac and many are difficult to install and setup (require custom servers, inside access points, obscure libraries). Only programs that output data are included, so no actual exploits or anything. Most of these output extremely useful al

read more | digg story

Simple Wordpress Security Tips

Simple ways to protect your blog from malicious activity.

read more | digg story

10.10.08

Wikipedia adopts Ubuntu for its server infrastructure

The Wikimedia Foundation, the organization behind the hugely successful Wikipedia project, is migrating all of its server infrastructure to the Ubuntu Linux distribution. This move reflects the growing viability of Ubuntu for enterprise-scale server deployments.

read more | digg story

How Much Do Top Bloggers & Social Media Consultants Get Paid

The media world is changing and its jobs are changing too. The rise of the blogger is an often-told story, but are the lucky few bloggers who do ...

read more | digg story

2.10.08

Eight Online Places to Learn something New!

If there is one thing I strongly believe is tapping the power of the Internet to learn. It is with always with great happiness that everything I have learnt in the past ten years (since I got online) has been only through tutorial sites.Here are a list of some of that where you can quickly and easily find tutorials, articles and information.

read more | digg story