<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>fetegeos.conf.sample</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1 +1,2 @@
 *.pyc
+fetegeos.conf
\ No newline at end of file</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -20,6 +20,12 @@ if it exists). Importing the data is likely to take a while; however you
 can start testing with incomplete data as soon as Fetegeo has imported a
 couple of countries worth of data.
 
+fetegeos is the Fetegeo server. In order to set this up, you need to give it
+a valid config file. A sample config file is included with the distribution
+and can be moved into place with:
+
+  $ cp fetegeos.conf.sample fetegeos.conf
+
 The easiest way to test things is to run the server fetegeos in one shell:
 
   $ ./fetegeos</diff>
      <filename>INSTALL</filename>
    </modified>
    <modified>
      <diff>@@ -21,7 +21,7 @@
 # IN THE SOFTWARE.
 
 
-import re, socket, SocketServer, sys, xml.dom.minidom as minidom
+import imp, re, os, socket, SocketServer, sys, xml.dom.minidom as minidom
 
 try:
     import psycopg2 as dbmod
@@ -39,6 +39,9 @@ import Geo.Queryier
 _DEFAULT_HOST = &quot;&quot;
 _DEFAULT_PORT = 8263
 
+_CONF_DIRS = [&quot;/etc/&quot;, sys.path[0]]
+_CONF_LEAF = &quot;fetegeos.conf&quot;
+
 _RE_QUERY_END = re.compile(&quot;&lt;/(?:geo|country)query&gt;&quot;)
 
 _RE_TRUE = re.compile(&quot;true&quot;)
@@ -210,8 +213,28 @@ class Fetegeos_Server(SocketServer.TCPServer, SocketServer.ThreadingMixIn):
 
     def __init__(self, addr, rhc):
     
-        self.allow_reuse_address = True # XXX
+        # Load the config file
+    
+        for dir in _CONF_DIRS:
+            conf_path = os.path.join(dir, _CONF_LEAF)
+            if os.path.exists(conf_path):
+                break
+        else:
+            sys.stderr.write(&quot;Error: No config file found.&quot;)
+            sys.exit(1)
+        
+        f = open(conf_path, &quot;r&quot;)
+        # We fool load_source by pretending the config file comes from /dev/null,
+        # which (because it's a filename without a &quot;.&quot; in it, but which is
+        # genuinely present) stops it trying to write a .pyc file. Otherwise for
+        # a file fetegeos.conf, one ends up with a fetegeos.confc file, which is
+        # plain ugly.
+        self._config = imp.load_source(&quot;config&quot;, &quot;/dev/null&quot;, f)
+        f.close()
     
+        # Setup the server
+    
+        self.allow_reuse_address = True # XXX
         SocketServer.TCPServer.__init__(self, addr, rhc)
         
         self.queryier = Geo.Queryier.Queryier()
@@ -225,6 +248,29 @@ class Fetegeos_Server(SocketServer.TCPServer, SocketServer.ThreadingMixIn):
                 pass
 
 
+    def verify_request(self, requst, client_address):
+    
+        # Check that client_address is an IP address allowed to connect to fetegeos.
+        # NOTE: This is rather IP4 specific at the moment.
+    
+        split_client_address = client_address[0].split(&quot;.&quot;)
+        for addr in self._config.accept_connect:
+            split_addr = addr.split(&quot;.&quot;)
+            if len(split_addr) == len(split_client_address):
+                match = True
+                for i in range(len(split_addr)):
+                    if split_addr[i] == &quot;*&quot;:
+                        continue
+                    elif split_addr[i] != split_client_address[i]:
+                        match = False
+                        break
+                
+                if match:
+                    return True
+
+        return False
+
+
 
 
 if __name__ == &quot;__main__&quot;:</diff>
      <filename>fetegeos</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ef32b2455b188464c26b68ad9efc2b02e41f5a80</id>
    </parent>
  </parents>
  <author>
    <name>Laurence Tratt</name>
    <email>laurie@tratt.net</email>
  </author>
  <url>http://github.com/ltratt/fetegeo/commit/b6395c86ebff20025decd3947f6e9a89271b27af</url>
  <id>b6395c86ebff20025decd3947f6e9a89271b27af</id>
  <committed-date>2009-04-22T03:39:09-07:00</committed-date>
  <authored-date>2009-04-22T03:39:09-07:00</authored-date>
  <message>Add config file support to fetegeos.

As it stands this is rather crude, but it does a job.

Currently the only config option is which client IP4 addresses can connect to fetegeos. This allows one to run a fetegeos server without having to open it up to the entire world.</message>
  <tree>e08460aec351441d0c33633972eb68c52d7d8dde</tree>
  <committer>
    <name>Laurence Tratt</name>
    <email>laurie@tratt.net</email>
  </committer>
</commit>
