Added some simple configuration examples.
authorFredrik Tolf <fredrik@dolda2000.com>
Wed, 2 Mar 2011 14:17:45 +0000 (15:17 +0100)
committerFredrik Tolf <fredrik@dolda2000.com>
Wed, 2 Mar 2011 14:18:02 +0000 (15:18 +0100)
17 files changed:
examples/README [new file with mode: 0644]
examples/python/dynhosts/127.0.0.1/index.txt [new file with mode: 0644]
examples/python/dynhosts/README [new file with mode: 0644]
examples/python/dynhosts/dynhosts [new file with mode: 0755]
examples/python/dynhosts/localhost/index.txt [new file with mode: 0644]
examples/python/dynhosts/run [new file with mode: 0755]
examples/static-files/README [new file with mode: 0644]
examples/static-files/index.html [new file with mode: 0644]
examples/static-files/run [new file with mode: 0755]
examples/static-files/test.css [new file with mode: 0644]
examples/vhosts/README [new file with mode: 0644]
examples/vhosts/default-site/index.html [new file with mode: 0644]
examples/vhosts/default-site/test.css [new file with mode: 0644]
examples/vhosts/localhost/index.html [new file with mode: 0644]
examples/vhosts/localhost/test.css [new file with mode: 0644]
examples/vhosts/patterns.conf [new file with mode: 0644]
examples/vhosts/run [new file with mode: 0755]

