]> git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_report.c
Removed Pedro Orso's e-mail as per his request
[thirdparty/sarg.git] / dansguardian_report.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27 #include "include/conf.h"
28 #include "include/defs.h"
29
30 void dansguardian_report(void)
31 {
32
33 FILE *fp_in = NULL, *fp_ou = NULL;
34
35 char url[MAXLEN];
36 char dansguardian_in[MAXLEN];
37 char per[MAXLEN];
38 char report[MAXLEN];
39 char period[100];
40 char ip[MAXLEN];
41 char rule[255];
42 char oip[MAXLEN];
43 char user[MAXLEN];
44 char ouser[MAXLEN];
45 char date[15];
46 char date2[15];
47 char hour[15];
48 char *str;
49 int z=0;
50 int count=0;
51 struct getwordstruct gwarea;
52
53 ouser[0]='\0';
54
55 sprintf(dansguardian_in,"%s/dansguardian.log",tmp);
56 if(!dansguardian_count) {
57 unlink(dansguardian_in);
58 return;
59 }
60
61 sprintf(per,"%s/sarg-period",dirname);
62 sprintf(report,"%s/dansguardian.html",dirname);
63
64 if ((fp_in = fopen(per, "r")) == 0) {
65 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[45],per);
66 exit(1);
67 }
68
69 if (!fgets(period,sizeof(period),fp_in)) {
70 fprintf(stderr,"SARG: (dansguardian_report) read error in %s\n",per);
71 exit(1);
72 }
73 fclose(fp_in);
74
75 if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) {
76 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in);
77 exit(1);
78 }
79
80 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
81 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report);
82 exit(1);
83 }
84
85 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);
86 css(fp_ou);
87 fputs("</head>\n",fp_ou);
88 if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
89 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
90 write_logo_image(fp_ou);
91
92 if(strcmp(IndexTree,"date") == 0)
93 show_sarg(fp_ou, "../../..");
94 else
95 show_sarg(fp_ou,"..");
96 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
97 fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title);
98
99 fprintf(fp_ou,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],period);
100 fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[128]);
101 fputs("</table></div>\n",fp_ou);
102
103 fputs("<div align=\"center\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
104 fputs("<tr><td></td></tr>\n",fp_ou);
105 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]);
106
107 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
108 getword_start(&gwarea,buf);
109 if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
110 getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
111 getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
112 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
113 exit(1);
114 }
115
116 if(UserIp)
117 strcpy(user,ip);
118
119 bzero(date, 15);
120 if(strncmp(df,"u",1) != 0) {
121 strncpy(date,date2+6,2);
122 strcat(date,"/");
123 strncat(date,date2+4,2);
124 strcat(date,"/");
125 strncat(date,date2,4);
126 } else {
127 strncpy(date,date2+4,2);
128 strcat(date,"/");
129 strncat(date,date2+6,2);
130 strcat(date,"/");
131 strncat(date,date2,4);
132 }
133
134 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
135 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
136 fixip(user);
137 }
138
139 if(Ip2Name)
140 ip2name(ip,sizeof(ip));
141
142 if(!z) {
143 strcpy(ouser,user);
144 strcpy(oip,ip);
145 z++;
146 } else {
147 if(strcmp(ouser,user) == 0)
148 user[0]='\0';
149 if(user[0] != '\0')
150 strcpy(ouser,user);
151 if(strcmp(oip,ip) == 0)
152 ip[0]='\0';
153 if(ip[0] != '\0')
154 strcpy(oip,ip);
155 }
156
157 get_usertab_name(user,name,sizeof(name));
158
159 if(dotinuser && strchr(name,'_')) {
160 subs(name,sizeof(name),"_",".");
161 }
162
163 if(DansGuardianReportLimit) {
164 if(strcmp(ouser2,name) == 0) {
165 count++;
166 } else {
167 count=1;
168 strcpy(ouser2,name);
169 }
170 if(count >= DansGuardianReportLimit)
171 continue;
172 }
173
174 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);
175 }
176
177 fputs("</table>\n",fp_ou);
178
179 show_info(fp_ou);
180
181 fputs("</body>\n</html>\n",fp_ou);
182
183 fclose(fp_in);
184 fclose(fp_ou);
185
186 unlink(dansguardian_in);
187
188 return;
189 }