The unified diff between revisions [f6ef05d7..] and [379e01ab..] is displayed below. It can also be downloaded as a raw diff.
#
#
# add_file "service.py"
# content [0d5b73c156955ccae2fff57e1fd1cb7c8485bfb8]
#
# patch "phonehome.py"
# from [7215d569159913685d473102ad7ca95d91637121]
# to [b8c0c8fb4603036b3cd9be15ca0129de7119c155]
#
# patch "plugins/iptables.py"
# from [11eeacf4315fd988618da4d30f3209985e75b058]
# to [1b153de261ff6843afbed6103461f9fdb4e7c9d8]
#
============================================================
--- service.py 0d5b73c156955ccae2fff57e1fd1cb7c8485bfb8
+++ service.py 0d5b73c156955ccae2fff57e1fd1cb7c8485bfb8
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+import os
+import sys
+import service
+import syslog
+import traceback
+from ZSI import dispatch
+from mod_python import apache
+
+mod = __import__('encodings.utf_8', globals(), locals(), '*')
+mod = __import__('encodings.utf_16_be', globals(), locals(), '*')
+
+## soap methods
+
+def plugin_results(results):
+ syslog.syslog("results=%s" % str(results))
+ return []
+
+def handler(req):
+ dispatch.AsHandler(modules=(service,), request=req)
+ return apache.OK
+
+## end soap methods
+
+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()
+ 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]:
+ return apache.OK
+ else:
+ return apache.HTTP_UNAUTHORIZED
+
============================================================
--- phonehome.py 7215d569159913685d473102ad7ca95d91637121
+++ phonehome.py b8c0c8fb4603036b3cd9be15ca0129de7119c155
@@ -3,20 +3,24 @@
#
# the phonehome client
#
-# python program with plugins; runs each plugin according to the configuration file
-#
+# python program with plugins that run various tests
+# also sends information about the machine to server
+# client<->server communication happens over SOAP
#
import sys
import os
import config
import traceback
+import ZSI
+from ZSI.client import Binding
if __name__ == '__main__':
# load each of the plugins
results = []
sys.path.insert(0, config.plugin_path)
+ # run each plugin
for plugin_name in config.plugins:
def run_plugin():
mod = __import__(plugin_name, globals(), locals(), [''])
@@ -28,11 +32,34 @@ if __name__ == '__main__':
try:
result = run_plugin()
except:
- result = [ ("critical", traceback.format_exc()) ]
+ result = [ ("traceback", traceback.format_exc()) ]
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)
- for plugin_name, urgency, description in results:
- print plugin_name, urgency, description
+ # we also want to send over information about this machine
+ def cpuinfo():
+ rv = []
+ if not os.access('/proc/cpuinfo', os.R_OK):
+ return rv
+ for line in open('/proc/cpuinfo'):
+ fields = [t.strip() for t in line.split(':', 1)]
+ if len(fields) != 2: continue
+ key, value = fields
+ if key == 'cpu MHz':
+ rv.append(value)
+ return rv
+ cpus = cpuinfo()
+ b.cpu_info(cpus)
+ def memoryinfo():
+ if not os.access('/proc/meminfo', os.R_OK):
+ return None
+ return open('/proc/meminfo').readline().split(':', 1)[1].strip()
+ mem = memoryinfo()
+ b.memory_info(mem)
============================================================
--- plugins/iptables.py 11eeacf4315fd988618da4d30f3209985e75b058
+++ plugins/iptables.py 1b153de261ff6843afbed6103461f9fdb4e7c9d8
@@ -10,7 +10,7 @@ def run():
fd.close()
line_count = len(result.split('\n'))
- if line_count > 2:
+ if line_count > 3:
return []
else:
return [("medium", 'no iptables rules in chain "INPUT"')]