home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sarg1221.zip / report.c < prev    next >
C/C++ Source or Header  |  2002-10-11  |  21KB  |  585 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 criatmp(char *user, char *dirname, int debug, int indexonly);
  9. void criatmp_hora(char *user, char *dirname, int indexonly);
  10. void gravatmp(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
  11. void gravatmp_hora(char *dirname, char *user, char *data, char *hora, char *elap, char *accbytes, int indexonly);
  12. void gravatmpf(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache);
  13. void gravaporuser(char *user, char *dirname, char *url, char *ip, char *data, char *hora, char *tam, char *elap, int indexonly);
  14. void gravager(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache);
  15. void grava_SmartFilter(char *dirname, char *user, char *ip, char *data, char *hora, char *url, char *smart);
  16.  
  17. void gerarel(char *tmp, int debug, const char *periodo, int debugz, int iprel, char* outdir, char *addr, char *site, char *us, int userip, char *email, char *temp2, 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 *Ip2Name, char *TopuserSortField, char *UserSortField, char *TopuserSortOrder, char *UserSortOrder, char *UserAgentLog, char *DateFormat, int indexonly, char *PerUserLimitFile, char *PerUserLimit)
  18. {
  19.  
  20.    FILE *fp_in;
  21.  
  22.    char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10];
  23.    char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN];
  24.    char dirname[MAXLEN], wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN];
  25.    char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50];
  26.    char ipantes[MAXLEN], nameantes[MAXLEN]; 
  27.    char accsmart[MAXLEN];
  28.    int  smartfilter=0;
  29.    char wcrc[50];
  30.    char crc2[50];
  31.    long long int nbytes=0; 
  32.    long long int nelap=0; 
  33.    long long int nacc=0;
  34.    long long int rtotal=0;
  35.    long long int incache=0;
  36.    long long int oucache=0;
  37.    char *s;
  38.  
  39.    ipantes[0]='\0';
  40.    nameantes[0]='\0';
  41.  
  42.    sprintf(dirname, "%s%s", outdir, periodo);
  43.    sprintf(wdir, "%s%s", outdir, periodo);
  44.    strcpy(per1,periodo);
  45.    vrfydir(wdir, dirname, per1, addr, site, us, debug, email);
  46.  
  47.    if(debugz){
  48.       debugaz("dirname",dirname);
  49.       debugaz("wdir",wdir);
  50.    }
  51.  
  52.    strcpy(wdirname,dirname);
  53.    gperiodo(wdirname, periodo, debug);
  54.  
  55.    if(strlen(UserAgentLog) > 0 && email[0] == '\0') {
  56.       strcpy(wdirname,dirname);
  57.       useragent(wdirname,debug,outdir,TempDir,UserAgentLog,periodo,BgColor,TxColor,TxBgColor,TiColor,LogoImage,LogoText,LogoTextColor,Width,Height,Title,BgImage,FontFace,HeaderColor,HeaderBgColor,FontSize,Ip2Name, DateFormat);
  58.    }
  59.  
  60.    olduser[0]='\0';
  61.  
  62.    if((fp_in=fopen(tmp,"r"))==NULL){
  63.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],tmp);
  64.       exit(1);
  65.    }
  66.  
  67.    ttopen=0;
  68.    bzero(html_old, MAXLEN);
  69.  
  70.    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
  71.       getword(accdia,buf,' ');
  72.       getword(acchora,buf,' ');
  73.       getword(accuser,buf,' ');
  74.       getword(accip,buf,' ');
  75.       getword(accurl,buf,' ');
  76.       getword(accbytes,buf,' ');
  77.       getword(acccode,buf,' ');
  78.       getword(accelap,buf,' ');
  79.       getword(accsmart,buf,' ');
  80.       getword(accsmart,buf,'"');
  81.  
  82.       if(strlen(accsmart) > 0) {
  83.          smartfilter++;
  84.          strcpy(wdirname,dirname);
  85.          grava_SmartFilter(wdirname,accuser,accip,accdia,acchora,accurl,accsmart);
  86.       }
  87.  
  88.       if(strcmp(Ip2Name,"yes") == 0) {
  89.          if(strcmp(accip,ipantes) != 0) {
  90.             strcpy(ipantes,accip);
  91.             ip2name(accip);
  92.             strcpy(nameantes,accip);
  93.          } else strcpy(accip,nameantes);
  94.       }
  95.      
  96.       if(strcmp(olduser,accuser) != 0){
  97.          strcpy(wdirname,dirname);
  98.      criatmp(accuser,wdirname,debug,indexonly);
  99.      criatmp_hora(accuser,wdirname,indexonly);
  100.          strcpy(olduser,accuser);
  101.       }
  102.  
  103.       strcpy(wdirname,dirname);
  104.       gravatmp_hora(wdirname,accuser,accdia,acchora,accelap,accbytes,indexonly);
  105.  
  106.       if(iprel){
  107.          strcpy(wdirname,dirname);
  108.          gravaporuser(accuser,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly);
  109.       }
  110.  
  111.       if(!rtotal){
  112.          strcpy(oldurl,accurl);
  113.          strcpy(oldacccode,acccode);
  114.          strcpy(oldaccelap,accelap);
  115.          strcpy(oldaccuser,accuser);
  116.          strcpy(oldaccip,accip);
  117.          strcpy(oldaccdia,accdia);
  118.          strcpy(oldacchora,acchora);
  119.          rtotal++;
  120.       }
  121.  
  122.       if(site[0] != '\0') {
  123.          if(strcmp(oldaccuser,accuser) != 0){
  124.             strcpy(oldmsg,"OK");
  125.             if(strstr(oldacccode,"DENIED") != 0)
  126.                sprintf(oldmsg,"%s",text[46]);
  127.             strcpy(wdirname,dirname);
  128.             gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
  129.             strcpy(wdirname,dirname);
  130.             gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
  131.             nacc=0;
  132.             nbytes=0;
  133.             nelap=0;
  134.             incache=0;
  135.             oucache=0;
  136.          }
  137.       } else {     
  138.          if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){
  139.             strcpy(oldmsg,"OK");
  140.             if(strstr(oldacccode,"DENIED") != 0)
  141.                sprintf(oldmsg,"%s",text[46]);
  142.             strcpy(wdirname,dirname);
  143.             gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
  144.             strcpy(wdirname,dirname);
  145.             gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
  146.             nacc=0;
  147.             nbytes=0;
  148.             nelap=0;
  149.             incache=0;
  150.             oucache=0;
  151.         if(strcmp(oldaccuser,accuser) != 0)
  152.            ind2=0;
  153.          }
  154.       }
  155.       nacc++;
  156.       nbytes+=my_atoll(accbytes);
  157.       nelap+=my_atoll(accelap);
  158.  
  159.       if(strstr(ReportType,"site_user_time_date") != 0) {
  160.          if(!ttopen) {
  161.             ind2++;
  162.             encode_filename( siteind, accurl );
  163.         sprintf(arqtt,"%s/tt%s-%s.html",dirname,accuser,siteind);
  164.             if ((fp_tt = fopen(arqtt, "w")) == 0) {
  165.                fprintf(stderr, "SARG: (report) %s: %s\n",text[45],arqtt);
  166.                exit(1);
  167.             }
  168.         ttopen=1;
  169.  
  170.            if(strcmp(Privacy,"yes") == 0)
  171.                sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s",    \
  172.                       FontSize,PrivacyStringColor,PrivacyString,PrivacyString);
  173.          else
  174.                sprintf(httplink,"<font size=%s><a href=http://%s>%s</a>",FontSize,accurl,accurl);
  175.  
  176.             sprintf(ltext110,"%s",text[110]);
  177.             if(*ltext110){
  178.                for(s=ltext110; *s; ++s)
  179.                   *s=tolower(*s);
  180.             }
  181.  
  182.             fputs("<html>\n",fp_tt);
  183.             fputs("<head>\n",fp_tt);
  184.             sprintf(html,"  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
  185.             fputs(html,fp_tt);
  186.             fputs("</head>\n",fp_tt);
  187.  
  188.             // DAS: Using style=font-family more corresponds to standards. 
  189.             sprintf(html,"<body bgcolor=%s text=%s background='%s' style='font-family:%s;'>\n",BgColor,TxColor,BgImage,FontFace);
  190.             fputs(html,fp_tt);
  191.             fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_tt);
  192.  
  193.             if(strlen(LogoImage) > 0) {
  194.                sprintf(html,"<tr><th align=left><img src='%s' border=0 align=absmiddle width=%s height=%s><font color=%s>%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
  195.                fputs(html,fp_tt);
  196.             }
  197.  
  198.             sprintf(html,"<tr><th align=center colspan=2><b><font color=%s size=+1>%s</font></b></th></tr>\n",TiColor,Title);
  199.             fputs(html,fp_tt);
  200.             fputs("<tr><td></td></tr><tr><td></td></tr>",fp_tt);
  201.             fputs("</table></center>\n",fp_tt);
  202.             fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_tt);
  203.  
  204.             sprintf(html,"<tr><td align=right bgcolor=%s><font size=%s>%s:</font></td><td align=left bgcolor=%s><font size=%s> %s</font></td></td></tr>\n",HeaderBgColor,FontSize,text[89],TxBgColor,FontSize,periodo);
  205.             fputs(html,fp_tt);
  206.             sprintf(html,"<tr><td align=right bgcolor=%s><font size=%s>%s:</font></td><td align=left bgcolor=%s><font size=%s> %s</font></td></td></tr>\n",HeaderBgColor,FontSize,text[90],TxBgColor,FontSize,name);
  207.             fputs(html,fp_tt);
  208.             sprintf(html,"<tr><td align=right bgcolor=%s><font size=%s>%s:</font></td><td align=left bgcolor=%s><font size=%s> %s, %s</font></td></td></tr>\n",HeaderBgColor,FontSize,text[104],TxBgColor,FontSize,UserSortField,UserSortOrder);
  209.             fputs(html,fp_tt);
  210.             sprintf(html,"<tr><td align=center bgcolor=%s colspan=2><font size=%s>%s %s</font></td></tr>\n",HeaderBgColor,FontSize,text[32],text[55]);
  211.             fputs(html,fp_tt);
  212.  
  213.             fputs("</table></center>\n",fp_tt);
  214.             fputs("<center><table cellpadding=1 cellspacing=1>\n",fp_tt);
  215.             fputs("<tr><td></td><td></td></tr>",fp_tt);
  216.             bzero(tmp4, MAXLEN);
  217.             bzero(tmp5, MAXLEN);
  218.             strncpy(tmp4,text[110],4);   // FIXME: This is not multilanguage!
  219.             strncpy(tmp5,text[110]+5,4); // FIXME: This is not multilanguage!
  220.             sprintf(html,"<tr><th align=left bgcolor=%s><font size=%s color=%s>%s</font></th><td></td><td></td><th bgcolor=%s><font size=%s color=%s>%s</font></th><td></td><td></td><th bgcolor=%s><font size=%s color=%s>%s</font></th></tr>\n",HeaderBgColor,FontSize,HeaderColor,text[91],HeaderBgColor,FontSize,HeaderColor,tmp4,HeaderBgColor,FontSize,HeaderColor,tmp5);
  221.             fputs(html,fp_tt);
  222.      }
  223.  
  224.          sprintf(html,"<tr><td align=left bgcolor=%s><font size=%s>%s</font></td><td></td><td></td><td align=left bgcolor=%s><font size=%s>%s</font></td><td></td><td></td><td align=left bgcolor=%s><font size=%s>%s</font></td></tr>\n",TxBgColor,FontSize,accurl,TxBgColor,FontSize,accdia,TxBgColor,FontSize,acchora);
  225.  
  226.      if(strcmp(html,html_old) != 0)
  227.             fputs(html,fp_tt);
  228.      strcpy(html_old, html);
  229.       } else {
  230.          bzero(ltext110, 50);
  231.       } 
  232.  
  233.       strcpy(wcrc,acccode);
  234.       getword(crc2,wcrc,'/');
  235.  
  236.       if(strstr(crc2,"MISS") != 0)
  237.          oucache+=my_atoll(accbytes);
  238.        else incache+=my_atoll(accbytes);
  239.  
  240.       strcpy(oldurl,accurl);
  241.  
  242.       if(strcmp(accuser,oldaccuser) != 0) {
  243.          strcpy(wdirname,dirname);
  244.          totaliza_day(wdirname,oldaccuser,indexonly);
  245.       }
  246.  
  247.       strcpy(oldaccuser,accuser);
  248.       strcpy(oldacccode,acccode);
  249.       strcpy(oldaccelap,accelap);
  250.       strcpy(oldaccip,accip);
  251.       strcpy(oldaccdia,accdia);
  252.       strcpy(oldacchora,acchora);
  253.  
  254.    }
  255.  
  256.    strcpy(oldmsg,"OK");
  257.    if(strstr(oldacccode,"DENIED") != 0)
  258.       sprintf(oldmsg,"%s",text[46]);
  259.    strcpy(wdirname,dirname);
  260.    gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache);
  261.    strcpy(wdirname,dirname);
  262.    gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
  263.    strcpy(wdirname,dirname);
  264.    totaliza_day(wdirname,oldaccuser,indexonly);
  265.  
  266.    fclose(fp_in);
  267.  
  268.    strcpy(wdirname,dirname);
  269.    tmpsort(wdirname, debug, TempDir, TopuserSortField, UserSortField, TopuserSortOrder, UserSortOrder, indexonly);
  270.  
  271.    strcpy(wdirname,dirname);
  272.    totalger(wdirname, debug, outdir);
  273.  
  274.    if(strlen(email) == 0) {
  275.       strcpy(wdirname,dirname);
  276.       topuser(wdirname, debug, outdir, userip, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, Ip2Name, TopuserSortField, TopuserSortOrder, UserAgentLog, DateFormat, smartfilter);
  277.  
  278.       if(strstr(ReportType,"topsites") != 0) {
  279.          strcpy(wdirname,dirname);
  280.          topsites(wdirname, debug, outdir, userip, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, Ip2Name, TopuserSortField, TopuserSortOrder, UserAgentLog, DateFormat);
  281.       }
  282.  
  283.       if(strstr(ReportType,"sites_users") != 0) {
  284.          strcpy(wdirname,dirname);
  285.          siteuser(wdirname, debug, outdir, userip, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, Ip2Name, TopuserSortField, TopuserSortOrder, UserAgentLog, DateFormat);
  286.       }
  287.  
  288.       strcpy(wdirname,dirname);
  289.       gen_denied_report(wdirname, debug, outdir, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, DateFormat);
  290.  
  291.       strcpy(wdirname,dirname);
  292.       authfail_report(wdirname, debug, outdir, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, DateFormat);
  293.  
  294.       if(smartfilter) {
  295.          strcpy(wdirname,dirname);
  296.          smartfilter_report(wdirname, debug, outdir, userip, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, Ip2Name, TopuserSortField, TopuserSortOrder, UserAgentLog, DateFormat);
  297.       }
  298.  
  299.       if(strstr(ReportType,"users_sites") != 0) {
  300.          strcpy(wdirname,dirname);
  301.          htmlrel(wdirname, debug, iprel, userip, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, UserSortField, UserSortOrder, DateFormat, indexonly, PerUserLimitFile, PerUserLimit, Ip2Name);
  302.       }
  303.  
  304.       strcpy(wdirname,outdir);
  305.       geraindex(wdirname, debug, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, TempDir, DateFormat, periodo);
  306.  
  307.       if(strncmp(SuccessfulMsg,"yes",3) == 0)
  308.          fprintf(stderr, "SARG: %s %s\n",text[47],dirname);
  309.     } else {
  310.       strcpy(wdirname,dirname);
  311.       geramail(wdirname, debug, outdir, userip, email, TempDir);
  312.  
  313.       if(strcmp(email,"stdout") != 0) {
  314.          if(strncmp(SuccessfulMsg,"yes",3) == 0)
  315.             fprintf(stderr, "SARG: %s %s\n",text[48],email);
  316.       }
  317.    }
  318.  
  319.    if(indexonly) {
  320.       strcpy(wdirname,dirname);
  321.       index_only(wdirname, debug);
  322.    }
  323.  
  324.    removetmp(dirname,debug);
  325.  
  326.    return;
  327. }
  328.  
  329.  
  330. void criatmp(char *user, char *dirname, int debug, int indexonly)
  331. {
  332.  
  333.    FILE *fp_ou;
  334.  
  335.    char wdirname[MAXLEN];
  336.  
  337.    if(indexonly) return;
  338.    if(strstr(ReportType,"users_sites") == 0) return;
  339.  
  340.    strcpy(wdirname,dirname);
  341.    strcat(wdirname,"/");
  342.    strcat(wdirname,user);
  343.  
  344.    if(debug){
  345.       sprintf(msg,"%s: %s",text[49],wdirname);
  346.       debuga(msg);
  347.    }
  348.  
  349.    strcat(wdirname,".tmp");
  350.    if((fp_ou=fopen(wdirname,"w"))==NULL){
  351.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  352.       exit(1);
  353.    }
  354.  
  355.    fclose(fp_ou);
  356.    return;
  357. }
  358.  
  359.  
  360. void criatmp_hora(char *user, char *dirname, int indexonly)
  361. {
  362.  
  363.    FILE *fp_ou;
  364.  
  365.    char wdirname[MAXLEN];
  366.  
  367.    if(indexonly) return;
  368.    if(strstr(ReportType,"users_sites") == 0) return;
  369.  
  370.    strcpy(wdirname,dirname);
  371.    strcat(wdirname,"/");
  372.    strcat(wdirname,user);
  373.  
  374.    strcat(wdirname,".htmp");
  375.    if((fp_ou=fopen(wdirname,"w"))==NULL){
  376.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  377.       exit(1);
  378.    }
  379.  
  380.    fclose(fp_ou);
  381.    return;
  382. }
  383.  
  384.  
  385. void gravatmp(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
  386. {
  387.  
  388.    FILE *fp_ou;
  389.  
  390.    char reg[MAXLEN];
  391.    char wdirname[MAXLEN];
  392.  
  393.    if(indexonly) return;
  394.    if(strstr(ReportType,"users_sites") == 0) return;
  395.  
  396.    strcpy(wdirname,dirname);
  397.    strcat(wdirname,"/");
  398.    strcat(wdirname,oldaccuser);
  399.    strcat(wdirname,".tmp");
  400.  
  401.    if((fp_ou=fopen(wdirname,"a"))==NULL){
  402.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  403.       exit(1);
  404.    } 
  405.  
  406.    my_lltoa(nacc,val1,15);
  407.    my_lltoa(nbytes,val2,15);
  408.    my_lltoa(nelap,val3,15);
  409.    my_lltoa(incache,val4,15);
  410.    my_lltoa(oucache,val5,15);
  411.    sprintf(reg,"%s %s %s %s %s %s %s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
  412.    fputs(reg,fp_ou);
  413.  
  414.    fclose(fp_ou);
  415.    ttopen=0;
  416.  
  417.    if(fp_tt) {
  418.       fputs("</table>\n",fp_tt);
  419.       fputs("</html>\n",fp_tt);
  420.       fclose(fp_tt);
  421.    }
  422.  
  423.    return;
  424.  
  425. }
  426.  
  427.  
  428. void gravatmp_hora(char *dirname, char *user, char *data, char *hora, char *elap, char *bytes, int indexonly)
  429. {
  430.  
  431.    FILE *fp_ou;
  432.  
  433.    char reg[MAXLEN];
  434.    char wdirname[MAXLEN];
  435.  
  436.    if(indexonly) return;
  437.    if(strstr(ReportType,"users_sites") == 0) return;
  438.  
  439.    strcpy(wdirname,dirname);
  440.    strcat(wdirname,"/");
  441.    strcat(wdirname,user);
  442.    strcat(wdirname,".htmp");
  443.  
  444.    if((fp_ou=fopen(wdirname,"a"))==NULL){
  445.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  446.       exit(1);
  447.    }
  448.  
  449.    if(strcmp(datetimeby,"bytes") == 0)
  450.       sprintf(reg,"%s %s %s\n",data,hora,bytes);
  451.    else sprintf(reg,"%s %s %s\n",data,hora,elap);
  452.    fputs(reg,fp_ou);
  453.  
  454.    fclose(fp_ou);
  455.  
  456.    return;
  457. }
  458.  
  459.  
  460. void gravaporuser(char *user, char *dirname, char *url, char *ip, char *data, char *hora, char *tam, char *elap, int indexonly)
  461. {
  462.  
  463.    FILE *fp_ou;
  464.  
  465.    char reg[MAXLEN];
  466.    char wdirname[MAXLEN];
  467.  
  468.    if(indexonly) return;
  469.    if(strstr(ReportType,"users_sites") == 0) return;
  470.  
  471.    strcpy(wdirname,dirname);
  472.    strcat(wdirname,"/");
  473.    strcat(wdirname,user);
  474.    strcat(wdirname,".ip");
  475.  
  476.    if((fp_ou=fopen(wdirname,"a"))==NULL){
  477.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  478.       exit(1);
  479.    } 
  480.  
  481.    sprintf(reg,"%s %s %s %s %s %s\n",ip,url,data,hora,tam,elap);
  482.    fputs(reg,fp_ou);
  483.  
  484.    fclose(fp_ou);
  485.  
  486.    return;
  487.  
  488. }
  489.  
  490.  
  491. void gravatmpf(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache)
  492. {
  493.  
  494.    FILE *fp_ou;
  495.  
  496.    char reg[MAXLEN];
  497.    char wdirname[MAXLEN];
  498.  
  499.    if(indexonly) return;
  500.    if(strstr(ReportType,"users_sites") == 0) return;
  501.  
  502.    strcpy(wdirname,dirname);
  503.    strcat(wdirname,"/");
  504.    strcat(wdirname,oldaccuser);
  505.    strcat(wdirname,".tmp");
  506.  
  507.    if((fp_ou=fopen(wdirname,"a"))==NULL){
  508.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  509.       exit(1);
  510.    }
  511.  
  512.    my_lltoa(nacc,val1,15);
  513.    my_lltoa(nbytes,val2,15);
  514.    my_lltoa(nelap,val3,15);
  515.    my_lltoa(incache,val4,15);
  516.    my_lltoa(oucache,val5,15);
  517.    sprintf(reg,"%s %s %s %s %s %s %s\n",val1,val2,oldurl,oldmsg,val3,val4,val5);
  518.    fputs(reg,fp_ou);
  519.  
  520.    fclose(fp_ou);
  521.    ttopen=0;
  522.    ind2=0;
  523.  
  524.    if(fp_tt) {
  525.       fputs("</table>\n",fp_tt);
  526.       fputs("</html>\n",fp_tt);
  527.       fclose(fp_tt);
  528.    }
  529.  
  530.    return;
  531.      
  532. }
  533.  
  534.  
  535. void gravager(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache)
  536. {
  537.  
  538.    FILE *fp_ou;
  539.    char reg[MAXLEN];
  540.  
  541.    strcat(dirname,"/");
  542.    strcat(dirname,"geral");
  543.    
  544.    if((fp_ou=fopen(dirname,"a"))==NULL){
  545.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],dirname);
  546.       exit(1);
  547.    }
  548.  
  549.    my_lltoa(nacc,val1,15);
  550.    my_lltoa(nbytes,val2,15);
  551.    my_lltoa(nelap,val3,15);
  552.    my_lltoa(incache,val4,15);
  553.    my_lltoa(oucache,val5,15);
  554.    sprintf(reg,"%s %s %s %s %s %s %s %s %s %s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5);
  555.    fputs(reg,fp_ou);
  556.  
  557.    fclose(fp_ou);
  558.    return;
  559.  
  560. }
  561.  
  562. void grava_SmartFilter(char *dirname, char *user, char *ip, char *data, char *hora, char *url, char *smart)
  563. {
  564.  
  565.    FILE *fp_ou;
  566.  
  567.    char reg[MAXLEN];
  568.    char wdirname[MAXLEN];
  569.  
  570.    sprintf(wdirname,"%s/smartfilter.unsort",dirname);
  571.  
  572.    if((fp_ou=fopen(wdirname,"a"))==NULL){
  573.       fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);
  574.       exit(1);
  575.    }
  576.  
  577.    sprintf(reg,"%s %s %s %s %s %s\n",user,data,hora,ip,url,smart);
  578.    fputs(reg,fp_ou);
  579.  
  580.    fclose(fp_ou);
  581.  
  582.    return;
  583.  
  584. }
  585.