#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
int iarq=0;
int isa_ncols=0,isa_cols[ISACOL_Last];
bool from_stdin;
+ bool from_pipe;
int blen;
int maxopenfiles;
int nopen;
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,"");
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,"***.***.***.***");
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;
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;
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) {
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);
}
}
}
}
- 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];
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);
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)
}
}
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 );
}
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);
}