1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import logging
import datetime
import flask
import db_handler
class CustomFormatter(logging.Formatter):
grey = "\x1b[90;20m"
blue = "\x1b[34;20m"
yellow = "\x1b[33;20m"
red = "\x1b[31;20m"
bold_red = "\x1b[31;1m"
reset = "\x1b[0m"
format = "%(asctime)s,%(msecs)03d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s"
FORMATS = {
logging.DEBUG: grey + format + reset,
logging.INFO: blue + format + reset,
logging.WARNING: yellow + format + reset,
logging.ERROR: red + format + reset,
logging.CRITICAL: bold_red + format + reset
}
def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt)
return formatter.format(record)
logger = logging.getLogger(__name__)
logger.root.setLevel(logging.INFO)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(CustomFormatter())
logger.root.addHandler(stream_handler)
app = flask.Flask(__name__, template_folder='templates', static_folder='static', static_url_path='')
@app.route("/password_of_the_month")
@app.route("/password of the month")
@app.route("/passwd")
def password_of_the_month():
password = db_handler.get_password_of_the_month()
return password
def format_time(input: datetime.datetime) -> str:
return input.strftime('%e %b %Y %H:%M')
@app.route("/")
def index():
latest_loging_attempts = db_handler.get_latest_login_attempts()
top_usernames = db_handler.get_top('username')
top_passwords = db_handler.get_top('password')
histogram = db_handler.get_histogram()
histogram_data = [a['total_count'] for a in histogram]
histogram_labels = [format_time(a['date']) for a in histogram]
return flask.render_template(
'index.html',
latest_login_attempts=latest_loging_attempts,
top_usernames=top_usernames,
top_passwords=top_passwords,
histogram_data=histogram_data,
histogram_labels=histogram_labels)
|