#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.
void gerarel(void)
{
- FILE *fp_in;
+ FileObject *fp_in;
FILE *fp_gen;
FILE *fp_tmp=NULL;
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];
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){
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;
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;
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);
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);