def post(self,type): try: if type == "whitelist": file = request.files['import_whitelist'] if file: reader = csv.reader(file) for row in reader: if row[0] == "whitelist": rule = Whitelist.query.filter_by(rule=row[5],category=row[1],type = row[2]).first() if not rule: rule = Whitelist(rule=row[5],category=row[1],type = row[2],source="import",description=row[4]) # Insert the record in our database and commit it db.session.add(rule) db.session.commit() cmd = CommandExecAcl(rule.rule,rule.category,rule.type,Command("_pub_rule_server")) cmd.add_acl() elif type == "blacklist": file = request.files['import_blacklist'] if file: reader = csv.reader(file) for row in reader: if row[0] == "blacklist": rule = Blacklist.query.filter_by(rule=row[5],category=row[1],type = row[2]).first() if not rule: rule = Blacklist(rule=row[5],category=row[1],type = row[2],source="import",description=row[4]) # Insert the record in our database and commit it db.session.add(rule) db.session.commit() cmd = CommandExecAcl(rule.rule,rule.category,rule.type,Command("_pub_rule_server")) cmd.add_acl() elif type == "patrol": file = request.files['import_patrol'] if file: reader = csv.reader(file) for row in reader: if row[0] == "patrol": rule = Patrollist.query.filter_by(rule=row[5],category=row[1],type = row[2]).first() if not rule: rule = Patrollist(rule=row[5],threshold=int(row[3]),category=row[1],type = row[2],source="import",description=row[4]) # Insert the record in our database and commit it db.session.add(rule) db.session.commit() else: return {"result":"failed","reason":"no type"} return {"result":"successful"} except Exception,e : print(e) return {"result":"failed","reason":"server exception"}
def get(self,name): try: cmd = CommandExecStats(name,Command("_rep_stats_server")) metric =cmd.get_stats() return metric except Exception,e: print(e) return 0.0
def delete(self,guid): try: rule = Blacklist.query.filter_by(guid=guid).first() if rule: cmd = CommandExecAcl(rule.rule,rule.category,rule.type,Command("_pub_rule_server")) cmd.del_acl() db.session.delete(rule) db.session.commit() return {"result":"successful"} except Exception,e : print(e) return {"result":"failed"}
def put(self,guid): try: rule = Patrollist.query.filter_by(guid=guid).first() if rule: cmd = CommandExecAcl(rule.rule,rule.category,rule.type,Command("_pub_rule_server")) cmd.add_acl() rule.active = True db.session.add(rule) db.session.commit() return {"result":"successful"} except Exception,e : return {"result":"failed"}
def post(self): try: req_json = request.json rule = Blacklist.query.filter_by(rule=req_json[u"rule"],category=req_json[u"category"],type = req_json[u"type"]).first() if not rule: rule = Blacklist(req_json["rule"],req_json["category"],req_json["type"],None,req_json["description"]) # Insert the record in our database and commit it db.session.add(rule) db.session.commit() cmd = CommandExecAcl(rule.rule,rule.category,rule.type,Command("_pub_rule_server")) cmd.add_acl() return {"result":"successful"} except Exception,e : print(e) return {"result":"failed"}