summaryrefslogtreecommitdiff
path: root/cgi/subscribe
blob: 960e807b36b4000e51e2d8d9a169917c5aefd205 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/local/bin/python

"""Process listinfo form submission, ie subscriptions or roster requests."""

__version__ = "$Revision: 388 $"

import sys
sys.path.append('/home/mailman/mailman/modules')

import os, cgi, string
from regsub import gsub
import mm_utils, maillist, mm_err, mm_message, mm_cfg, htmlformat

try:
    sys.stderr = mm_utils.StampedLogger("error", label = 'subscribe',
                                        manual_reprime=1, nofail=0)
except IOError:
    pass                        # Oh well - SOL on redirect, errors show thru.

NEED_CONFIRM_NOTICE = """
A request for subscription of your address to the %s@%s
mailing list has been received via the web%s

This is a confirmation request, to prevent anyone from subscribing
you against your wishes.  In order to complete this subscription you
must send a confirming email, to %s, by 
repling to this mail, and including just the line: 

subscribe %s%s

in the body or as the subject line.  If you do not actually wish to
subscribe you need not do anything.  Upon subscribing you will receive 
a message welcoming you to the list and describing how to tailor your
account.

Questions or comments?
Send them to """ + mm_cfg.MAILMAN_OWNER

UNKNOWN_ERROR = '''An unknown error occured.  <p>
Please send mail to <a href=%s>%s</a> explaining
exactly what you did to get this error.<p>''' % (mm_cfg.MAILMAN_OWNER,
	mm_cfg.MAILMAN_OWNER)

doc = htmlformat.Document()

path = os.environ['PATH_INFO']
list_info = mm_utils.GetPathPieces(path)
list_name = string.lower(list_info[0])

if len(list_info) < 1:
    doc.AddItem(htmlformat.Header(2, "Error"))
    doc.AddItem(htmlformat.Bold("Invalid options to CGI script."))
    print doc.Format()
    sys.exit(0)

try:
  list = maillist.MailList(list_name)
except:
  doc.AddItem(htmlformat.Header(2, "Error"))
  doc.AddItem(htmlformat.Bold("%s: No such list." % list_name ))
  print doc.Format()
  sys.exit(0)


if not list._ready:
    doc.AddItem(htmlformat.Header(2, "Error"))
    doc.AddItem(htmlformat.Bold("%s: No such list." % list_name ))
    print doc.Format()
    sys.exit(0)

form = cgi.FieldStorage()

error = 0
results = ''

def call_script(which, pathinfo):
    "A little bit of a hack to call one of the scripts..."
    os.environ['PATH_INFO'] = string.join(pathinfo, '/')
    file = os.path.join(mm_cfg.MAILMAN_DIR, 'cgi/%s' % which)
    list.Unlock()
    execfile(file)
    sys.exit(0)

#######
# Preliminaries done, actual processing of the form input below.

if (form.has_key("UserOptions")
      or (form.has_key("info") and not form.has_key("email"))):
    # Go to user options section.
    if not form.has_key("info"):
	doc.AddItem(htmlformat.Header(2, "Error"))
        doc.AddItem(htmlformat.Bold("You must supply your email address."))
	doc.AddItem(list.GetMailmanFooter())
	print doc.Format()
	sys.exit(0)
    addr = form['info'].value
    member = list.FindUser(addr)
    if not list.FindUser(addr):
	doc.AddItem(htmlformat.Header(2, "Error"))
        doc.AddItem(htmlformat.Bold("%s has no subscribed addr <i>%s</i>."
                                    % (list.real_name, addr)))
	doc.AddItem(list.GetMailmanFooter())
	print doc.Format()
	sys.exit(0)
    call_script('options', [list._internal_name, member])

if not form.has_key("email"):
    error = 1
    results = results + "You must supply a valid email address.<br>"
else:
    email = form["email"].value
if not form.has_key("pw") or not form.has_key("pw-conf"):
    error = 1
    results = results + "You must supply a valid password, and confirm it.<br>"
else:
    pw  = form["pw"].value
    pwc = form["pw-conf"].value

if not error and (pw <> pwc):
    error = 1
    results = results + "Your passwords did not match.<br>"

if form.has_key("digest"):
    digest = eval(form["digest"].value)

if not list.digestable:
    digest = 0
elif not list.nondigestable:
    digest = 1


def PrintResults():
    replacements = list.GetStandardReplacements()
    replacements['<mm-results>'] = results
    output = list.ParseTags('subscribe.html', replacements)

    doc.AddItem(output)
    print doc.Format()
    list.Unlock()
    sys.exit(0)

if error:
    PrintResults()

else:

    try:
	list.AddMember(email, pw, digest, web_subscribe=1)
	results = results + ("You have successfully been added.  "
			     "You should receive confirmation by "
			     "e-mail within an hour.  If you do not "
			     "receive confirmation, then the email "
			     "address you gave probably bounced, "
			     "in which case you should try again.<p>")
    except mm_err.MMWebSubscribeRequiresConfirmation:
	results = results + ("Confirmation from your email address is "
			     "required, to prevent anyone from covertly "
			     "subscribing you.  Instructions are being "
			     "sent to you at %s." % email)
	if os.environ.has_key('REMOTE_HOST'):
	    remote = ", from\n%s. " % os.environ['REMOTE_HOST']
	elif os.environ.has_key('REMOTE_ADDR'):
	    remote = ", from\n%s." % os.environ['REMOTE_ADDR']
	else:
	    remote = "."
        if digest:
            digesting = " digest"
        else:
            digesting = ""
	list.SendTextToUser(subject = 'Subscribing to %s' % list.real_name,
			    recipient = email,
			    sender = list.GetRequestEmail(),
			    text = (NEED_CONFIRM_NOTICE
                                    % (list.real_name,
                                       list.host_name,
                                       remote,
                                       list.GetRequestEmail(),
                                       pw,
                                       digesting)),
                            add_headers = ["Errors-To: %s"
					   % list.GetAdminEmail()])
    except mm_err.MMBadEmailError:
	results = results + ("Mailman won't accept the given email "
			     "address as a valid address. (Does it "
			     "have an @ in it???)<p>")
    except mm_err.MMListNotReady:
        results = results + ("The list is not fully functional, and "
			     "can not accept subscription requests.<p>")
    except mm_err.MMNeedApproval, x:
        results = results + ("Subscription was <em>deferred</em> "
			     "because:<br> %s<p>Your request must "
			     "be approved by the list admin.  "
			     "You will receive email informing you "
			     "of the moderator's descision when they "
			     "get to your request.<p>" % x)
    except mm_err.MMHostileAddress:
        results = results + ("Your subscription is not allowed because "
			     "the email address you gave is insecure.<p>")
    except mm_err.MMAlreadyAMember:
        results = results + "You are already subscribed!<p>"
    except:
        results = results + UNKNOWN_ERROR

PrintResults()