]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed FM |
2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
3 | * 1998, 2008 | |
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 | ||
32e71fa4 | 28 | void dansguardian_report(void) |
25697a35 GS |
29 | { |
30 | ||
31 | FILE *fp_in = NULL, *fp_ou = NULL; | |
32 | ||
33 | char url[MAXLEN]; | |
25697a35 GS |
34 | char html2[MAXLEN]; |
35 | char dansguardian_in[MAXLEN]; | |
25697a35 GS |
36 | char per[MAXLEN]; |
37 | char report[MAXLEN]; | |
d6e703cc | 38 | char period[100]; |
25697a35 GS |
39 | char ip[MAXLEN]; |
40 | char rule[255]; | |
41 | char oip[MAXLEN]; | |
42 | char user[MAXLEN]; | |
43 | char ouser[MAXLEN]; | |
44 | char date[15]; | |
45 | char date2[15]; | |
46 | char hour[15]; | |
25697a35 GS |
47 | char *str; |
48 | int z=0; | |
49 | int count=0; | |
50 | ||
51 | ouser[0]='\0'; | |
52 | ||
53 | sprintf(dansguardian_in,"%s/dansguardian.log",tmp); | |
54 | if(!dansguardian_count) { | |
55 | unlink(dansguardian_in); | |
56 | return; | |
57 | } | |
58 | ||
d6e703cc | 59 | sprintf(per,"%s/sarg-period",dirname); |
25697a35 GS |
60 | sprintf(report,"%s/dansguardian.html",dirname); |
61 | ||
62 | if ((fp_in = fopen(per, "r")) == 0) { | |
63 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[45],per); | |
64 | exit(1); | |
65 | } | |
66 | ||
d6e703cc | 67 | fgets(period,sizeof(period),fp_in); |
25697a35 GS |
68 | fclose(fp_in); |
69 | ||
0dda06bf | 70 | #if defined(HAVE_FOPEN64) |
32e71fa4 | 71 | if((fp_in=fopen64(dansguardian_in,"r"))==NULL) { |
0dda06bf | 72 | #else |
25697a35 | 73 | if((fp_in=fopen(dansguardian_in,"r"))==NULL) { |
0dda06bf | 74 | #endif |
25697a35 GS |
75 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in); |
76 | exit(1); | |
77 | } | |
78 | ||
0dda06bf | 79 | #if defined(HAVE_FOPEN64) |
32e71fa4 | 80 | if((fp_ou=fopen64(report,"w"))==NULL) { |
0dda06bf | 81 | #else |
25697a35 | 82 | if((fp_ou=fopen(report,"w"))==NULL) { |
0dda06bf | 83 | #endif |
25697a35 GS |
84 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report); |
85 | exit(1); | |
86 | } | |
87 | ||
d6e703cc | 88 | 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 |
89 | css(fp_ou); |
90 | fputs("</head>\n",fp_ou); | |
d6e703cc FM |
91 | if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace); |
92 | fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); | |
93 | 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); | |
94 | ||
491b862f GS |
95 | if(strcmp(IndexTree,"date") == 0) |
96 | show_sarg(fp_ou, "../../.."); | |
97 | else | |
98 | show_sarg(fp_ou,".."); | |
25697a35 GS |
99 | fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou); |
100 | sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title); | |
101 | fputs(url,fp_ou); | |
102 | ||
d6e703cc | 103 | sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period); |
25697a35 | 104 | fputs(url,fp_ou); |
d6e703cc | 105 | sprintf(url,"<tr><th class=\"header3\">%s</th></tr>\n",text[128]); |
25697a35 GS |
106 | fputs(url,fp_ou); |
107 | fputs("</table></center>\n",fp_ou); | |
108 | ||
109 | fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou); | |
110 | fputs("<tr><td></td></tr>\n",fp_ou); | |
111 | 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]); | |
112 | fputs(url,fp_ou); | |
113 | ||
114 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
4bcb77cf FM |
115 | if (getword(user,sizeof(user),buf,' ')<0 || getword(date2,sizeof(date2),buf,' ')<0 || |
116 | getword(hour,sizeof(hour),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 || | |
117 | getword(url,sizeof(url),buf,' ')<0 || getword(rule,sizeof(rule),buf,'\n')<0) { | |
118 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in); | |
119 | exit(1); | |
120 | } | |
25697a35 GS |
121 | |
122 | if(strcmp(UserIp,"yes") == 0) | |
123 | strcpy(user,ip); | |
124 | ||
125 | bzero(date, 15); | |
126 | if(strncmp(df,"u",1) != 0) { | |
127 | strncpy(date,date2+6,2); | |
128 | strcat(date,"/"); | |
129 | strncat(date,date2+4,2); | |
130 | strcat(date,"/"); | |
131 | strncat(date,date2,4); | |
132 | } else { | |
133 | strncpy(date,date2+4,2); | |
134 | strcat(date,"/"); | |
135 | strncat(date,date2+6,2); | |
136 | strcat(date,"/"); | |
137 | strncat(date,date2,4); | |
138 | } | |
139 | ||
140 | if((str=(char *) strstr(user, "_")) != (char *) NULL ) { | |
141 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
142 | fixip(user); | |
143 | } | |
144 | ||
145 | if(strcmp(Ip2Name,"yes") == 0) | |
a1c55d8c | 146 | ip2name(ip,sizeof(ip)); |
25697a35 GS |
147 | |
148 | if(!z) { | |
149 | strcpy(ouser,user); | |
150 | strcpy(oip,ip); | |
151 | z++; | |
152 | } else { | |
153 | if(strcmp(ouser,user) == 0) | |
154 | user[0]='\0'; | |
155 | if(user[0] != '\0') | |
156 | strcpy(ouser,user); | |
157 | if(strcmp(oip,ip) == 0) | |
158 | ip[0]='\0'; | |
159 | if(ip[0] != '\0') | |
160 | strcpy(oip,ip); | |
161 | } | |
162 | ||
163 | if(UserTabFile[0] != '\0') { | |
164 | sprintf(warea,":%s:",user); | |
165 | if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) { | |
166 | z1=0; | |
167 | str2=(char *) strstr(str+1,":"); | |
168 | str2++; | |
169 | bzero(name, MAXLEN); | |
170 | while(str2[z1] != ':') { | |
171 | name[z1]=str2[z1]; | |
172 | z1++; | |
173 | } | |
174 | } else strcpy(name,user); | |
175 | } else strcpy(name,user); | |
176 | ||
94ff9470 GS |
177 | if(dotinuser && strstr(name,"_")) { |
178 | str2=(char *)subs(name,"_","."); | |
179 | strcpy(name,str2); | |
180 | } | |
181 | ||
25697a35 GS |
182 | if(DansGuardianReportLimit) { |
183 | if(strcmp(ouser2,name) == 0) { | |
184 | count++; | |
185 | } else { | |
186 | count=1; | |
187 | strcpy(ouser2,name); | |
188 | } | |
189 | if(count >= DansGuardianReportLimit) | |
190 | continue; | |
191 | } | |
192 | ||
491b862f | 193 | sprintf(html2,"<tr><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s</td><td class=\"data2\" nospaw>%s-%s</td><td class=\"data2\" nospaw><a href=\"http://%s\">%s</a></td><td class=\"data2\" nospaw>%s</td></tr>\n",name,ip,date,hour,url,url,rule); |
25697a35 GS |
194 | fputs(html2,fp_ou); |
195 | } | |
196 | ||
197 | fputs("</table>\n",fp_ou); | |
198 | ||
199 | show_info(fp_ou); | |
200 | ||
201 | fputs("</body>\n</html>\n",fp_ou); | |
202 | ||
203 | fclose(fp_in); | |
204 | fclose(fp_ou); | |
205 | ||
206 | unlink(dansguardian_in); | |
207 | ||
208 | return; | |
209 | } |