diff --git a/examples/README b/examples/README
new file mode 100644 (file)
index 0000000..b29ef70
--- /dev/null
@@ -0,0 +1,12 @@
+This directory contains some examples of more or less simple ashd
+configurations. Each sub-directory contains a self-contained example
+with a shell script called `run'. Simply run that script to start the
+example, and examine it to see how it was made. All of them will start
+an non-SSL HTTP server on port 8080.
+
+Note that ashd must be installed on the system to be able to run the
+examples, including the default configuration files.
+
+The `python' sub-directory contains examples for using the Python
+module. To run then, the Python module has to be installed and
+accessible as well.
diff --git a/examples/python/dynhosts/127.0.0.1/index.txt b/examples/python/dynhosts/127.0.0.1/index.txt
new file mode 100644 (file)
index 0000000..e874877
--- /dev/null
@@ -0,0 +1 @@
+You're accessing via IP address.
diff --git a/examples/python/dynhosts/README b/examples/python/dynhosts/README
new file mode 100644 (file)
index 0000000..a7f806e
--- /dev/null
@@ -0,0 +1,7 @@
+This example uses Python to dynamically dispatch requests for
+different vhosts. The Python program dynhosts will look in a directory
+for subdirectories named after the virtual host and start a dirplex
+instance for each such host that is requested.
+
+To try this example, run it on your local machine and request
+<http://localhost:8080/> or <http://127.0.0.1:8080/>.
diff --git a/examples/python/dynhosts/dynhosts b/examples/python/dynhosts/dynhosts
new file mode 100755 (executable)
index 0000000..fae28c8
--- /dev/null
@@ -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)
diff --git a/examples/python/dynhosts/localhost/index.txt b/examples/python/dynhosts/localhost/index.txt
new file mode 100644 (file)
index 0000000..e6b86d8
--- /dev/null
@@ -0,0 +1 @@
+You're accessing via hostname.
diff --git a/examples/python/dynhosts/run b/examples/python/dynhosts/run
new file mode 100755 (executable)
index 0000000..fe81f84
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+cd "$(dirname "$0")"
+
+htparser plain:port=8080 -- setsid ./dynhosts .
diff --git a/examples/static-files/README b/examples/static-files/README
new file mode 100644 (file)
index 0000000..d1987ca
--- /dev/null
@@ -0,0 +1,2 @@
+To view this example, simply run it on your local machine and point
+your web browser at <http://localhost:8080/>.
diff --git a/examples/static-files/index.html b/examples/static-files/index.html
new file mode 100644 (file)
index 0000000..0492ddb
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+<head>
+<title>Test page</title>
+<link rel="stylesheet" title="Default style" type="text/css" href="test.css" />
+</head>
+<body>
+<h1>Test page</h1>
+<p>
+Note how this page is accessible as
+<a href="/"><code>/</code></a>,
+<a href="/index"><code>/index</code></a> and
+<a href="/index.html"><code>/index.html</code></a>.
+</p>
+</body>
+</html>
diff --git a/examples/static-files/run b/examples/static-files/run
new file mode 100755 (executable)
index 0000000..f667252
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+cd "$(dirname "$0")"
+
+htparser plain:port=8080 -- dirplex .
diff --git a/examples/static-files/test.css b/examples/static-files/test.css
new file mode 100644 (file)
index 0000000..178f96e
--- /dev/null
@@ -0,0 +1,11 @@
+body {
+       font-family: sans-serif;
+}
+
+h1 {
+       font-size: 1.75em;
+}
+
+p {
+       font-size: 1em;
+}
diff --git a/examples/vhosts/README b/examples/vhosts/README
new file mode 100644 (file)
index 0000000..d1987ca
--- /dev/null
@@ -0,0 +1,2 @@
+To view this example, simply run it on your local machine and point
+your web browser at <http://localhost:8080/>.
diff --git a/examples/vhosts/default-site/index.html b/examples/vhosts/default-site/index.html
new file mode 100644 (file)
index 0000000..8f75829
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+<head>
+<title>Default site</title>
+<link rel="stylesheet" title="Default style" type="text/css" href="test.css" />
+</head>
+<body>
+<h1>Default site</h1>
+<p>
+This site is called when the requested Host is not exactly
+<code>localhost</code>, such as 127.0.0.1.
+</p><p>
+Try visiting
+<a href="http://localhost:8080/"><code>localhost</code></a>
+instead (and make sure the server is running on your local machine).
+</p>
+</body>
+</html>
diff --git a/examples/vhosts/default-site/test.css b/examples/vhosts/default-site/test.css
new file mode 100644 (file)
index 0000000..178f96e
--- /dev/null
@@ -0,0 +1,11 @@
+body {
+       font-family: sans-serif;
+}
+
+h1 {
+       font-size: 1.75em;
+}
+
+p {
+       font-size: 1em;
+}
diff --git a/examples/vhosts/localhost/index.html b/examples/vhosts/localhost/index.html
new file mode 100644 (file)
index 0000000..26796c0
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="US-ASCII"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+<head>
+<title>localhost site</title>
+<link rel="stylesheet" title="Default style" type="text/css" href="test.css" />
+</head>
+<body>
+<h1><code>localhost</code> site</h1>
+<p>
+This site is called when the requested Host is
+exactly <code>localhost</code> (plus any port specification).
+</p><p>
+Try requesting the server via a different hostname, such as
+<a href="http://127.0.0.1:8080/"><code>127.0.0.1</code></a>,
+instead.
+</p>
+</body>
+</html>
diff --git a/examples/vhosts/localhost/test.css b/examples/vhosts/localhost/test.css
new file mode 100644 (file)
index 0000000..178f96e
--- /dev/null
@@ -0,0 +1,11 @@
+body {
+       font-family: sans-serif;
+}
+
+h1 {
+       font-size: 1.75em;
+}
+
+p {
+       font-size: 1em;
+}
diff --git a/examples/vhosts/patterns.conf b/examples/vhosts/patterns.conf
new file mode 100644 (file)
index 0000000..552f2d0
--- /dev/null
@@ -0,0 +1,13 @@
+child default
+  exec dirplex default-site
+
+child localhost
+  exec dirplex localhost
+
+match
+  default
+  handler default
+
+match
+  header host localhost(:[0-9]+)?$ i
+  handler localhost
diff --git a/examples/vhosts/run b/examples/vhosts/run
new file mode 100755 (executable)
index 0000000..bba9e68
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+cd "$(dirname "$0")"
+
+htparser plain:port=8080 -- patplex patterns.conf