]> git.ipfire.org Git - thirdparty/sarg.git/blob - siteuser.c
Imported sarg 2.0.9
[thirdparty/sarg.git] / siteuser.c
1 /*
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
3 * 1998, 2005
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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 class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
99 fputs(url,fp_ou);
100 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
101 fputs("</table>\n",fp_ou);
102 }
103
104 show_sarg(fp_ou, "..");
105 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
106 sprintf(url,"<tr><th class=\"title\">%s</th></tr>\n",Title);
107 fputs(url,fp_ou);
108
109 sprintf(url,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],periodo);
110 fputs(url,fp_ou);
111 sprintf(url,"<tr><td class=\"header3\">%s</td></tr>\n",text[85]);
112 fputs(url,fp_ou);
113 fputs("</table></center>\n",fp_ou);
114
115 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
116 fputs("<tr><td></td></tr>\n",fp_ou);
117 fputs("<tr><td></td></tr>\n",fp_ou);
118 fputs("<tr><td></td></tr>\n",fp_ou);
119 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]);
120 fputs(url,fp_ou);
121
122 user[0]='\0';
123 ourl[0]='\0';
124
125 if((users=(char *) malloc(204800))==NULL){
126 fprintf(stderr, "SARG: ERROR: %s",text[87]);
127 exit(1);
128 }
129 strcat(users," ");
130
131 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
132 getword(user,buf,' ');
133 if(strcmp(user,"TOTAL") == 0)
134 continue;
135 if(userip)
136 fixip(user);
137
138 if(UserTabFile[0] != '\0') {
139 sprintf(warea,":%s:",user);
140 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
141 z1=0;
142 str2=(char *) strstr(str+1,":");
143 str2++;
144 bzero(name, MAXLEN);
145 while(str2[z1] != ':') {
146 name[z1]=str2[z1];
147 z1++;
148 }
149 } else strcpy(name,user);
150 } else strcpy(name,user);
151
152 if(dotinuser && strstr(name,"_")) {
153 str2=(char *)subs(name,"_",".");
154 strcpy(name,str2);
155 }
156
157 if(strcmp(Ip2Name,"yes") == 0)
158 ip2name(user);
159
160 if(strcmp(Ip2Name,"yes") == 0)
161 ip2name(user);
162
163 getword(nacc,buf,' ');
164 getword(nbytes,buf,' ');
165 getword(url,buf,' ');
166
167 if(!regs) {
168 strcpy(ourl,url);
169 regs++;
170 }
171
172 sprintf(wuser," %s ",name);
173 if(strstr(users,wuser) == 0 && strcmp(url,ourl) == 0) {
174 strcat(users,name);
175 strcat(users," ");
176 ucount++;
177 if(ucount>4) {
178 strcat(users,"<br>");
179 ucount=0;
180 }
181 }
182
183 if(SiteUsersReportLimit) {
184 if(regs >= SiteUsersReportLimit)
185 continue;
186 }
187
188 if(strlen(BlockIt) > 0)
189 sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,ourl);
190 else BlockImage[0]='\0';
191
192 if(strcmp(url,ourl) != 0) {
193 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);
194 fputs(html,fp_ou);
195 regs++;
196 ucount=0;
197 strcpy(users,name);
198 strcat(users," ");
199 strcpy(ourl,url);
200 }
201 }
202
203 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);
204 fputs(html,fp_ou);
205
206 unlink(geral2);
207
208 fputs("</table></center>\n",fp_ou);
209
210 show_info(fp_ou);
211
212 fputs("</body>\n</html>\n",fp_ou);
213
214 fclose(fp_in);
215 fclose(fp_ou);
216
217 return;
218
219 }