]>
git.ipfire.org Git - thirdparty/sarg.git/blob - dansguardian_report.c
fd6b0c927d40ccfe1f5a293bdde04a5256fed3b0
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
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 dansguardian_report()
31 FILE *fp_in
= NULL
, *fp_ou
= NULL
;
36 char dansguardian_in
[MAXLEN
];
37 char dansguardian_ou
[MAXLEN
];
56 sprintf(dansguardian_in
,"%s/dansguardian.log",tmp
);
57 if(!dansguardian_count
) {
58 unlink(dansguardian_in
);
62 sprintf(per
,"%s/periodo",dirname
);
63 sprintf(report
,"%s/dansguardian.html",dirname
);
65 if ((fp_in
= fopen(per
, "r")) == 0) {
66 fprintf(stderr
, "SARG: (dansguardian_report) %s: %s\n",text
[45],per
);
70 fgets(periodo
,sizeof(periodo
),fp_in
);
73 if((fp_in
=fopen(dansguardian_in
,"r"))==NULL
) {
74 fprintf(stderr
, "SARG: (dansguardian_report) %s: %s\n",text
[8],dansguardian_in
);
78 if((fp_ou
=fopen(report
,"w"))==NULL
) {
79 fprintf(stderr
, "SARG: (dansguardian_report) %s: %s\n",text
[8],report
);
83 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou
);
84 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou
);
85 fputs("<html>\n",fp_ou
);
86 fputs("<head>\n",fp_ou
);
87 sprintf(html
," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
90 fputs("</head>\n",fp_ou
);
92 if(strlen(FontFace
) > 0) {
93 sprintf(url
,"<font face=%s>\n",FontFace
);
97 sprintf(url
,"<body bgcolor=%s text=%s background='%s'>\n",BgColor
,TxColor
,BgImage
);
100 if(strlen(LogoImage
) > 0) {
101 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou
);
102 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
);
104 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou
);
105 fputs("</table>\n",fp_ou
);
108 show_sarg(fp_ou
,"..");
109 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
110 sprintf(url
,"<tr><th class=\"title\">%s</th></tr>\n",Title
);
113 sprintf(url
,"<tr><td class=\"header\">%s: %s</td></tr>\n",text
[89],periodo
);
115 sprintf(url
,"<tr><th class=\"header3\">%s %s</th></tr>\n",text
[128],text
[55]);
117 fputs("</table></center>\n",fp_ou
);
119 fputs("<center><table cellpadding=1 cellspacing=2>\n",fp_ou
);
120 fputs("<tr><td></td></tr>\n",fp_ou
);
121 sprintf(url
,"<tr><th class=\"header\">%s</th><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],text
[129]);
124 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
125 getword(user
,buf
,' ');
126 getword(date2
,buf
,' ');
127 getword(hour
,buf
,' ');
129 getword(url
,buf
,' ');
130 getword(rule
,buf
,'\n');
132 if(strcmp(UserIp
,"yes") == 0)
136 if(strncmp(df
,"u",1) != 0) {
137 strncpy(date
,date2
+6,2);
139 strncat(date
,date2
+4,2);
141 strncat(date
,date2
,4);
143 strncpy(date
,date2
+4,2);
145 strncat(date
,date2
+6,2);
147 strncat(date
,date2
,4);
150 if((str
=(char *) strstr(user
, "_")) != (char *) NULL
) {
151 if((str
=(char *) strstr(str
+1, "_")) != (char *) NULL
)
155 if(strcmp(Ip2Name
,"yes") == 0)
163 if(strcmp(ouser
,user
) == 0)
167 if(strcmp(oip
,ip
) == 0)
173 if(UserTabFile
[0] != '\0') {
174 sprintf(warea
,":%s:",user
);
175 if((str
=(char *) strstr(userfile
,warea
)) != (char *) NULL
) {
177 str2
=(char *) strstr(str
+1,":");
180 while(str2
[z1
] != ':') {
184 } else strcpy(name
,user
);
185 } else strcpy(name
,user
);
187 if(dotinuser
&& strstr(name
,"_")) {
188 str2
=(char *)subs(name
,"_",".");
192 if(DansGuardianReportLimit
) {
193 if(strcmp(ouser2
,name
) == 0) {
199 if(count
>= DansGuardianReportLimit
)
203 sprintf(html2
,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",name
,ip
,date
,hour
,url
,url
,rule
);
207 fputs("</table>\n",fp_ou
);
211 fputs("</body>\n</html>\n",fp_ou
);
216 unlink(dansguardian_in
);