Added some simple configuration examples.
[ashd.git] / examples / python / dynhosts / dynhosts
... / ...
CommitLineData
1#!/usr/bin/python
2
3import os, sys, signal
4from ashd import util
5
6children = {}
7root = sys.argv[1]
8signal.signal(signal.SIGCHLD, signal.SIG_IGN)
9
10def serve(req):
11 if "Host" in req:
12 # Strip port specification
13 dname = req["Host"].split(':')[0]
14 dname = dname.lower()
15 path = os.path.join(root, dname)
16 if os.path.isdir(path):
17 if dname not in children:
18 children[dname] = util.pchild(["dirplex", path], autorespawn = True)
19 children[dname].passreq(req)
20 return
21 util.respond(req, "No such host in configured.\n", status = "404 Not Found", ctype = "text/plain")
22
23util.serveloop(serve)