]>
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" | |
5f3cfd1d | 27 | #include "include/defs.h" |
25697a35 | 28 | |
32e71fa4 | 29 | void dansguardian_report(void) |
25697a35 GS |
30 | { |
31 | ||
32 | FILE *fp_in = NULL, *fp_ou = NULL; | |
33 | ||
34 | char url[MAXLEN]; | |
25697a35 | 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 | ||
936c9905 | 70 | if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) { |
25697a35 GS |
71 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in); |
72 | exit(1); | |
73 | } | |
74 | ||
936c9905 | 75 | if((fp_ou=MY_FOPEN(report,"w"))==NULL) { |
25697a35 GS |
76 | fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report); |
77 | exit(1); | |
78 | } | |
79 | ||
d6e703cc | 80 | 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 |
81 | css(fp_ou); |
82 | fputs("</head>\n",fp_ou); | |
d6e703cc FM |
83 | if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace); |
84 | fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); | |
85 | 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); | |
86 | ||
491b862f GS |
87 | if(strcmp(IndexTree,"date") == 0) |
88 | show_sarg(fp_ou, "../../.."); | |
89 | else | |
90 | show_sarg(fp_ou,".."); | |
25697a35 | 91 | fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou); |
354c1a68 | 92 | fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title); |
25697a35 | 93 | |
354c1a68 FM |
94 | fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period); |
95 | fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[128]); | |
25697a35 GS |
96 | fputs("</table></center>\n",fp_ou); |
97 | ||
98 | fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou); | |
99 | fputs("<tr><td></td></tr>\n",fp_ou); | |
354c1a68 | 100 | fprintf(fp_ou,"<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]); |
25697a35 GS |
101 | |
102 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
4bcb77cf FM |
103 | if (getword(user,sizeof(user),buf,' ')<0 || getword(date2,sizeof(date2),buf,' ')<0 || |
104 | getword(hour,sizeof(hour),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 || | |
105 | getword(url,sizeof(url),buf,' ')<0 || getword(rule,sizeof(rule),buf,'\n')<0) { | |
106 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in); | |
107 | exit(1); | |
108 | } | |
25697a35 GS |
109 | |
110 | if(strcmp(UserIp,"yes") == 0) | |
111 | strcpy(user,ip); | |
112 | ||
113 | bzero(date, 15); | |
114 | if(strncmp(df,"u",1) != 0) { | |
115 | strncpy(date,date2+6,2); | |
116 | strcat(date,"/"); | |
117 | strncat(date,date2+4,2); | |
118 | strcat(date,"/"); | |
119 | strncat(date,date2,4); | |
120 | } else { | |
121 | strncpy(date,date2+4,2); | |
122 | strcat(date,"/"); | |
123 | strncat(date,date2+6,2); | |
124 | strcat(date,"/"); | |
125 | strncat(date,date2,4); | |
126 | } | |
127 | ||
128 | if((str=(char *) strstr(user, "_")) != (char *) NULL ) { | |
129 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
130 | fixip(user); | |
131 | } | |
132 | ||
133 | if(strcmp(Ip2Name,"yes") == 0) | |
a1c55d8c | 134 | ip2name(ip,sizeof(ip)); |
25697a35 GS |
135 | |
136 | if(!z) { | |
137 | strcpy(ouser,user); | |
138 | strcpy(oip,ip); | |
139 | z++; | |
140 | } else { | |
141 | if(strcmp(ouser,user) == 0) | |
142 | user[0]='\0'; | |
143 | if(user[0] != '\0') | |
144 | strcpy(ouser,user); | |
145 | if(strcmp(oip,ip) == 0) | |
146 | ip[0]='\0'; | |
147 | if(ip[0] != '\0') | |
148 | strcpy(oip,ip); | |
149 | } | |
150 | ||
936c9905 | 151 | get_usertab_name(user,name,sizeof(name)); |
25697a35 | 152 | |
94ff9470 GS |
153 | if(dotinuser && strstr(name,"_")) { |
154 | str2=(char *)subs(name,"_","."); | |
155 | strcpy(name,str2); | |
156 | } | |
157 | ||
25697a35 GS |
158 | if(DansGuardianReportLimit) { |
159 | if(strcmp(ouser2,name) == 0) { | |
160 | count++; | |
161 | } else { | |
162 | count=1; | |
163 | strcpy(ouser2,name); | |
164 | } | |
165 | if(count >= DansGuardianReportLimit) | |
166 | continue; | |
167 | } | |
168 | ||
354c1a68 | 169 | fprintf(fp_ou,"<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 |
170 | } |
171 | ||
172 | fputs("</table>\n",fp_ou); | |
173 | ||
174 | show_info(fp_ou); | |
175 | ||
176 | fputs("</body>\n</html>\n",fp_ou); | |
177 | ||
178 | fclose(fp_in); | |
179 | fclose(fp_ou); | |
180 | ||
181 | unlink(dansguardian_in); | |
182 | ||
183 | return; | |
184 | } |