]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 GS |
2 | * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br |
3 | * 1998, 2005 | |
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 | ||
28 | void authfail_report() | |
29 | { | |
30 | ||
31 | FILE *fp_in = NULL, *fp_ou = NULL; | |
32 | ||
33 | char url[MAXLEN]; | |
34 | char html[MAXLEN]; | |
35 | char html2[MAXLEN]; | |
36 | char authfail_in[MAXLEN]; | |
37 | char per[MAXLEN]; | |
38 | char report[MAXLEN]; | |
39 | char periodo[100]; | |
40 | char ip[MAXLEN]; | |
41 | char oip[MAXLEN]; | |
42 | char user[MAXLEN]; | |
43 | char ouser[MAXLEN]; | |
44 | char ouser2[MAXLEN]; | |
45 | char data[15]; | |
46 | char hora[15]; | |
47 | char ftime[128]; | |
48 | char *str; | |
49 | int z=0; | |
50 | int count=0; | |
51 | ||
52 | if(strlen(DataFile) > 0) return; | |
53 | ||
54 | ouser[0]='\0'; | |
55 | ||
491b862f | 56 | sprintf(tmp4,"%s/sarg/authfail.log.unsort",TempDir); |
25697a35 GS |
57 | |
58 | if(!authfail_count) { | |
59 | unlink(tmp4); | |
60 | return; | |
61 | } | |
62 | ||
63 | sprintf(authfail_in,"%s/authfail.log",TempDir); | |
64 | sprintf(per,"%s/periodo",dirname); | |
65 | sprintf(report,"%s/authfail.html",dirname); | |
66 | ||
94ff9470 | 67 | sprintf(csort,"sort -b -T %s -k 3,3 -k 5,5 -o '%s' '%s'", TempDir, authfail_in, tmp4); |
25697a35 GS |
68 | system(csort); |
69 | unlink(tmp4); | |
70 | ||
71 | if ((fp_in = fopen(per, "r")) == 0) { | |
72 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],per); | |
73 | exit(1); | |
74 | } | |
75 | ||
76 | fgets(periodo,sizeof(periodo),fp_in); | |
77 | fclose(fp_in); | |
78 | ||
79 | if((fp_in=fopen(authfail_in,"r"))==NULL) { | |
80 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in); | |
81 | exit(1); | |
82 | } | |
83 | ||
84 | if((fp_ou=fopen(report,"w"))==NULL) { | |
85 | fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],report); | |
86 | exit(1); | |
87 | } | |
88 | ||
89 | fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou); | |
90 | fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou); | |
91 | fputs("<html>\n",fp_ou); | |
92 | fputs("<head>\n",fp_ou); | |
93 | sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet); | |
94 | fputs(html,fp_ou); | |
95 | css(fp_ou); | |
96 | fputs("</head>\n",fp_ou); | |
97 | ||
98 | if(strlen(FontFace) > 0) { | |
99 | sprintf(url,"<font face=%s>\n",FontFace); | |
100 | fputs(url,fp_ou); | |
101 | } | |
102 | ||
103 | sprintf(url,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); | |
104 | fputs(url,fp_ou); | |
105 | ||
106 | if(strlen(LogoImage) > 0) { | |
94ff9470 GS |
107 | fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou); |
108 | sprintf(url,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n",LogoImage,Width,Height,LogoText); | |
25697a35 | 109 | fputs(url,fp_ou); |
94ff9470 | 110 | fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou); |
25697a35 GS |
111 | fputs("</table>\n",fp_ou); |
112 | } | |
113 | ||
491b862f GS |
114 | if(strcmp(IndexTree,"date") == 0) |
115 | show_sarg(fp_ou, "../../.."); | |
116 | else | |
117 | show_sarg(fp_ou,".."); | |
25697a35 GS |
118 | fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou); |
119 | sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title); | |
120 | fputs(url,fp_ou); | |
121 | ||
122 | sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],periodo); | |
123 | fputs(url,fp_ou); | |
124 | sprintf(url,"<tr><th class=\"header\">%s %s</th></tr>\n",text[117],text[55]); | |
125 | fputs(url,fp_ou); | |
126 | fputs("</table></center>\n",fp_ou); | |
127 | ||
128 | fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou); | |
129 | fputs("<tr><td></td></tr>\n",fp_ou); | |
130 | fputs("<tr><td></td></tr>\n",fp_ou); | |
131 | fputs("<tr><td></td></tr>\n",fp_ou); | |
132 | sprintf(url,"<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]); | |
133 | fputs(url,fp_ou); | |
134 | ||
135 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
136 | getword(data,buf,' '); | |
137 | getword(hora,buf,' '); | |
138 | getword(user,buf,' '); | |
139 | getword(ip,buf,' '); | |
140 | getword(url,buf,' '); | |
141 | ||
142 | if((str=(char *) strstr(user, "_")) != (char *) NULL ) { | |
143 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
144 | fixip(user); | |
145 | } | |
146 | ||
147 | if(strcmp(Ip2Name,"yes") == 0) | |
148 | ip2name(ip); | |
149 | ||
150 | if(!z) { | |
151 | strcpy(ouser,user); | |
152 | strcpy(oip,ip); | |
153 | z++; | |
154 | } else { | |
155 | if(strcmp(ouser,user) == 0) | |
156 | user[0]='\0'; | |
157 | if(user[0] != '\0') | |
158 | strcpy(ouser,user); | |
159 | if(strcmp(oip,ip) == 0) | |
160 | ip[0]='\0'; | |
161 | if(ip[0] != '\0') | |
162 | strcpy(oip,ip); | |
163 | } | |
164 | ||
165 | if(UserTabFile[0] != '\0') { | |
166 | sprintf(warea,":%s:",user); | |
167 | if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) { | |
168 | z1=0; | |
169 | str2=(char *) strstr(str+1,":"); | |
170 | str2++; | |
171 | bzero(name, MAXLEN); | |
172 | while(str2[z1] != ':') { | |
173 | name[z1]=str2[z1]; | |
174 | z1++; | |
175 | } | |
176 | } else strcpy(name,user); | |
177 | } else strcpy(name,user); | |
178 | ||
94ff9470 GS |
179 | if(dotinuser && strstr(name,"_")) { |
180 | str2=(char *)subs(name,"_","."); | |
181 | strcpy(name,str2); | |
182 | } | |
183 | ||
25697a35 GS |
184 | if(AuthfailReportLimit) { |
185 | if(strcmp(ouser2,name) == 0) { | |
186 | count++; | |
187 | } else { | |
188 | count=1; | |
189 | strcpy(ouser2,name); | |
190 | } | |
191 | if(count >= AuthfailReportLimit) | |
192 | continue; | |
193 | } | |
194 | ||
195 | sprintf(html2,"<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); | |
196 | fputs(html2,fp_ou); | |
197 | } | |
198 | ||
199 | fputs("</table>\n",fp_ou); | |
200 | ||
201 | show_info(fp_ou); | |
202 | ||
203 | fputs("</body>\n</html>\n",fp_ou); | |
204 | ||
205 | fclose(fp_in); | |
206 | fclose(fp_ou); | |
207 | ||
208 | unlink(authfail_in); | |
209 | ||
210 | return; | |
211 | } |