mirror of
https://github.com/marcus-alicia/iRedAdmin-Pro-SQL.git
synced 2026-05-26 15:13:38 +00:00
Add files via upload
This commit is contained in:
0
controllers/f2b/__init__.py
Normal file
0
controllers/f2b/__init__.py
Normal file
11
controllers/f2b/api_log.py
Normal file
11
controllers/f2b/api_log.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from controllers import decorators
|
||||
from controllers.utils import api_render
|
||||
|
||||
from libs.f2b import log as f2b_log
|
||||
|
||||
|
||||
class APIBannedCount:
|
||||
@decorators.api_require_global_admin
|
||||
def GET(self):
|
||||
total = f2b_log.num_banned()
|
||||
return api_render((True, total))
|
||||
81
controllers/f2b/log.py
Normal file
81
controllers/f2b/log.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from base64 import b64decode
|
||||
import web
|
||||
from controllers import decorators
|
||||
from controllers.utils import api_render
|
||||
|
||||
from libs import iredutils
|
||||
from libs.logger import log_activity
|
||||
|
||||
|
||||
class Banned:
|
||||
@decorators.require_global_admin
|
||||
def GET(self):
|
||||
_qr = web.conn_f2b.select(
|
||||
'banned',
|
||||
what='id, ip, rdns, ports, jail, country, failures, timestamp, remove',
|
||||
order='ip',
|
||||
)
|
||||
rows = list(_qr)
|
||||
|
||||
return web.render('fail2ban/banned.html', rows=rows)
|
||||
|
||||
|
||||
class UnbanIP:
|
||||
"""Unban given IP address, or the IP addresses submitted by form.
|
||||
|
||||
Note: It returns JSON.
|
||||
"""
|
||||
@decorators.require_global_admin
|
||||
def DELETE(self, ip=None):
|
||||
if ip:
|
||||
ips = [ip]
|
||||
else:
|
||||
# Get IP addresses from web form.
|
||||
form = web.input(ip=[])
|
||||
ips = form.get('ip', [])
|
||||
|
||||
ips = [ip for ip in ips if iredutils.is_strict_ip(ip)]
|
||||
|
||||
if not ips:
|
||||
return api_render(True)
|
||||
|
||||
try:
|
||||
web.conn_f2b.update(
|
||||
'banned',
|
||||
vars={"ips": ips},
|
||||
remove=1,
|
||||
where="ip IN $ips",
|
||||
)
|
||||
|
||||
log_activity(msg="Unbanned: " + ', '.join(ips),
|
||||
event='unban')
|
||||
|
||||
return api_render(True)
|
||||
except Exception as e:
|
||||
return api_render((False, repr(e)))
|
||||
|
||||
|
||||
class MatchedLogLines:
|
||||
@decorators.require_global_admin
|
||||
def GET(self, record_id):
|
||||
_qr = web.conn_f2b.select(
|
||||
'banned',
|
||||
vars={'id': record_id},
|
||||
what='loglines',
|
||||
where='id=$id',
|
||||
limit=1,
|
||||
)
|
||||
|
||||
if _qr:
|
||||
loglines = _qr[0]['loglines']
|
||||
|
||||
# Assume its base64 encoded, try to decode it.
|
||||
if loglines:
|
||||
try:
|
||||
loglines = iredutils.bytes2str(b64decode(loglines))
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
loglines = 'NO_MATCHED_LOG_LINES'
|
||||
|
||||
return web.render('fail2ban/matched_log_lines.html', loglines=loglines)
|
||||
14
controllers/f2b/urls.py
Normal file
14
controllers/f2b/urls.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Author: Zhang Huangbin <zhb@iredmail.org>
|
||||
|
||||
# fmt: off
|
||||
urls = [
|
||||
'/activities/fail2ban/banned', 'controllers.f2b.log.Banned',
|
||||
r'/activities/fail2ban/banned/loglines/(\d+)', 'controllers.f2b.log.MatchedLogLines',
|
||||
|
||||
# Warning: it returns JSON.
|
||||
'/activities/fail2ban/unbanip/(.*)', 'controllers.f2b.log.UnbanIP',
|
||||
|
||||
# API interfaces used by web ui.
|
||||
'/api/activities/fail2ban/banned/count', 'controllers.f2b.api_log.APIBannedCount',
|
||||
]
|
||||
# fmt: on
|
||||
Reference in New Issue
Block a user