diff --git a/scripts/cgi-bin/eressea-confirm.py b/scripts/cgi-bin/eressea-confirm.py new file mode 100755 index 000000000..8f55c133c --- /dev/null +++ b/scripts/cgi-bin/eressea-confirm.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +import sys +import MySQLdb +import cgi +import re + +# specify the filename of the template file +scripturl="http://eressea.upb.de/~enno/cgi-bin/eressea-confirm.py" +HTMLTemplate = "eressea.html" +DefaultTitle = "Eressea Anmeldung" +dbname = "eressea" +db=None + +# define a new function called Display +# it takes one parameter - a string to Display +def Display(Content, Title=DefaultTitle): + TemplateHandle = open(HTMLTemplate, "r") # open in read only mode + # read the entire file as a string + TemplateInput = TemplateHandle.read() + TemplateHandle.close() # close the file + + # 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("", Title, TemplateInput) + SubResult = re.subn("", Content, SubResult[0]) + if SubResult[1] == 0: + raise BadTemplateException + + print "Content-Type: text/html\n\n" + print SubResult[0] + return + + +def GetKey(Form, key): + if Form.has_key(key): + value=Form[key].value + if value!="": + return value + return None + + +def genpasswd(): + newpasswd="" + chars = string.letters + string.digits + for i in range(8): + newpasswd = newpasswd + choice(chars) + return newpasswd + + +Form = cgi.FieldStorage() + +custid=GetKey(Form, "custid") +password=GetKey(Form, "password") + +if (password==None) or (custid==None): + output="
Um Deine Anmeldung zu bestätigen musst Du das Formular vollständig ausfüllen.\n "
+ for key in Form.keys():
+ output=output+"
"+str(key)+"="+str(Form[key])
+ Display(output)
+else:
+ db=MySQLdb.connect(db=dbname)
+ cursor=db.cursor()
+ exist=cursor.execute("select id from users where id="+custid+" and password='"+password+"'")
+ if exist==0:
+ Display('
Kundennummer oder Schlüssel falsch. Bitte beachte, dass Du beim Schlüssel auf Groß- und Kleinschreibung achten mußt.') + else: + cursor.execute("update users set status='CONFIRMED' where password='"+password+"' and id="+custid) + Display("
Deine Anmeldung wurde bestätigt.");
+ db.close()
diff --git a/scripts/cgi-bin/eressea-register.py b/scripts/cgi-bin/eressea-register.py
new file mode 100755
index 000000000..a599c8bec
--- /dev/null
+++ b/scripts/cgi-bin/eressea-register.py
@@ -0,0 +1,121 @@
+#!/usr/bin/env python
+
+import sys
+import MySQLdb
+import cgi
+import re
+import string
+import smtplib
+from whrandom import choice
+
+# specify the filename of the template file
+scripturl="http://eressea.upb.de/~enno/cgi-bin/eressea-register.py"
+HTMLTemplate = "eressea.html"
+MailTemplate="register.mail"
+DefaultTitle = "Eressea Anmeldung"
+dbname = "eressea"
+From = "accounts@eressea-pbem.de"
+smtpserver = 'localhost'
+db=None
+
+# define a new function called Display
+# it takes one parameter - a string to Display
+def Display(Content, Title=DefaultTitle):
+ TemplateHandle = open(HTMLTemplate, "r") # open in read only mode
+ # read the entire file as a string
+ TemplateInput = TemplateHandle.read()
+ TemplateHandle.close() # close the file
+
+ # 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("", Title, TemplateInput)
+ SubResult = re.subn("", Content, SubResult[0])
+ if SubResult[1] == 0:
+ raise BadTemplateException
+
+ print "Content-Type: text/html\n\n"
+ print SubResult[0]
+ return
+
+
+def Send(email, custid, firstname, password, position):
+ TemplateHandle = open(MailTemplate, "r") # open in read only mode
+ # read the entire file as a string
+ TemplateInput = TemplateHandle.read()
+ TemplateHandle.close() # close the file
+
+ SubResult = re.subn(" Um Dich zu Eressea anzumelden musst Du das Formular vollständig ausfüllen.\n "
+ for key in Form.keys():
+ output=output+" Du stehst bereits auf der Warteliste')
+ else:
+ password=genpasswd()
+ fields = "firstname, lastname, email, address, city, status, password"
+ values = "'"+firstname+"', '"+lastname+"', '"+email+"', '"+address+"', '"+city+"', 'WAITING', '"+password+"'"
+ if phone!=None:
+ fields=fields+", phone"
+ values=values+", '"+phone+"'"
+ if info!=None:
+ fields=fields+", info"
+ values=values+", '"+info+"'"
+ if country!=None:
+ fields=fields+", country"
+ values=values+", "+country+""
+ cursor.execute("insert into users ("+fields+") VALUES ("+values+")")
+ cursor.execute("SELECT LAST_INSERT_ID() from dual")
+ custid=cursor.fetchone()[0]
+ cursor.execute("insert into subscriptions (user, race, game, status) VALUES ("+str(int(custid))+", '"+race+"', 0, 'PENDING')")
+ cursor.execute("select count(*) from users")
+ Send(email, custid, firstname, password, cursor.fetchone()[0])
+ Display(" Deine Anmeldung wurde bearbeitet. Eine EMail mit Hinweisen ist unterwegs zu Dir.")
+ db.close()
diff --git a/scripts/cgi-bin/eressea.html b/scripts/cgi-bin/eressea.html
new file mode 100644
index 000000000..7dd87d963
--- /dev/null
+++ b/scripts/cgi-bin/eressea.html
@@ -0,0 +1,53 @@
+
+
+ Um eine der folgenden Parteien zu übernehmen, musst du zuerst ein Spielerkonto anlegen. Wenn Du eines hast, markiere die Partei, die Du übernehmen willst, und trage Kundennummer und Kundenpasswort ein.'
- 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'"
+ 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"
results = cursor.execute(query)
output=output+'
"+str(key)+"="+str(Form[key])
+ Display(output)
+else:
+ db=MySQLdb.connect(db=dbname)
+ cursor=db.cursor()
+ exist=cursor.execute("select id from users where email='"+email+"' and (status='WAITING' or status='PENDING')")
+ if exist>0:
+ Display('
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/scripts/cgi-bin/info.py b/scripts/cgi-bin/info.py
index eb9bd3eb8..2f8b54e5b 100755
--- a/scripts/cgi-bin/info.py
+++ b/scripts/cgi-bin/info.py
@@ -85,6 +85,11 @@ def ShowInfo(custid, Password):
cursor.execute("select max(date), max(id) from transactions")
lastdate, id = cursor.fetchone()
+ nraces = cursor.execute("select distinct race, name from races where locale='de'")
+ races=[('', 'Keine Anmeldung')]
+ while nraces>0:
+ nraces = nraces - 1
+ races.append(cursor.fetchone())
query=("select firstname, lastname, email, address, city, country, phone, status "+
"from users "+
"where id="+str(custid)+" and password='"+Password+"' ")
@@ -130,24 +135,26 @@ def ShowInfo(custid, Password):
while games>0:
games=games-1
gid, game, status, info = cursor.fetchone()
-
+ cself = db.cursor();
+ sub = cself.execute("select s.race from subscriptions s, users u where game="+str(int(gid))+" and u.id=s.user and u.id="+str(int(custid)))
+ prev=""
+ if sub>0:
+ prev=cself.fetchone()[0]
+ if prev==None:
+ prev=""
line = '
+
+
+
+
+
+
+
+
+
+
+
+
+
+\n
'
if status=='WAITING':
line = line+'' + game + ': ' + info + ' '
elif status=='RUNNING':
@@ -226,6 +233,27 @@ def Save(custid, Password):
cursor=db.cursor()
cursor.execute('UPDATE users SET '+values+' where id='+str(custid))
+ ngames = cursor.execute("select id from games where status='WAITING'")
+ while ngames > 0:
+ ngames=ngames - 1
+ gid = cursor.fetchone()[0]
+ key="race_"+str(int(gid))
+ if Form.has_key(key):
+ update = db.cursor()
+ newrace=Form[key].value
+ if newrace=='':
+ newrace=None
+ if newrace==None:
+ update.execute('delete from subscriptions where user='+str(int(custid))+' and game='+str(int(gid)))
+ else:
+ exist=update.execute('select id, race from subscriptions where game='+str(int(gid))+' and user='+str(int(custid)))
+ if exist>0:
+ sid, race = update.fetchone()
+ if race!=newrace:
+ update.execute("update subscriptions set race='"+newrace+"' where id="+str(int(sid)))
+ else:
+ update.execute("insert subscriptions (race, user, status, game) values ('"+newrace+"', "+str(int(custid))+", 'WAITING', "+str(int(gid))+") where id="+str(int(sid)))
+
nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='ACTIVE' and s.user="+str(custid) + " and s.game=g.id")
while nfactions > 0:
game, sid, faction = cursor.fetchone()
diff --git a/scripts/cgi-bin/register.mail b/scripts/cgi-bin/register.mail
new file mode 100644
index 000000000..d910c47d4
--- /dev/null
+++ b/scripts/cgi-bin/register.mail
@@ -0,0 +1,22 @@
+Hallo '
line = line + 'Ich möchte an diesem Spiel teilnehmen, und bevorzuge folgende Rasse:
\n'
- line = line + '