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