]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - log.c
Add an option to make sarg generates the css template
[thirdparty/sarg.git] / log.c
diff --git a/log.c b/log.c
index 0a6ba53d5493159870e9312c6b075ce8643cb02d..344fc3b1e268c5f6d3a530d07cc3775a4b175ada 100644 (file)
--- a/log.c
+++ b/log.c
 #include "include/conf.h"
 #include "include/defs.h"
 
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
 #define REPORT_EVERY_X_LINES 5000
 #define MAX_OPEN_USER_FILES 10
 
@@ -128,6 +132,7 @@ int main(int argc,char *argv[])
    int  iarq=0;
    int isa_ncols=0,isa_cols[ISACOL_Last];
    bool from_stdin;
+   bool from_pipe;
    int blen;
    int maxopenfiles;
    int nopen;
@@ -153,6 +158,17 @@ int main(int argc,char *argv[])
    struct stat logstat;
    struct userinfostruct *uinfo;
    struct userfilestruct *first_user_file, *ufile, *ufile1, *prev_ufile;
+   static int split=0;
+   static int convert=0;
+   static int output_css=0;
+   int option_index;
+   static struct option long_options[]=
+   {
+      {"convert",no_argument,&convert,1},
+      {"css",no_argument,&output_css,1},
+      {"split",no_argument,&split,1},
+      {0,0,0,0}
+   };
 
 #ifdef HAVE_LOCALE_H
    setlocale(LC_TIME,"");
@@ -227,7 +243,7 @@ int main(int argc,char *argv[])
    strcpy(TopsitesSortType,"D");
    LongUrl=0;
    strcpy(FontFace,"Verdana,Tahoma,Arial");
-   datetimeby=DATETIME_ELAP;
+   datetimeby=DATETIME_BYTE;
    strcpy(CharSet,"ISO-8859-1");
    Privacy=0;
    strcpy(PrivacyString,"***.***.***.***");
@@ -264,9 +280,9 @@ int main(int argc,char *argv[])
    NtlmUserFormat=NTLMUSERFORMAT_DOMAINUSER;
    IndexTree=INDEX_TREE_FILE;
    strcpy(RealtimeTypes,"GET,PUT,CONNECT");
-   strcpy(RealtimeUnauthRec,"show");
-   SquidguardIgnoreDate=0;
-   DansguardianIgnoreDate=0;
+   RealtimeUnauthRec=REALTIME_UNAUTH_REC_SHOW;
+   RedirectorIgnoreDate=false;
+   DansguardianIgnoreDate=false;
    DataFileUrl=DATAFILEURL_IP;
    strcpy(MaxElapsed,"28800000");
    BytesInSitesUsersReport=0;
@@ -349,9 +365,11 @@ int main(int argc,char *argv[])
 
    strcpy(Title,_("Squid User Access Report"));
 
