]>
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
];
53 struct generalitemstruct item
;
54 const struct userinfostruct
*uinfo
;
60 sprintf(general
,"%s/sarg-general",outdirname
);
61 sprintf(sites
,"%s/sarg-sites",outdirname
);
62 sprintf(general2
,"%s/sarg-general2",outdirname
);
63 sprintf(per
,"%s/sarg-period",outdirname
);
64 sprintf(report
,"%s/siteuser.html",outdirname
);
66 if ((fp_in
= fopen(per
, "r")) == 0) {
67 fprintf(stderr
, "SARG: (siteuser) %s: %s\n",_("Cannot open file"),per
);
71 if (!fgets(period
,sizeof(period
),fp_in
)) {
72 debuga(_("(siteuser) read error in %s\n"),per
);
77 sprintf(csort
,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2
,general
);
78 cstatus
=system(csort
);
79 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
80 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
81 debuga(_("sort command: %s\n"),csort
);
85 if((fp_in
=fopen(general2
,"r"))==NULL
) {
86 debuga(_("(siteuser) Cannot open log file %s\n"),general2
);
87 debuga(_("sort command: %s\n"),csort
);
91 if((fp_ou
=fopen(report
,"w"))==NULL
) {
92 debuga(_("(siteuser) Cannot open log file %s\n"),report
);
96 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("Sites & Users"));
97 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period
);
98 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Sites & Users"));
99 close_html_header(fp_ou
);
101 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou
);
102 fputs("<tr><td></td></tr>\n",fp_ou
);
103 if(BytesInSitesUsersReport
)
104 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"));
106 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"));
112 if((users
=(char *) malloc(204800))==NULL
){
113 debuga(_("ERROR: Cannot load. Memory fault\n"));
118 if ((line
=longline_create())==NULL
) {
119 debuga(_("Not enough memory to read file %s\n"),general2
);
123 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
124 ger_read(buf
,&item
,general2
);
125 if(item
.total
) continue;
126 uinfo
=userinfo_find_from_id(item
.user
);
128 debuga(_("Unknown user ID %s in file %s\n"),item
.user
,general2
);
132 if (item
.nacc
> 0) nsitesusers
= 1;
134 url_len
=strlen(item
.url
);
135 if (!ourl
|| url_len
>=ourl_size
) {
137 ourl
=realloc(ourl
,ourl_size
);
139 debuga(_("Not enough memory to store the url\n"));
143 strcpy(ourl
,item
.url
);
148 sprintf(wuser
," %s ",uinfo
->label
);
149 if(strstr(users
,wuser
) == 0 && strcmp(item
.url
,ourl
) == 0) {
150 strcat(users
,uinfo
->label
);
154 strcat(users
,"<br>");
159 if(SiteUsersReportLimit
) {
160 if(regs
>= SiteUsersReportLimit
)
164 if(strcmp(item
.url
,ourl
) != 0 && nsitesusers
) {
165 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs
);
166 if(BlockIt
[0]!='\0') {
167 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
168 output_html_url(fp_ou
,ourl
);
169 fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou
);
171 fputs("<a href=\"http://",fp_ou
);
172 output_html_url(fp_ou
,ourl
);
174 output_html_string(fp_ou
,ourl
,100);
175 fputs("</a></td>",fp_ou
);
177 if(BytesInSitesUsersReport
)
178 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(obytes
,1));
179 fprintf(fp_ou
,"<td class=\"data2\">%s</td></tr>\n",users
);
183 strcpy(users
,uinfo
->label
);
185 url_len
=strlen(item
.url
);
186 if (url_len
>=ourl_size
) {
188 ourl
=realloc(ourl
,ourl_size
);
190 debuga(_("Not enough memory to store the url\n"));
194 strcpy(ourl
,item
.url
);
199 longline_destroy(&line
);
202 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://",regs
);
203 output_html_url(fp_ou
,ourl
);
205 output_html_string(fp_ou
,ourl
,100);
206 fprintf(fp_ou
,"</a></td><td class=\"data2\">%s</td></tr>\n",users
);
208 if (ourl
) free(ourl
);
212 fputs("</table></div>\n",fp_ou
);
213 write_html_trailer(fp_ou
);