]>
git.ipfire.org Git - thirdparty/sarg.git/blob - siteuser.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
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.
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.
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.
27 #include "include/conf.h"
28 #include "include/defs.h"
38 char general2
[MAXLEN
];
48 struct generalitemstruct item
;
49 struct userinfostruct
*uinfo
;
52 if (debugz
) debugaz(_("Sites and users report not generated because privacy option is on\n"));
57 sprintf(general
,"%s/sarg-general",outdirname
);
58 sprintf(sites
,"%s/sarg-sites",outdirname
);
59 sprintf(general2
,"%s/sarg-general2",outdirname
);
60 sprintf(report
,"%s/siteuser.html",outdirname
);
62 if (snprintf(csort
,sizeof(csort
),"sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2
,general
)>=sizeof(csort
)) {
63 debuga(_("Command too long: "));
64 debuga_more("sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2
,general
);
67 cstatus
=system(csort
);
68 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
69 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
70 debuga(_("sort command: %s\n"),csort
);
74 if((fp_in
=fopen(general2
,"r"))==NULL
) {
75 debugapos("siteuser",_("Cannot open file \"%s\": %s\n"),general2
,strerror(errno
));
76 debuga(_("sort command: %s\n"),csort
);
80 if((fp_ou
=fopen(report
,"w"))==NULL
) {
81 debugapos("siteuser",_("Cannot open file \"%s\": %s\n"),report
,strerror(errno
));
85 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("Sites & Users"),HTML_JS_SORTTABLE
);
86 fputs("<tr><td class=\"header_c\">",fp_ou
);
87 fprintf(fp_ou
,_("Period: %s"),period
.html
);
88 fputs("</td></tr>\n",fp_ou
);
89 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Sites & Users"));
90 close_html_header(fp_ou
);
92 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\"",fp_ou
);
93 if (SortTableJs
[0]) fputs(" class=\"sortable\"",fp_ou
);
94 fprintf(fp_ou
,">\n<thead><tr><th class=\"header_l\">%s</th><th class=\"header_l",_("NUM"));
95 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
96 fprintf(fp_ou
,"\">%s</th>",_("ACCESSED SITE"));
97 if(BytesInSitesUsersReport
)
98 fprintf(fp_ou
,"<th class=\"header_l\">%s</th>",_("BYTES"));
99 fputs("<th class=\"header_l",fp_ou
);
100 if (SortTableJs
[0]) fputs(" sorttable_alpha",fp_ou
);
101 /* TRANSLATORS: This is a column header showing the users who visited each site. */
102 fprintf(fp_ou
,"\">%s</th></tr></thead>\n",_("USERS"));
107 userinfo_clearflag();
108 topuser_link
=((ReportType
& REPORT_TYPE_USERS_SITES
) != 0 && !indexonly
);
110 if ((line
=longline_create())==NULL
) {
111 debuga(_("Not enough memory to read file \"%s\"\n"),general2
);
115 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
116 ger_read(buf
,&item
,general2
);
117 if(item
.total
) continue;
118 uinfo
=userinfo_find_from_id(item
.user
);
120 debuga(_("Unknown user ID %s in file \"%s\"\n"),item
.user
,general2
);
124 if (item
.nacc
> 0) nsitesusers
= 1;
125 if (!nsitesusers
) continue;
127 if (ourl
==NULL
|| strcmp(item
.url
,ourl
) != 0) {
128 if (regs
>0) fputs("</td></tr>\n",fp_ou
);
131 if (SiteUsersReportLimit
&& regs
>= SiteUsersReportLimit
)
133 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs
);
135 url_len
=strlen(item
.url
);
136 if (url_len
>=ourl_size
) {
138 ourl
=realloc(ourl
,ourl_size
);
140 debuga(_("Not enough memory to store the url\n"));
144 strcpy(ourl
,item
.url
);
146 if(BlockIt
[0]!='\0' && ourl
[0]!=ALIAS_PREFIX
) {
147 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
148 output_html_url(fp_ou
,ourl
);
149 fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou
);
151 output_html_link(fp_ou
,ourl
,100);
152 fputs("</td>",fp_ou
);
154 if (BytesInSitesUsersReport
) {
155 fputs("<td class=\"data\"",fp_ou
);
156 if (SortTableJs
[0]) fprintf(fp_ou
," sorttable_customkey=\"%"PRId64
"\"",(int64_t)item
.nbytes
);
157 fprintf(fp_ou
,">%s</td>",fixnum(item
.nbytes
,1));
159 fputs("<td class=\"data2\">",fp_ou
);
161 userinfo_clearflag();
162 if (topuser_link
&& uinfo
->topuser
)
163 fprintf(fp_ou
,"<a href=\"%s/%s.html\">%s</a>",uinfo
->filename
,uinfo
->filename
,uinfo
->label
);
165 fprintf(fp_ou
,"%s",uinfo
->label
);
168 else if (uinfo
->flag
==0) {
169 if (topuser_link
&& uinfo
->topuser
)
170 fprintf(fp_ou
," <a href=\"%s/%s.html\">%s</a>",uinfo
->filename
,uinfo
->filename
,uinfo
->label
);
172 fprintf(fp_ou
," %s",uinfo
->label
);
178 longline_destroy(&line
);
181 fputs("</td></tr>\n",fp_ou
);
183 if (ourl
) free(ourl
);
185 if (!KeepTempLog
&& unlink(general2
)) {
186 debuga(_("Cannot delete \"%s\": %s\n"),general2
,strerror(errno
));
190 fputs("</table></div>\n",fp_ou
);
191 if (write_html_trailer(fp_ou
)<0)
192 debuga(_("Write error in file \"%s\"\n"),report
);
193 if (fclose(fp_ou
)==EOF
)
194 debuga(_("Failed to close file \"%s\": %s\n"),report
,strerror(errno
));