]>
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
];
52 struct longlinestruct line
;
53 struct generalitemstruct item
;
59 sprintf(general
,"%s/sarg-general",dirname
);
60 sprintf(sites
,"%s/sarg-sites",dirname
);
61 sprintf(general2
,"%s/sarg-general2",dirname
);
62 sprintf(per
,"%s/sarg-period",dirname
);
63 sprintf(report
,"%s/siteuser.html",dirname
);
65 if ((fp_in
= fopen(per
, "r")) == 0) {
66 fprintf(stderr
, "SARG: (siteuser) %s: %s\n",text
[45],per
);
70 if (!fgets(period
,sizeof(period
),fp_in
)) {
71 fprintf(stderr
,"SARG: (siteuser) read error in %s\n",per
);
76 sprintf(csort
,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2
,general
);
77 cstatus
=system(csort
);
78 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
79 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
80 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
84 if((fp_in
=fopen(general2
,"r"))==NULL
) {
85 fprintf(stderr
, "SARG: (topsite) %s: %s\n",text
[8],general2
);
86 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
90 if((fp_ou
=fopen(report
,"w"))==NULL
) {
91 fprintf(stderr
, "SARG: (topsite) %s: %s\n",text
[8],report
);
95 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("Sites & Users"));
96 fprintf(fp_ou
,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",text
[89],period
);
97 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",text
[85]);
98 close_html_header(fp_ou
);
100 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou
);
101 fputs("<tr><td></td></tr>\n",fp_ou
);
102 if(BytesInSitesUsersReport
)
103 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",text
[100],text
[91],text
[93],text
[103]);
105 fprintf(fp_ou
,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",text
[100],text
[91],text
[103]);
111 if((users
=(char *) malloc(204800))==NULL
){
112 fprintf(stderr
, "SARG: ERROR: %s",text
[87]);
117 if (longline_prepare(&line
)<0) {
118 debuga(_("Not enough memory to read file %s"),general2
);
122 while((buf
=longline_read(fp_in
,&line
))!=NULL
) {
123 ger_read(buf
,&item
,general2
);
124 if(item
.total
) continue;
128 user_find(name
, sizeof(name
), item
.user
);
130 if(dotinuser
&& strchr(name
,'_')) {
131 subs(name
,sizeof(name
),"_",".");
134 if (item
.nacc
> 0) nsitesusers
= 1;
136 url_len
=strlen(item
.url
);
137 if (!ourl
|| url_len
>=ourl_size
) {
139 ourl
=realloc(ourl
,ourl_size
);
141 debuga(_("Not enough memory to store the url"));
145 strcpy(ourl
,item
.url
);
150 sprintf(wuser
," %s ",name
);
151 if(strstr(users
,wuser
) == 0 && strcmp(item
.url
,ourl
) == 0) {
156 strcat(users
,"<br>");
161 if(SiteUsersReportLimit
) {
162 if(regs
>= SiteUsersReportLimit
)
166 if(strcmp(item
.url
,ourl
) != 0 && nsitesusers
) {
167 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs
);
168 if(BlockIt
[0]!='\0') {
169 fprintf(fp_ou
,"<a href=\"%s%s?url=",wwwDocumentRoot
,BlockIt
);
170 output_html_url(fp_ou
,ourl
);
171 fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",fp_ou
);
173 fputs("<a href=\"http://",fp_ou
);
174 output_html_url(fp_ou
,ourl
);
176 output_html_string(fp_ou
,ourl
,100);
177 fputs("</a></td>",fp_ou
);
179 if(BytesInSitesUsersReport
)
180 fprintf(fp_ou
,"<td class=\"data\">%s</td>",fixnum(obytes
,1));
181 fprintf(fp_ou
,"<td class=\"data2\">%s</td></tr>\n",users
);
187 url_len
=strlen(item
.url
);
188 if (url_len
>=ourl_size
) {
190 ourl
=realloc(ourl
,ourl_size
);
192 debuga(_("Not enough memory to store the url"));
196 strcpy(ourl
,item
.url
);
201 longline_free(&line
);
204 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://",regs
);
205 output_html_url(fp_ou
,ourl
);
207 output_html_string(fp_ou
,ourl
,100);
208 fprintf(fp_ou
,"</a></td><td class=\"data2\">%s</td></tr>\n",users
);
210 if (ourl
) free(ourl
);
214 fputs("</table></div>\n",fp_ou
);
215 write_html_trailer(fp_ou
);