]> git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_report.c
Moved all the functions declarations from conf.h to defs.h for consistency.
[thirdparty/sarg.git] / dansguardian_report.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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 #include "include/defs.h"
28
29 void dansguardian_report(void)
30 {
31
32 FILE *fp_in = NULL, *fp_ou = NULL;
33
34 char url[MAXLEN];
35 char dansguardian_in[MAXLEN];
36 char per[MAXLEN];
37 char report[MAXLEN];
38 char period[100];
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];
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
59 sprintf(per,"%s/sarg-period",dirname);
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
67 fgets(period,sizeof(period),fp_in);
68 fclose(fp_in);
69
70 #if defined(HAVE_FOPEN64)
71 if((fp_in=fopen64(dansguardian_in,"r"))==NULL) {
72 #else
73 if((fp_in=fopen(dansguardian_in,"r"))==NULL) {
74 #endif
75 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in);
76 exit(1);
77 }
78
79 #if defined(HAVE_FOPEN64)
80 if((fp_ou=fopen64(report,"w"))==NULL) {
81 #else
82 if((fp_ou=fopen(report,"w"))==NULL) {
83 #endif
84 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report);
85 exit(1);
86 }
87
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);
89 css(fp_ou);
90 fputs("</head>\n",fp_ou);
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>&nbsp;%s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText);
94
95 if(strcmp(IndexTree,"date") == 0)
96 show_sarg(fp_ou, "../../..");
97 else
98 show_sarg(fp_ou,"..");
99 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
100 fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title);
101
102 fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
103 fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[128]);
104 fputs("</table></center>\n",fp_ou);
105
106 fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou);
107 fputs("<tr><td></td></tr>\n",fp_ou);
108 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]);
109
110 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
111 if (getword(user,sizeof(user),buf,' ')<0 || getword(date2,sizeof(date2),buf,' ')<0 ||
112 getword(hour,sizeof(hour),buf,' ')<0 || getword(ip,sizeof(ip),buf,' ')<0 ||
113 getword(url,sizeof(url),buf,' ')<0 || getword(rule,sizeof(rule),buf,'\n')<0) {
114 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
115 exit(1);
116 }
117
118 if(strcmp(UserIp,"yes") == 0)
119 strcpy(user,ip);
120
121 bzero(date, 15);
122 if(strncmp(df,"u",1) != 0) {
123 strncpy(date,date2+6,2);
124 strcat(date,"/");
125 strncat(date,date2+4,2);
126 strcat(date,"/");
127 strncat(date,date2,4);
128 } else {
129 strncpy(date,date2+4,2);
130 strcat(date,"/");
131 strncat(date,date2+6,2);
132 strcat(date,"/");
133 strncat(date,date2,4);
134 }
135
136 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
137 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
138 fixip(user);
139 }
140
141 if(strcmp(Ip2Name,"yes") == 0)
142 ip2name(ip,sizeof(ip));
143
144 if(!z) {
145 strcpy(ouser,user);
146 strcpy(oip,ip);
147 z++;
148 } else {
149 if(strcmp(ouser,user) == 0)
150 user[0]='\0';
151 if(user[0] != '\0')
152 strcpy(ouser,user);
153 if(strcmp(oip,ip) == 0)
154 ip[0]='\0';
155 if(ip[0] != '\0')
156 strcpy(oip,ip);
157 }
158
159 if(UserTabFile[0] != '\0') {
160 sprintf(warea,":%s:",user);
161 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
162 z1=0;
163 str2=(char *) strstr(str+1,":");
164 str2++;
165 bzero(name, MAXLEN);
166 while(str2[z1] != ':') {
167 name[z1]=str2[z1];
168 z1++;
169 }
170 } else strcpy(name,user);
171 } else strcpy(name,user);
172
173 if(dotinuser && strstr(name,"_")) {
174 str2=(char *)subs(name,"_",".");
175 strcpy(name,str2);
176 }
177
178 if(DansGuardianReportLimit) {
179 if(strcmp(ouser2,name) == 0) {
180 count++;
181 } else {
182 count=1;
183 strcpy(ouser2,name);
184 }
185 if(count >= DansGuardianReportLimit)
186 continue;
187 }
188
189 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);
190 }
191
192 fputs("</table>\n",fp_ou);
193
194 show_info(fp_ou);
195
196 fputs("</body>\n</html>\n",fp_ou);
197
198 fclose(fp_in);
199 fclose(fp_ou);
200
201 unlink(dansguardian_in);
202
203 return;
204 }