The unified diff between revisions [379e01ab..] and [87768252..] is displayed below. It can also be downloaded as a raw diff.
#
#
# patch "phonehome.py"
# from [b8c0c8fb4603036b3cd9be15ca0129de7119c155]
# to [4434ac4a1bd518d75dfda56cf764d58170c6650e]
#
# patch "service.py"
# from [0d5b73c156955ccae2fff57e1fd1cb7c8485bfb8]
# to [37a31e887b320de737da756b4809c9228df4deec]
#
============================================================
--- phonehome.py b8c0c8fb4603036b3cd9be15ca0129de7119c155
+++ phonehome.py 4434ac4a1bd518d75dfda56cf764d58170c6650e
@@ -20,6 +20,9 @@ if __name__ == '__main__':
results = []
sys.path.insert(0, config.plugin_path)
+ # SOAP connection to send information back
+ b = Binding(url=config.soap_address, auth=(ZSI.AUTH.httpbasic, 'phonehome', config.soap_password), tracefile=open('test.txt', 'w'))
+
# run each plugin
for plugin_name in config.plugins:
def run_plugin():
@@ -37,8 +40,6 @@ if __name__ == '__main__':
result = [(plugin_name,) + t for t in result]
results += result
- # send the results of our plugins back to the server
- b = Binding(url=config.soap_address, auth=(ZSI.AUTH.httpbasic, 'phonehome', 'goats'))
b.plugin_results(results)
sys.exit(0)
============================================================
--- service.py 0d5b73c156955ccae2fff57e1fd1cb7c8485bfb8
+++ service.py 37a31e887b320de737da756b4809c9228df4deec
@@ -7,22 +7,31 @@ from mod_python import apache
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(), '*')
-## soap methods
+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 plugin_results(results):
- syslog.syslog("results=%s" % str(results))
- return []
-
def handler(req):
- dispatch.AsHandler(modules=(service,), request=req)
+ methods = ServiceMethods(req)
+ dispatch.AsHandler(modules=(methods,), request=req)
return apache.OK
-## end soap methods
-
def authenhandler(req):
passphrase_file = '/home/grahame/monotone/phonehome/passphrases'
passphrases = {}
@@ -34,7 +43,6 @@ def authenhandler(req):
remote_host = req.get_remote_host(apache.REMOTE_NOLOOKUP)
pw = req.get_basic_auth_pw()
- syslog.syslog("auth attempt: %s %s" % (remote_host, pw))
if not passphrases.has_key(remote_host):
return apache.HTTP_UNAUTHORIZED
if pw == passphrases[remote_host]: