dirplex: Inverted the default root capture behaviour and changed its flag.
[ashd.git] / examples / python / dynhosts / dynhosts
1 #!/usr/bin/python
2
3 import os, sys, signal
4 from ashd import util
5
6 children = {}
7 root = sys.argv[1]
8
9 # Automatically reap all children that die for any reason.
10 signal.signal(signal.SIGCHLD, signal.SIG_IGN)
11
12 def serve(req):
13     if "Host" in req:
14         # Strip port specification
15         dname = req["Host"].split(':')[0]
16         dname = dname.lower()
17         path = os.path.join(root, dname)
18         if os.path.isdir(path):
19             if dname not in children:
20                 children[dname] = util.pchild(["dirplex", path], autorespawn = True)
21             children[dname].passreq(req)
22             return
23     util.respond(req, "No such host is configured.\n", status = "404 Not Found", ctype = "text/plain")
24
25 util.serveloop(serve)