summaryrefslogtreecommitdiffstats
path: root/cgi-bin/ml-request
blob: 9a21d0bd6ca1e1bc9967507e2e2c45b3ddf45bd1 (plain)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#! /bin/sh

CONVAWK=/www/sourceware/cgi-bin/conv.awk
MAIL=/usr/bin/Mail

HEADER=/www/sourceware/htdocs/include/header-subpages.html
FOOTER=/www/sourceware/htdocs/include/footer-subpages.html

case "$REQUEST_METHOD" in
    POST) QUERY_STRING=`cat` ;;
esac

if [ ! -f /usr/bin/gawk ]
then
     GAWK=gawk
else
     GAWK=/usr/bin/gawk
fi

normalize()
{
   resultstr="`echo $1 | sed 's/+/ /g'`" # first convert +s to spaces
   resultstr=`echo $resultstr | $GAWK -f $CONVAWK`

} # normalize()

##  input on stdin will be of the format
##  username=emailaddr@domain.com
##  listname=mailing-list-name

hasgoodform=0
email=""
cmdargs=""
prnum=""
format=""

for i in `echo $QUERY_STRING | awk '-F&' '{for (i = 1 ; i <= NF ; i++)  \
                                    printf "%s\n" , $i }'`
do
   normalize $i     # modifies global var ``resultstr''

   case "$resultstr" in
          username=*) email=`echo $resultstr | sed 's/^username=//' | tr '[A-Z]' '[a-z]'`
                      resultstr="" ;;
          listname=*) listname=`echo $resultstr | sed -e 's/^listname=//' -e 's,@.*$,,' | tr '[A-Z]' '[a-z]'`
                      resultstr="" ;;
          operation=*) operation=`echo $resultstr | sed 's/^operation=//'`
                      resultstr="" ;;
          digest=*) digest=`echo $resultstr | sed 's/^digest=//'`
                      resultstr="" ;;
          *) resultstr="" ;;
   esac
done

error=0

if [ -z "$operation" ]
then
  error=1
fi

if [ "$operation" != subscribe -a "$operation" != unsubscribe ]
then
  error=1
fi

if [ -n "$digest" -a "$digest" != on -a "$digest" != off ]
then
  error=1
fi

if [ $error -eq 1 ]
then
  echo "Content-type: text/html"
  echo ""
  echo "<HTML>"
  echo "<head>"
  echo "<TITLE>Cannot add you to the mailing list at this time...</TITLE>"
  echo "</head>"
  cat $HEADER

  echo "<p>There was an internal error in this script.  Please report"
  echo "this problem to sourcemaster@sourceware.org."

  cat $FOOTER
  exit 0
fi

# echo "Content-type: text/html"
# echo "<HTML>"
# echo "<head>"
# echo "<TITLE>HELLO</TITLE>"
# echo "</head>"
# echo "<body>echo "LISTNAME $listname</body></HTML>"

if expr "$email" : '[a-zA-Z0-9._+-]*@[a-zA-Z0-9._-]*$' && expr "$listname" : '[a-zA-Z0-9._+-]*$'; then
  hasgoodform=1
else
  hasgoodform=0
fi >/dev/null

if [ -z "$listname" ]
then
  has_listname=0
else
  if [ -d /qmail/lists*/$listname ]
  then
    has_listname=1
  else
    has_listname=0
  fi
fi

if [ "x$digest" = "xon" ]
then
  digest=digest-
else
  digest=
fi

##
## Digest versions of announce lists don't make any sense; undo that.
##

if echo "$listname" | grep announce >/dev/null 2>&1
then
  if [ "$digest" = "digest-" ]
  then
    digest_changed=1
    digest=""
  fi
fi

if [ -n "$email" -a "$hasgoodform" -eq 1 -a "$has_listname" -eq 1 ]
then

  if [ "$operation" = "subscribe" ]
  then
    sub_prefix=""
    sub_direction="to"
  else
    sub_prefix="un"
    sub_direction="from"
  fi

  echo "Content-type: text/html"
  echo ""
  echo "<HTML>"
  echo "<head>"
  echo "<TITLE>Your ${sub_prefix}subscribe request is being sent in...</TITLE>"
  echo "</head>"
  cat $HEADER

  QMAILHOST=sourceware.org
  export QMAILHOST
  orig_email="${email}"
  email="`echo ${email} | sed 's,@,=,g'`"
  echo "" | $MAIL "${listname}-${digest}${operation}-${email}@sourceware.org"

  echo "<h2>Your ${sub_prefix}subscribe request is being sent in...</h2>"

  echo "<p>Your request to ${sub_prefix}subscribe the address ${orig_email} ${sub_direction}"

  echo "the mailing list <code>\"${listname}\""
  if [ "$digest" = "digest-" ]
  then
    echo '(digest version)'
  fi
  
  echo "</code> has been received."

  
  echo '<p>'
  echo "An e-mail note will be sent to"
  echo "<tt>${orig_email}</tt> to confirm that this address works properly."
  echo "Send that confirmation note"
  echo "back (reply to it), and your request will be finished.  "
  echo "If you do not see this"
  echo "confirmation note soon, please try submitting your request again.  "
  echo "<p>You can"
  echo "also do your request by sending an e-mail note to"
  echo "<code>${listname}-${digest}${operation}@sourceware.org</code>"
  echo "<p>The message body and Subject line are ignored."

  echo "<p>See the"
  echo "<a href=\"http://sourceware.org/lists.html#faqs\">mailing"
  echo "list FAQ page</a> for more information."
else
  if [ "$has_listname" -eq 1 ]
  then
    echo "Content-type: text/html"
    echo ""
    echo "<HTML>"
    echo "<head>"
    echo "<TITLE>Cannot handle your mailing list request...</TITLE>"
    echo "</head>"
    cat $HEADER
  
    echo '<h2>Cannot handle your mailing list request...</h2>'
    echo '<p>'
    echo "Something is wrong with the e-mail address.  Maybe it is empty,"
    echo "or possibly you did not include any @ sign or dots in the"
    echo "domain name.  Sorry, we don't support UUCP mail addresses.  "
    echo "Please go back"
    echo "and give it another try."

    echo "<p>You can"
    echo "also subscribe by sending an e-mail note to"
    echo "<code>LISTNAME-[digest-][un]subscribe@sourceware.org</code>"
    echo "<p>The message body and Subject line are ignored."

    echo "<p>See the"
    echo "<a href=\"http://sourceware.org/ml/index.html#faqs\">sourceware"
    echo "mailing list FAQ page</a> for more information."
  else
    echo "Content-type: text/html"
    echo ""
    echo "<HTML>"
    echo "<head>"
    echo "<TITLE>Cannot handle your mailing list request at this time...</TITLE>"
    echo "</head>"
    cat $HEADER

    echo '<h2>Cannot handle your mailing list request at this time...</h2>'

    echo '<p>'
    echo "You did not provide a mailing list name, or you've entered a mailing"
    echo 'list name which is not handled on <tt>sourceware.org</tt>.'

    echo '<p>If you are trying to (un)subscribe to/from a mailing list hosted at <b>gnu.org</b>,'
    echo "send a mail note to <b>LISTNAME-request@gnu.org</b> with a message body"
    echo like, \"subscribe LISTNAME\".

    echo "<p>See the"
    echo "<a href=\"http://sourceware.org/ml/index.html#faqs\">sourceware"
    echo "mailing list FAQ page</a> for more information."
  fi
fi

cat $FOOTER

exit 0