From 2c4e172eaa971019468d3d2f0e25297e6723c371 Mon Sep 17 00:00:00 2001 From: halex Date: Tue, 15 May 2007 10:17:18 +0000 Subject: [PATCH] Added antispam module to Hawkeye. --- src/www/Bongo.rules | 5 ++ src/www/bongo/hawkeye/AgentView.py | 55 +++++++++++++ src/www/bongo/hawkeye/AntispamView.py | 110 ++++++++++++++++++++++++++ src/www/bongo/hawkeye/HawkeyePath.py | 4 +- src/www/hawkeye/antispam/index.tpl | 13 +++ 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/www/bongo/hawkeye/AntispamView.py create mode 100644 src/www/hawkeye/antispam/index.tpl diff --git a/src/www/Bongo.rules b/src/www/Bongo.rules index 58927a0..d3bcf53 100644 --- a/src/www/Bongo.rules +++ b/src/www/Bongo.rules @@ -306,6 +306,7 @@ pkgpythonhawkeyedir = $(pkgpythondir)/hawkeye pkgpythonhawkeye_PYTHON := \ src/www/bongo/hawkeye/__init__.py \ + src/www/bongo/hawkeye/AntispamView.py \ src/www/bongo/hawkeye/AgentView.py \ src/www/bongo/hawkeye/Auth.py \ src/www/bongo/hawkeye/BackupView.py \ @@ -340,6 +341,10 @@ dist_hawkeyetplsystem_DATA := \ hawkeyetplagentsdir = $(htdocsdir)/hawkeye/agents dist_hawkeyetplagents_DATA := \ src/www/hawkeye/agents/index.tpl + +hawkeyetplantispamdir = $(htdocsdir)/hawkeye/antispam +dist_hawkeyetplantispam_DATA := \ + src/www/hawkeye/antispam/index.tpl hawkeyetpldir = $(htdocsdir)/hawkeye dist_hawkeyetpl_DATA := \ diff --git a/src/www/bongo/hawkeye/AgentView.py b/src/www/bongo/hawkeye/AgentView.py index c9d5aa1..f9915c9 100644 --- a/src/www/bongo/hawkeye/AgentView.py +++ b/src/www/bongo/hawkeye/AgentView.py @@ -1,10 +1,65 @@ import bongo.dragonfly +import bongo.dragonfly.BongoUtil +from bongo.store.StoreClient import StoreClient, DocTypes +import bongo.external.simplejson as simplejson from HawkeyeHandler import HawkeyeHandler +doneop = 0 + class AgentHandler(HawkeyeHandler): def index_GET(self, req, rp): + global doneop + + if doneop: + self.SetVariable("opsuccess", 1) + doneop = 0 + else: + self.SetVariable("opsuccess", 0) + self.SetVariable("breadcrumb", "Agents") self.SetVariable("agntab", "selecteditem") self.SetVariable("title", "Agents") return self.SendTemplate(req, rp, "index.tpl") + + def index_POST(self, req, rp): + global doneop + + if not req.form: + return bongo.dragonfly.HTTP_UNAUTHORIZED + + if not req.form.has_key("command"): + return bongo.dragonfly.HTTP_UNAUTHORIZED + + # Operation completed OK. + doneop = 1 + return self.index_GET(req, rp) + + def _getAntispam(self, req): + config = {} + store = None + decoder = simplejson.JSONDecoder() + try: + store = StoreClient(req.session["credUser"], req.session["credUser"], authPassword=req.session["credPass"]) + store.Store("_system") + configfile = store.Read("/config/antispam") + config = decoder.decode(configfile) + store.Quit() + except: + if store: + store.Quit() + return None + + return config + + def _setAntispam(self, req, obj): + encoder = simplejson.JSONEncoder() + store = None + try: + store = StoreClient(req.session["credUser"], req.session["credUser"], authPassword=req.session["credPass"]) + store.Store("_system") + configfile = encoder.encode(obj) + store.Replace("/config/antispam", configfile) + finally: + if store: + store.Quit() diff --git a/src/www/bongo/hawkeye/AntispamView.py b/src/www/bongo/hawkeye/AntispamView.py new file mode 100644 index 0000000..c67721e --- /dev/null +++ b/src/www/bongo/hawkeye/AntispamView.py @@ -0,0 +1,110 @@ +import bongo.dragonfly +import bongo.dragonfly.BongoUtil +from bongo.store.StoreClient import StoreClient, DocTypes +import bongo.external.simplejson as simplejson +from HawkeyeHandler import HawkeyeHandler + +doneop = 0 + +class AntispamHandler(HawkeyeHandler): + def NeedsAuth(self, rp): + return True + + def index_GET(self, req, rp): + global doneop + config = self._getAntispam(req) + + if doneop: + self.SetVariable("opsuccess", 1) + doneop = 0 + else: + self.SetVariable("opsuccess", 0) + + nosetcheck = 0 + + # Set values to display back + if config != None and config.has_key("enabled"): + self.SetVariable("success", 1) + for key in config: + if key == "timeout": + if config[key] > 1: + self.SetVariable("timeout", config[key]) + else: + self.SetVariable("timeout", "20") + nosetcheck = 1 + elif key == "host": + hval = config[key].split(':', 3) + if len(hval) > 1: + self.SetVariable("host", hval[0]) + self.SetVariable("port", hval[1]) + else: + self.SetVariable("host", "not set") + self.SetVariable("port", "783") + + if nosetcheck: + self.SetVariable("error", "Antispam is not currently set up correctly. Please enter the correct values below, and click save to rectify this.") + else: + self.SetVariable("success", 0) + self.SetVariable("error", "Unable to read configuration information from the Bongo store. Are you logged in as a user with administrative permissions?") + + self.SetVariable("breadcrumb", "Agents » Antispam") + self.SetVariable("title", "Antispam") + self.SetVariable("agntab", "selecteditem") + + return self.SendTemplate(req, rp, "index.tpl") + + def index_POST(self, req, rp): + global doneop + + config = self._getAntispam(req) + if config.has_key("enabled"): + for key in req.form: + print "got key=" + str(key) + print "val=" + str(req.form[key].value) + if key == "timeout": + config["timeout"] = int(req.form[key].value); + elif key == "host": + config["host"] = req.form[key].value; + elif key == "port": + config["host"] += ":" + req.form[key].value; + + # Set weight (always 1 since we can only handle 1 host) + config["host"] += ":1" + else: + self.SetVariable("error", "Unable to read config") + + self._setAntispam(req, config) + # Operation completed OK. + doneop = 1 + + return self.index_GET(req, rp) + + def _getAntispam(self, req): + config = {} + store = None + decoder = simplejson.JSONDecoder() + try: + store = StoreClient(req.session["credUser"], req.session["credUser"], authPassword=req.session["credPass"]) + store.Store("_system") + configfile = store.Read("/config/antispam") + config = decoder.decode(configfile) + store.Quit() + except: + if store: + store.Quit() + return None + + return config + + def _setAntispam(self, req, obj): + encoder = simplejson.JSONEncoder() + store = None + try: + store = StoreClient(req.session["credUser"], req.session["credUser"], authPassword=req.session["credPass"]) + store.Store("_system") + configfile = encoder.encode(obj) + store.Replace("/config/antispam", configfile) + finally: + if store: + store.Quit() + diff --git a/src/www/bongo/hawkeye/HawkeyePath.py b/src/www/bongo/hawkeye/HawkeyePath.py index 438f610..b371091 100644 --- a/src/www/bongo/hawkeye/HawkeyePath.py +++ b/src/www/bongo/hawkeye/HawkeyePath.py @@ -7,6 +7,7 @@ from bongo.dragonfly.HttpError import HttpError import RootView import AgentView +import AntispamView import BackupView import ServerView import SystemView @@ -16,7 +17,8 @@ views = { "agents" : AgentView.AgentHandler(), "backup" : BackupView.BackupHandler(), "system" : SystemView.SystemHandler(), - "server" : ServerView.ServerHandler() + "server" : ServerView.ServerHandler(), + "antispam" : AntispamView.AntispamHandler() } class HawkeyePath: diff --git a/src/www/hawkeye/antispam/index.tpl b/src/www/hawkeye/antispam/index.tpl new file mode 100644 index 0000000..e1bdc6e --- /dev/null +++ b/src/www/hawkeye/antispam/index.tpl @@ -0,0 +1,13 @@ +%(include|header.tpl)s + +
+ + + +
milliseconds
:
+
+
+ +
+ +%(include|footer.tpl)s