]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
1164c474 | 3 | * 1998, 2010 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
9 | * --------------------------------------------------------------------- |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "include/conf.h" | |
5f3cfd1d | 28 | #include "include/defs.h" |
25697a35 GS |
29 | |
30 | extern numlist hours; | |
31 | ||
32e71fa4 | 32 | void report_day(const char *user) |
25697a35 GS |
33 | { |
34 | ||
35 | FILE *fp_in, *fp_ou; | |
36 | ||
37 | char data[20]; | |
25697a35 | 38 | char odata[20]; |
d6e703cc | 39 | char hour[20]; |
25697a35 GS |
40 | char html[8000]; |
41 | char arqout[MAXLEN]; | |
42 | char wdirname[MAXLEN]; | |
43 | char wuser[255]; | |
44 | char c[ 24 ][20]; | |
45 | int count=0; | |
d6e703cc | 46 | int ihour=0; |
6e792ade | 47 | long long int elap; |
120d768c | 48 | long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, |
25697a35 | 49 | 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L }; |
120d768c | 50 | long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, |
25697a35 GS |
51 | 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L }; |
52 | long long int tt=0, ttt=0; | |
25697a35 | 53 | int i; |
9c7c6346 | 54 | struct getwordstruct gwarea; |
25697a35 GS |
55 | |
56 | sprintf(arqout,"%s/%s/d%s.html",dirname,user,user); | |
57 | sprintf(wdirname,"%s/%s.day",tmp,user); | |
58 | ||
59 | if(access(wdirname, R_OK) != 0) | |
60 | return; | |
61 | ||
62 | if((fp_in=fopen(wdirname,"r"))==NULL) { | |
63 | fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname); | |
64 | exit(1); | |
65 | } | |
66 | ||
67 | if((fp_ou=fopen(arqout,"w"))==NULL) { | |
68 | fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout); | |
69 | exit(1); | |
70 | } | |
71 | ||
d6e703cc | 72 | 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); |
25697a35 GS |
73 | css(fp_ou); |
74 | fputs("</head>\n",fp_ou); | |
dfb337be FM |
75 | //if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace); |
76 | fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage); | |
77 | write_logo_image(fp_ou); | |
25697a35 | 78 | |
0349fa24 | 79 | if(IndexTree == INDEX_TREE_DATE) |
491b862f GS |
80 | show_sarg(fp_ou, "../../../.."); |
81 | else | |
82 | show_sarg(fp_ou, "../.."); | |
83 | ||
dfb337be FM |
84 | fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou); |
85 | fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title); | |
86 | ||
87 | fputs("</table></div>\n",fp_ou); | |
88 | fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou); | |
25697a35 | 89 | |
b18ce4a0 | 90 | fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s: %s</td></tr>\n",text[89],period); |
25697a35 GS |
91 | |
92 | strcpy(wuser,user); | |
93 | if(strstr(wuser,"_") != 0) | |
94 | fixip(wuser); | |
95 | ||
246c8489 | 96 | if(Ip2Name) |
25697a35 GS |
97 | if((str=(char *) strstr(name, ".")) != (char *) NULL) { |
98 | if((str=(char *) strstr(str+1, ".")) != (char *) NULL) | |
a1c55d8c | 99 | ip2name(wuser,sizeof(wuser)); |
25697a35 GS |
100 | } |
101 | ||
965c4a6f | 102 | user_find(name, sizeof(name), wuser); |
94ff9470 | 103 | |
48864d28 FM |
104 | if(dotinuser && strchr(name,'_')) { |
105 | subs(name,sizeof(name),"_","."); | |
94ff9470 | 106 | } |
48864d28 | 107 | |
b18ce4a0 | 108 | fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s: %s</th></tr>\n",text[90],name); |
25697a35 GS |
109 | |
110 | fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou); | |
111 | fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou); | |
112 | ||
dfb337be | 113 | fputs("<table cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou); |
25697a35 | 114 | |
dfb337be | 115 | fputs( "<tr><td></td>\n", fp_ou ); |
25697a35 GS |
116 | |
117 | if(strcmp(datetimeby,"bytes") == 0) | |
d6e703cc | 118 | strcpy( html, text[93] ); |
25697a35 GS |
119 | else |
120 | strcpy( html, "H:M:S" ); | |
121 | ||
122 | for( i = 0; i < hours.len; i++ ) | |
b18ce4a0 | 123 | fprintf( fp_ou, "<td class=\"header_c\">%02dH<br>%s</td>\n", hours.list[ i ], html ); |
25697a35 | 124 | fprintf( fp_ou, |
b18ce4a0 | 125 | "<td class=\"header_c\">%s<br>%s</td></tr>\n", text[107], html ); |
25697a35 GS |
126 | |
127 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
9c7c6346 FM |
128 | fixendofline(buf); |
129 | getword_start(&gwarea,buf); | |
130 | if (getword(data,sizeof(data),&gwarea,'\t')<0) { | |
4bcb77cf FM |
131 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname); |
132 | exit(1); | |
133 | } | |
25697a35 GS |
134 | if(!count) { |
135 | strcpy(odata,data); | |
136 | count++; | |
137 | } | |
138 | ||
6e792ade | 139 | if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) { |
4bcb77cf FM |
140 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname); |
141 | exit(1); | |
142 | } | |
25697a35 GS |
143 | |
144 | if(strcmp(data,odata) != 0) { | |
dfb337be FM |
145 | for( i = 0; i < hours.len; i++ ) |
146 | sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ])); | |
147 | ||
148 | for( i = 8; i <= 17; i++ ) | |
149 | if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) | |
150 | bzero(c[ hours.list[ i ] ],12); | |
151 | ||
152 | fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", odata ); | |
153 | for( i = 0; i < hours.len; i++ ) | |
154 | fprintf(fp_ou,"<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] ); | |
155 | fprintf( fp_ou, "<td class=\"data\">%s</td>\n", fixtime(tt) ); | |
156 | ||
25697a35 | 157 | tt=0; |
dfb337be | 158 | for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0; |
25697a35 | 159 | strcpy(odata,data); |
25697a35 GS |
160 | } |
161 | ||
d6e703cc | 162 | ihour=atoi(hour); |
25697a35 | 163 | |
6e792ade FM |
164 | v[ ihour ]+=elap; |
165 | tt+=elap; | |
166 | t[ ihour ]+=elap; | |
167 | ttt+=elap; | |
25697a35 GS |
168 | |
169 | } | |
170 | ||
171 | for( i = 0; i < hours.len; i++ ) | |
172 | sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ])); | |
173 | ||
174 | for( i = 0; i < hours.len; i++ ) | |
175 | if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12); | |
dfb337be FM |
176 | |
177 | fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data ); | |
25697a35 | 178 | for( i = 0; i < hours.len; i++ ) |
dfb337be FM |
179 | fprintf(fp_ou, "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] ); |
180 | fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n", fixtime(tt) ); | |
25697a35 GS |
181 | |
182 | for( i = 0; i < hours.len; i++ ) | |
183 | sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ])); | |
184 | ||
b18ce4a0 | 185 | fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", text[107] ); |
25697a35 | 186 | for( i = 0; i < hours.len; i++ ) |
b18ce4a0 FM |
187 | fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n", c[ hours.list[ i ] ] ); |
188 | fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n", fixtime(ttt) ); | |
25697a35 | 189 | |
dfb337be | 190 | fputs("</table></div>\n",fp_ou); |
25697a35 GS |
191 | |
192 | show_info(fp_ou); | |
193 | ||
dfb337be | 194 | fputs("</body>\n</html>\n",fp_ou); |
25697a35 GS |
195 | fclose(fp_in); |
196 | fclose(fp_ou); | |
25697a35 GS |
197 | return; |
198 | } |