]>
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"
41 char general2
[MAXLEN
];
53 struct getwordstruct gwarea
;
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 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
118 getword_start(&gwarea
,buf
);
119 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0) {
120 printf("SARG: Maybe you have an invalid user in the %s file of the siteuser.\n",general2
);
123 if(strcmp(user
,"TOTAL") == 0)
128 user_find(name
, sizeof(name
), user
);
130 if(dotinuser
&& strchr(name
,'_')) {
131 subs(name
,sizeof(name
),"_",".");
135 In fact, even the first call is unecessary as the resolved user variable is never used.
137 ip2name(user,sizeof(user));
141 Is this redundant ip2name a mistake or is it really necessary ? It definitely slow down sarg
142 if the first ip2name succeed because it will try to resolve a name which is not an IP but if
143 the first ip2name failed, the second attempt may find the expected address which was resolved
144 in the mean time by the DNS server.
146 ip2name(user,sizeof(user));
149 if (getword_atoll(&nacc
,&gwarea
,'\t')<0){
150 printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2
);
153 if (nacc
> 0) nsitesusers
= 1;
154 if (getword_atoll(&nbytes
,&gwarea
,'\t')<0){
155 printf("SARG: Maybe you have an invalid number of bytes in your %s file of the siteuser.\n",general2
);
158 if (getword(url
,sizeof(url
),&gwarea
,'\t')<0) {
159 printf("SARG: Maybe you have an invalid url in your %s file of the siteuser.\n",general2
);
169 sprintf(wuser
," %s ",name
);
170 if(strstr(users
,wuser
) == 0 && strcmp(url
,ourl
) == 0) {
175 strcat(users
,"<br>");
180 if(SiteUsersReportLimit
) {
181 if(regs
>= SiteUsersReportLimit
)
186 sprintf(BlockImage
,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\"></a> ",wwwDocumentRoot
,BlockIt
,ourl
);
187 else BlockImage
[0]='\0';
189 if(strcmp(url
,ourl
) != 0 && nsitesusers
) {
190 if(BytesInSitesUsersReport
) {
191 sprintf(wwork2
,"%s",fixnum(obytes
,1));
192 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data\">%s</td><td class=\"data2\">%s</td></tr>\n",regs
,BlockImage
,ourl
,ourl
,wwork2
,users
);
194 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs
,BlockImage
,ourl
,ourl
,users
);
206 fprintf(fp_ou
,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs
,ourl
,ourl
,users
);
211 fputs("</table></div>\n",fp_ou
);
212 write_html_trailer(fp_ou
);