Below is the file 'service/service.py' from this revision. You can also download the file.
#!/usr/bin/python import os import sys import service import syslog import traceback from ZSI import dispatch from mod_python import apache import libpq import config mod = __import__('encodings.utf_8', globals(), locals(), '*') mod = __import__('encodings.utf_16_be', globals(), locals(), '*') class ServiceMethods: def __init__(self, req): self.req = req self.cnx = libpq.PQconnectdb(config.sql_connect_string) def plugin_results(self, results): # results is a list of (plugin,urgency,description) q = libpq.PgQuoteString remote_host = req.get_remote_host(apache.REMOTE_NOLOOKUP) for plugin, urgency, description in results: query = 'INSERT INTO plugin_results (ip_address, plugin, urgency, description) VALUES (%s,%s,%s,%s)' % \ (q(remote_host), q(plugin), q(urgency), q(description)) self.cnx.query(query) return True def handler(req): methods = ServiceMethods(req) dispatch.AsHandler(modules=(methods,), request=req) return apache.OK def authenhandler(req): passphrase_file = '/home/grahame/monotone/phonehome/passphrases' passphrases = {} for line in open(passphrase_file): line = line.strip() if not line: continue fields = line.split() passphrases[fields[0]] = fields[1] remote_host = req.get_remote_host(apache.REMOTE_NOLOOKUP) pw = req.get_basic_auth_pw() if not passphrases.has_key(remote_host): return apache.HTTP_UNAUTHORIZED if pw == passphrases[remote_host]: return apache.OK else: return apache.HTTP_UNAUTHORIZED