]>
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"
40 char general2
[MAXLEN
];
51 struct generalitemstruct item
;
52 const struct userinfostruct
*uinfo
;
58 sprintf(general
,"%s/sarg-general",outdirname
);
59 sprintf(sites
,"%s/sarg-sites",outdirname
);
60 sprintf(general2
,"%s/sarg-general2",outdirname
);
61 sprintf(report
,"%s/siteuser.html",outdirname
);
63 sprintf(csort
,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2
,general
);
64 cstatus
=system(csort
);
65 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
66 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
67 debuga(_("sort command: %s\n"),csort
);
71 if((fp_in
=fopen(general2
,"r"))==NULL
) {
72 debuga(_("(siteuser) Cannot open log file %s\n"),general2
);
73 debuga(_("sort command: %s\n"),csort
);
77 if((fp_ou
=fopen(report
,"w"))==NULL
) {
78 debuga(_("(siteuser) Cannot open log file %s\n"),report
);
82 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("Sites & Users"));
83 fputs("<tr><td class=\"header_c\">",fp_ou
);
84 fprintf(fp_ou
,_("Period: %s"),period
.html
);
85 fputs("</td></tr>\n",fp_ou
);
86 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Sites & Users"));
87 close_html_header(fp_ou
);
89 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou
);
90 fputs("<tr><td></td></tr>\n",fp_ou
);
91 if(BytesInSitesUsersReport
)
92 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></tr>\n",_("NUM"),_("ACCESSED SITE"),_("BYTES"),_("USERS"));
94 fprintf(fp_ou
,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("NUM"),_("ACCESSED SITE"),_("USERS"));
100 if((users
=(char *) malloc(204800))==NULL
){
101 debuga(_("ERROR: Cannot load. Memory fault\n"));
106 if ((line
=longline_create())==NULL
) {
107 debuga(_("Not enough memory to read file %s\n"),general2
);
111 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
112 ger_read(buf
,&item
,general2
);
113 if(item
.total
) continue;
114 uinfo
=userinfo_find_from_id(item
.user
);
116 debuga(_("Unknown user ID %s in file %s\n"),item
.user
,general2
);
120 if (item
.nacc
> 0) nsitesusers
= 1;
122 url_len
=strlen(item
.url
);
123 if (!ourl
|| url_len
>=ourl_size
) {
125 ourl
=realloc(ourl
,ourl_size
);
127 debuga(_("Not enough memory to store the url\n"));
131 strcpy(ourl
,item
.url
);
136 sprintf(wuser
," %s ",uinfo
->label
);
137 if(strstr(users
,wuser
) == 0 && strcmp(item
.url
,ourl
) == 0) {
138 strcat(users
,uinfo
->label
);
142 strcat(users
,"<br>");
147 if(SiteUsersReportLimit
) {
148 if(regs
>= SiteUsersReportLimit
)
152 if(strcmp(item
.url
,ourl
) != 0 && nsitesusers
) {
153 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs
);
154 if(BlockIt
[0]!='\0') {
155 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
156 output_html_url(fp_ou
,ourl
);
157 fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou
);
159 fputs("<a href=\"http://",fp_ou
);
160 output_html_url(fp_ou
,ourl
);
162 output_html_string(fp_ou
,ourl
,100);
163 fputs("</a></td>",fp_ou
);
165 if(BytesInSitesUsersReport
)
166 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(obytes
,1));
167 fprintf(fp_ou
,"<td class=\"data2\">%s</td></tr>\n",users
);
171 strcpy(users
,uinfo
->label
);
173 url_len
=strlen(item
.url
);
174 if (url_len
>=ourl_size
) {
176 ourl
=realloc(ourl
,ourl_size
);
178 debuga(_("Not enough memory to store the url\n"));
182 strcpy(ourl
,item
.url
);
187 longline_destroy(&line
);
190 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://",regs
);
191 output_html_url(fp_ou
,ourl
);
193 output_html_string(fp_ou
,ourl
,100);
194 fprintf(fp_ou
,"</a></td><td class=\"data2\">%s</td></tr>\n",users
);
196 if (ourl
) free(ourl
);
200 fputs("</table></div>\n",fp_ou
);
201 if (write_html_trailer(fp_ou
)<0)
202 debuga(_("Write error in file %s\n"),report
);
203 if (fclose(fp_ou
)==EOF
)
204 debuga(_("Failed to close file %s - %s\n"),report
,strerror(errno
));