]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - report.c
Add support to decompress xz files
[thirdparty/sarg.git] / report.c
index df609f46a3088011a67c36310635f254750c8436..3a82015917f169ff80b4f05a0c64c68e6aee9676 100644 (file)
--- a/report.c
+++ b/report.c
 
 #include "include/conf.h"
 #include "include/defs.h"
+#include "include/filelist.h"
 
 //! The global statistics of the whole log read.
 struct globalstatstruct globstat;
 //! \c True to enable the smart filter.
 bool smartfilter=false;
 
+extern FileListObject UserAgentLog;
+
 //! The file to store the HTML page where the time of access is reported for one site and one user.
 static FILE *fp_tt=NULL;
 //! The name of the file containing the access time of the site/user.
@@ -46,7 +49,7 @@ static void grava_SmartFilter(const char *dirname, const char *user, const char
 
 void gerarel(void)
 {
-       FILE *fp_in;
+       FileObject *fp_in;
        FILE *fp_gen;
        FILE *fp_tmp=NULL;
 
@@ -56,7 +59,8 @@ void gerarel(void)
        char oldacciptt[256];
        char wdirname[MAXLEN];
        char *oldurl=NULL;
-       char oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1];
+       const char *oldmsg;
+       char acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1];
        char ipantes[256], nameantes[MAXLEN];
        char accsmart[MAXLEN];
        char crc2[MAXLEN/2 -1];
@@ -91,16 +95,29 @@ void gerarel(void)
        smartfilter=false;
        memset(&globstat,0,sizeof(globstat));
 
-       if (vrfydir(&period, addr, site, us, email)<0) {
-               debuga(__FILE__,__LINE__,_("Cannot create the output directory name containing the period as part of the name\n"));
-               exit(EXIT_FAILURE);
+       if (email[0]=='\0') {
+               if (vrfydir(&period, addr, site, us)<0) {
+                       debuga(__FILE__,__LINE__,_("Cannot create the output directory name containing the period as part of the name\n"));
+                       exit(EXIT_FAILURE);
+               }
+       } else {
+               if (snprintf(outdirname,sizeof(outdirname),"%s/emailrep",tmp)>=sizeof(outdirname)) {
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
+                       debuga_more("%s/emailrep\n",tmp);
+                       exit(EXIT_FAILURE);
+               }
+               my_mkdir(outdirname);
        }
 
        if(debugz>=LogLevel_Process){
                debugaz(__FILE__,__LINE__,_("outdirname=%s\n"),outdirname);
        }
 
-       if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent();
+       if (email[0] == '\0' && !FileList_IsEmpty(UserAgentLog))
+               UserAgent_Readlog();
+
+       UserAgent();
+       init_usertab(UserTabFile);
 
        snprintf(wdirname,sizeof(wdirname),"%s/sarg-general",outdirname);
        if((fp_gen=MY_FOPEN(wdirname,"w"))==NULL){
@@ -128,8 +145,8 @@ void gerarel(void)
                        debuga_more("%s/%s.user_log\n",tmp,uinfo->filename);
                        exit(EXIT_FAILURE);
                }
-               if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){
-                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tmp3,strerror(errno));
+               if((fp_in=FileObject_Open(tmp3))==NULL){
+                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tmp3,FileObject_GetLastOpenError());
                        exit(EXIT_FAILURE);
                }
                user=uinfo->filename;
@@ -226,9 +243,9 @@ void gerarel(void)
                        if(site[0] == '\0') {
                                if(!same_url){
                                        if(strstr(oldacccode,"DENIED") != 0)
-                                               strcpy(oldmsg,"DENIED");
+                                               oldmsg="DENIED";
                                        else
-                                               strcpy(oldmsg,"OK");
+                                               oldmsg="OK";
                                        if (fp_tmp) gravatmp(fp_tmp,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache);
                                        gravager(fp_gen,wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
                                        nacc=0;
@@ -330,17 +347,17 @@ void gerarel(void)
                        strcpy(oldaccdia,accdia);
                        strcpy(oldacchora,acchora);
                }
-               if (fclose(fp_in)==EOF) {
-                       debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),tmp3,strerror(errno));
+               if (FileObject_Close(fp_in)) {
+                       debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),tmp3,FileObject_GetLastCloseError());
                        exit(EXIT_FAILURE);
                }
                longline_destroy(&line);
                if (oldurltt) free(oldurltt);
                if (oldurl) {
                        if(strstr(oldacccode,"DENIED") != 0)
-                               strcpy(oldmsg,"DENIED");
+                               oldmsg="DENIED";
                        else
-                               strcpy(oldmsg,"OK");
+                               oldmsg="OK";
                        if (fp_tmp) gravatmp(fp_tmp,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache);
                        closett();
                        gravager(fp_gen,wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
@@ -426,7 +443,7 @@ void gerarel(void)
 
                if(SuccessfulMsg) debuga(__FILE__,__LINE__,_("Successful report generated on %s\n"),outdirname);
        } else {
-               geramail(outdirname, debug, outdir, email, tmp);
+               topuser();
 
                if((strcmp(email,"stdout") != 0) && SuccessfulMsg)
                        debuga(__FILE__,__LINE__,_("Successful report generated and sent to %s\n"),email);