]>
git.ipfire.org Git - thirdparty/sarg.git/blob - repday.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"
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 class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n",LogoImage
,Width
,Height
,LogoText
);
97 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou
);
98 fputs("</table>\n",fp_ou
);
101 if(strcmp(IndexTree
,"date") == 0)
102 show_sarg(fp_ou
, "../../../..");
104 show_sarg(fp_ou
, "../..");
106 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
107 sprintf(html
,"<tr><th class=\"title\" colspan=2>%s</th></tr>\n",Title
);
110 fputs("</table></center>\n",fp_ou
);
111 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
113 sprintf(html
,"<tr><td class=\"header3\" colspan=\"2\">%s: %s</td></tr>\n",text
[89],periodo
);
117 if(strstr(wuser
,"_") != 0)
120 if(strcmp(Ip2Name
,"yes") == 0)
121 if((str
=(char *) strstr(name
, ".")) != (char *) NULL
) {
122 if((str
=(char *) strstr(str
+1, ".")) != (char *) NULL
)
126 if(UserTabFile
[0] != '\0') {
127 sprintf(warea
,":%s:",wuser
);
128 if((str
=(char *) strstr(userfile
,warea
)) != (char *) NULL
) {
130 str2
=(char *) strstr(str
+1,":");
133 while(str2
[z1
] != ':') {
137 } else strcpy(name
,wuser
);
138 } else strcpy(name
,user
);
140 if(dotinuser
&& strstr(name
,"_")) {
141 str2
=(char *)subs(name
,"_",".");
145 sprintf(html
,"<tr><td class=\"header3\" colspan=\"2\">%s: %s</td></tr>\n",text
[90],name
);
148 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou
);
149 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou
);
151 fputs("<table cellpadding=0 cellspacing=2>\n", fp_ou
);
153 fputs( "<tr><td border=0></td>\n", fp_ou
);
155 if(strcmp(datetimeby
,"bytes") == 0)
156 strcpy( html
, "BYTES" );
158 strcpy( html
, "H:M:S" );
160 for( i
= 0; i
< hours
.len
; i
++ )
162 "<td class=\"header3\">%02dH<br>%s</td>\n", hours
.list
[ i
], html
);
164 "<td class=\"header3\">%s<br>%s</td></tr>\n", text
[107], html
);
166 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
167 getword(data
,buf
,' ');
173 getword(hora
,buf
,' ');
174 getword(elap
,buf
,' ');
175 elap
[strlen(elap
)-1]='\0';
177 if(strcmp(data
,odata
) != 0) {
180 for( i
= 0; i
< hours
.len
; i
++ )
181 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
183 for( i
= 8; i
<= 17; i
++ )
184 if(strcmp(c
[ hours
.list
[ i
] ],"00:00:00") == 0)
185 bzero(c
[ hours
.list
[ i
] ],12);
188 "<tr><td class=\"data\">%s</td>\n", odata
);
189 for( i
= 0; i
< hours
.len
; i
++ )
191 "<td class=\"data\">%s</td>\n", c
[ hours
.list
[ i
] ] );
193 "<td class=\"data\">%s</td>\n", fixtime(tt
) );
196 for( i
= 0; i
< hours
.len
; i
++ ) v
[ hours
.list
[ i
] ]=0;
203 v
[ ihora
]+=my_atoll(elap
);
205 t
[ ihora
]+=my_atoll(elap
);
210 for( i
= 0; i
< hours
.len
; i
++ )
211 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
213 for( i
= 0; i
< hours
.len
; i
++ )
214 if(strcmp(c
[ hours
.list
[ i
] ],"00:00:00") == 0) bzero(c
[ hours
.list
[ i
] ],12);
217 "<tr><td class=\"data\">%s</td>\n", data
);
218 for( i
= 0; i
< hours
.len
; i
++ )
220 "<td class=\"data\">%s</td>\n", c
[ hours
.list
[ i
] ] );
222 "<td class=\"data\">%s</td></tr>\n", fixtime(tt
) );
224 for( i
= 0; i
< hours
.len
; i
++ )
225 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(t
[ hours
.list
[ i
] ]));
228 "<tr><td class=\"header\">%s</td>\n", text
[107] );
229 for( i
= 0; i
< hours
.len
; i
++ )
231 "<td class=\"header2\">%s</td>\n", c
[ hours
.list
[ i
] ] );
233 "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt
) );
235 fputs("</body>\n</html>\n",fp_ou
);