Back to index

webcit  8.12-dfsg
listsub.c
Go to the documentation of this file.
00001 /*
00002  * Web forms for handling mailing list subscribe/unsubscribe requests.
00003  *
00004  * Copyright (c) 1996-2012 by the citadel.org team
00005  *
00006  * This program is open source software.  You can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License, version 3.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  */
00014 
00015 #include "webcit.h"
00016 
00017 /*
00018  * List subscription handling
00019  */
00020 #ifndef EXPERIMENTAL_LISTSUB
00021 void do_listsub(void)
00022 {
00023        char cmd[256];
00024        char room[256];
00025        char token[256];
00026        char email[256];
00027        char subtype[256];
00028        char escaped_email[256];
00029        char escaped_room[256];
00030 
00031        char buf[SIZ];
00032        int self;
00033        char sroom[SIZ];
00034 
00035        FlushStrBuf(WC->wc_fullname);
00036        FlushStrBuf(WC->wc_username);
00037        FlushStrBuf(WC->wc_password);
00038        FlushStrBuf(WC->CurRoom.name);
00039 
00040        output_headers(1, 0, 0, 1, 1, 0);
00041        begin_burst();
00042 
00043        wc_printf("<HTML><HEAD>\n"
00044               "<meta name=\"MSSmartTagsPreventParsing\" content=\"TRUE\" />\n"
00045               "<link href=\"static/styles/webcit.css\" rel=\"stylesheet\" type=\"text/css\">\n"
00046               "<TITLE>\n"
00047        );
00048        wc_printf(_("List subscription"));
00049        wc_printf("</TITLE></HEAD><BODY>\n");
00050 
00051        strcpy(cmd, bstr("cmd"));
00052        strcpy(room, bstr("room"));
00053        strcpy(token, bstr("token"));
00054        strcpy(email, bstr("email"));
00055        strcpy(subtype, bstr("subtype"));
00056 
00057        wc_printf("<div align=center>");
00058        wc_printf("<table border=0 width=75%%><tr><td>");
00059 
00060        do_template("box_begin_1");
00061        StrBufAppendBufPlain(WC->WBuf, _("List subscribe/unsubscribe"), -1, 0);
00062        do_template("box_begin_2");
00063        wc_printf("<div align=center><br>");
00064 
00065        /*
00066         * Subscribe command
00067         */
00068        if (!strcasecmp(cmd, "subscribe")) {
00069               serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
00070                      room,
00071                      email,
00072                      subtype,
00073                      ChrPtr(site_prefix)
00074               );
00075               serv_getln(buf, sizeof buf);
00076               if (buf[0] == '2') {
00077                      stresc(escaped_email, 256, email, 0, 0);
00078                      stresc(escaped_room, 256, room, 0, 0);
00079 
00080                      wc_printf("<CENTER><H1>");
00081                      wc_printf(_("Confirmation request sent"));
00082                      wc_printf("</H1>");
00083                      wc_printf(_("You are subscribing <TT>%s"
00084                             "</TT> to the <b>%s</b> mailing list.  "
00085                             "The listserver has "
00086                             "sent you an e-mail with one additional "
00087                             "Web link for you to click on to confirm "
00088                             "your subscription.  This extra step is for "
00089                             "your protection, as it prevents others from "
00090                             "being able to subscribe you to lists "
00091                             "without your consent.<br><br>"
00092                             "Please click on the link which is being "
00093                             "e-mailed to you and your subscription will "
00094                             "be confirmed.<br>\n"),
00095                             escaped_email, escaped_room);
00096                      wc_printf("<a href=\"listsub\">%s</A></CENTER>\n", _("Go back..."));
00097               }
00098               else {
00099                      wc_printf("<FONT SIZE=+1><B>ERROR: %s</B>"
00100                             "</FONT><br><br>\n",
00101                             &buf[4]);
00102                      goto FORM;
00103               }
00104        }
00105 
00106        /*
00107         * Unsubscribe command
00108         */
00109        else if (!strcasecmp(cmd, "unsubscribe")) {
00110               serv_printf("SUBS unsubscribe|%s|%s|%s/listsub",
00111                      room,
00112                      email,
00113                      ChrPtr(site_prefix)
00114               );
00115               serv_getln(buf, sizeof buf);
00116               if (buf[0] == '2') {
00117                      wc_printf("<CENTER><H1>Confirmation request sent</H1>"
00118                             "You are unsubscribing <TT>");
00119                      escputs(email);
00120                      wc_printf("</TT> from the &quot;");
00121                      escputs(room);
00122                      wc_printf("&quot; mailing list.  The listserver has "
00123                             "sent you an e-mail with one additional "
00124                             "Web link for you to click on to confirm "
00125                             "your unsubscription.  This extra step is for "
00126                             "your protection, as it prevents others from "
00127                             "being able to unsubscribe you from "
00128                             "lists without your consent.<br><br>"
00129                             "Please click on the link which is being "
00130                             "e-mailed to you and your unsubscription will "
00131                             "be confirmed.<br>\n"
00132                             "<a href=\"listsub\">Back...</A></CENTER>\n"
00133                      );
00134               }
00135               else {
00136                      wc_printf("<FONT SIZE=+1><B>ERROR: %s</B>"
00137                             "</FONT><br><br>\n",
00138                             &buf[4]);
00139                      goto FORM;
00140               }
00141        }
00142 
00143        /*
00144         * Confirm command
00145         */
00146        else if (!strcasecmp(cmd, "confirm")) {
00147               serv_printf("SUBS confirm|%s|%s",
00148                      room,
00149                      token
00150               );
00151               serv_getln(buf, sizeof buf);
00152               if (buf[0] == '2') {
00153                      wc_printf("<CENTER><H1>Confirmation successful!</H1>");
00154               }
00155               else {
00156                      wc_printf("<CENTER><H1>Confirmation failed.</H1>"
00157                             "This could mean one of two things:<UL>\n"
00158                             "<LI>You waited too long to confirm your "
00159                             "subscribe/unsubscribe request (the "
00160                             "confirmation link is only valid for three "
00161                             "days)\n<LI>You have <i>already</i> "
00162                             "successfully confirmed your "
00163                             "subscribe/unsubscribe request and are "
00164                             "attempting to do it again.</UL>\n"
00165                             "The error returned by the server was: "
00166                      );
00167               }
00168               wc_printf("%s</CENTER><br>\n", &buf[4]);
00169        }
00170 
00171        /*
00172         * Any other (invalid) command causes the form to be displayed
00173         */
00174        else {
00175 FORM:         wc_printf("<form method=\"POST\" action=\"listsub\">\n");
00176 
00177               wc_printf("Name of list: "
00178                      "<select name=\"room\" size=1>\n");
00179 
00180               serv_puts("LPRM");
00181               serv_getln(buf, sizeof buf);
00182               if (buf[0] == '1') {
00183                      while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
00184                             extract_token(sroom, buf, 0, '|', sizeof sroom);
00185                             self = extract_int(buf, 4) & QR2_SELFLIST ;
00186                             if (self) {
00187                                    wc_printf("<option value=\"");
00188                                    escputs(sroom);
00189                                    wc_printf("\">");
00190                                    escputs(sroom);
00191                                    wc_printf("</option>\n");
00192                             }
00193                      }
00194               }
00195               wc_printf("</select><br><br>\n");
00196 
00197               wc_printf("Your e-mail address: "
00198                      "<INPUT TYPE=\"text\" NAME=\"email\" "
00199                      "VALUE=\""
00200               );
00201               escputs(email);
00202               wc_printf("\" maxlength=128 size=60><br><br>\n");
00203 
00204               wc_printf("(If subscribing) preferred format: "
00205                      "<INPUT TYPE=\"radio\" NAME=\"subtype\" "
00206                      "VALUE=\"list\" CHECKED>One message at a time&nbsp; "
00207                      "<INPUT TYPE=\"radio\" NAME=\"subtype\" "
00208                      "VALUE=\"digest\">Digest format&nbsp; "
00209                      "<br><br>\n"
00210                      "<INPUT TYPE=\"submit\" NAME=\"cmd\""
00211                      " VALUE=\"subscribe\">\n"
00212                      "<INPUT TYPE=\"submit\" NAME=\"cmd\""
00213                      " VALUE=\"unsubscribe\"><br><br>\n"
00214                      "</FORM>\n"
00215               );
00216 
00217               wc_printf("<hr>When you attempt to subscribe or unsubscribe to "
00218                      "a mailing list, you will receive an e-mail containing"
00219                      " one additional web link to click on for final "
00220                      "confirmation.  This extra step is for your "
00221                      "protection, as it prevents others from being able to "
00222                      "subscribe or unsubscribe you to lists.<br>\n"
00223               );
00224 
00225        }
00226 
00227        wc_printf("</div>");
00228        do_template("box_end");
00229        wc_printf("</td></tr></table></div>");
00230 
00231        wc_printf("</BODY></HTML>\n");
00232        wDumpContent(0);
00233        end_webcit_session();
00234 }
00235 #endif
00236 
00237 int Conditional_LISTSUB_EXECUTE_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP)
00238 {
00239        int rc;
00240        StrBuf *Line;
00241        const char *ImpMsg;
00242        const StrBuf *Room, *Email, *SubType;
00243        
00244        Room = sbstr("room");
00245        if (Room == NULL)
00246        {
00247               ImpMsg = _("You need to specify the mailinglist to subscribe to.");
00248               AppendImportantMessage(ImpMsg, -1);
00249               return 0;
00250        }
00251        Email = sbstr("email");
00252        if (Email == NULL)
00253        {
00254               ImpMsg = _("You need to specify the email address you'd like to subscribe with.");
00255               AppendImportantMessage(ImpMsg, -1);
00256               return 0;
00257        }
00258        SubType = sbstr("subtype");
00259 
00260        Line = NewStrBuf();
00261        serv_printf("SUBS subscribe|%s|%s|%s|%s/listsub",
00262                   ChrPtr(Room),
00263                   ChrPtr(Email),
00264                   ChrPtr(SubType),
00265                   ChrPtr(site_prefix)
00266               );
00267        StrBuf_ServGetln(Line);
00268        rc = GetServerStatusMsg(Line, NULL, 1, 2);
00269        FreeStrBuf(&Line);
00270        if (rc == 2)
00271               putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
00272        return rc == 2;
00273 }
00274 
00275 int Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE(StrBuf *Target, WCTemplputParams *TP)
00276 {
00277        int rc;
00278        StrBuf *Line;
00279        const char *ImpMsg;
00280        const StrBuf *Room, *Email;
00281        
00282        Room = sbstr("room");
00283        if (Room == NULL)
00284        {
00285               ImpMsg = _("You need to specify the mailinglist to subscribe to.");
00286               AppendImportantMessage(ImpMsg, -1);
00287               return 0;
00288        }
00289        Email = sbstr("email");
00290        if (Email == NULL)
00291        {
00292               ImpMsg = _("You need to specify the email address you'd like to subscribe with.");
00293               AppendImportantMessage(ImpMsg, -1);
00294               return 0;
00295        }
00296 
00297        serv_printf("SUBS unsubscribe|%s|%s|%s/listsub",
00298                   ChrPtr(Room),
00299                   ChrPtr(Email),
00300                   ChrPtr(site_prefix)
00301               );
00302        Line = NewStrBuf();
00303        StrBuf_ServGetln(Line);
00304        rc = GetServerStatusMsg(Line, NULL, 1, 2);
00305        FreeStrBuf(&Line);
00306        if (rc == 2)
00307               putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
00308        return rc == 2;
00309 }
00310 
00311 int Conditional_LISTSUB_EXECUTE_CONFIRM_SUBSCRIBE(StrBuf *Target, WCTemplputParams *TP)
00312 {
00313        int rc;
00314        StrBuf *Line;
00315        const char *ImpMsg;
00316        const StrBuf *Room, *Token;
00317        
00318        Room = sbstr("room");
00319        if (Room == NULL)
00320        {
00321               ImpMsg = _("You need to specify the mailinglist to subscribe to.");
00322               AppendImportantMessage(ImpMsg, -1);
00323               return 0;
00324        }
00325        Token = sbstr("token");
00326        if (Room == NULL)
00327        {
00328               ImpMsg = _("You need to specify the mailinglist to subscribe to.");
00329               AppendImportantMessage(ImpMsg, -1);
00330               return 0;
00331        }
00332 
00333        Line = NewStrBuf();
00334        serv_printf("SUBS confirm|%s|%s",
00335                   ChrPtr(Room),
00336                   ChrPtr(Token)
00337               );
00338        StrBuf_ServGetln(Line);
00339        rc = GetServerStatusMsg(Line, NULL, 1, 2);
00340        FreeStrBuf(&Line);
00341        if (rc == 2)
00342               putbstr("__FAIL", NewStrBufPlain(HKEY("1")));
00343        return rc == 2;
00344 }
00345 
00346 #ifdef EXPERIMENTAL_LISTSUB
00347 void do_listsub(void)
00348 {
00349        if (!havebstr("cmd"))
00350        {
00351               putbstr("cmd", NewStrBufPlain(HKEY("")));
00352        }
00353        output_headers(1, 0, 0, 0, 1, 0);
00354        do_template("listsub_display");
00355        end_burst();
00356 }
00357 #endif
00358 
00359 void 
00360 InitModule_LISTSUB
00361 (void)
00362 {
00363        RegisterConditional(HKEY("COND:LISTSUB:EXECUTE:SUBSCRIBE"), 0, Conditional_LISTSUB_EXECUTE_SUBSCRIBE,  CTX_NONE);
00364        RegisterConditional(HKEY("COND:LISTSUB:EXECUTE:UNSUBSCRIBE"), 0, Conditional_LISTSUB_EXECUTE_UNSUBSCRIBE,  CTX_NONE);
00365        RegisterConditional(HKEY("COND:LISTSUB:EXECUTE:CONFIRM:SUBSCRIBE"), 0, Conditional_LISTSUB_EXECUTE_CONFIRM_SUBSCRIBE,  CTX_NONE);
00366 
00367        WebcitAddUrlHandler(HKEY("listsub"), "", 0, do_listsub, ANONYMOUS|COOKIEUNNEEDED|FORCE_SESSIONCLOSE);
00368 
00369 
00370 }