if (debugz) debugaz(_("Authentication failure report not produced because privacy option is active\n"));
return;
}
-
+
snprintf(authfail_unsort,sizeof(authfail_unsort),"%s/authfail.int_unsort",tmp);
if ((fp_authfail=MY_FOPEN(authfail_unsort,"w"))==NULL) {
debuga(_("(log) Cannot open file: %s - %s\n"),authfail_unsort,strerror(errno));
void authfail_write(const struct ReadLogStruct *log_entry)
{
char date[80];
-
+
if (fp_authfail && (strstr(log_entry->HttpCode,"DENIED/401") != 0 || strstr(log_entry->HttpCode,"DENIED/407") != 0)) {
strftime(date,sizeof(date),"%d/%m/%Y\t%H:%M:%S",&log_entry->EntryTime);
fprintf(fp_authfail, "%s\t%s\t%s\t%s\n",date,log_entry->User,log_entry->Ip,log_entry->Url);
fprintf(fp_css,".link a:link,a:visited {font-family:%s;font-size:%s;color:#0000FF;text-decoration:none;}\n", FontFace, FontSize);
fprintf(fp_css,"a > img {border:none;}\n");
-
+
fputs(".warn {margin:0.5em;}\n",fp_css);
fprintf(fp_css,".warn > span {padding:0.5em;border:2px solid black;background-color:orange;font-family:%s;font-size:%s;}\n",FontFace,FontSize);
if (debugz) debugaz(_("Denied report not produced because privacy option is active\n"));
return;
}
-
+
snprintf(denied_unsort,sizeof(denied_unsort),"%s/denied.int_unsort",tmp);
if ((fp_denied=MY_FOPEN(denied_unsort,"w"))==NULL) {
debuga(_("(log) Cannot open file: %s - %s\n"),denied_unsort,strerror(errno));
void denied_write(const struct ReadLogStruct *log_entry)
{
char date[80];
-
+
if (fp_denied && strstr(log_entry->HttpCode,"DENIED/403") != 0) {
strftime(date,sizeof(date),"%d/%m/%Y\t%H:%M:%S",&log_entry->EntryTime);
fprintf(fp_denied, "%s\t%s\t%s\t%s\n",date,log_entry->User,log_entry->Ip,log_entry->Url);
DichotomicObject Dichotomic_Create(void)
{
DichotomicObject Obj;
-
+
Obj=malloc(sizeof(*Obj));
if (!Obj)
{
{
DichotomicObject Obj;
int i;
-
+
if (!ObjPtr || !*ObjPtr) return;
Obj=*ObjPtr;
*ObjPtr=NULL;
int down,up;
int middle=0;
int cmp=0;
-
+
down=0;
up=Obj->NItems-1;
while (up>=down)
int Position;
bool Found;
int i;
-
+
if (!Obj) return(false);
if (Obj->Items)
{
}
else
Position=0;
-
+
if (Obj->NItems>=Obj->NAllocated)
{
struct DichotomicItemStruct *Items;
}
Obj->Items=Items;
}
-
+
for (i=Obj->NItems ; i>Position ; i--)
{
Obj->Items[i].Key=Obj->Items[i-1].Key;
exit(EXIT_FAILURE);
}
Obj->NItems++;
-
+
return(true);
}
{
int Position;
bool Found;
-
+
if (!Obj) return(NULL);
if (Obj->NItems==0 || !Obj->Items) return(NULL);
Position=Dichotomic_FindKeyPos(Obj,key,&Found);
int clen;
char csort[MAXLEN];
int cstatus;
-
+
clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s\" \"%s/download.int_unsort\"",
tmp, report_in, tmp);
if (clen>=sizeof(csort)) {
{
struct Ip2NameProcess *Chain;
struct Ip2NameProcess *Last;
-
+
if (debug) debuga(_("Chaining IP resolving module \"%s\"\n"),Module->Name);
-
+
Last=NULL;
for (Chain=FirstModule ; Chain ; Chain=Chain->Next) {
if (Chain==Module) {
}
Last=Chain;
}
-
+
if (Last)
Last->Next=Module;
else {
const char *candidate;
int length;
int ModuleIdx;
-
+
while (*list) {
candidate=list;
while (*candidate && (unsigned char)*candidate<=' ') candidate++;
{
int length;
unsigned int ModuleIdx;
-
+
for (length=0 ; module[length] && (unsigned char)module[length]>' ' ; length++);
for (ModuleIdx=0 ; ModuleIdx<sizeof(ModulesList)/sizeof(*ModulesList) ; ModuleIdx++) {
if (strncasecmp(module,ModulesList[ModuleIdx].Name,length)==0 && ModulesList[ModuleIdx].Name[length]=='\0') {
ip2name_buildmoduleslist(param);
return(1);
}
-
+
// parameter for a module?
if (*param=='_') {
ip2name_configmodule(param+1);
return(1);
}
-
+
return(0);
}
int i;
struct Ip2NameProcess *Chain;
struct Ip2NameProcess *Last;
-
+
// find the dns module
for (i=0 ; i<sizeof(ModulesList)/sizeof(*ModulesList) ; i++) {
if (strcmp("dns",ModulesList[i].Name)==0) {
if (debugz) debuga(_("No known module to resolve an IP address using the DNS\n"));
exit(EXIT_FAILURE);
}
-
+
// add the module to the list if it isn't there yet
Last=NULL;
for (Chain=FirstModule ; Chain && Chain!=DnsModule ; Chain=Chain->Next) {
enum ip2name_retcode Status;
const char *Name;
char OrigIp[80];
-
+
if (!KnownIp) {
KnownIp=Dichotomic_Create();
if (!KnownIp) {
exit(EXIT_FAILURE);
}
}
-
+
Name=Dichotomic_Search(KnownIp,ip);
if (Name) {
safe_strcpy(ip,Name,ip_len);
return;
}
-
+
safe_strcpy(OrigIp,ip,sizeof(OrigIp));
for (Module=FirstModule ; Module ; Module=Module->Next) {
if (Module->Resolve) {
static void ip2name_execconfig(const char *name,const char *param)
{
int len;
-
+
len=strlen(param);
if (len>=sizeof(ExecCmd)) {
debuga(_("Command to execute to resolve the IP addresses is too long (maximum is %d bytes)\n"),(int)sizeof(ExecCmd));
FILE *cmd_in;
char buffer[512];
size_t nread;
-
+
if (ExecCmd[0]=='\0') {
debuga(_("No command to run to resolve an IP address. Please configure it in sarg.conf\n"));
exit(EXIT_FAILURE);
}
-
+
j=0;
len=strlen(ip);
for (i=0 ; i<sizeof(ExecCmd) && ExecCmd[i] ; i++) {
}
}
cmd[j]='\0';
-
+
cmd_in=popen(cmd,"r");
if (!cmd_in) {
debuga(_("Cannot run command %s\n"),cmd);
exit(EXIT_FAILURE);
}
-
+
nread=fread(buffer,1,sizeof(buffer),cmd_in);
-
+
if (pclose(cmd_in)==-1) {
debuga(_("Command failed: %s\n"),cmd);
exit(EXIT_FAILURE);
}
if (nread==0) return(INRC_NotFound);
-
+
safe_strcpy(ip,buffer,ip_len);
return(INRC_Found);
}
int UrlLen;
int UserLen;
struct tm *tt;
-
+
// get log time.
Begin=Line;
log_time=0;
while (isdigit(*Line)) log_time=log_time*10+(*Line++-'0');
if (*Line!='.' || Line==Begin) return(RLRC_Unknown);
-
+
// ignore decimal part to log time.
Begin=++Line;
while (isdigit(*Line)) Line++;
if (*Line!=' ' || Line==Begin) return(RLRC_Unknown);
-
+
// skip spaces before the elapsed time.
while (*Line==' ') Line++;
if (!isdigit(*Line)) return(RLRC_Unknown);
-
+
// get the elapsed time.
Begin=Line;
Entry->ElapsedTime=0L;
Entry->DataSize=0LL;
while (isdigit(*Line)) Entry->DataSize=Entry->DataSize*10+(*Line++-'0');
if (*Line!=' ' || Begin==Line) return(RLRC_Unknown);
-
+
// skip the HTTP function
Begin=++Line;
while (*Line && *Line!=' ') Line++;
if (*Line!=' '|| Line==Begin) return(RLRC_Unknown);
-
+
// the url
Entry->Url=++Line;
for (UrlLen=0 ; *Line && *Line!=' ' ; UrlLen++) Line++;
if (*Line!=' ' || UrlLen==0) return(RLRC_Unknown);
-
+
// the ID of the user or - if the user is unidentified
Entry->User=++Line;
for (UserLen=0 ; *Line && *Line!=' ' ; UserLen++) Line++;
if (*Line!=' ' || UserLen==0) return(RLRC_Unknown);
-
+
// now, the format is known with a good confidence. If the time doesn't decode, it is an error.
tt=localtime(&log_time);
if (tt==NULL) {
return(RLRC_InternalError);
}
memcpy(&Entry->EntryTime,tt,sizeof(struct tm));
-
+
// it is safe to alter the line buffer now that we are returning a valid entry
Entry->Ip[IpLen]='\0';
Entry->HttpCode[HttpCodeLen]='\0';
Entry->Url[UrlLen]='\0';
Entry->User[UserLen]='\0';
-
+
return(RLRC_NoError);
}
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M", t);
else if (df=='e')
strftime(tbuf, sizeof(tbuf), "%d-%m-%Y %H:%M", t);
-
+
printf("<tr><td class=\"data\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data3\">%s</td><td class=\"data2\"><a href=\"http://%s\">%s</td></tr>\n",tbuf,ip,name,typ,url,url);
strcpy(ouser,user);
show_ignored_redirector(fp_ou,count-SquidGuardReportLimit);
fputs("</table>\n",fp_ou);
-
+
if (RedirectorErrors>0)
{
fputs("<div class=\"warn\"><span>",fp_ou);
fprintf(fp_ou,ngettext("%d error found in the log file. Some entries may be missing.","%d errors found in the log file. Some entries may be missing.",RedirectorErrors),RedirectorErrors);
fputs("</span></div>\n",fp_ou);
}
-
+
fputs("</div>\n",fp_ou);
if (write_html_trailer(fp_ou)<0)
debuga(_("Write error in file %s\n"),report);
daystat=NULL;
else
daystat=day_prepare();
-
+
uscan=userinfo_startscan();
if (uscan == NULL) {
debuga(_("Cannot enumerate the user list\n"));
siteuser();
else if (debugz)
debugaz(_("Sites & users report not requested in report_type\n"));
-
+
if ((ReportType & REPORT_TYPE_DENIED) != 0)
gen_denied_report();
else if (debugz)
}
}
strcpy(ourl,item.url);
-
+
if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
output_html_url(fp_ou,ourl);
{
char tusr[1024];
FILE *fp_ou;
-
+
snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname);
if((fp_ou=fopen(tusr,"w"))==NULL) {
debuga(_("(topuser) Cannot open file %s\n"),tusr);
DayObject day_prepare(void)
{
DayObject ddata;
-
+
ddata=(DayObject)malloc(sizeof(*ddata));
if (!ddata)
{
debuga(_("Not enough memory to store the daily statistics\n"));
exit(EXIT_FAILURE);
}
-
+
return(ddata);
}
tmp[len]='\0';
NameEnd=tmp;
}
-
+
// ignore duplicates
prev_alias=NULL;
for (alias=FirstAliasName ; alias ; alias=alias->Next) {
}
new_alias->Alias=tmp;
}
-
+
new_alias->Next=NULL;
if (prev_alias)
prev_alias->Next=new_alias;
sprintf(tmp,"%c%d.%d.%d.%d/%d",ALIAS_PREFIX,ipv4[0],ipv4[1],ipv4[2],ipv4[3],nbits);
new_alias->Alias=tmp;
}
-
+
if (prev_alias) {
new_alias->Next=prev_alias->Next;
prev_alias->Next=new_alias;
sprintf(tmp,"%c%x:%x:%x:%x:%x:%x:%x:%x/%d",ALIAS_PREFIX,ipv6[0],ipv6[1],ipv6[2],ipv6[3],ipv6[4],ipv6[5],ipv6[6],ipv6[7],nbits);
new_alias->Alias=tmp;
}
-
+
if (prev_alias) {
new_alias->Next=prev_alias->Next;
prev_alias->Next=new_alias;
int len;
char *tmp;
int i;
-
+
// find the pattern
Delimiter=*buf++;
for (End=buf ; *End && *End!=Delimiter ; End++) {
return(-1);
}
*End++='\0';
-
+
// find the alias
for (Replace=End ; *Replace==' ' || *Replace=='\t' ; Replace++);
for (End=Replace ; *End && (unsigned char)*End>' ' ; End++);
*End='\0';
-
+
// store it
new_alias=malloc(sizeof(*new_alias));
if (!new_alias) {
memcpy(tmp+1,Replace,len);
tmp[len+1]='\0';
new_alias->Alias=tmp;
-
+
new_alias->SubPartern=false;
for (i=1 ; tmp[i] ; i++)
// both the sed \1 and the perl $1 replacement operators are accepted
new_alias->SubPartern=true;
break;
}
-
+
// chain it
prev_alias=&FirstAliasRe;
for (alias=FirstAliasRe ; alias ; alias=alias->Next)
prev_alias=&alias->Next;
*prev_alias=new_alias;
-
+
return(1);
}
#endif
int nbits;
const char *next;
int Error;
-
+
if (strncasecmp(buf,"re:",3)==0) {
#ifdef USE_PCRE
if (Alias_StoreRegexp(buf+3)<0)
debuga(_("Cannot read host name alias file \"%s\" - %s\n"),Filename,strerror(errno));
exit(EXIT_FAILURE);
}
-
+
if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read the host name aliases\n"));
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
}
-
+
longline_destroy(&line);
fclose(fi);
-
+
if (debug) {
struct hostalias_name *alias1;
struct hostalias_ipv4 *alias4;
{
struct hostalias_name *alias1;
struct hostalias_name *next1;
-
+
for (alias1=FirstAliasName ; alias1 ; alias1=next1) {
next1=alias1->Next;
if (alias1->HostName_Prefix) free((void *)alias1->HostName_Prefix);
{
struct hostalias_ipv4 *alias4;
struct hostalias_ipv4 *next4;
-
+
for (alias4=FirstAliasIpv4 ; alias4 ; alias4=next4) {
next4=alias4->Next;
free((void *)alias4->Alias);
{
struct hostalias_ipv6 *alias6;
struct hostalias_ipv6 *next6;
-
+
for (alias6=FirstAliasIpv6 ; alias6 ; alias6=next6) {
next6=alias6->Next;
free((void *)alias6->Alias);
{
struct hostalias_regex *alias;
struct hostalias_regex *next;
-
+
for (alias=FirstAliasRe ; alias ; alias=next) {
next=alias->Next;
pcre_free(alias->Re);
int len;
for (alias=FirstAliasIpv4 ; alias ; alias=alias->Next) {
- len=alias->NBits;
+ len=alias->NBits;
if ((len<8 || memcmp(ipv4,alias->Ip,len/8)==0) && ((len%8)==0 || (ipv4[len/8] ^ alias->Ip[len/8]) & (0xFFU<<(8-len%8)))==0) {
return(alias->Alias);
}
const char *skip_scheme(const char *url)
{
const char *str;
-
+
/*
Skip any scheme:// at the beginning of the URL (see rfc2396 section 3.1).
The underscore is not part of the standard but is found in the squid logs as cache_object://.
dirp=opendir(dir);
if (!dirp) return;
-
+
// make sure the temporary directory contains only our files
while ((direntp = readdir(dirp)) != NULL) {
if (direntp->d_name[0] == '.' && (direntp->d_name[1] == '\0' ||
"directory or manually delete the content of \"%s\"\n"),direntp->d_name,dir,dir);
exit(EXIT_FAILURE);
}
-
+
if (snprintf(dname,sizeof(dname),"%s/%s",dir,direntp->d_name)>=sizeof(dname)) {
debuga(_("directory name to delete too long: %s/%s\n"),dir,direntp->d_name);
exit(EXIT_FAILURE);
}
-
+
#ifdef HAVE_LSTAT
err=lstat(dname,&st);
#else
"directory or manually delete the content of \"%s\"\n"),direntp->d_name,dir,dir);
exit(EXIT_FAILURE);
}
-
+
if (snprintf(dname,sizeof(dname),"%s/%s",dir,direntp->d_name)>=sizeof(dname)) {
debuga(_("directory name to delete too long: %s/%s\n"),dir,direntp->d_name);
exit(EXIT_FAILURE);
// skip leading spaces and tabs
while (*buf && (*buf==' ' || *buf=='\t')) buf++;
-
+
// find out the nature of the pattern
ip_size=0x60 | 0x04;
if (*buf=='[') {