]> git.ipfire.org Git - thirdparty/sarg.git/blame - dansguardian_report.c
Imported Sarg 2.1.0
[thirdparty/sarg.git] / dansguardian_report.c
CommitLineData
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
28void 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>&nbsp;%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
491b862f
GS
108 if(strcmp(IndexTree,"date") == 0)
109 show_sarg(fp_ou, "../../..");
110 else
111 show_sarg(fp_ou,"..");
25697a35
GS
112 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
113 sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title);
114 fputs(url,fp_ou);
115
116 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],periodo);
117 fputs(url,fp_ou);
118 sprintf(url,"<tr><th class=\"header3\">%s %s</th></tr>\n",text[128],text[55]);
119 fputs(url,fp_ou);
120 fputs("</table></center>\n",fp_ou);
121
122 fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou);
123 fputs("<tr><td></td></tr>\n",fp_ou);
124 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]);
125 fputs(url,fp_ou);
126
127 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
128 getword(user,buf,' ');
129 getword(date2,buf,' ');
130 getword(hour,buf,' ');
131 getword(ip,buf,' ');
132 getword(url,buf,' ');
133 getword(rule,buf,'\n');
134
135 if(strcmp(UserIp,"yes") == 0)
136 strcpy(user,ip);
137
138 bzero(date, 15);
139 if(strncmp(df,"u",1) != 0) {
140 strncpy(date,date2+6,2);
141 strcat(date,"/");
142 strncat(date,date2+4,2);
143 strcat(date,"/");
144 strncat(date,date2,4);
145 } else {
146 strncpy(date,date2+4,2);
147 strcat(date,"/");
148 strncat(date,date2+6,2);
149 strcat(date,"/");
150 strncat(date,date2,4);
151 }
152
153 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
154 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
155 fixip(user);
156 }
157
158 if(strcmp(Ip2Name,"yes") == 0)
159 ip2name(ip);
160
161 if(!z) {
162 strcpy(ouser,user);
163 strcpy(oip,ip);
164 z++;
165 } else {
166 if(strcmp(ouser,user) == 0)
167 user[0]='\0';
168 if(user[0] != '\0')
169 strcpy(ouser,user);
170 if(strcmp(oip,ip) == 0)
171 ip[0]='\0';
172 if(ip[0] != '\0')
173 strcpy(oip,ip);
174 }
175
176 if(UserTabFile[0] != '\0') {
177 sprintf(warea,":%s:",user);
178 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
179 z1=0;
180 str2=(char *) strstr(str+1,":");
181 str2++;
182 bzero(name, MAXLEN);
183 while(str2[z1] != ':') {
184 name[z1]=str2[z1];
185 z1++;
186 }
187 } else strcpy(name,user);
188 } else strcpy(name,user);
189
94ff9470
GS
190 if(dotinuser && strstr(name,"_")) {
191 str2=(char *)subs(name,"_",".");
192 strcpy(name,str2);
193 }
194
25697a35
GS
195 if(DansGuardianReportLimit) {
196 if(strcmp(ouser2,name) == 0) {
197 count++;
198 } else {
199 count=1;
200 strcpy(ouser2,name);
201 }
202 if(count >= DansGuardianReportLimit)
203 continue;
204 }
205
491b862f 206 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
207 fputs(html2,fp_ou);
208 }
209
210 fputs("</table>\n",fp_ou);
211
212 show_info(fp_ou);
213
214 fputs("</body>\n</html>\n",fp_ou);
215
216 fclose(fp_in);
217 fclose(fp_ou);
218
219 unlink(dansguardian_in);
220
221 return;
222}