]> git.ipfire.org Git - thirdparty/sarg.git/blob - siteuser.c
This commit was generated by cvs2svn to compensate for changes in r2,
[thirdparty/sarg.git] / siteuser.c
1 /*
2 * AUTHOR: Pedro Lineu Orso orso@brturbo.com.br
3 * 1998, 2005
4 * SARG Squid Analysis Report Generator http://sarg-squid.org
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
23 *
24 */
25
26 #include "include/conf.h"
27
28 void siteuser()
29 {
30
31 FILE *fp_in, *fp_ou;
32
33 char user[MAXLEN];
34 char url[MAXLEN];
35 char wuser[MAXLEN];
36 char ourl[MAXLEN];
37 char nacc[20];
38 char nbytes[20];
39 char csort[255];
40 char geral[MAXLEN];
41 char geral2[MAXLEN];
42 char per[MAXLEN];
43 char html[MAXLEN];
44 char sites[MAXLEN];
45 char report[MAXLEN];
46 char periodo[100];
47 char ftime[128];
48 int regs=0;
49 int ucount=0;
50 char *users;
51
52 sprintf(geral,"%s/geral",dirname);
53 sprintf(sites,"%s/sites",dirname);
54 sprintf(geral2,"%s/geral2",dirname);
55 sprintf(per,"%s/periodo",dirname);
56 sprintf(report,"%s/siteuser.html",dirname);
57
58 if ((fp_in = fopen(per, "r")) == 0) {
59 fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],per);
60 exit(1);
61 }
62
63 fgets(periodo,sizeof(periodo),fp_in);
64 fclose(fp_in);
65
66 sprintf(csort,"sort -k 4,4 -k 1,1 -o %s %s",geral2,geral);
67 system(csort);
68
69 if((fp_in=fopen(geral2,"r"))==NULL) {
70 fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],geral2);
71 exit(1);
72 }
73
74 if((fp_ou=fopen(report,"w"))==NULL) {
75 fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],report);
76 exit(1);
77 }
78
79 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
80 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
81 fputs("<html>\n",fp_ou);
82 fputs("<head>\n",fp_ou);
83 sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
84 fputs(html,fp_ou);
85 css(fp_ou);
86 fputs("</head>\n",fp_ou);
87
88 if(strlen(FontFace) > 0) {
89 sprintf(url,"<font face=%s>\n",FontFace);
90 fputs(url,fp_ou);
91 }
92
93 sprintf(url,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
94 fputs(url,fp_ou);
95
96 if(strlen(LogoImage) > 0) {
97 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
98 sprintf(url,"<tr><th align=\"center\"><img src='%s' border=0 align=absmiddle width=%s height=%s><font color=%s>%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
99 fputs(url,fp_ou);
100 fputs("</table>\n",fp_ou);
101 }
102
103 show_sarg(fp_ou, "..");
104 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
105 sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title);
106 fputs(url,fp_ou);
107
108 sprintf(url,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],periodo);
109 fputs(url,fp_ou);
110 sprintf(url,"<tr><td class=\"header3\">%s</td></tr>\n",text[85]);
111 fputs(url,fp_ou);
112 fputs("</table></center>\n",fp_ou);
113
114 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
115 fputs("<tr><td></td></tr>\n",fp_ou);
116 fputs("<tr><td></td></tr>\n",fp_ou);
117 fputs("<tr><td></td></tr>\n",fp_ou);
118 sprintf(url,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[100],text[91],text[103]);
119 fputs(url,fp_ou);
120
121 user[0]='\0';
122 ourl[0]='\0';
123
124 if((users=(char *) malloc(204800))==NULL){
125 fprintf(stderr, "SARG: ERROR: %s",text[87]);
126 exit(1);
127 }
128 strcat(users," ");
129
130 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
131 getword(user,buf,' ');
132 if(strcmp(user,"TOTAL") == 0)
133 continue;
134 if(userip)
135 fixip(user);
136
137 if(UserTabFile[0] != '\0') {
138 sprintf(warea,":%s:",user);
139 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
140 z1=0;
141 str2=(char *) strstr(str+1,":");
142 str2++;
143 bzero(name, MAXLEN);
144 while(str2[z1] != ':') {
145 name[z1]=str2[z1];
146 z1++;
147 }
148 } else strcpy(name,user);
149 } else strcpy(name,user);
150
151 if(strcmp(Ip2Name,"yes") == 0)
152 ip2name(user);
153
154 if(strcmp(Ip2Name,"yes") == 0)
155 ip2name(user);
156
157 getword(nacc,buf,' ');
158 getword(nbytes,buf,' ');
159 getword(url,buf,' ');
160
161 if(!regs) {
162 strcpy(ourl,url);
163 regs++;
164 }
165
166 sprintf(wuser," %s ",name);
167 if(strstr(users,wuser) == 0 && strcmp(url,ourl) == 0) {
168 strcat(users,name);
169 strcat(users," ");
170 ucount++;
171 if(ucount>4) {
172 strcat(users,"<br>");
173 ucount=0;
174 }
175 }
176
177 if(SiteUsersReportLimit) {
178 if(regs >= SiteUsersReportLimit)
179 continue;
180 }
181
182 if(strlen(BlockIt) > 0)
183 sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,ourl);
184 else BlockImage[0]='\0';
185
186 if(strcmp(url,ourl) != 0) {
187 sprintf(html,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,users);
188 fputs(html,fp_ou);
189 regs++;
190 ucount=0;
191 strcpy(users,name);
192 strcat(users," ");
193 strcpy(ourl,url);
194 }
195 }
196
197 sprintf(html,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://%s\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,ourl,ourl,users);
198 fputs(html,fp_ou);
199
200 unlink(geral2);
201
202 fputs("</table></center>\n",fp_ou);
203
204 show_info(fp_ou);
205
206 fputs("</body>\n</html>\n",fp_ou);
207
208 fclose(fp_in);
209 fclose(fp_ou);
210
211 return;
212
213 }