-
Notifications
You must be signed in to change notification settings - Fork 299
/
setup.py
118 lines (94 loc) · 2.6 KB
/
setup.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import sys
import os
import shutil
import config
import random
from ipaddress import IPv4Network
from app import db
from core.models import Paste, Owner, User, ServerMode
from db.agents import agents
from db.owners import owners
from db.titles import titles
from db.content import content
def clean_up():
if os.path.exists(config.WEB_UPLOADDIR):
shutil.rmtree(config.WEB_UPLOADDIR)
os.mkdir(config.WEB_UPLOADDIR)
else:
os.mkdir(config.WEB_UPLOADDIR)
print('Reconstructing Database')
if os.path.exists(config.SQLALCHEMY_FILE):
try:
os.remove(config.SQLALCHEMY_FILE)
except OSError:
pass
return
def random_title():
return random.choice(titles)
def random_content():
return random.choice(content)
def random_owner():
return random.choice(owners)
def random_address():
addresses = []
for addr in IPv4Network('215.0.2.0/24'):
addresses.append(str(addr))
return random.choice(addresses)
def random_password():
weak_passwords = ['changeme']
return random.choice(weak_passwords)
def random_useragent():
user_agents = []
for uas in agents:
user_agents.append(uas)
return random.choice(user_agents)
def pump_db():
print('Populating Database')
db.create_all()
admin = User(username="admin", email="[email protected]", password=random_password())
operator = User(username="operator", email="[email protected]", password="password123")
# create tokens for admin & operator
db.session.add(admin)
db.session.add(operator)
owner = Owner(name='DVGAUser')
db.session.add(owner)
paste = Paste()
paste.title = 'Testing Testing'
paste.content = "My First Paste"
paste.public = False
paste.owner_id = owner.id
paste.owner = owner
paste.ip_addr = '127.0.0.1'
paste.user_agent = 'User-Agent not set'
db.session.add(paste)
paste = Paste()
paste.title = '555-555-1337'
paste.content = "My Phone Number"
paste.public = False
paste.owner_id = owner.id
paste.owner = owner
paste.ip_addr = '127.0.0.1'
paste.user_agent = 'User-Agent not set'
db.session.add(paste)
db.session.commit()
for _ in range(0, 10):
owner = Owner(name=random_owner())
paste = Paste()
paste.title = random_title()
paste.content = random_content()
paste.public = True
paste.owner_id = owner.id
paste.owner = owner
paste.ip_addr = random_address()
paste.user_agent = random_useragent()
db.session.add(owner)
db.session.add(paste)
mode = ServerMode()
mode.hardened = False
db.session.add(mode)
db.session.commit()
print('done')
if __name__ == '__main__':
clean_up()
pump_db()
sys.exit()