]>
git.ipfire.org Git - thirdparty/sarg.git/blob - download.c
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
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.
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.
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.
26 #include "include/conf.h"
28 void download_report()
31 FILE *fp_in
= NULL
, *fp_ou
= NULL
;
36 char report_in
[MAXLEN
];
37 char wdirname
[MAXLEN
];
53 sprintf(report_in
,"%s/sarg/download.log",TempDir
);
54 if(access(report_in
, R_OK
) != 0)
57 strcpy(wdirname
,dirname
);
58 sprintf(report
,"%s/download.html",wdirname
);
60 strcat(wdirname
,"sarg-period");
62 if ((fp_in
= fopen(wdirname
, "r")) == 0) {
63 fprintf(stderr
, "SARG: (download) %s: %s\n",text
[45],wdirname
);
67 fgets(period
,sizeof(period
),fp_in
);
70 if((fp_in
=fopen(report_in
,"r"))==NULL
) {
71 fprintf(stderr
, "SARG: (download) %s: %s\n",text
[8],report_in
);
75 if((fp_ou
=fopen(report
,"w"))==NULL
) {
76 fprintf(stderr
, "SARG: (download) %s: %s\n",text
[8],report
);
80 fputs("<html>\n",fp_ou
);
81 fputs("<head>\n",fp_ou
);
82 sprintf(html
," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
85 fputs("</head>\n",fp_ou
);
87 sprintf(url
,"<body bgcolor=%s text=%s background='%s'>\n",BgColor
,TxColor
,BgImage
);
90 if(strlen(LogoImage
) > 0) fprintf(fp_ou
, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage
,Width
,Height
,LogoText
);
92 if(strcmp(IndexTree
,"date") == 0)
93 show_sarg(fp_ou
, "../../..");
95 show_sarg(fp_ou
, "..");
97 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
98 sprintf(url
,"<tr><th class=\"title\">%s</b></th></tr>\n",Title
);
101 sprintf(url
,"<tr><td class=\"header\">%s: %s</td></tr>\n",text
[89],period
);
103 sprintf(url
,"<tr><th class=\"header3\">%s</th></tr>\n",text
[125]);
105 fputs("</table></center>\n",fp_ou
);
107 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou
);
108 fputs("<tr><td></td></tr>\n",fp_ou
);
109 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]);
112 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
113 if (getword(data
,sizeof(data
),buf
,' ')<0 || getword(hora
,sizeof(hora
),buf
,' ')<0 ||
114 getword(user
,sizeof(user
),buf
,' ')<0 || getword(ip
,sizeof(ip
),buf
,' ')<0 ||
115 getword(url
,sizeof(url
),buf
,' ')<0) {
116 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",report_in
);
120 if((str
=(char *) strstr(user
, "_")) != (char *) NULL
) {
121 if((str
=(char *) strstr(str
+1, "_")) != (char *) NULL
)
125 if(strcmp(Ip2Name
,"yes") == 0)
133 if(strcmp(ouser
,user
) == 0)
137 if(strcmp(oip
,ip
) == 0)
143 if(UserTabFile
[0] != '\0') {
144 sprintf(warea
,":%s:",user
);
145 if((str
=(char *) strstr(userfile
,warea
)) != (char *) NULL
) {
147 str2
=(char *) strstr(str
+1,":");
150 while(str2
[z1
] != ':') {
154 } else strcpy(name
,user
);
155 } else strcpy(name
,user
);
157 if(dotinuser
&& strstr(name
,"_")) {
158 str2
=(char *)subs(name
,"_",".");
162 if(DownloadReportLimit
) {
163 if(strcmp(ouser2
,name
) == 0) {
169 if(count
>= DownloadReportLimit
)
173 if(strlen(BlockIt
) > 0)
174 sprintf(BlockImage
,"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a> ",wwwDocumentRoot
,BlockIt
,url
,ImageFile
);
175 else BlockImage
[0]='\0';
177 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
);
181 fputs("</table>\n",fp_ou
);
184 fputs("</html>\n",fp_ou
);