-
Notifications
You must be signed in to change notification settings - Fork 8
/
generate_passwords.py
87 lines (74 loc) · 2.3 KB
/
generate_passwords.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
from shutil import copyfile
import string, random, crypt
import MySQLdb
def find_check_ids_by_name(checks, cursor):
# execute SQL query using execute() method.
cursor.execute(
"SELECT id FROM kipa_tehtava WHERE sarja_id IN (26, 27, 28, 29, 30) AND nimi IN ('%s')"
% "', '".join(checks)
)
data = cursor.fetchall()
res = []
for row in data:
for val in row:
res.append(str(val))
return res
prefix = "llhk19-"
baseurl = "/kipa/Leon_lenkki_ja_Hilkan_kilpa_2019/"
accounts = {
"hamk": ["Tyoesuhdealias", "RistiNollaKorolla"],
"liikennepuisto": ["RushHour"],
"vanaja": ["HPK"],
"actionfactory": ["Action_Factory"],
"yo": [
"Larry",
"Hexed",
"Escape_room",
"Commodore_64",
"Ruokaralli",
"Kanaset",
"Kummitusmetsae",
],
"tekoaltaat": ["Scrabble"],
"kankaantausta": ["Super_Mario_suunnistusmaassa"],
"hameensanomat": ["Rubikin_kuutio"],
"jaahalli": ["Deja_vu"],
"linna": ["Risk", "Arvaa_kuka"],
"ahvenisto": ["Afrikan_taehti"],
"hakovuori": ["Laulava_muistipeli"],
"verkatehdas": ["Roskaviesti"],
}
templatefile = "/srv/django/kipa/passwords-llhk19"
path = "/srv/django/kipa/auth_files/llhk19/"
letters = string.ascii_letters
access_config = ""
db = MySQLdb.connect(user="kipa", passwd="PWD", host="localhost", db="kipa")
cursor = db.cursor()
print(accounts)
for name, checks in accounts.items():
username = prefix + name
pwdfile = path + name
password = "".join(random.choice(letters) for i in range(10))
pwhash = crypt.crypt(password)
copyfile(templatefile, pwdfile)
f = open(pwdfile, "a")
print(username + ":" + pwhash, file=f)
print(username + ";" + password)
ids = find_check_ids_by_name(checks, cursor)
for id in ids:
access_config = (
access_config
+ """
location {baseurl}syota/tehtava/{id} {{
auth_basic "Vain {name}-rastin tulosten syottajille";
auth_basic_user_file "{pwdfile}";
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/kipa.sock;
}}
""".format(
baseurl=baseurl, name=name.capitalize(), id=id, pwdfile=pwdfile
)
)
c = open(path + "access.conf", "w")
print(access_config, file=c)
db.close()