]> git.ipfire.org Git - thirdparty/sarg.git/blame - siteuser.c
Fix some translations
[thirdparty/sarg.git] / siteuser.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
fbd133bb 3 * 1998, 2011
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 siteuser(void)
25697a35 31{
9bd92830
FM
32 FILE *fp_in, *fp_ou;
33
34 char *buf;
35 char wuser[MAXLEN];
36 char *ourl;
37 char csort[255];
38 char general[MAXLEN];
39 char general2[MAXLEN];
40 char sites[MAXLEN];
41 char report[MAXLEN];
42 int regs=0;
43 int ucount=0;
44 int ourl_size;
45 int url_len;
46 char *users;
47 long long int obytes;
48 int cstatus;
49 longline line;
50 struct generalitemstruct item;
51 const struct userinfostruct *uinfo;
52
9f93fec3
FM
53 if(Privacy) {
54 if (debugz) debugaz(_("Sites and users report not generated because privacy option is on\n"));
9bd92830 55 return;
9f93fec3 56 }
9bd92830
FM
57
58 nsitesusers = 0;
59 sprintf(general,"%s/sarg-general",outdirname);
60 sprintf(sites,"%s/sarg-sites",outdirname);
61 sprintf(general2,"%s/sarg-general2",outdirname);
62 sprintf(report,"%s/siteuser.html",outdirname);
63
78eeb33f
FM
64 if (snprintf(csort,sizeof(csort),"sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general)>=sizeof(csort)) {
65 debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general,general2);
66 exit(EXIT_FAILURE);
67 }
9bd92830
FM
68 cstatus=system(csort);
69 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
70 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
71 debuga(_("sort command: %s\n"),csort);
72 exit(EXIT_FAILURE);
73 }
74
75 if((fp_in=fopen(general2,"r"))==NULL) {
007905af
FM
76 debuga(_("(siteuser) Cannot open log file %s\n"),general2);
77 debuga(_("sort command: %s\n"),csort);
78 exit(EXIT_FAILURE);
9bd92830
FM
79 }
80
81 if((fp_ou=fopen(report,"w"))==NULL) {
007905af
FM
82 debuga(_("(siteuser) Cannot open log file %s\n"),report);
83 exit(EXIT_FAILURE);
9bd92830
FM
84 }
85
86 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Sites & Users"),HTML_JS_SORTTABLE);
87 fputs("<tr><td class=\"header_c\">",fp_ou);
88 fprintf(fp_ou,_("Period: %s"),period.html);
89 fputs("</td></tr>\n",fp_ou);
90 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Sites & Users"));
91 close_html_header(fp_ou);
92
93 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\"",fp_ou);
94 if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou);
95 fprintf(fp_ou,">\n<thead><tr><th class=\"header_l\">%s</th><th class=\"header_l",_("NUM"));
96 if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
97 fprintf(fp_ou,"\">%s</th>",_("ACCESSED SITE"));
98 if(BytesInSitesUsersReport)
99 fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
100 fputs("<th class=\"header_l",fp_ou);
101 if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
102 fprintf(fp_ou,"\">%s</th></tr></thead>\n",_("USERS"));
103
104 ourl=NULL;
105 ourl_size=0;
106 obytes=0;
107
108 if((users=(char *) malloc(204800))==NULL){
109 debuga(_("ERROR: Cannot load. Memory fault\n"));
110 exit(EXIT_FAILURE);
111 }
112 strcpy(users," ");
113
114 if ((line=longline_create())==NULL) {
115 debuga(_("Not enough memory to read file %s\n"),general2);
116 exit(EXIT_FAILURE);
117 }
118
119 while((buf=longline_read(fp_in,line))!=NULL) {
120 ger_read(buf,&item,general2);
121 if(item.total) continue;
122 uinfo=userinfo_find_from_id(item.user);
123 if (!uinfo) {
124 debuga(_("Unknown user ID %s in file %s\n"),item.user,general2);
125 exit(EXIT_FAILURE);
126 }
127
128 if (item.nacc > 0) nsitesusers = 1;
129 if(!regs) {
130 url_len=strlen(item.url);
131 if (!ourl || url_len>=ourl_size) {
132 ourl_size=url_len+1;
133 ourl=realloc(ourl,ourl_size);
134 if (!ourl) {
135 debuga(_("Not enough memory to store the url\n"));
136 exit(EXIT_FAILURE);
137 }
138 }
139 strcpy(ourl,item.url);
140 obytes=item.nbytes;
141 regs++;
142 }
143
144 sprintf(wuser," %s ",uinfo->label);
145 if(strstr(users,wuser) == 0 && strcmp(item.url,ourl) == 0) {
146 strcat(users,uinfo->label);
147 strcat(users," ");
148 ucount++;
149 if(ucount>4) {
150 strcat(users,"<br>");
151 ucount=0;
152 }
153 }
154
155 if(SiteUsersReportLimit) {
156 if(regs >= SiteUsersReportLimit)
157 continue;
158 }
159
160 if(strcmp(item.url,ourl) != 0 && nsitesusers) {
161 fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
67a93701 162 if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
9bd92830
FM
163 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
164 output_html_url(fp_ou,ourl);
165 fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
166 }
67a93701
FM
167 output_html_link(fp_ou,ourl,100);
168 fputs("</td>",fp_ou);
9bd92830
FM
169
170 if (BytesInSitesUsersReport) {
171 fputs("<td class=\"data\"",fp_ou);
172 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)obytes);
173 fprintf(fp_ou,">%s</td>",fixnum(obytes,1));
174 }
175 fprintf(fp_ou,"<td class=\"data2\">%s</td></tr>\n",users);
176
177 regs++;
178 ucount=0;
179 strcpy(users,uinfo->label);
180 strcat(users," ");
181 url_len=strlen(item.url);
182 if (url_len>=ourl_size) {
183 ourl_size=url_len+1;
184 ourl=realloc(ourl,ourl_size);
185 if (!ourl) {
186 debuga(_("Not enough memory to store the url\n"));
187 exit(EXIT_FAILURE);
188 }
189 }
190 strcpy(ourl,item.url);
191 obytes=item.nbytes;
192 }
193 }
194 fclose(fp_in);
195 longline_destroy(&line);
196
197 if(nsitesusers) {
198 fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
67a93701 199 if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
9bd92830
FM
200 fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
201 output_html_url(fp_ou,ourl);
202 fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
203 }
67a93701
FM
204 output_html_link(fp_ou,ourl,100);
205 fputs("</td>",fp_ou);
9bd92830
FM
206 if (BytesInSitesUsersReport) {
207 fputs("<td class=\"data\"",fp_ou);
208 if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)obytes);
209 fprintf(fp_ou,">%s</td>",fixnum(obytes,1));
210 }
211 fprintf(fp_ou,"<td class=\"data2\">%s</td></tr>\n",users);
212 }
213 if (ourl) free(ourl);
214
08f9b029
FM
215 if (unlink(general2)) {
216 debuga(_("Cannot delete %s - %s\n"),general2,strerror(errno));
217 exit(EXIT_FAILURE);
218 }
9bd92830
FM
219
220 fputs("</table></div>\n",fp_ou);
221 if (write_html_trailer(fp_ou)<0)
222 debuga(_("Write error in file %s\n"),report);
223 if (fclose(fp_ou)==EOF)
224 debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
225
226 if(users)
227 free(users);
228
229 return;
25697a35 230}