server/scripts/cgi-bin/standin.py

125 lines
5.0 KiB
Python
Raw Normal View History

2002-03-03 19:20:34 +01:00
#!/usr/bin/env python
import smtplib
import MySQLdb
import cgi
import re
# specify the filename of the template file
scripturl='http://eressea.upb.de/~enno/cgi-bin/standin.py'
TemplateFile = "vinyambar.html"
DefaultTitle = "Vinyambar Parteib<69>rse"
dbname = "vinyambar"
From = "accounts@vinyambar.de"
Errors = ""
db = MySQLdb.connect(db=dbname)
smtpserver='localhost'
2002-04-03 00:33:07 +02:00
notify='accounts@vinyambar.de'
2002-04-05 22:35:22 +02:00
minnmr=0
2002-03-03 19:20:34 +01:00
# define a new function called Display
# it takes one parameter - a string to Display
def Display(Content, Title=DefaultTitle):
TemplateHandle = open(TemplateFile, "r") # open in read only mode
# read the entire file as a string
TemplateInput = TemplateHandle.read()
TemplateHandle.close() # close the file
# for key in Form.keys():
# Content=Content+"<br>"+str(key)+"="+str(Form[key])
# this defines an exception string in case our
# template file is messed up
BadTemplateException = "There was a problem with the HTML template."
SubResult = re.subn("<!-- INSERT TITLE HERE -->", Title, TemplateInput)
SubResult = re.subn("<!-- INSERT CONTENT HERE -->", Content, SubResult[0])
if SubResult[1] == 0:
raise BadTemplateException
print "Content-Type: text/html\n\n"
print SubResult[0]
return
def ShowPage():
cursor=db.cursor()
maxturn = {}
games = cursor.execute("SELECT max(lastturn), game from subscriptions GROUP by game")
while games>0:
games=games-1
lastturn, game = cursor.fetchone()
maxturn[game] = lastturn
output='<p>Um eine der folgenden Parteien zu <20>bernehmen, musst du zuerst ein <a href="register.php">Spielerkonto anlegen</a>. Wenn Du eines hast, markiere die Partei, die Du <20>bernehmen willst, und trage Kundennummer und Kundenpasswort ein.'
2002-03-17 18:13:59 +01:00
query = "SELECT g.id, g.name, s.faction, s.lastturn, s.id, r.name, s.info from games g, subscriptions s, races r where s.game=g.id and s.race=r.race and s.status='CANCELLED' order by s.lastturn DESC"
2002-03-03 19:20:34 +01:00
results = cursor.execute(query)
2002-03-04 11:34:05 +01:00
output=output+'<div align=center><form action="'+scripturl+'" method=post><table bgcolor="#e0e0e0" width="80%" border>\n'
2002-03-03 19:20:34 +01:00
output=output+'<tr><th>Rasse</th><th>Spiel</th><th>NMRs</th><th>Informationen</th><th>Markieren</th></tr>'
while results>0:
results=results-1
gid, game, faction, lastturn, sid, race, info = cursor.fetchone()
2002-04-05 22:35:22 +02:00
if lastturn<=maxturn[gid]+minnmr:
2002-04-03 00:33:07 +02:00
if info==None:
info='Keine Informationen'
output=output+'<tr><td>'+ race + '</td><td>'+ game + '</td><td>' + str(int(maxturn[gid]-lastturn)) + '</td><td>' + info + '</td>'
output=output+'<td><input type="checkbox" name="accept_' + str(int(sid)) + '"> <20>bernehmen</td></tr>\n'
2002-03-03 19:20:34 +01:00
output=output+'</table>'
2002-03-04 11:34:05 +01:00
output=output+'<p><table><tr><td>Kundennummer:</td><td><input name="user" size="4"></tr><tr><td>Passwort:</td><td><input name="pass" type="password" size="40"></td>'
output=output+'<tr><td>'
output=output+'<input name="save" type="submit" value="Abschicken">'
output=output+'</td></tr></table>'
# output=output+'<p>Aus technischen Gr<47>nden wird diese Seite erst am Dienstag abend wieder benutzbar sein.'
2002-03-03 19:20:34 +01:00
output=output+'</form></div>'
Display(output)
return
Form = cgi.FieldStorage()
custid=None
password=None
if Form.has_key("user"):
custid = int(Form["user"].value)
if Form.has_key("pass"):
password = Form["pass"].value
if (password!=None) & (custid!=None):
cursor=db.cursor()
output=""
2002-04-03 00:33:07 +02:00
if cursor.execute("select firstname, lastname, email, id from users where password='"+password+"' and id="+str(int(custid)))==1:
firstname, lastname, email, custid = cursor.fetchone()
2002-03-17 18:13:59 +01:00
c = cursor.execute("SELECT id, game, password, faction from subscriptions where status='CANCELLED'")
2002-03-03 19:20:34 +01:00
while c>0:
c=c-1
2002-03-17 18:13:59 +01:00
sid, gid, newpass, faction = cursor.fetchone()
2002-03-03 19:20:34 +01:00
if Form.has_key("accept_"+str(int(sid))):
update = db.cursor()
update.execute("UPDATE subscriptions set user=" + str(int(custid)) + ", status='ACTIVE' where id=" + str(int(sid)))
output=output+"Die Partei " + faction + " wurde Dir <20>berschrieben. Eine Email mit dem Passwort und weiteren Hinweisen ist unterwegs zu Dir.<br>"
2002-04-03 00:33:07 +02:00
server=smtplib.SMTP(smtpserver)
2002-03-03 19:20:34 +01:00
Msg="From: "+From+"\nTo: "+email+"\nSubject: Vinambar Parteiuebernahme\n\n"
Msg=Msg+"Das Passwort f<>r deine neue Vinyambar-Partei "+faction+" lautet\n"
2002-03-17 18:13:59 +01:00
Msg=Msg+" "+newpass+"\n"
2002-03-03 19:20:34 +01:00
Msg=Msg+"\nUm den Report der letzten Woche zu erhalten, schicke eine Mail mit dem Betreff\n"
2002-03-17 18:13:59 +01:00
Msg=Msg+"VIN"+str(int(gid))+" REPORT "+faction+" \""+newpass+"\" an die Adresse "
Msg=Msg+"vinyambar@eressea.amber.kn-bremen.de"
2002-03-03 19:20:34 +01:00
server.sendmail(From, email, Msg)
2002-04-03 00:33:07 +02:00
Msg="From: "+From+"\nTo: "+notify+"\nSubject: Vinambar Parteiuebernahme\n\n"
Msg=Msg+"Die Partei "+faction+" wurde <20>bernommen.\n"
Msg=Msg+" Spieler: "+str(int(custid))+"\n"
Msg=Msg+" Name : "+firstname+" "+lastname+"\n"
Msg=Msg+" email : "+email+"\n"
server.sendmail(From, notify, Msg)
2002-03-03 19:20:34 +01:00
server.close()
else:
output="<font color=red>Fehler in Passwort oder Kundennummer<br></font>"
Display(output)
else:
ShowPage()
db.close()