# Author: Zhang Huangbin import sys import types import web from controllers import base from libs.policyd import blacklist as blist cfg = web.iredconfig session = web.config.get('_session') class List: @base.require_global_admin def GET(self, listcategory='ip', cur_page=1,): self.listcategory = web.safestr(listcategory) self.cur_page = int(cur_page) blacklistLib = blist.Blacklist() total, entries = blacklistLib.list(listcategory=self.listcategory, cur_page=self.cur_page) if self.cur_page > total and self.cur_page != 1: # Redirect to last page if cur_page > total if total % session.pageSizeLimit > 0: page = total/session.pageSizeLimit + 1 else: page = total/session.pageSizeLimit return web.seeother('/system/blacklist/%s/page/%d' % (listcategory, page)) else: return web.render( 'policyd/wblist.html', total=total, entries=entries, listname='blacklist', listcategory=self.listcategory, cur_page=self.cur_page, ) @base.require_global_admin def POST(self, listcategory='ip', cur_page=1,): self.listcategory = web.safestr(listcategory) self.cur_page = int(cur_page) i = web.input(_unicode=False, record=[],) blacklistLib = blist.Blacklist() result = blacklistLib.delete(listcategory=self.listcategory, records=i.get('record', [])) if result[0] is True: return web.seeother('/system/blacklist/%s/page/%d' % (self.listcategory, self.cur_page)) else: return web.seeother('/system/blacklist/%s/page/%d?msg=%s' % ( self.listcategory, self.cur_page, result[1]), ) class Create: @base.require_global_admin def GET(self): i = web.input(_unicode=False,) return web.render( 'policyd/blacklist/create.html', msg=i.get('msg'), ) @base.require_global_admin def POST(self): i = web.input(_unicode=False,) blistLib = blist.Blacklist() result = blistLib.add(form=i) if result[0] is True: return web.seeother('/create/blacklist?msg=CREATED_SUCCESS') else: return web.seeother('/create/blacklist?msg=%s' % result[1])