Implemented a simple Password scheme.

Added a Help link to the FAQ Edit Wizard.
This commit is contained in:
Guido van Rossum 1997-05-23 22:29:24 +00:00
parent f8f0fb7069
commit a78a3c30dd

View file

@ -44,6 +44,8 @@ XXX Code organization TO DO
# NB for timing purposes, the imports are at the end of this file # NB for timing purposes, the imports are at the end of this file
PASSWORD = "Spam"
NAMEPAT = "faq??.???.htp" NAMEPAT = "faq??.???.htp"
NAMEREG = "^faq\([0-9][0-9]\)\.\([0-9][0-9][0-9]\)\.htp$" NAMEREG = "^faq\([0-9][0-9]\)\.\([0-9][0-9][0-9]\)\.htp$"
@ -75,7 +77,7 @@ class FAQServer:
KEYS = ['req', 'query', 'name', 'text', 'commit', 'title', KEYS = ['req', 'query', 'name', 'text', 'commit', 'title',
'author', 'email', 'log', 'section', 'number', 'add', 'author', 'email', 'log', 'section', 'number', 'add',
'version', 'edit'] 'version', 'edit', 'password']
def __getattr__(self, key): def __getattr__(self, key):
if key not in self.KEYS: if key not in self.KEYS:
@ -94,7 +96,7 @@ class FAQServer:
return value return value
def do_frontpage(self): def do_frontpage(self):
self.prologue("Python FAQ (alpha) Front Page") self.prologue("Python FAQ (beta test) Front Page")
print """ print """
<UL> <UL>
<LI><A HREF="faq.py?req=index">FAQ index</A> <LI><A HREF="faq.py?req=index">FAQ index</A>
@ -330,7 +332,8 @@ class FAQServer:
if not headers: if not headers:
self.error("Invalid file name", name) self.error("Invalid file name", name)
return return
self.prologue("Python FAQ Edit Form") self.prologue("Python FAQ Edit Wizard - Edit Form")
print '<A HREF="/python/faqhelp.html">Click for Help</A>'
title = headers['title'] title = headers['title']
version = self.getversion(name) version = self.getversion(name)
print "<FORM METHOD=POST ACTION=faq.py>" print "<FORM METHOD=POST ACTION=faq.py>"
@ -362,13 +365,15 @@ class FAQServer:
if not headers: if not headers:
self.error("Invalid file name", name) self.error("Invalid file name", name)
return return
if self.author and '@' in self.email: if self.author or '@' in self.email or self.password:
self.set_cookie(self.author, self.email) self.set_cookie(self.author, self.email, self.password)
self.prologue("Python FAQ Review Form") self.prologue("Python FAQ Edit Wizard - Review Form")
print '<A HREF="/python/faqhelp.html">Click for Help</A>'
print "<HR>" print "<HR>"
self.show(name, title, text, edit=0) self.show(name, title, text, edit=0)
print "<FORM METHOD=POST ACTION=faq.py>" print "<FORM METHOD=POST ACTION=faq.py>"
if self.log and self.author and '@' in self.email: if self.password == PASSWORD \
and self.log and self.author and '@' in self.email:
print """ print """
<INPUT TYPE=submit NAME=commit VALUE="Commit"> <INPUT TYPE=submit NAME=commit VALUE="Commit">
Click this button to commit the change. Click this button to commit the change.
@ -378,8 +383,9 @@ class FAQServer:
""" """
else: else:
print """ print """
To commit this change, please enter your name, To commit this change, please enter a log message,
email and a log message in the form below. your name, your email address,
and the correct password in the form below.
<P> <P>
<HR> <HR>
<P> <P>
@ -434,7 +440,13 @@ class FAQServer:
def checkin(self): def checkin(self):
import regsub, time, tempfile import regsub, time, tempfile
name = self.name name = self.name
password = self.password
if password != PASSWORD:
self.error("Invalid password.")
return
if not (self.log and self.author and '@' in self.email):
self.error("No log message, no author, or invalid email.")
return
headers, oldtext = self.read(name) headers, oldtext = self.read(name)
if not headers: if not headers:
self.error("Invalid file name", name) self.error("Invalid file name", name)
@ -549,7 +561,7 @@ class FAQServer:
output = p.read() output = p.read()
sts = p.close() sts = p.close()
if not sts: if not sts:
self.set_cookie(author, email) self.set_cookie(author, email, password)
self.prologue("Python FAQ Entry Edited") self.prologue("Python FAQ Entry Edited")
print "<HR>" print "<HR>"
self.show(name, title, text) self.show(name, title, text)
@ -561,9 +573,9 @@ class FAQServer:
if output: if output:
print "<PRE>%s</PRE>" % cgi.escape(output) print "<PRE>%s</PRE>" % cgi.escape(output)
def set_cookie(self, author, email): def set_cookie(self, author, email, password):
name = "Python-FAQ-ID" name = "Python-FAQ-ID"
value = "%s;%s" % (author, email) value = "%s/%s/%s" % (author, email, password)
import urllib import urllib
value = urllib.quote(value) value = urllib.quote(value)
print "Set-Cookie: %s=%s; path=/cgi-bin/;" % (name, value), print "Set-Cookie: %s=%s; path=/cgi-bin/;" % (name, value),
@ -585,36 +597,48 @@ class FAQServer:
key, value = word[:i], word[i+1:] key, value = word[:i], word[i+1:]
cookies[key] = value cookies[key] = value
if not cookies.has_key('Python-FAQ-ID'): if not cookies.has_key('Python-FAQ-ID'):
return "", "" return "", "", ""
value = cookies['Python-FAQ-ID'] value = cookies['Python-FAQ-ID']
import urllib import urllib
value = urllib.unquote(value) value = urllib.unquote(value)
i = string.rfind(value, ';') words = string.split(value, '/')
author, email = value[:i], value[i+1:] while len(words) < 3:
return author, email words.append('')
author = string.join(words[:-2], '/')
email = words[-2]
password = words[-1]
return author, email, password
def showedit(self, name, title, text): def showedit(self, name, title, text):
author = self.author author = self.author
email = self.email email = self.email
password = self.password
if not author or not email: if not author or not email:
a, e = self.get_cookie() a, e, p = self.get_cookie()
author = author or a author = author or a
email = email or e email = email or e
password = password or p
print """ print """
Title: <INPUT TYPE=text SIZE=70 NAME=title VALUE="%s"><BR> Title: <INPUT TYPE=text SIZE=70 NAME=title VALUE="%s"><BR>
<TEXTAREA COLS=80 ROWS=20 NAME=text>%s</TEXTAREA> <TEXTAREA COLS=80 ROWS=20 NAME=text>%s\n</TEXTAREA>""" % (
""" % (self.escape(title), cgi.escape(string.strip(text))) self.escape(title), cgi.escape(string.strip(text)))
print """ print """<BR>
<BR>
Log message (reason for the change):<BR> Log message (reason for the change):<BR>
<TEXTAREA COLS=80 ROWS=5 NAME=log>%s\n</TEXTAREA> <TEXTAREA COLS=80 ROWS=5 NAME=log>%s\n</TEXTAREA><BR>
<BR>
Please provide the following information for logging purposes: Please provide the following information for logging purposes:
<BR> <TABLE FRAME=none COLS=2>
<CODE>Name : </CODE><INPUT TYPE=text SIZE=40 NAME=author VALUE="%s"> <TR>
<BR> <TD>Name:
<CODE>Email: </CODE><INPUT TYPE=text SIZE=40 NAME=email VALUE="%s"> <TD><INPUT TYPE=text SIZE=40 NAME=author VALUE="%s">
""" % (self.escape(self.log), self.escape(author), self.escape(email)) <TR>
<TD>Email:
<TD><INPUT TYPE=text SIZE=40 NAME=email VALUE="%s">
<TR>
<TD>Password:
<TD><INPUT TYPE=password SIZE=40 NAME=password VALUE="%s">
</TABLE>
""" % (self.escape(self.log), self.escape(author),
self.escape(email), self.escape(password))
def escape(self, s): def escape(self, s):
import regsub import regsub