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