]> git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_report.c
Use a lower case message and avoid the extra processing
[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 buf[MAXLEN];
36 char *url;
37 char dansguardian_in[MAXLEN];
38 char report[MAXLEN];
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 ouser2[255];
48 int z=0;
49 int count=0;
50 struct getwordstruct gwarea;
51
52 ouser[0]='\0';
53
54 snprintf(dansguardian_in,sizeof(dansguardian_in),"%s/dansguardian.log",tmp);
55 if(!dansguardian_count) {
56 unlink(dansguardian_in);
57 return;
58 }
59
60 sprintf(report,"%s/dansguardian.html",outdirname);
61
62 if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) {
63 debuga(_("(dansguardian_report) Cannot open log file %s\n"),dansguardian_in);
64 exit(EXIT_FAILURE);
65 }
66
67 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
68 debuga(_("(dansguardian_report) Cannot open log file %s\n"),report);
69 exit(EXIT_FAILURE);
70 }
71
72 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGuardian"));
73 fputs("<tr><td class=\"header_c\">",fp_ou);
74 fprintf(fp_ou,_("Period: %s"),period.html);
75 fputs("</td></tr>\n",fp_ou);
76 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("DansGuardian"));
77 close_html_header(fp_ou);
78
79 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
80 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",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"),_("CAUSE"));
81
82 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
83 getword_start(&gwarea,buf);
84 if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
85 getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
86 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),dansguardian_in);
87 exit(EXIT_FAILURE);
88 }
89 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
90 debuga(_("Maybe you have a broken url in your %s file\n"),dansguardian_in);
91 exit(EXIT_FAILURE);
92 }
93 if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
94 debuga(_("Maybe you have a broken rule in your %s file\n"),dansguardian_in);
95 exit(EXIT_FAILURE);
96 }
97
98 if(UserIp)
99 strcpy(user,ip);
100
101 bzero(date, 15);
102 if(strncmp(df,"u",1) != 0) {
103 strncpy(date,date2+6,2);
104 strcat(date,"/");
105 strncat(date,date2+4,2);
106 strcat(date,"/");
107 strncat(date,date2,4);
108 } else {
109 strncpy(date,date2+4,2);
110 strcat(date,"/");
111 strncat(date,date2+6,2);
112 strcat(date,"/");
113 strncat(date,date2,4);
114 }
115
116 if(Ip2Name)
117 ip2name(ip,sizeof(ip));
118
119 if(!z) {
120 strcpy(ouser,user);
121 strcpy(oip,ip);
122 z++;
123 } else {
124 if(strcmp(ouser,user) == 0)
125 user[0]='\0';
126 if(user[0] != '\0')
127 strcpy(ouser,user);
128 if(strcmp(oip,ip) == 0)
129 ip[0]='\0';
130 if(ip[0] != '\0')
131 strcpy(oip,ip);
132 }
133
134 user_find(name, sizeof(name), user);
135
136 if(DansGuardianReportLimit) {
137 if(strcmp(ouser2,name) == 0) {
138 count++;
139 } else {
140 count=1;
141 strcpy(ouser2,name);
142 }
143 if(count >= DansGuardianReportLimit)
144 continue;
145 }
146
147 fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://",name,ip,date,hour);
148 output_html_url(fp_ou,url);
149 fputs("\">",fp_ou);
150 output_html_string(fp_ou,url,100);
151 fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></tr>\n",rule);
152 }
153 fclose(fp_in);
154
155 fputs("</table></div>\n",fp_ou);
156 if (write_html_trailer(fp_ou)<0)
157 debuga(_("Write error in file %s\n"),report);
158 if (fclose(fp_ou)==EOF)
159 debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
160
161 unlink(dansguardian_in);
162
163 return;
164 }