Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

"""LICENSE 

Copyright 2019 Hermann Krumrey <hermann@krumreyh.com> 

 

This file is part of status-page. 

 

status-page is free software: you can redistribute it and/or modify 

it under the terms of the GNU General Public License as published by 

the Free Software Foundation, either version 3 of the License, or 

(at your option) any later version. 

 

status-page is distributed in the hope that it will be useful, 

but WITHOUT ANY WARRANTY; without even the implied warranty of 

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

GNU General Public License for more details. 

 

You should have received a copy of the GNU General Public License 

along with status-page. If not, see <http://www.gnu.org/licenses/>. 

LICENSE""" 

 

from status_page import app, db 

from status_page.config import server_list_config 

from status_page.models.User import User 

from status_page.utils.crypto import verify_password, generate_hash 

from status_page.analytics import generate_analytics_data 

from flask import render_template, redirect, request 

from flask_login import login_required, current_user, login_user 

 

 

@app.route("/") 

def index(): 

""" 

The index/home page 

:return: The generated HTML 

""" 

if current_user.is_authenticated: 

return redirect("display") 

elif len(User.query.all()) == 0: 

return redirect("init") 

else: 

return redirect("login") 

 

 

@app.route("/init", methods=["GET", "POST"]) 

def init(): 

""" 

The initialization page 

:return: The generated HTML 

""" 

if len(User.query.all()) != 0: 

return redirect("login") 

elif request.method == "GET": 

return render_template("init.html") 

else: 

data = request.form 

username = data["username"] 

email = data["email"] 

pw = data["password"] 

pw_repeat = data["password-repeat"] 

 

if pw != pw_repeat: 

return render_template("init.html") 

else: 

pw_hash = generate_hash(pw) 

user = User( 

id=1, 

username=username, 

email=email, 

password_hash=pw_hash 

) 

db.session.add(user) 

db.session.commit() 

return redirect("login") 

 

 

@app.route("/login", methods=["GET"]) 

def login_page(): 

""" 

The login page 

:return: The generated HTML 

""" 

return render_template("login.html") 

 

 

@app.route("/login", methods=["POST"]) 

def login(): 

""" 

Logs in the user 

:return: The generated HTML 

""" 

data = request.form 

username = data["username"] 

password = data["password"] 

remember = data.get("remember_me") in ["on", True] 

 

user = User.query.filter_by(username=username).first() 

 

verified = False 

if user is not None: 

verified = verify_password(password, user.password_hash) 

 

if verified: 

login_user(user, remember=remember) 

return redirect("display") 

else: 

return redirect("login") 

 

 

@app.route("/display") 

@login_required 

def display(): 

""" 

The main page of the application 

:return: The generated HTML 

""" 

display_data = generate_analytics_data(server_list_config) 

return render_template("display.html", display_data=display_data)