home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sarg1221.zip / authfail.c next >
C/C++ Source or Header  |  2002-10-11  |  6KB  |  181 lines

  1. /*
  2.  * sarg - Squid user management log
  3.  * Mar/98 - Pedro L Orso - orso@onda.com.br
  4.  */
  5.  
  6. #include "include/conf.h"
  7.  
  8. void authfail_report(const char *dirname, int debug, const char *outdir, char *BgColor, char *TxColor, char *TxBgColor, char *TiColor, char *LogoImage, char *LogoText, char *LogoTextColor, char *Width, char *Height, char *Title, char *BgImage, char *FontFace, char *HeaderColor, char *HeaderBgColor, char *FontSize, char *TempDir, char *DateFormat)
  9. {
  10.  
  11.    FILE *fp_in = NULL, *fp_ou = NULL;
  12.       
  13.    char url[MAXLEN];
  14.    char html[MAXLEN];
  15.    char html2[MAXLEN];
  16.    char authfail_in[MAXLEN];
  17.    char per[MAXLEN];
  18.    char report[MAXLEN];
  19.    char periodo[100];
  20.    char ip[MAXLEN];
  21.    char oip[MAXLEN];
  22.    char user[MAXLEN];
  23.    char ouser[MAXLEN];
  24.    char data[15];
  25.    char hora[15];
  26.    char ftime[128];
  27.    char *str;
  28.    int  z=0;
  29.  
  30.    if(strlen(DataFile) > 0) return;
  31.  
  32.    ouser[0]='\0';
  33.  
  34.    sprintf(tmp4,"%s/authfail.log.unsort",TempDir);
  35.    
  36.    if(!authfail_count) {
  37.       unlink(tmp4);
  38.       return;
  39.    }
  40.  
  41.    sprintf(authfail_in,"%s/authfail.log",TempDir);
  42.    sprintf(per,"%s/periodo",dirname);
  43.    sprintf(report,"%s/authfail.html",dirname);
  44.  
  45.    sprintf(csort, SORT" -b -T %s -k 3,3 -k 5,5 -o %s %s", TempDir, authfail_in, tmp4);
  46.    system(csort);
  47.    unlink(tmp4);
  48.  
  49.    if ((fp_in = fopen(per, "r")) == 0) {
  50.       fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],per);
  51.       exit(1);
  52.    }
  53.  
  54.    fgets(periodo,sizeof(periodo),fp_in);
  55.    fclose(fp_in);
  56.  
  57.    if((fp_in=fopen(authfail_in,"r"))==NULL) {
  58.      fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in);
  59.      exit(1);
  60.    }
  61.  
  62.    if((fp_ou=fopen(report,"w"))==NULL) {
  63.      fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],report);
  64.      exit(1);
  65.    }
  66.  
  67.    fputs("<html>\n",fp_ou);
  68.    fputs("<head>\n",fp_ou);
  69.    sprintf(html,"  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
  70.    fputs(html,fp_ou);
  71.    fputs("</head>\n",fp_ou);
  72.  
  73.    // DAS: Using style=font-family more corresponds to standards. 
  74.    sprintf(url,"<body bgcolor=%s text=%s background='%s' style='font-family:%s;'>\n",BgColor,TxColor,BgImage,FontFace);
  75.    fputs(url,fp_ou);
  76.    fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
  77.  
  78.    if(strlen(LogoImage) > 0) {
  79.       sprintf(url,"<tr><th><img src='%s' border=0 align=absmiddle width=%s height=%s>        \
  80.            <font color=%s>%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
  81.       fputs(url,fp_ou);
  82.    }
  83.  
  84.    sprintf(url,"<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr>\n",TiColor,Title);
  85.    fputs(url,fp_ou);
  86.  
  87.    sprintf(url,"<tr><td align=center bgcolor=%s><font size=%s color=%s>%s: %s</font></td></tr>\n",    \
  88.         HeaderBgColor,FontSize,HeaderColor,text[89],periodo);
  89.    fputs(url,fp_ou);
  90.    sprintf(url,"<tr><th bgcolor=%s align=center><font size=%s color=red>%s</font>        \
  91.          <font size=%s>%s</font></th></tr>\n",    \
  92.         HeaderBgColor,FontSize,text[117],FontSize,text[55]);
  93.    fputs(url,fp_ou);
  94.    fputs("</table></center>\n",fp_ou);
  95.  
  96.    fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
  97.    fputs("<tr><td></td></tr>\n",fp_ou);
  98.    fputs("<tr><td></td></tr>\n",fp_ou);
  99.    fputs("<tr><td></td></tr>\n",fp_ou);
  100.    sprintf(url,"<tr><th bgcolor=%s><font size=%s color=%s>%s</font></th>        \
  101.         <th bgcolor=%s><font size=%s color=%s>%s</font></th>            \
  102.         <th bgcolor=%s><font size=%s color=%s>%s</font></th>            \
  103.         <th bgcolor=%s><font size=%s color=%s>%s</font></th></tr>\n",        \
  104.         HeaderBgColor,FontSize,HeaderColor,text[98],                        \
  105.         HeaderBgColor,FontSize,HeaderColor,text[111],                        \
  106.         HeaderBgColor,FontSize,HeaderColor,text[110],                        \
  107.         HeaderBgColor,FontSize,HeaderColor,text[91]);
  108.    fputs(url,fp_ou);
  109.  
  110.    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
  111.       getword(data,buf,' ');
  112.       getword(hora,buf,' ');
  113.       getword(user,buf,' ');
  114.       getword(ip,buf,' ');
  115.       getword(url,buf,' ');
  116.  
  117.       if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
  118.          if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
  119.             fixip(user);
  120.       }
  121.  
  122.       if(strcmp(Ip2Name,"yes") == 0) 
  123.          ip2name(ip);
  124.  
  125.       if(!z) {
  126.          strcpy(ouser,user);
  127.          strcpy(oip,ip);
  128.          z++;
  129.       } else {
  130.          if(strcmp(ouser,user) == 0)
  131.             user[0]='\0';
  132.          if(user[0] != '\0')
  133.             strcpy(ouser,user);
  134.          if(strcmp(oip,ip) == 0) 
  135.             ip[0]='\0';
  136.          if(ip[0] != '\0')
  137.             strcpy(oip,ip);
  138.       }
  139.  
  140.       if(UserTabFile[0] != '\0') {
  141.          sprintf(warea,":%s:",user);
  142.          if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
  143.             z1=0;
  144.             str2=(char *) strstr(str+1,":");
  145.             str2++;
  146.             bzero(name, MAXLEN);
  147.             while(str2[z1] != ':') {
  148.                name[z1]=str2[z1];
  149.                z1++;
  150.             }
  151.          } else strcpy(name,user);
  152.       } else strcpy(name,user);
  153.  
  154.       // DAS: The string must be terminated before end of line
  155.       sprintf(html2,"<tr><td bgcolor=%s><font size=%s>%s</font></td>"
  156.             "<td bgcolor=%s><font size=%s>%s</font></td>"
  157.             "<td bgcolor=%s><font size=%s>%s-%s</font></td>"
  158.             "<td bgcolor=%s><font size=%s><a href=\"%s\">%s</a></font></td></th>\n",
  159.             TxBgColor,FontSize,name,
  160.             TxBgColor,FontSize,ip,
  161.             TxBgColor,FontSize,data,hora,
  162.             TxBgColor,FontSize,url,url);
  163.       fputs(html2,fp_ou);
  164.    }
  165.  
  166.    fputs("</table>\n",fp_ou);
  167.  
  168.    zdate(ftime, DateFormat);
  169.    sprintf(html,"<br><br><center><font size=-2>%s <a href='%s'>%s-%s</a> %s %s</font></center>\n",    \
  170.         text[108],URL,PGM,VERSION,text[109],ftime);
  171.    fputs(html,fp_ou);
  172.    fputs("</html>\n",fp_ou);
  173.  
  174.    fclose(fp_in);
  175.    fclose(fp_ou);
  176.  
  177.    unlink(authfail_in);
  178.  
  179.    return;
  180. }
  181.