]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br |
25697a35 | 3 | * 1998, 2005 |
94ff9470 | 4 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
25697a35 GS |
5 | * |
6 | * SARG donations: | |
7 | * please look at http://sarg.sourceforge.net/donations.php | |
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 dansguardian_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 dansguardian_in[MAXLEN]; | |
37 | char dansguardian_ou[MAXLEN]; | |
38 | char per[MAXLEN]; | |
39 | char report[MAXLEN]; | |
40 | char periodo[100]; | |
41 | char ip[MAXLEN]; | |
42 | char rule[255]; | |
43 | char oip[MAXLEN]; | |
44 | char user[MAXLEN]; | |
45 | char ouser[MAXLEN]; | |
46 | char date[15]; | |
47 | char date2[15]; | |
48 | char hour[15]; | |
49 | char ftime[128]; | |
50 | char *str; | |
51 | int z=0; | |
52 | int count=0; | |
53 | ||
54 | ouser[0]='\0'; | |
55 | ||
56 | sprintf(dansguardian_in,"%s/dansguardian.log",tmp); | |
57 | if(!dansguardian_count) { | |
58 | unlink(dansguardian_in); | |
59 | return; | |
60 | } | |
61 | ||
62 | sprintf(per,"%s/periodo",dirname); | |
63 | sprintf(report,"%s/dansguardian.html",dirname); | |
64 | ||
65 | if ((fp_in = fopen(per, "r")) == 0) { | |
66 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[45],per); | |
67 | exit(1); | |
68 | } | |
69 | ||
70 | fgets(periodo,sizeof(periodo),fp_in); | |
71 | fclose(fp_in); | |
72 | ||
73 | if((fp_in=fopen(dansguardian_in,"r"))==NULL) { | |
74 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in); | |
75 | exit(1); | |
76 | } | |
77 | ||
78 | if((fp_ou=fopen(report,"w"))==NULL) { | |
79 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report); | |
80 | exit(1); | |
81 | } | |
82 | ||
83 | fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou); | |
84 | fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou); | |
85 | fputs("<html>\n",fp_ou); | |
86 | fputs("<head>\n",fp_ou); | |
87 | sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet); | |
88 | fputs(html,fp_ou); | |
89 | css(fp_ou); | |
90 | fputs("</head>\n",fp_ou); | |
91 | ||
92 | if(strlen(FontFace) > 0) { | |
93 | sprintf(url,"<font face=%s>\n",FontFace); | |
94 | fputs(url,fp_ou); | |
95 | } | |
96 | ||
97 | sprintf(url,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); | |
98 | fputs(url,fp_ou); | |
99 | ||
100 | if(strlen(LogoImage) > 0) { | |
94ff9470 GS |
101 | fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou); |
102 | 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 | 103 | fputs(url,fp_ou); |
94ff9470 | 104 | fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou); |
25697a35 GS |
105 | fputs("</table>\n",fp_ou); |
106 | } | |
107 | ||
108 | show_sarg(fp_ou,".."); | |
109 | fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou); | |
110 | sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title); | |
111 | fputs(url,fp_ou); | |
112 | ||
113 | sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],periodo); | |
114 | fputs(url,fp_ou); | |
115 | sprintf(url,"<tr><th class=\"header3\">%s %s</th></tr>\n",text[128],text[55]); | |
116 | fputs(url,fp_ou); | |
117 | fputs("</table></center>\n",fp_ou); | |
118 | ||
119 | fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou); | |
120 | fputs("<tr><td></td></tr>\n",fp_ou); | |
121 | sprintf(url,"<tr><th class=\"header\">%s</th><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],text[129]); | |
122 | fputs(url,fp_ou); | |
123 | ||
124 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
125 | getword(user,buf,' '); | |
126 | getword(date2,buf,' '); | |
127 | getword(hour,buf,' '); | |
128 | getword(ip,buf,' '); | |
129 | getword(url,buf,' '); | |
130 | getword(rule,buf,'\n'); | |
131 | ||
132 | if(strcmp(UserIp,"yes") == 0) | |
133 | strcpy(user,ip); | |
134 | ||
135 | bzero(date, 15); | |
136 | if(strncmp(df,"u",1) != 0) { | |
137 | strncpy(date,date2+6,2); | |
138 | strcat(date,"/"); | |
139 | strncat(date,date2+4,2); | |
140 | strcat(date,"/"); | |
141 | strncat(date,date2,4); | |
142 | } else { | |
143 | strncpy(date,date2+4,2); | |
144 | strcat(date,"/"); | |
145 | strncat(date,date2+6,2); | |
146 | strcat(date,"/"); | |
147 | strncat(date,date2,4); | |
148 | } | |
149 | ||
150 | if((str=(char *) strstr(user, "_")) != (char *) NULL ) { | |
151 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
152 | fixip(user); | |
153 | } | |
154 | ||
155 | if(strcmp(Ip2Name,"yes") == 0) | |
156 | ip2name(ip); | |
157 | ||
158 | if(!z) { | |
159 | strcpy(ouser,user); | |
160 | strcpy(oip,ip); | |
161 | z++; | |
162 | } else { | |
163 | if(strcmp(ouser,user) == 0) | |
164 | user[0]='\0'; | |
165 | if(user[0] != '\0') | |
166 | strcpy(ouser,user); | |
167 | if(strcmp(oip,ip) == 0) | |
168 | ip[0]='\0'; | |
169 | if(ip[0] != '\0') | |
170 | strcpy(oip,ip); | |
171 | } | |
172 | ||
173 | if(UserTabFile[0] != '\0') { | |
174 | sprintf(warea,":%s:",user); | |
175 | if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) { | |
176 | z1=0; | |
177 | str2=(char *) strstr(str+1,":"); | |
178 | str2++; | |
179 | bzero(name, MAXLEN); | |
180 | while(str2[z1] != ':') { | |
181 | name[z1]=str2[z1]; | |
182 | z1++; | |
183 | } | |
184 | } else strcpy(name,user); | |
185 | } else strcpy(name,user); | |
186 | ||
94ff9470 GS |
187 | if(dotinuser && strstr(name,"_")) { |
188 | str2=(char *)subs(name,"_","."); | |
189 | strcpy(name,str2); | |
190 | } | |
191 | ||
25697a35 GS |
192 | if(DansGuardianReportLimit) { |
193 | if(strcmp(ouser2,name) == 0) { | |
194 | count++; | |
195 | } else { | |
196 | count=1; | |
197 | strcpy(ouser2,name); | |
198 | } | |
199 | if(count >= DansGuardianReportLimit) | |
200 | continue; | |
201 | } | |
202 | ||
203 | sprintf(html2,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",name,ip,date,hour,url,url,rule); | |
204 | fputs(html2,fp_ou); | |
205 | } | |
206 | ||
207 | fputs("</table>\n",fp_ou); | |
208 | ||
209 | show_info(fp_ou); | |
210 | ||
211 | fputs("</body>\n</html>\n",fp_ou); | |
212 | ||
213 | fclose(fp_in); | |
214 | fclose(fp_ou); | |
215 | ||
216 | unlink(dansguardian_in); | |
217 | ||
218 | return; | |
219 | } |