Back to index

courier  0.68.2
webmlm.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2007 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 **
00005 */
00006 
00007 
00008 #include      "config.h"
00009 #include      "sysconfdir.h"
00010 #include      <stdio.h>
00011 #include      <string.h>
00012 #include      <strings.h>
00013 #include      <stdlib.h>
00014 #include      <ctype.h>
00015 
00016 #include      "cgi/cgi.h"
00017 
00018 
00019 int main(int argc, char **argv)
00020 {
00021        const char *envdir=getenv("WEBMLMRC_DIR");
00022        const char *p=strrchr(argv[0], '/');
00023        char *q;
00024        char   buf[1024];
00025        FILE *fp;
00026 
00027        if (!envdir || !*envdir)
00028               envdir= SYSCONFDIR;
00029 
00030        if (p == NULL) p=argv[0];
00031        else ++p;
00032 
00033        q=malloc(strlen(envdir)+strlen(p)+10);
00034 
00035        if (!q)
00036               exit(1);
00037 
00038        strcat(strcat(strcat(strcpy(q, envdir), "/"), p), "rc");
00039 
00040        fp=fopen(q, "r");
00041 
00042        if (!fp)
00043        {
00044               cginocache();
00045 
00046               printf("Content-Type: text/html; charset=utf-8\n\n"
00047                      "<html><head><title>Internal error</title></head>\n"
00048                      "<body><h1>Internal Error</h1>\n"
00049                      "<p>The webmail system is temporarily unavailable.  Missing configuration file: %s</p></body></html>\n", q);
00050               fflush(stdout);
00051               exit(0);
00052        }
00053 
00054        while (fgets(buf, sizeof(buf), fp))
00055        {
00056               char *w=buf;
00057 
00058               while (*w)
00059               {
00060                      if (!isspace((unsigned char)*w))
00061                             break;
00062 
00063                      ++w;
00064               }
00065 
00066               if (strncasecmp(w, "PORT=", 5))
00067                      continue;
00068 
00069               w += 5;
00070 
00071               w=strtok(w, " \t\r\n");
00072 
00073               if (w)
00074               {
00075                      fclose(fp);
00076                      cgi_connectdaemon(w, CGI_PASSFD);
00077                      return (0);
00078               }
00079               break;
00080        }
00081        fclose(fp);
00082 
00083        cginocache();
00084 
00085        printf("Content-Type: text/html; charset=utf-8\n\n"
00086               "<html><head><title>Internal error</title></head>\n"
00087               "<body><h1>Internal Error</h1>\n"
00088               "<p>The webmail system is temporarily unavailable.  Missing PORT setting in %s</p></body></html>\n", q);
00089        fflush(stdout);
00090        exit(0);
00091 }