]> git.ipfire.org Git - thirdparty/sarg.git/blame - download.c
Imported Sarg 2.1.0
[thirdparty/sarg.git] / download.c
CommitLineData
25697a35 1/*
94ff9470 2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
25697a35 3 * 1998, 2005
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
28void download_report()
29{
30
31 FILE *fp_in = NULL, *fp_ou = NULL;
32
33 char url[MAXLEN];
34 char html[MAXLEN];
35 char html2[MAXLEN];
36 char report_in[MAXLEN];
37 char report_ou[MAXLEN];
38 char wdirname[MAXLEN];
39 char report[MAXLEN];
40 char periodo[100];
41 char ip[MAXLEN];
42 char oip[MAXLEN];
43 char user[MAXLEN];
44 char ouser[MAXLEN];
45 char ouser2[MAXLEN];
46 char data[15];
47 char hora[15];
48 char ftime[128];
49 char *str;
50 int z=0;
51 int count=0;
52
53 ouser[0]='\0';
54
55 sprintf(report_in,"%s/sarg/download.log",TempDir);
56 if(access(report_in, R_OK) != 0)
57 return;
58
59 strcpy(wdirname,dirname);
60 sprintf(report,"%s/download.html",wdirname);
61 strcat(wdirname,"/");
62 strcat(wdirname,"periodo");
63
64 if ((fp_in = fopen(wdirname, "r")) == 0) {
65 fprintf(stderr, "SARG: (download) %s: %s\n",text[45],wdirname);
66 exit(1);
67 }
68
69 fgets(periodo,sizeof(periodo),fp_in);
70 fclose(fp_in);
71
72 if((fp_in=fopen(report_in,"r"))==NULL) {
73 fprintf(stderr, "SARG: (download) %s: %s\n",text[8],report_in);
74 exit(1);
75 }
76
77 if((fp_ou=fopen(report,"w"))==NULL) {
78 fprintf(stderr, "SARG: (download) %s: %s\n",text[8],report);
79 exit(1);
80 }
81
82 fputs("<html>\n",fp_ou);
83 fputs("<head>\n",fp_ou);
84 sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
85 fputs(html,fp_ou);
86 css(fp_ou);
87 fputs("</head>\n",fp_ou);
88
89 sprintf(url,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
90 fputs(url,fp_ou);
91
92 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
93
94 if(strlen(LogoImage) > 0) {
94ff9470
GS
95 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
96 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);
25697a35 97 fputs(url,fp_ou);
94ff9470
GS
98 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
99 fputs("</table>\n",fp_ou);
25697a35
GS
100 }
101
491b862f
GS
102 if(strcmp(IndexTree,"date") == 0)
103 show_sarg(fp_ou, "../../..");
104 else
105 show_sarg(fp_ou, "..");
25697a35
GS
106 sprintf(url,"<tr><th class=\"title\">%s</b></th></tr>\n",Title);
107 fputs(url,fp_ou);
108
109 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],periodo);
110 fputs(url,fp_ou);
111 sprintf(url,"<tr><th class=\"header3\">%s %s</th></tr>\n",text[125],text[55]);
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><th class=\"header\">%s</th></tr>\n",text[98],text[111],text[110],text[91]);
120 fputs(url,fp_ou);
121
122 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
123 getword(data,buf,' ');
124 getword(hora,buf,' ');
125 getword(user,buf,' ');
126 getword(ip,buf,' ');
127 getword(url,buf,' ');
128
129 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
130 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
131 fixip(user);
132 }
133
134 if(strcmp(Ip2Name,"yes") == 0)
135 ip2name(ip);
136
137 if(!z) {
138 strcpy(ouser,user);
139 strcpy(oip,ip);
140 z++;
141 } else {
142 if(strcmp(ouser,user) == 0)
143 user[0]='\0';
144 if(user[0] != '\0')
145 strcpy(ouser,user);
146 if(strcmp(oip,ip) == 0)
147 ip[0]='\0';
148 if(ip[0] != '\0')
149 strcpy(oip,ip);
150 }
151
152 if(UserTabFile[0] != '\0') {
153 sprintf(warea,":%s:",user);
154 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
155 z1=0;
156 str2=(char *) strstr(str+1,":");
157 str2++;
158 bzero(name, MAXLEN);
159 while(str2[z1] != ':') {
160 name[z1]=str2[z1];
161 z1++;
162 }
163 } else strcpy(name,user);
164 } else strcpy(name,user);
165
94ff9470
GS
166 if(dotinuser && strstr(name,"_")) {
167 str2=(char *)subs(name,"_",".");
168 strcpy(name,str2);
169 }
170
171 if(DownloadReportLimit) {
25697a35
GS
172 if(strcmp(ouser2,name) == 0) {
173 count++;
174 } else {
175 count=1;
176 strcpy(ouser2,name);
177 }
94ff9470 178 if(count >= DownloadReportLimit)
25697a35
GS
179 continue;
180 }
181
182 if(strlen(BlockIt) > 0)
491b862f 183 sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url,ImageFile);
25697a35
GS
184 else BlockImage[0]='\0';
185
186 sprintf(html2,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s-%s</td><td class=\"data2\">%s<a href=\"%s\">%s</a></td></th>\n",name,ip,data,hora,BlockImage,url,url);
187 fputs(html2,fp_ou);
188 }
189
190 fputs("</table>\n",fp_ou);
191
192 show_info(fp_ou);
193 fputs("</html>\n",fp_ou);
194
195 fclose(fp_in);
196 fclose(fp_ou);
197
198 unlink(report_in);
199
200 return;
201}