scripts zur automatischen verarbeitung von anmeldungen.

This commit is contained in:
Enno Rehling 2001-11-05 23:43:00 +00:00
parent 9dbe4cef87
commit 29dd35b877
5 changed files with 298 additions and 0 deletions

53
scripts/register/confirm.py Executable file
View File

@ -0,0 +1,53 @@
#!/usr/bin/env python
import sys
import MySQLdb
import smtplib
dbname=sys.argv[1]
db = MySQLdb.connect(db=dbname)
From="accounts@vinyambar.de"
server=smtplib.SMTP('localhost')
cursor=db.cursor()
records=cursor.execute("SELECT users.id, users.password, users.email, "+
"races.name, "+
"games.name, games.info, subscriptions.id "+
"from users, games, subscriptions, races "+
"where users.id = subscriptions.user AND games.id = subscriptions.game "+
"AND races.race = subscriptions.race AND races.locale='de' "+
"AND subscriptions.status='NEW'")
while (records>0):
row=cursor.fetchone()
records = records - 1
customerid=row[0]
passwd=row[1]
email=row[2]
race=row[3]
gamename=row[4]
gameinfo=row[5]
subscription=row[6]
Msg = ("From: "+From+"\nTo: "+email+"\nSubject: Vinyambar Anmeldung angenommen.\n\n"+
"Deine Anmeldung für '"+gamename+"' wurde akzeptiert.\n"
"\n"+
gameinfo +"\n"+
"Kundennummer: " + str(int(customerid)) + "\n"+
"Auftragsnummer: " + str(int(subscription)) + "\n"+
"Passwort: " + passwd + "\n" +
"Rasse: " + race + "\n\n"+
"Bitte bewahre diese Mail sorgfältig auf, da Du deine Kundennummerund das\n"+
"Passwort für das Spiel benötigst. Solltest Du noch Fragen zu Deiner \n"+
"Anmeldung haben, wende Dich bitte an accounts@vinyambar.de.\n\n"+
"Das Vinyambar-Team")
try:
server.sendmail(From, email, Msg)
update=db.cursor()
update.execute("UPDATE subscriptions set status='CONFIRMED' WHERE id="+
str(int(subscription)));
except:
print "Could not send Error to "+To
print "Reason was: '"+Reason+"'"
print "Exception is:", sys.exc_type, ":", sys.exc_value

