forked from sysr-q/flask-nsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_app.py
101 lines (91 loc) · 2.95 KB
/
example_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
""" This is an example application demonstrating the
NSA ~~Backdoor~~ *ahem*, sorry, "Panel".
It's really this easy to protect your users from
possible threats of terror (or privacy) online!
"""
import random
import sys
from flask import Flask
from flask_nsa import install_backdoor
def gen_users(id=None):
""" Pull and yield all of the relevant information
about your application's users.
Provide a dictionary with at the very least their
`id` and `name`. Anything extra you provide will be
shown in the user info table, so make sure **not**
to redact completely private and confidential info
from the NSA.
Alternatively, return "__blackout__" and it will
magically transform into a black text block.
Oh, and if you can pull just one user's data based
on a given `id`, that'd be really helpful. Otherwise,
just assign it to None, since it will still be called.
"""
yield {
"id": 0,
"name": "John Smith",
"creation": "__blackout__",
"friends": 10
}
yield {
"id": 1,
"name": "Jane Smith",
"creation": "__blackout__",
"friends": 2 # Nobody loves Jane. :'(
}
yield {
"id": 2,
"name": "Little Bobby Tables",
"creation": "__blackout__",
"friends": 7
}
yield {
"id": 3,
"name": "Elaine Roberts",
"creation": "__blackout__",
"friends": 5
}
def gen_secrets():
""" Purely a hypothetical example; you should provide
the NSA with the __real__ secrets of your users.
This simply generates 25 secrets per user from
the above users() function. Static numbers are fun.
"""
for u in xrange(0, 4):
for i in xrange(0, 25):
yield {
"id": i,
"uid": u,
"secret": "Something that should not be seen."
}
def gen_friends():
""" Another hypothetical example, with a small subset
of names.
If only the real world would let you make friends
with a generator statement, eh?
"""
fnames = ["John", "Jane", "Mary", "Kate", "Ashleigh",
"Chris", "Timothy", "Bobby", "Maxwell", "Amy"]
lnames = ["Smith", "Hansen", "Carter", "Macky", "Hull",
"Richards", "Chan", "Cameron", "Sharp", "Dicken"]
for u in gen_users():
for i in xrange(0, u['friends']):
yield {
"id": i,
"uid": u['id'],
"name": "{0} {1}".format(
random.choice(fnames),
random.choice(lnames)
)
}
if __name__ == "__main__":
app = Flask(__name__)
app.config['SECRET_KEY'] = "NSA_ROX!"
app.debug = "--debug" in sys.argv
data = [
("secrets", gen_secrets),
("friends", gen_friends)
]
install_backdoor(app, gen_users, data)
app.run()