]> 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 66ad4551e86f2f7f558ec18ea102730058e9c215..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
 
@@ -154,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,"");
@@ -228,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,"***.***.***.***");
@@ -265,7 +280,7 @@ int main(int argc,char *argv[])
    NtlmUserFormat=NTLMUSERFORMAT_DOMAINUSER;
    IndexTree=INDEX_TREE_FILE;
    strcpy(RealtimeTypes,"GET,PUT,CONNECT");
-   strcpy(RealtimeUnauthRec,"show");
+   RealtimeUnauthRec=REALTIME_UNAUTH_REC_SHOW;
    RedirectorIgnoreDate=false;
    DansguardianIgnoreDate=false;
    DataFileUrl=DATAFILEURL_IP;
@@ -350,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;
@@ -470,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) {
@@ -520,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);
    }
 
@@ -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)