-   while((ch = getopt(argc, argv, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
+   while((ch = getopt_long_only(argc, argv, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz",long_options,&option_index)) != -1){
       switch(ch)
       {
+         case 0:
+            break;
          case 'a':
             strcpy(addr,optarg);
             break;
@@ -469,15 +487,16 @@ int main(int argc,char *argv[])
          case 'z':
             debugz++;
             break;
-         case ':':
+         /*case ':':
             debuga(_("Option -%c require an argument\n"),optopt);
             errflg++;
-            break;
+            break;*/
          case '?':
             usage(argv[0]);
             exit(EXIT_FAILURE);
+         default:
+            abort();
       }
-
    }
 
    if (errflg>0) {
@@ -519,13 +538,16 @@ int main(int argc,char *argv[])
       NAccessLog++;
    }
 
-   if(strcmp(hexclude,"onvert") == 0 && strcmp(site,"plit") != 0) {
-      convlog(AccessLog[0], df, dfrom, duntil);
+   if(output_css) {
+      css_content(stdout);
       exit(EXIT_SUCCESS);
    }
-
-   if(strcmp(site,"plit") == 0) {
-      splitlog(AccessLog[0], df, dfrom, duntil, hexclude);
+   if(split) {
+      splitlog(AccessLog[0], df, dfrom, duntil, convert);
+      exit(EXIT_SUCCESS);
+   }
+   if(convert) {
+      convlog(AccessLog[0], df, dfrom, duntil);
       exit(EXIT_SUCCESS);
    }
 
@@ -755,19 +777,18 @@ int main(int argc,char *argv[])
                }
             }
          }
-         decomp(arq,zip,tmp);
-         if(debug)
-            debuga(_("Reading access log file: %s\n"),arq);
-         if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
+         fp_in=decomp(arq,&from_pipe);
+         if(fp_in==NULL) {
             debuga(_("(log) Cannot open log file: %s - %s\n"),arq,strerror(errno));
             exit(EXIT_FAILURE);
          }
+         if(debug) debuga(_("Reading access log file: %s\n"),arq);
          from_stdin=false;
       }
       ilf=ILF_Unknown;
       download_flag=false;
       // pre-read the file only if we have to show stats
-      if(ShowReadStatistics && !from_stdin) {
+      if(ShowReadStatistics && !from_stdin && !from_pipe) {
          size_t nread,i;
          bool skipcr=false;
          char tmp4[MAXLEN];
@@ -1049,24 +1070,13 @@ int main(int argc,char *argv[])
                exit(EXIT_FAILURE);
             }
             getword_start(&gwarea,data);
-            if(strcmp(df,"u") == 0) {
-               if (getword_atoll(&imonth,&gwarea,'/')<0){
-                  debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                  exit(EXIT_FAILURE);
-               }
-               if (getword_atoll(&iday,&gwarea,'/')<0){
-                  debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                  exit(EXIT_FAILURE);
-               }
-            } else {
-               if (getword_atoll(&iday,&gwarea,'/')<0){
-                  debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                  exit(EXIT_FAILURE);
-               }
-               if (getword_atoll(&imonth,&gwarea,'/')<0){
-                  debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                  exit(EXIT_FAILURE);
-               }
+            if (getword_atoll(&iday,&gwarea,'/')<0 || iday<1 || iday>31){
+               debuga(_("Maybe you have a broken date in your %s file\n"),arq);
+               exit(EXIT_FAILURE);
+            }
+            if (getword_atoll(&imonth,&gwarea,'/')<0 || imonth<1 || imonth>12){
+               debuga(_("Maybe you have a broken date in your %s file\n"),arq);
+               exit(EXIT_FAILURE);
             }
             if (getword_atoll(&iyear,&gwarea,'\0')<0){
                debuga(_("Maybe you have a broken date in your %s file\n"),arq);
@@ -1192,10 +1202,7 @@ int main(int argc,char *argv[])
             break;
          }
 
-         if(strncmp(df,"u",1)==0)
-            strftime(dia, sizeof(dia), "%m/%d/%Y", t);
-         else
-            strftime(dia, sizeof(dia), "%d/%m/%Y", t);
+         strftime(dia, sizeof(dia), "%d/%m/%Y", t);
          snprintf(hora,sizeof(hora),"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
 
          if(debugm)
@@ -1513,7 +1520,10 @@ int main(int argc,char *argv[])
          }
       }
       if (!from_stdin) {
-         fclose(fp_in);
+         if (from_pipe)
+            pclose(fp_in);
+         else
+            fclose(fp_in);
          if( ShowReadStatistics )
             printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs1, (float) 100 );
       }
@@ -1646,11 +1656,6 @@ int main(int argc,char *argv[])
    if((ReportType & REPORT_TYPE_DENIED) != 0)
       unlink(denied_sort);
 
-   if(zip[0] != '\0' && strcmp(zip,"zcat") !=0) {
-      recomp(arq, zip);
-   }
-//   else  unlink(arq);
-
    if(strcmp(tmp,"/tmp") != 0) {
       unlinkdir(tmp,0);
    }