]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
Use boolean to enable some options instead of string compares
[thirdparty/sarg.git] / repday.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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 #include "include/defs.h"
28
29 extern numlist hours;
30
31 void report_day(const char *user)
32 {
33
34 FILE *fp_in, *fp_ou;
35
36 char data[20];
37 char odata[20];
38 char hour[20];
39 char html[8000];
40 char arqout[MAXLEN];
41 char wdirname[MAXLEN];
42 char wuser[255];
43 char c[ 24 ][20];
44 int count=0;
45 int ihour=0;
46 long long int elap;
47 long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
48 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
49 long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
50 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
51 long long int tt=0, ttt=0;
52 int i;
53 struct getwordstruct gwarea;
54
55 sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
56 sprintf(wdirname,"%s/%s.day",tmp,user);
57
58 if(access(wdirname, R_OK) != 0)
59 return;
60
61 if((fp_in=fopen(wdirname,"r"))==NULL) {
62 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
63 exit(1);
64 }
65
66 if((fp_ou=fopen(arqout,"w"))==NULL) {
67 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
68 exit(1);
69 }
70
71 fprintf(fp_ou, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
72 css(fp_ou);
73 fputs("</head>\n",fp_ou);
74 //if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
75 fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
76 write_logo_image(fp_ou);
77
78 if(strcmp(IndexTree,"date") == 0)
79 show_sarg(fp_ou, "../../../..");
80 else
81 show_sarg(fp_ou, "../..");
82
83 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
84 fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
85
86 fputs("</table></div>\n",fp_ou);
87 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
88
89 fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
90
91 strcpy(wuser,user);
92 if(strstr(wuser,"_") != 0)
93 fixip(wuser);
94
95 if(Ip2Name)
96 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
97 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
98 ip2name(wuser,sizeof(wuser));
99 }
100
101 get_usertab_name(wuser,name,sizeof(name));
102
103 if(dotinuser && strchr(name,'_')) {
104 subs(name,sizeof(name),"_",".");
105 }
106
107 fprintf(fp_ou,"<tr><th class=\"header3\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],name);
108
109 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
110 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
111
112 fputs("<table cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
113
114 fputs( "<tr><td></td>\n", fp_ou );
115
116 if(strcmp(datetimeby,"bytes") == 0)
117 strcpy( html, text[93] );
118 else
119 strcpy( html, "H:M:S" );
120
121 for( i = 0; i < hours.len; i++ )
122 fprintf( fp_ou, "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
123 fprintf( fp_ou,
124 "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
125
126 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
127 fixendofline(buf);
128 getword_start(&gwarea,buf);
129 if (getword(data,sizeof(data),&gwarea,'\t')<0) {
130 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
131 exit(1);
132 }
133 if(!count) {
134 strcpy(odata,data);
135 count++;
136 }
137
138 if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) {
139 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
140 exit(1);
141 }
142
143 if(strcmp(data,odata) != 0) {
144 for( i = 0; i < hours.len; i++ )
145 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
146
147 for( i = 8; i <= 17; i++ )
148 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
149 bzero(c[ hours.list[ i ] ],12);
150
151 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", odata );
152 for( i = 0; i < hours.len; i++ )
153 fprintf(fp_ou,"<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
154 fprintf( fp_ou, "<td class=\"data\">%s</td>\n", fixtime(tt) );
155
156 tt=0;
157 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
158 strcpy(odata,data);
159 }
160
161 ihour=atoi(hour);
162
163 v[ ihour ]+=elap;
164 tt+=elap;
165 t[ ihour ]+=elap;
166 ttt+=elap;
167
168 }
169
170 for( i = 0; i < hours.len; i++ )
171 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
172
173 for( i = 0; i < hours.len; i++ )
174 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
175
176 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
177 for( i = 0; i < hours.len; i++ )
178 fprintf(fp_ou, "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
179 fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
180
181 for( i = 0; i < hours.len; i++ )
182 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
183
184 fprintf(fp_ou, "<tr><td class=\"header\">%s</td>\n", text[107] );
185 for( i = 0; i < hours.len; i++ )
186 fprintf(fp_ou, "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
187 fprintf(fp_ou, "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
188
189 fputs("</table></div>\n",fp_ou);
190
191 show_info(fp_ou);
192
193 fputs("</body>\n</html>\n",fp_ou);
194 fclose(fp_in);
195 fclose(fp_ou);
196 return;
197 }