| 1 |
#!/usr/bin/python2.2 |
#!/usr/bin/python |
| 2 |
# vim: expandtab |
# vim: expandtab |
| 3 |
|
|
| 4 |
# Copyright 2002 Raphaël Hertzog |
# Copyright 2002 Raphaël Hertzog |
| 5 |
# Available under the terms of the General Public License version 2 |
# Available under the terms of the General Public License version 2 |
| 6 |
# or (at your option) any later version. |
# or (at your option) any later version. |
| 7 |
|
|
| 8 |
import cgi, urllib, sys, email, smtplib |
import cgi, urllib, sys, smtplib, string |
| 9 |
import cgitb; cgitb.enable() |
#import cgitb; cgitb.enable() |
| 10 |
|
|
| 11 |
form = cgi.FieldStorage() |
form = cgi.FieldStorage() |
| 12 |
pkg = form.getfirst("package", "") |
pkg = "" |
| 13 |
addr = form.getfirst("email", "") |
addr = "" |
| 14 |
|
what = "" |
| 15 |
|
advanced = "" |
| 16 |
|
if form.has_key("package"): pkg = form["package"].value |
| 17 |
|
if form.has_key("email"): addr = form["email"].value |
| 18 |
|
if form.has_key("what"): what = form["what"].value |
| 19 |
|
if form.has_key("advanced"): advanced = form["advanced"].value |
| 20 |
command = "" |
command = "" |
| 21 |
|
|
| 22 |
if addr.find("@") == -1: |
if string.find(addr, "@") == -1: |
| 23 |
print "Content-Type: text/html" |
print "Content-Type: text/html" |
| 24 |
print |
print |
| 25 |
print "<html><body><h2 style='color:red'>The submitted email is invalid : " + addr + "</h2></body></html>" |
print "<html><body><h2 style='color:red'>The submitted email is invalid : " + addr + "</h2></body></html>" |
| 26 |
sys.exit(0) |
sys.exit(0) |
| 27 |
|
|
| 28 |
if form.getfirst("what") == "subscribe": |
if what == "subscribe": |
| 29 |
command = "subscribe %s %s\n" % (pkg, addr) |
command = "subscribe %s %s\n" % (pkg, addr) |
| 30 |
elif form.getfirst("what") == "unsubscribe": |
elif what == "unsubscribe": |
| 31 |
command = "unsubscribe %s %s\n" % (pkg, addr) |
command = "unsubscribe %s %s\n" % (pkg, addr) |
| 32 |
elif form.getfirst("what") == "advanced": |
elif what == "advanced": |
| 33 |
f = open("subscription.html", "r") |
f = open("subscription.html", "r") |
| 34 |
print "Content-Type: text/html" |
print "Content-Type: text/html" |
| 35 |
print |
print |
| 36 |
while 1: |
while 1: |
| 37 |
line = f.readline() |
line = f.readline() |
| 38 |
if not line: break #eof |
if not line: break #eof |
| 39 |
line = line.replace("#PKG#", pkg) |
line = string.replace(line,"#PKG#", pkg) |
| 40 |
line = line.replace("#EMAIL#", addr) |
line = string.replace(line, "#EMAIL#", addr) |
| 41 |
print line, |
print line, |
| 42 |
sys.exit(0) |
sys.exit(0) |
| 43 |
else: |
else: |
| 44 |
sys.exit(1) |
sys.exit(1) |
| 45 |
|
|
| 46 |
if form.getfirst("advanced"): |
if advanced: |
| 47 |
# Add all tags treatment |
# Add all tags treatment |
| 48 |
command += "keyword %s %s =" % (pkg, addr) |
command = command + "keyword %s %s =" % (pkg, addr) |
| 49 |
for tag in ["bts", "bts-control", "upload-source", "upload-binary", "katie-other", "summary", "default", "cvs"]: |
for tag in ["bts", "bts-control", "upload-source", "upload-binary", "katie-other", "summary", "default", "cvs"]: |
| 50 |
if form.getfirst("kw_" + tag): |
choice = "" |
| 51 |
|
if form.has_key("kw_" + tag): choice = form["kw_" + tag].value |
| 52 |
|
if choice: |
| 53 |
command = command + " " + tag |
command = command + " " + tag |
| 54 |
command += "\n" |
command = command + "\n" |
| 55 |
|
|
| 56 |
msg = email.Message.Message() |
msg = """From: PTS Web Subscriber <%s> |
| 57 |
msg["From"] = "PTS Web Subscriber <%s>" % addr |
To: PTS Mailbot <pts@qa.debian.org> |
| 58 |
msg["To"] = "PTS Mailbot <pts@qa.debian.org>" |
Subject: Web subscription for %s package |
|
msg["Subject"] = "Web subscription for %s package" % pkg |
|
| 59 |
|
|
| 60 |
msg.add_payload(command) |
%s""" % (addr, pkg, command) |
| 61 |
|
|
| 62 |
smtp = smtplib.SMTP() |
smtp = smtplib.SMTP() |
| 63 |
smtp.connect() |
smtp.connect() |
| 64 |
smtp.sendmail("owner@packages.qa.debian.org", ["pts@qa.debian.org"], msg.as_string()) |
smtp.sendmail("owner@packages.qa.debian.org", ["pts@qa.debian.org"], msg) |
| 65 |
smtp.quit() |
smtp.quit() |
| 66 |
|
|
| 67 |
print "Content-Type: text/html" |
print "Content-Type: text/html" |
| 71 |
print "<p>Your command has been sent to the Package Tracking System mailbot" |
print "<p>Your command has been sent to the Package Tracking System mailbot" |
| 72 |
print "with the following mail :" |
print "with the following mail :" |
| 73 |
print "<blockquote><pre>" |
print "<blockquote><pre>" |
| 74 |
print cgi.escape(msg.as_string()) |
print cgi.escape(msg) |
| 75 |
print "</pre></blockquote>" |
print "</pre></blockquote>" |
| 76 |
print "You will soon receive a confirmation mail, please read it carefully." |
print "You will soon receive a confirmation mail, please read it carefully." |
| 77 |
print "</body></html>" |
print "</body></html>" |