-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
83 lines (61 loc) · 2 KB
/
app.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from flask import Flask
from flask import render_template, request, redirect, url_for, session
from imaplib import IMAP4
from os import urandom
app = Flask(__name__, static_url_path='', static_folder="public", template_folder="public")
app.config['SECRET_KEY'] = urandom(12)
s = IMAP4("hahacking.local")
def checkAlive(e):
global s
if "Broken pipe" in e or "EOF" in e:
s = IMAP4("hahacking.local")
@app.route('/')
def index():
global s
try:
s.noop()
except Exception as e:
e = str(e)
checkAlive(e)
return render_template("index.html", result=f"Failed! Error message: {e}")
if "success" in session and session["success"]:
try:
s.select()
typ, data = s.search(None, "ALL")
messages = {}
for num in data[0].split():
typ, data = s.fetch(num, '(RFC822)')
messages[num.decode()] = data[0][1].decode()
return render_template("messages.html", messages=messages)
except Exception as e:
e = str(e)
checkAlive(e)
return render_template("index.html", result=f"Failed! Error message: {e}")
return render_template("index.html", result='')
@app.route("/signin", methods=["GET", "POST"])
def signinPost():
global s
if request.method == "POST":
username = request.form.get("username")
password = request.form.get("password")
try:
s.login(username, password)
session["success"] = True
except Exception as e:
e = str(e)
checkAlive(e)
return render_template("index.html", result=f"Failed! Error message: {e}")
return redirect(url_for('index'), 302)
@app.route("/logout", methods=["GET", "POST"])
def logoutPost():
global s
try:
s.logout()
session["success"] = False
except Exception as e:
e = str(e)
return render_template("index.html", result=f"Failed! Error message: {e}")
s = IMAP4("hahacking.local")
return redirect(url_for('index'), 302)
if __name__ == "__main__":
app.run(host="hahacking.local", port=80)