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