X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=blobdiff_plain;f=examples%2Fpython%2Fdynhosts%2Fdynhosts;fp=examples%2Fpython%2Fdynhosts%2Fdynhosts;h=fae28c8228ed279344b7d40e802531cbc0d385c8;hp=0000000000000000000000000000000000000000;hb=7f8383098e49588529e3a203ed6d7bb2f27aef5c;hpb=c6df3d367a1f7bd7ac66ee93e4aa336b0eba15fa diff --git a/examples/python/dynhosts/dynhosts b/examples/python/dynhosts/dynhosts new file mode 100755 index 0000000..fae28c8 --- /dev/null +++ b/examples/python/dynhosts/dynhosts @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import os, sys, signal +from ashd import util + +children = {} +root = sys.argv[1] +signal.signal(signal.SIGCHLD, signal.SIG_IGN) + +def serve(req): + if "Host" in req: + # Strip port specification + dname = req["Host"].split(':')[0] + dname = dname.lower() + path = os.path.join(root, dname) + if os.path.isdir(path): + if dname not in children: + children[dname] = util.pchild(["dirplex", path], autorespawn = True) + children[dname].passreq(req) + return + util.respond(req, "No such host in configured.\n", status = "404 Not Found", ctype = "text/plain") + +util.serveloop(serve)