Index: tools/gformat.py
===================================================================
--- tools/gformat.py	(revision 13930)
+++ tools/gformat.py	(revision 13935)
@@ -1,3 +1,3 @@
-#!/usr/bin/env python
+#!/usr/local/bin/python
 #
 # vim:ts=2:et:sw=2:ai
@@ -7,20 +7,14 @@
 #
 # Sample apache configuration (mind the AcceptPathInfo!)
-#  ScriptAlias /wleiden/config /usr/local/www/genesis/tools/gformat.py
-#  <Directory /usr/local/www/genesis>
-#    Allow from all
-#    AcceptPathInfo On
-#  </Directory>
-#
-# MUCH FASTER WILL IT BE with mod_wsgi, due to caches and avoiding loading all
-# the heavy template lifting all the time.
-#
-# WSGIDaemonProcess gformat threads=25
-# WSGISocketPrefix run/wsgi
+# Alias /config /usr/local/www/config
+# <Directory /usr/local/www/config>
+#    AddHandler cgi-script .py
+#    Require all granted
 # 
-# <Directory /var/www/cgi-bin>
-#   WSGIProcessGroup gformat
+#    RewriteEngine on
+#    RewriteCond %{REQUEST_FILENAME} !-f
+#    RewriteRule ^(.*)$ gformat.py/$1 [L,QSA]
+#    Options +FollowSymlinks +ExecCGI
 # </Directory>
-# WSGIScriptAlias /hello /var/www/cgi-bin/genesis/tools/gformat.py
 #
 # Package dependencies list:
@@ -99,6 +93,8 @@
   NODE_DIR = os.environ['CONFIGROOT']
 else:
-  NODE_DIR = os.path.abspath(os.path.dirname(__file__)) + '/../nodes'
+  NODE_DIR = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) + '/../nodes'
 __version__ = '$Id$'
+
+CACHE_DIR = os.path.abspath(os.path.dirname(__file__))
 
 files = [
@@ -435,7 +431,8 @@
   return "\n".join(files)
 
-def generate_node_overview(host):
+def generate_node_overview(host, datadump=False):
   """ Print overview of all files available for node """
-  datadump = get_yaml(host)
+  if not datadump:
+    datadump = get_yaml(host)
   params = { 'host' : host }
   output = "<em><a href='..'>Back to overview</a></em><hr />"
@@ -443,5 +440,5 @@
   for cf in files:
     params['cf'] = cf
-    output += '<li><a href="%(host)s/%(cf)s">%(cf)s</a></li>\n' % params
+    output += '<li><a href="%(cf)s">%(cf)s</a></li>\n' % params
   output += "</ul>"
 
@@ -459,5 +456,5 @@
           continue
         params = { 'remote': remote, 'remote_ip' : ifacedump['ip'] }
-        output += '<li><a href="%(remote)s">%(remote)s</a> -- %(remote_ip)s</li>\n' % params
+        output += '<li><a href="../%(remote)s">%(remote)s</a> -- %(remote_ip)s</li>\n' % params
   output += "</ul>"
   output += "<h2>MOTD details:</h2><pre>" + generate_motd(datadump) + "</pre>"
@@ -1489,6 +1486,6 @@
     reload_cache()
   else:
-    base_uri = environ['PATH_INFO']
-    uri = base_uri.strip('/').split('/')
+    base_uri = environ['REQUEST_URI']
+    uri = base_uri.strip('/').split('/')[1:]
 
     output = "Template Holder"
@@ -1499,5 +1496,5 @@
         content_type='application/json'
         output = make_network_kml.make_nodeplanner_json()
-    elif not uri[0]:
+    elif not uri:
       if is_text_request(environ):
         output = '\n'.join(get_hostlist())
@@ -1510,5 +1507,5 @@
       else:
         content_type = 'text/html'
-        output = generate_node_overview(uri[0])
+        output = open(os.path.join(CACHE_DIR, uri[0], 'index.html'), 'r').read()
     elif len(uri) == 2:
       output = generate_config(uri[0], uri[1])
@@ -1812,5 +1809,5 @@
   """Hard working sub"""
   # Allow easy hacking using the CLI
-  if not os.environ.has_key('PATH_INFO'):
+  if not os.environ.has_key('REQUEST_URI'):
     if len(sys.argv) < 2:
       usage()
@@ -1869,5 +1866,5 @@
          print generate_config(node, config, datadump)
     elif sys.argv[1] == "test-cgi":
-      os.environ['PATH_INFO'] = "/".join(sys.argv[2:])
+      os.environ['REQUEST_URI'] = "/".join(['config'] + sys.argv[2:])
       os.environ['SCRIPT_NAME'] = __file__
       response_headers, output = process_cgi_request()
@@ -1882,4 +1879,7 @@
           os.makedirs(items['wdir'])
         datadump = get_yaml(node)
+        f = open("%(wdir)s/index.html" % items, "w")
+        f.write(generate_node_overview(items['node'], datadump))
+        f.close()
         for config in files:
           items['config'] = config
