diff --git a/scripts/generate_passwords.py b/scripts/generate_passwords.py new file mode 100644 index 00000000..73e36fd1 --- /dev/null +++ b/scripts/generate_passwords.py @@ -0,0 +1,58 @@ +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 = { + "actionfactory": ["Action_Factory"], + "yo": ["Tehtavan 1 nimi", "Tehtavan 2 nimi"] +} +templatefile = '/srv/django/kipa/passwords-llhk19' +path = '/srv/django/kipa/auth_files/llhk19/' +letters = string.ascii_letters + +access_config = '' + +db = MySQLdb.connect(user="USER", passwd="PASSWORD", host="localhost", db="DATABASE") +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() diff --git a/web/settings.py b/web/settings.py index 224142d1..ae068094 100644 --- a/web/settings.py +++ b/web/settings.py @@ -1,16 +1,5 @@ import os -import time -try : - fin = open("templates/version.html", "r") - revision_line=fin.readline() ; - fin.close() - fout = open("templates/version.html", "w") - fout.write( revision_line ) - fout.write( "{% comment %} " +time.strftime('%X %x') +" {% endcomment %}" ) # Add clock to force svn commit - fout.close() -except: pass - hakemisto=os.path.normpath(os.path.dirname(__file__)) tarkistus= os.getcwd() diff --git a/web/templates/tupa/base.html b/web/templates/tupa/base.html index 40ae2406..d657ff3d 100644 --- a/web/templates/tupa/base.html +++ b/web/templates/tupa/base.html @@ -69,7 +69,6 @@ {{kisa_nimi|alaviiva_pois}} {%if taakse.url and taakse.title%}» {{taakse.title|alaviiva_pois}} {% endif %}» {{heading|alaviiva_pois}} {% endif %} -