]>
git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
2 * AUTHOR: Pedro Lineu Orso orso@brturbo.com.br
4 * SARG Squid Analysis Report Generator http://sarg-squid.org
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"
30 void report_day(char *user
, int *iprel
, int *ipuser
)
46 char wdirname
[MAXLEN
];
51 long long int telap
=0;
52 long long int v
[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
53 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
54 long long int t
[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
55 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
56 long long int tt
=0, ttt
=0;
60 sprintf(arqout
,"%s/%s/d%s.html",dirname
,user
,user
);
61 sprintf(wdirname
,"%s/%s.day",tmp
,user
);
63 if(access(wdirname
, R_OK
) != 0)
66 if((fp_in
=fopen(wdirname
,"r"))==NULL
) {
67 fprintf(stderr
, "SARG: (repday) %s: %s\n",text
[8],wdirname
);
71 if((fp_ou
=fopen(arqout
,"w"))==NULL
) {
72 fprintf(stderr
, "SARG: (repday) %s: %s\n",text
[8],arqout
);
76 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou
);
77 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou
);
78 fputs("<html>\n",fp_ou
);
79 fputs("<head>\n",fp_ou
);
80 sprintf(html
," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
83 fputs("</head>\n",fp_ou
);
85 if(strlen(FontFace
) > 0) {
86 sprintf(html
,"<font face=%s>\n",FontFace
);
90 sprintf(html
,"<body bgcolor=%s text=%s background='%s'>\n",BgColor
,TxColor
,BgImage
);
93 if(strlen(LogoImage
) > 0) {
94 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
95 sprintf(html
,"<tr><th align=left><img src='%s' border=0 align=absmiddle width=%s height=%s><font color=%s>%s</font>\n",LogoImage
,Width
,Height
,LogoTextColor
,LogoText
);
97 fputs("</table>\n",fp_ou
);
100 show_sarg(fp_ou
,"../..");
101 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
102 sprintf(html
,"<tr><th class=\"title\" colspan=2>%s</th></tr>\n",Title
);
105 fputs("</table></center>\n",fp_ou
);
106 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
108 sprintf(html
,"<tr><td class=\"header3\" colspan=\"2\">%s: %s</td></tr>\n",text
[89],periodo
);
112 if(strstr(wuser
,"_") != 0)
115 if(strcmp(Ip2Name
,"yes") == 0)
116 if((str
=(char *) strstr(name
, ".")) != (char *) NULL
) {
117 if((str
=(char *) strstr(str
+1, ".")) != (char *) NULL
)
121 if(UserTabFile
[0] != '\0') {
122 sprintf(warea
,":%s:",wuser
);
123 if((str
=(char *) strstr(userfile
,warea
)) != (char *) NULL
) {
125 str2
=(char *) strstr(str
+1,":");
128 while(str2
[z1
] != ':') {
132 } else strcpy(name
,wuser
);
133 } else strcpy(name
,user
);
135 sprintf(html
,"<tr><td class=\"header3\" colspan=\"2\">%s: %s</td></tr>\n",text
[90],name
);
138 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou
);
139 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou
);
141 fputs("<table cellpadding=0 cellspacing=2>\n", fp_ou
);
143 fputs( "<tr><td border=0></td>\n", fp_ou
);
145 if(strcmp(datetimeby
,"bytes") == 0)
146 strcpy( html
, "BYTES" );
148 strcpy( html
, "H:M:S" );
150 for( i
= 0; i
< hours
.len
; i
++ )
152 "<td class=\"header3\">%02dH<br>%s</td>\n", hours
.list
[ i
], html
);
154 "<td class=\"header3\">%s<br>%s</td></tr>\n", text
[107], html
);
156 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
157 getword(data
,buf
,' ');
163 getword(hora
,buf
,' ');
164 getword(elap
,buf
,' ');
165 elap
[strlen(elap
)-1]='\0';
167 if(strcmp(data
,odata
) != 0) {
170 for( i
= 0; i
< hours
.len
; i
++ )
171 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
173 for( i
= 8; i
<= 17; i
++ )
174 if(strcmp(c
[ hours
.list
[ i
] ],"00:00:00") == 0)
175 bzero(c
[ hours
.list
[ i
] ],12);
178 "<tr><td class=\"data\">%s</td>\n", odata
);
179 for( i
= 0; i
< hours
.len
; i
++ )
181 "<td class=\"data\">%s</td>\n", c
[ hours
.list
[ i
] ] );
183 "<td class=\"data\">%s</td>\n", fixtime(tt
) );
186 for( i
= 0; i
< hours
.len
; i
++ ) v
[ hours
.list
[ i
] ]=0;
193 v
[ ihora
]+=my_atoll(elap
);
195 t
[ ihora
]+=my_atoll(elap
);
200 for( i
= 0; i
< hours
.len
; i
++ )
201 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
203 for( i
= 0; i
< hours
.len
; i
++ )
204 if(strcmp(c
[ hours
.list
[ i
] ],"00:00:00") == 0) bzero(c
[ hours
.list
[ i
] ],12);
207 "<tr><td class=\"data\">%s</td>\n", data
);
208 for( i
= 0; i
< hours
.len
; i
++ )
210 "<td class=\"data\">%s</td>\n", c
[ hours
.list
[ i
] ] );
212 "<td class=\"data\">%s</td></tr>\n", fixtime(tt
) );
214 for( i
= 0; i
< hours
.len
; i
++ )
215 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(t
[ hours
.list
[ i
] ]));
218 "<tr><td class=\"header\">%s</td>\n", text
[107] );
219 for( i
= 0; i
< hours
.len
; i
++ )
221 "<td class=\"header2\">%s</td>\n", c
[ hours
.list
[ i
] ] );
223 "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt
) );
225 fputs("</body>\n</html>\n",fp_ou
);