]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed FM |
2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
3 | * 1998, 2008 | |
94ff9470 GS |
4 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
5 | * | |
6 | * SARG donations: | |
7 | * please look at http://sarg.sourceforge.net/donations.php | |
25697a35 GS |
8 | * --------------------------------------------------------------------- |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
23 | * | |
24 | */ | |
25 | ||
26 | #include "include/conf.h" | |
27 | ||
32e71fa4 | 28 | void authfail_report(void) |
25697a35 GS |
29 | { |
30 | ||
31 | FILE *fp_in = NULL, *fp_ou = NULL; | |
32 | ||
33 | char url[MAXLEN]; | |
25697a35 GS |
34 | char authfail_in[MAXLEN]; |
35 | char per[MAXLEN]; | |
36 | char report[MAXLEN]; | |
d6e703cc | 37 | char period[100]; |
25697a35 GS |
38 | char ip[MAXLEN]; |
39 | char oip[MAXLEN]; | |
40 | char user[MAXLEN]; | |
41 | char ouser[MAXLEN]; | |
42 | char ouser2[MAXLEN]; | |
43 | char data[15]; | |
44 | char hora[15]; | |
25697a35 GS |
45 | char *str; |
46 | int z=0; | |
47 | int count=0; | |
456d78a5 | 48 | int cstatus; |
25697a35 GS |
49 | |
50 | if(strlen(DataFile) > 0) return; | |
51 | ||
52 | ouser[0]='\0'; | |
53 | ||
491b862f | 54 | sprintf(tmp4,"%s/sarg/authfail.log.unsort",TempDir); |
25697a35 GS |
55 | |
56 | if(!authfail_count) { | |
57 | unlink(tmp4); | |
58 | return; | |
59 | } | |
60 | ||
61 | sprintf(authfail_in,"%s/authfail.log",TempDir); | |
d6e703cc | 62 | sprintf(per,"%s/sarg-period",dirname); |
25697a35 GS |
63 | sprintf(report,"%s/authfail.html",dirname); |
64 | ||
25697a35 GS |
65 | if ((fp_in = fopen(per, "r")) == 0) { |
66 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],per); | |
67 | exit(1); | |
68 | } | |
d6e703cc | 69 | fgets(period,sizeof(period),fp_in); |
25697a35 GS |
70 | fclose(fp_in); |
71 | ||
456d78a5 FM |
72 | sprintf(csort,"sort -b -T %s -k 3,3 -k 5,5 -o '%s' '%s'", TempDir, authfail_in, tmp4); |
73 | cstatus=system(csort); | |
74 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
75 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
76 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
77 | exit(1); | |
78 | } | |
0dda06bf | 79 | #if defined(HAVE_FOPEN64) |
32e71fa4 | 80 | if((fp_in=fopen64(authfail_in,"r"))==NULL) { |
0dda06bf | 81 | #else |
25697a35 | 82 | if((fp_in=fopen(authfail_in,"r"))==NULL) { |
0dda06bf | 83 | #endif |
456d78a5 FM |
84 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in); |
85 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
86 | exit(1); | |
25697a35 | 87 | } |
456d78a5 | 88 | unlink(tmp4); |
25697a35 | 89 | |
0dda06bf | 90 | #if defined(HAVE_FOPEN64) |
32e71fa4 | 91 | if((fp_ou=fopen64(report,"w"))==NULL) { |
0dda06bf | 92 | #else |
25697a35 | 93 | if((fp_ou=fopen(report,"w"))==NULL) { |
0dda06bf | 94 | #endif |
25697a35 GS |
95 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],report); |
96 | exit(1); | |
97 | } | |
98 | ||
d6e703cc | 99 | fprintf(fp_ou, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet); |
25697a35 GS |
100 | css(fp_ou); |
101 | fputs("</head>\n",fp_ou); | |
d6e703cc FM |
102 | if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace); |
103 | fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); | |
104 | if(strlen(LogoImage) > 0) fprintf(fp_ou, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText); | |
25697a35 | 105 | |
491b862f GS |
106 | if(strcmp(IndexTree,"date") == 0) |
107 | show_sarg(fp_ou, "../../.."); | |
108 | else | |
109 | show_sarg(fp_ou,".."); | |
25697a35 | 110 | fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou); |
354c1a68 | 111 | fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title); |
25697a35 | 112 | |
354c1a68 FM |
113 | fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period); |
114 | fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[117]); | |
25697a35 GS |
115 | fputs("</table></center>\n",fp_ou); |
116 | ||
117 | fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou); | |
118 | fputs("<tr><td></td></tr>\n",fp_ou); | |
119 | fputs("<tr><td></td></tr>\n",fp_ou); | |
120 | fputs("<tr><td></td></tr>\n",fp_ou); | |
354c1a68 | 121 | fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]); |
25697a35 GS |
122 | |
123 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
4bcb77cf FM |
124 | if (getword_multisep(data,sizeof(data),buf,' ')<0 || getword_multisep(hora,sizeof(hora),buf,' ')<0 || |
125 | getword_multisep(user,sizeof(user),buf,' ')<0 || getword_multisep(ip,sizeof(ip),buf,' ')<0 || | |
126 | getword_multisep(url,sizeof(url),buf,' ')<0) { | |
127 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",authfail_in); | |
128 | exit(1); | |
129 | } | |
25697a35 GS |
130 | |
131 | if((str=(char *) strstr(user, "_")) != (char *) NULL ) { | |
132 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
133 | fixip(user); | |
134 | } | |
135 | ||
136 | if(strcmp(Ip2Name,"yes") == 0) | |
a1c55d8c | 137 | ip2name(ip,sizeof(ip)); |
25697a35 GS |
138 | |
139 | if(!z) { | |
140 | strcpy(ouser,user); | |
141 | strcpy(oip,ip); | |
142 | z++; | |
143 | } else { | |
144 | if(strcmp(ouser,user) == 0) | |
145 | user[0]='\0'; | |
146 | if(user[0] != '\0') | |
147 | strcpy(ouser,user); | |
148 | if(strcmp(oip,ip) == 0) | |
149 | ip[0]='\0'; | |
150 | if(ip[0] != '\0') | |
151 | strcpy(oip,ip); | |
152 | } | |
153 | ||
154 | if(UserTabFile[0] != '\0') { | |
155 | sprintf(warea,":%s:",user); | |
156 | if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) { | |
157 | z1=0; | |
158 | str2=(char *) strstr(str+1,":"); | |
159 | str2++; | |
160 | bzero(name, MAXLEN); | |
161 | while(str2[z1] != ':') { | |
162 | name[z1]=str2[z1]; | |
163 | z1++; | |
164 | } | |
165 | } else strcpy(name,user); | |
166 | } else strcpy(name,user); | |
167 | ||
94ff9470 GS |
168 | if(dotinuser && strstr(name,"_")) { |
169 | str2=(char *)subs(name,"_","."); | |
170 | strcpy(name,str2); | |
171 | } | |
172 | ||
25697a35 GS |
173 | if(AuthfailReportLimit) { |
174 | if(strcmp(ouser2,name) == 0) { | |
175 | count++; | |
176 | } else { | |
177 | count=1; | |
178 | strcpy(ouser2,name); | |
179 | } | |
180 | if(count >= AuthfailReportLimit) | |
181 | continue; | |
182 | } | |
183 | ||
354c1a68 | 184 | fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">%s<a href=\"%s\">%s</a></td></th>\n",name,ip,data,hora,BlockImage,url,url); |
25697a35 GS |
185 | } |
186 | ||
187 | fputs("</table>\n",fp_ou); | |
188 | ||
189 | show_info(fp_ou); | |
190 | ||
191 | fputs("</body>\n</html>\n",fp_ou); | |
192 | ||
193 | fclose(fp_in); | |
194 | fclose(fp_ou); | |
195 | ||
196 | unlink(authfail_in); | |
197 | ||
198 | return; | |
199 | } |