]> git.ipfire.org Git - thirdparty/sarg.git/blame - dansguardian_report.c
Output w3c compliant strict html (almost every output).
[thirdparty/sarg.git] / dansguardian_report.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
1164c474 3 * 1998, 2010
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
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"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
32e71fa4 30void dansguardian_report(void)
25697a35
GS
31{
32
33 FILE *fp_in = NULL, *fp_ou = NULL;
120d768c 34
25697a35 35 char url[MAXLEN];
25697a35 36 char dansguardian_in[MAXLEN];
25697a35
GS
37 char per[MAXLEN];
38 char report[MAXLEN];
d6e703cc 39 char period[100];
25697a35
GS
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];
25697a35
GS
48 char *str;
49 int z=0;
50 int count=0;
9c7c6346 51 struct getwordstruct gwarea;
25697a35
GS
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
d6e703cc 61 sprintf(per,"%s/sarg-period",dirname);
25697a35
GS
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
05b90947
FM
69 if (!fgets(period,sizeof(period),fp_in)) {
70 fprintf(stderr,"SARG: (dansguardian_report) read error in %s\n",per);
71 exit(1);
72 }
25697a35
GS
73 fclose(fp_in);
74
936c9905 75 if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) {
25697a35
GS
76 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in);
77 exit(1);
78 }
79
936c9905 80 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
25697a35
GS
81 fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report);
82 exit(1);
83 }
84
c0ec9cc7 85 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGuardian"));
b18ce4a0
FM
86 fprintf(fp_ou,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",text[89],period);
87 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",text[128]);
c0ec9cc7 88 close_html_header(fp_ou);
25697a35 89
c0ec9cc7 90 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
25697a35 91 fputs("<tr><td></td></tr>\n",fp_ou);
b18ce4a0 92 fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text[98],text[111],text[110],text[91],text[129]);
25697a35
GS
93
94 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
9c7c6346
FM
95 getword_start(&gwarea,buf);
96 if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
97 getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 ||
98 getword(url,sizeof(url),&gwarea,'\t')<0 || getword(rule,sizeof(rule),&gwarea,'\n')<0) {
4bcb77cf
FM
99 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",dansguardian_in);
100 exit(1);
101 }
25697a35 102
246c8489 103 if(UserIp)
25697a35
GS
104 strcpy(user,ip);
105
106 bzero(date, 15);
107 if(strncmp(df,"u",1) != 0) {
108 strncpy(date,date2+6,2);
109 strcat(date,"/");
110 strncat(date,date2+4,2);
111 strcat(date,"/");
112 strncat(date,date2,4);
113 } else {
114 strncpy(date,date2+4,2);
115 strcat(date,"/");
116 strncat(date,date2+6,2);
117 strcat(date,"/");
118 strncat(date,date2,4);
119 }
120
121 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
122 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
123 fixip(user);
124 }
125
246c8489 126 if(Ip2Name)
a1c55d8c 127 ip2name(ip,sizeof(ip));
25697a35
GS
128
129 if(!z) {
130 strcpy(ouser,user);
131 strcpy(oip,ip);
132 z++;
133 } else {
134 if(strcmp(ouser,user) == 0)
135 user[0]='\0';
136 if(user[0] != '\0')
137 strcpy(ouser,user);
120d768c 138 if(strcmp(oip,ip) == 0)
25697a35
GS
139 ip[0]='\0';
140 if(ip[0] != '\0')
141 strcpy(oip,ip);
142 }
143
965c4a6f 144 user_find(name, sizeof(name), user);
25697a35 145
48864d28
FM
146 if(dotinuser && strchr(name,'_')) {
147 subs(name,sizeof(name),"_",".");
94ff9470
GS
148 }
149
25697a35
GS
150 if(DansGuardianReportLimit) {
151 if(strcmp(ouser2,name) == 0) {
152 count++;
153 } else {
154 count=1;
155 strcpy(ouser2,name);
156 }
157 if(count >= DansGuardianReportLimit)
158 continue;
159 }
160
354c1a68 161 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 162 }
25697a35 163 fclose(fp_in);
c0ec9cc7
FM
164
165 fputs("</table></div>\n",fp_ou);
166 write_html_trailer(fp_ou);
25697a35
GS
167 fclose(fp_ou);
168
169 unlink(dansguardian_in);
170
171 return;
172}