Skip to content

Commit

Permalink
Add requirements file
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeiP committed Sep 4, 2020
1 parent b39b0ff commit 149f3ac
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
69 changes: 69 additions & 0 deletions generate_passwords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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()
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#django
#django==1.2.7
#https://www.djangoproject.com/download/1.2.7/tarball/
-e git+https://github.com/django/[email protected]#egg=django
south
#mysql-python
-e git+https://github.com/PyMySQL/mysqlclient-python.git#egg=MySQLdb
6 changes: 3 additions & 3 deletions web/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
hakemisto=os.path.normpath(os.path.dirname(__file__))
tarkistus= os.getcwd()

DEBUG = True
DEBUG = False
TEMPLATE_DEBUG = DEBUG
RECORDING=False
if not hakemisto == tarkistus :
Expand Down Expand Up @@ -31,7 +31,7 @@
#CACHE_BACKEND = 'locmem:///' # Cache system for developement
#CACHE_BACKEND = 'locmem:///' # Cache system for developement
CACHE_BACKEND = 'db://tupa_tulos_cache'
if not CACHE_TULOKSET :
if not CACHE_TULOKSET:
CACHE_BACKEND = 'dummy:///' # No cache in use
TAUSTALASENTA = False

Expand Down Expand Up @@ -101,7 +101,7 @@
'django.contrib.admin',
#'django.contrib.formtools',
'django.template',
'django.contrib.databrowse'
'django.contrib.databrowse'

]

Expand Down

0 comments on commit 149f3ac

Please sign in to comment.