]>
Commit | Line | Data |
---|---|---|
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 | 30 | void squidguard_report(void) |
25697a35 GS |
31 | { |
32 | ||
33 | FILE *fp_in = NULL, *fp_ou = NULL; | |
120d768c | 34 | |
06b39c87 | 35 | char buf[MAXLEN]; |
e5b2c6f0 | 36 | char *url; |
25697a35 | 37 | char squidguard_in[MAXLEN]; |
25697a35 | 38 | char report[MAXLEN]; |
25697a35 GS |
39 | char ip[MAXLEN]; |
40 | char rule[255]; | |
41 | char oip[MAXLEN]; | |
42 | char user[MAXLEN]; | |
43 | char ouser[MAXLEN]; | |
44 | char data[15]; | |
45 | char data2[15]; | |
46 | char hora[15]; | |
06b39c87 | 47 | char ouser2[255]; |
25697a35 GS |
48 | int z=0; |
49 | int count=0; | |
9c7c6346 | 50 | struct getwordstruct gwarea; |
25697a35 GS |
51 | |
52 | ouser[0]='\0'; | |
53 | ||
54 | sprintf(squidguard_in,"%s/squidguard.log",tmp); | |
55 | if(!squidguard_count) { | |
56 | unlink(squidguard_in); | |
57 | return; | |
58 | } | |
59 | ||
d5d021c5 | 60 | snprintf(report,sizeof(report),"%s/squidguard.html",outdirname); |
25697a35 | 61 | |
25697a35 | 62 | if((fp_in=fopen(squidguard_in,"r"))==NULL) { |
fcdc0918 | 63 | debuga(_("(squidguard) Cannot open log file %s\n"),squidguard_in); |
06b39c87 | 64 | exit(EXIT_FAILURE); |
25697a35 GS |
65 | } |
66 | ||
67 | if((fp_ou=fopen(report,"w"))==NULL) { | |
fcdc0918 | 68 | debuga(_("(squidguard) Cannot open log file %s\n"),report); |
06b39c87 | 69 | exit(EXIT_FAILURE); |
25697a35 GS |
70 | } |
71 | ||
c0ec9cc7 | 72 | write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("SQUIDGUARD")); |
fa6552b0 | 73 | fputs("<tr><td class=\"header_l\">",fp_ou); |
fd46f082 | 74 | fprintf(fp_ou,_("Period: %s"),period.html); |
fa6552b0 | 75 | fputs("</td></tr>\n",fp_ou); |
c36c7384 | 76 | fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("SQUIDGUARD")); |
c0ec9cc7 | 77 | close_html_header(fp_ou); |
25697a35 | 78 | |
c0ec9cc7 | 79 | fputs("<div class=\"report\"><table cellpadding=1 cellspacing=2>\n",fp_ou); |
25697a35 | 80 | fputs("<tr><td></td></tr>\n",fp_ou); |
c36c7384 | 81 | 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"),_("RULE")); |
25697a35 GS |
82 | |
83 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
9c7c6346 FM |
84 | getword_start(&gwarea,buf); |
85 | if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data2,sizeof(data2),&gwarea,'\t')<0 || | |
e5b2c6f0 | 86 | getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) { |
10210234 | 87 | debuga(_("There is a broken record or garbage in file %s\n"),squidguard_in); |
06b39c87 | 88 | exit(EXIT_FAILURE); |
e5b2c6f0 FM |
89 | } |
90 | if (getword_ptr(buf,&url,&gwarea,'\t')<0) { | |
10210234 | 91 | debuga(_("There is a broken url in file %s\n"),squidguard_in); |
06b39c87 | 92 | exit(EXIT_FAILURE); |
e5b2c6f0 FM |
93 | } |
94 | if (getword(rule,sizeof(rule),&gwarea,'\n')<0) { | |
10210234 | 95 | debuga(_("There is a broken rule in file %s\n"),squidguard_in); |
06b39c87 | 96 | exit(EXIT_FAILURE); |
4bcb77cf | 97 | } |
25697a35 | 98 | |
246c8489 | 99 | if(UserIp) |
25697a35 GS |
100 | strcpy(user,ip); |
101 | ||
102 | bzero(data, 15); | |
103 | if(strncmp(df,"u",1) != 0) { | |
104 | strncpy(data,data2+6,2); | |
105 | strcat(data,"/"); | |
106 | strncat(data,data2+4,2); | |
107 | strcat(data,"/"); | |
108 | strncat(data,data2,4); | |
109 | } else { | |
110 | strncpy(data,data2+4,2); | |
111 | strcat(data,"/"); | |
112 | strncat(data,data2+6,2); | |
113 | strcat(data,"/"); | |
114 | strncat(data,data2,4); | |
115 | } | |
116 | ||
246c8489 | 117 | if(Ip2Name) |
a1c55d8c | 118 | ip2name(ip,sizeof(ip)); |
25697a35 GS |
119 | |
120 | if(!z) { | |
121 | strcpy(ouser,user); | |
122 | strcpy(oip,ip); | |
123 | z++; | |
124 | } else { | |
125 | if(strcmp(ouser,user) == 0) | |
126 | user[0]='\0'; | |
127 | if(user[0] != '\0') | |
128 | strcpy(ouser,user); | |
120d768c | 129 | if(strcmp(oip,ip) == 0) |
25697a35 GS |
130 | ip[0]='\0'; |
131 | if(ip[0] != '\0') | |
132 | strcpy(oip,ip); | |
133 | } | |
134 | ||
965c4a6f | 135 | user_find(name, sizeof(name), user); |
25697a35 GS |
136 | |
137 | if(SquidGuardReportLimit) { | |
138 | if(strcmp(ouser2,name) == 0) { | |
139 | count++; | |
140 | } else { | |
141 | count=1; | |
142 | strcpy(ouser2,name); | |
143 | } | |
144 | if(count >= SquidGuardReportLimit) | |
145 | continue; | |
146 | } | |
147 | ||
e5b2c6f0 FM |
148 | 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,data,hora); |
149 | output_html_url(fp_ou,url); | |
150 | fputs("\">",fp_ou); | |
151 | output_html_string(fp_ou,url,100); | |
152 | fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></th>\n",rule); | |
25697a35 | 153 | } |
25697a35 | 154 | fclose(fp_in); |
c0ec9cc7 FM |
155 | |
156 | fputs("</table></div>\n",fp_ou); | |
fa6552b0 FM |
157 | if (write_html_trailer(fp_ou)<0) |
158 | debuga(_("Write error in file %s\n"),report); | |
159 | if (fclose(fp_ou)==EOF) | |
160 | debuga(_("Failed to close file %s - %s\n"),report,strerror(errno)); | |
25697a35 GS |
161 | |
162 | unlink(squidguard_in); | |
163 | ||
164 | return; | |
165 | } |