Added antispam module to Hawkeye.
This commit is contained in:
@@ -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 := \
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
%(include|header.tpl)s
|
||||
|
||||
<form method="post">
|
||||
<table cellpadding="1">
|
||||
<tr><td style="padding-right: 16px;"><label for="timeout">Timeout: </label></td><td><input type="text" name="timeout" id="timeout" tal:attributes="value timeout" /> milliseconds</td></tr>
|
||||
<tr><td><label for="host">Host: </label></td><td><input type="text" name="host" id="host" tal:attributes="value host" />:<input type="text" name="port" tal:attributes="value port" style="width: 45px;" /></td></tr>
|
||||
</table>
|
||||
<br />
|
||||
<br />
|
||||
<span class="button"><button type="submit" value="Save">Save</button></span>
|
||||
</form>
|
||||
|
||||
%(include|footer.tpl)s
|
||||
Reference in New Issue
Block a user