46
scripts/register/errors.py Executable file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env python
import smtplib
import time
import sys
import os
import re
import locking
from locking import trylock, unlock
From="accounts@vinyambar.de"
# lock the input file:
if (trylock(sys.argv[1]+'.err')!=0):
print "Could not lock "+sys.argv[1]+".err"
sys.exit()
# move input file then unlock it:
os.rename(sys.argv[1]+'.err', sys.argv[1]+'.tmp')
unlock(sys.argv[1]+'.err')
infile=open(sys.argv[1]+".tmp", "r")
server=smtplib.SMTP('localhost')
#server.set_debuglevel(1)
matchline=re.compile(
r"""([^\s]+)\s*([^\n\r]+)*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
for line in infile.readlines():
match=matchline.match(line)
if match!=None:
To = match.group(1)
Reason = match.group(2)
Msg = ("From: "+From+"\nTo: "+To+"\nSubject: Vinyambar Anmeldung fehlgeschlagen.\n\n"
+"Deine Anmeldung konnte aus folgendem Grund nicht akzeptiert werden:\n "+Reason+"\n")
try:
server.sendmail(From, To, Msg)
except:
print "Could not send Error to "+To
print "Reason was: '"+Reason+"'"
print "Exception is:", sys.exc_type, ":", sys.exc_value
os.unlink(sys.argv[1]+".tmp")
infile.close()
server.quit()

33
scripts/register/locking.py Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env python
import os
import stat
def trylock(file):
try:
os.symlink(file, file+'.lock')
except OSError:
return 1
return 0
def lock(file):
locked=1
while locked:
try:
locked=0
os.symlink(file, file+'.lock')
except:
update=os.stat(file+'.lock')[stat.ST_MTIME]
now=time.time()
if (now > update + 60):
locked=0
print "removing stale lockfile "+file+".lock"
os.unlink(file+'.lock')
else:
locked=1
print "Waiting for lock on "+file+".lock"
time.sleep(20)
def unlock(file):
os.unlink(file+'.lock')

163
scripts/register/register.py Executable file
View File

@ -0,0 +1,163 @@
#!/usr/bin/python
import MySQLdb
import sys
import re
import string
from whrandom import choice
import locking
from locking import lock, unlock
dbname=sys.argv[2]
db=MySQLdb.connect(db=dbname)
lock(sys.argv[1]+".err")
errors=open(sys.argv[1]+".err", 'a')
def validrace(race):
validraces=('GOBLIN', 'DWARF', 'ELF', 'HALFLING', 'INSECT', 'AQUARIAN', 'HUMAN', 'CAT', 'TROLL', 'ORC', 'DEMON')
name = string.upper(str(race))
if name in validraces:
return name
return None
def genpasswd():
newpasswd=""
chars = string.letters + string.digits
for i in range(8):
newpasswd = newpasswd + choice(chars)
return newpasswd
def error(email, message):
errors.write(email + " "+ message+"\n");
matchfrom=re.compile(
r"""From ([^\s]*)""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
matchfirstname=re.compile(
r""".*vorname:\s*([^\n\r]*)""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
firstname=None
matchlastname=re.compile(
r""".*nachname:\s*([^\n\r]*)\s*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
lastname=None
matchemail=re.compile(
r""".*email:\s*([^\n\r]*)\s*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
email=None
matchaddress=re.compile(
r""".*adresse:\s*([^\n\r]*)\s*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
address=None
matchcity=re.compile(
r""".*ort:\s*([^\n\r]*)\s*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
city=None
matchcountry=re.compile(
r""".*land:\s*([^\n\r]*)""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
country=None
matchphone=re.compile(
r""".*telefon:\s*([^\n\r]*)\s*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
phone=None
matchnewrace=re.compile(
r""".*neues\sspiel:\s*([^\n\r]+)\s*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
newrace=0
matcholdrace=re.compile(
r""".*altes\sspiel:\s*([^\n\r]+)\s*""",
re.IGNORECASE | re.DOTALL | re.VERBOSE)
oldrace=0
for line in sys.stdin.readlines():
match=matcholdrace.match(line)
if (match!=None):
oldrace=match.group(1)
continue
match=matchnewrace.match(line)
if (match!=None):
newrace=match.group(1)
continue
match=matchfrom.match(line)
if (match!=None):
email=match.group(1)
continue
match=matchfirstname.match(line)
if (match!=None):
firstname=match.group(1)
continue
match=matchlastname.match(line)
if (match!=None):
lastname=match.group(1)
continue
match=matchemail.match(line)
if (match!=None):
email=match.group(1)
continue
match=matchaddress.match(line)
if (match!=None):
address=match.group(1)
continue
match=matchcity.match(line)
if (match!=None):
city=match.group(1)
continue
match=matchcountry.match(line)
if (match!=None):
country=match.group(1)
continue
match=matchphone.match(line)
if (match!=None):
phone=match.group(1)
continue
oldrace=validrace(oldrace)
newrace=validrace(newrace)
if (email==None):
error("enno@eressea.upb.de",
"Es wurde keine Emailadresse angegeben: "+firstname+" "+lastname)
elif (oldrace==None) & (newrace==None):
error(email, "Es wurde kein Spiel ausgewählt.")
elif (firstname==None):
error(email, "Es wurde kein Vorname angegeben")
elif (lastname==None):
error(email, "Es wurde kein Nachname angegeben")
elif (address==None):
error(email, "Es wurde keine Adresse angegeben")
elif (city==None):
error(email, "Es wurde kein Wohnort angegeben")
elif (country==None):
error(email, "Es wurde kein Land angegeben")
else:
if (phone==None):
phone = "NULL"
cursor=db.cursor()
cursor.execute("INSERT INTO users (firstname, lastname, email, address, city, phone, country, password) "+
"VALUES ('"+firstname+"', '"+lastname+"', '"+email+"', '"+address+"', '"+city+"', '"+phone+"', "+country+", '"+genpasswd()+"')")
if (oldrace!=None):
cursor.execute("INSERT INTO subscriptions (user, race, game) "+
"VALUES (LAST_INSERT_ID(), '"+oldrace+"', 1)")
if (newrace!=None):
cursor.execute("INSERT INTO subscriptions (user, race, game) "+
"VALUES (LAST_INSERT_ID(), '"+newrace+"', 1)")
errors.close()
unlock(sys.argv[1]+".err")

3
scripts/register/test.py Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/python
import sys
print sys.argv[0], sys.argv[1]