]> git.ipfire.org Git - thirdparty/sarg.git/blame - download.c
Imported sarg 2.0.9
[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
102 show_sarg(fp_ou, "..");
103 sprintf(url,"<tr><th class=\"title\">%s</b></th></tr>\n",Title);
104 fputs(url,fp_ou);
105
106 sprintf(url,"<tr><td class=\"header\">%s: %s</td></tr>\n",text[89],periodo);
107 fputs(url,fp_ou);
108 sprintf(url,"<tr><th class=\"header3\">%s %s</th></tr>\n",text[125],text[55]);
109 fputs(url,fp_ou);
110 fputs("</table></center>\n",fp_ou);
111
112 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
113 fputs("<tr><td></td></tr>\n",fp_ou);
114 fputs("<tr><td></td></tr>\n",fp_ou);
115 fputs("<tr><td></td></tr>\n",fp_ou);
116 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]);
117 fputs(url,fp_ou);
118
119 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
120 getword(data,buf,' ');
121 getword(hora,buf,' ');
122 getword(user,buf,' ');
123 getword(ip,buf,' ');
124 getword(url,buf,' ');
125
126 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
127 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
128 fixip(user);
129 }
130
131 if(strcmp(Ip2Name,"yes") == 0)
132 ip2name(ip);
133
134 if(!z) {
135 strcpy(ouser,user);
136 strcpy(oip,ip);
137 z++;
138 } else {
139 if(strcmp(ouser,user) == 0)
140 user[0]='\0';
141 if(user[0] != '\0')
142 strcpy(ouser,user);
143 if(strcmp(oip,ip) == 0)
144 ip[0]='\0';
145 if(ip[0] != '\0')
146 strcpy(oip,ip);
147 }
148
149 if(UserTabFile[0] != '\0') {
150 sprintf(warea,":%s:",user);
151 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
152 z1=0;
153 str2=(char *) strstr(str+1,":");
154 str2++;
155 bzero(name, MAXLEN);
156 while(str2[z1] != ':') {
157 name[z1]=str2[z1];
158 z1++;
159 }
160 } else strcpy(name,user);
161 } else strcpy(name,user);
162
94ff9470
GS
163 if(dotinuser && strstr(name,"_")) {
164 str2=(char *)subs(name,"_",".");
165 strcpy(name,str2);
166 }
167
168 if(DownloadReportLimit) {
25697a35
GS
169 if(strcmp(ouser2,name) == 0) {
170 count++;
171 } else {
172 count=1;
173 strcpy(ouser2,name);
174 }
94ff9470 175 if(count >= DownloadReportLimit)
25697a35
GS
176 continue;
177 }
178
179 if(strlen(BlockIt) > 0)
180 sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,url);
181 else BlockImage[0]='\0';
182
183 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);
184 fputs(html2,fp_ou);
185 }
186
187 fputs("</table>\n",fp_ou);
188
189 show_info(fp_ou);
190 fputs("</html>\n",fp_ou);
191
192 fclose(fp_in);
193 fclose(fp_ou);
194
195 unlink(report_in);
196
197 return;
198}