]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed FM |
2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
3 | * 1998, 2008 | |
94ff9470 | 4 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
25697a35 GS |
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 | ||
28 | int blue; | |
29 | int white; | |
30 | int lavender; | |
31 | int darkblue; | |
32 | int dimgray; | |
33 | int goldenrod; | |
34 | int goldenrod2; | |
35 | int gray; | |
36 | int silver; | |
37 | int black; | |
38 | int x1; | |
d6e703cc FM |
39 | //char *font1 = SYSCONFDIR"/fonts/FreeSans.ttf"; |
40 | char *font1 = SYSCONFDIR"/fonts/DejaVuSans.ttf"; | |
25697a35 GS |
41 | char s[15]; |
42 | ||
d6e703cc | 43 | #if defined(HAVE_GD) && defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode) |
25697a35 GS |
44 | #include <iconv.h> |
45 | #define SARGgdImageStringFT I18NgdImageStringFT | |
46 | ||
d6e703cc FM |
47 | char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, |
48 | double ptsize, double angle, int x, int y, char *string) | |
25697a35 GS |
49 | { |
50 | iconv_t localtoutf; | |
51 | char *sstring, *str, *sstr, *retval; | |
52 | size_t slen, sslen; | |
53 | ||
54 | slen = strlen(string) + 1; // We must include string termination character | |
55 | sslen = slen * 2; // We assume that UTF8 maximum 2 times large than local | |
56 | sstring = (char *)malloc(sslen); | |
57 | ||
58 | str = (char *) string; | |
59 | sstr = (char *) sstring; | |
60 | ||
61 | localtoutf = iconv_open ("UTF-8", CharSet); | |
d6e703cc | 62 | iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen); |
25697a35 GS |
63 | iconv_close (localtoutf); |
64 | ||
65 | retval = gdImageStringFTEx (im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode); | |
66 | free(sstring); | |
67 | ||
68 | return retval; | |
69 | } | |
70 | #else | |
71 | #define SARGgdImageStringFT gdImageStringFT | |
72 | #endif | |
73 | ||
32e71fa4 | 74 | void bar(long long int n) |
25697a35 GS |
75 | { |
76 | #ifdef HAVE_GD | |
77 | gdPoint points[4]; | |
78 | int brect[8]; | |
79 | int val=0, x; | |
32e71fa4 | 80 | long long int num; |
25697a35 GS |
81 | char v[15]; |
82 | ||
32e71fa4 FM |
83 | static const long long int limits[400]={0,500,1000,2000,3000,4000, |
84 | 5000,6000,7000,8000,9000,10000, | |
85 | 20000,30000,40000,50000,70000,90000, | |
86 | 110000,130000,150000,170000,190000,210000, | |
87 | 230000,250000,280000,310000,340000,370000, | |
88 | 400000,430000,450000,460000,490000,500000, | |
89 | 550000,600000,650000,700000,750000,800000, | |
90 | 850000,900000,950000,1000000,1100000,1200000, | |
91 | 1300000,1400000,1500000,1600000,1700000,1800000, | |
92 | 1900000,2000000,2100000,2200000,2300000,2400000, | |
93 | 2500000,2600000,2700000,2800000,2900000,3000000, | |
94 | 3100000,3200000,3300000,3400000,3500000,3600000, | |
95 | 3700000,3800000,3900000,4000000,4100000,4200000, | |
96 | 4300000,4400000,4500000,4600000,4700000,4800000, | |
97 | 4900000,5000000,5100000,5200000,5300000,5400000, | |
98 | 5500000,5600000,5700000,5800000,5900000,6000000, | |
99 | 6100000,6200000,6300000,6400000,6500000,6600000, | |
100 | 6700000,6800000,6900000,7000000,7100000,7200000, | |
101 | 7300000,7400000,7500000,7600000,7700000,7800000, | |
102 | 7900000,8000000,8100000,8200000,8300000,8400000, | |
103 | 8500000,8600000,8700000,8800000,8900000,9000000, | |
104 | 9100000,9200000,9300000,9400000,9500000,9600000, | |
105 | 9700000,9800000,9900000,10000000,10500000,11000000, | |
106 | 11500000,12000000,12500000,13000000,13500000,14000000, | |
107 | 14500000,15000000,15500000,16000000,16500000,17000000, | |
108 | 17500000,18000000,18500000,19000000,19500000,20000000, | |
109 | 21000000,22000000,23000000,24000000,25000000,26000000, | |
110 | 27000000,28000000,29000000,30000000,31000000,32000000, | |
111 | 33000000,34000000,35000000,36000000,37000000,38000000, | |
112 | 39000000,40000000,41000000,42000000,43000000,44000000, | |
113 | 45000000,46000000,47000000,48000000,49000000,50000000, | |
114 | 51000000,52000000,53000000,54000000,55000000,56000000, | |
115 | 57000000,58000000,59000000,60000000,61000000,62000000, | |
116 | 63000000,64000000,65000000,66000000,67000000,68000000, | |
117 | 69000000,70000000,71000000,72000000,73000000,74000000, | |
118 | 75000000,76000000,77000000,78000000,79000000,80000000, | |
119 | 81000000,82000000,83000000,84000000,85000000,86000000, | |
120 | 87000000,88000000,89000000,90000000,91000000,92000000, | |
121 | 93000000,94000000,95000000,96000000,97000000,98000000, | |
122 | 99000000,100000000,110000000,120000000,130000000,140000000, | |
123 | 150000000,160000000,170000000,180000000,190000000,200000000, | |
124 | 210000000,220000000,230000000,240000000,250000000,260000000, | |
125 | 270000000,280000000,290000000,300000000,310000000,320000000, | |
126 | 330000000,340000000,350000000,360000000,370000000,380000000, | |
127 | 390000000,400000000,410000000,420000000,430000000,440000000, | |
128 | 450000000,460000000,470000000,480000000,490000000,500000000, | |
129 | 510000000,520000000,530000000,540000000,550000000,560000000, | |
130 | 570000000,580000000,590000000,600000000,610000000,620000000, | |
131 | 630000000,640000000,650000000,660000000,670000000,680000000, | |
132 | 690000000,700000000,710000000,720000000,730000000,740000000, | |
133 | 750000000,760000000,770000000,780000000,790000000,800000000, | |
134 | 810000000,820000000,830000000,840000000,850000000,860000000, | |
135 | 870000000,880000000,890000000,900000000,910000000,920000000, | |
136 | 930000000,940000000,950000000,960000000,970000000,980000000, | |
137 | 990000000LL,1000000000LL,1100000000LL,1200000000LL,1300000000LL,1400000000LL, | |
138 | 1500000000LL,1600000000LL,1700000000LL,1800000000LL,1900000000LL,2000000000LL, | |
139 | 2100000000LL,2200000000LL,2300000000LL,2400000000LL,2500000000LL,2600000000LL, | |
140 | 2700000000LL,2800000000LL,2900000000LL,3000000000LL,3100000000LL,3200000000LL, | |
141 | 3300000000LL,3400000000LL,3500000000LL,3600000000LL,3700000000LL,3800000000LL, | |
142 | 3900000000LL,4000000000LL,4100000000LL,4200000000LL,4300000000LL,4400000000LL, | |
143 | 4500000000LL,4600000000LL,4700000000LL,4800000000LL,4900000000LL,5000000000LL}; | |
25697a35 GS |
144 | |
145 | if(access(font1, R_OK) != 0) { | |
146 | fprintf(stderr, "SARG: (grepday) Fontname: %s not found.\n",font1); | |
147 | exit(1); | |
148 | } | |
149 | ||
150 | if(strcmp(GraphDaysBytesBarColor,"orange") == 0) { | |
151 | color1 = gdImageColorAllocate(im, 255, 233, 142); | |
152 | color2 = gdImageColorAllocate(im, 220, 163, 72); | |
153 | color3 = gdImageColorAllocate(im, 255, 198, 107); | |
154 | } | |
155 | if(strcmp(GraphDaysBytesBarColor,"blue") == 0) { | |
156 | color1 = gdImageColorAllocate(im, 62, 80, 167); | |
157 | color2 = gdImageColorAllocate(im, 40, 51, 101); | |
158 | color3 = gdImageColorAllocate(im, 57, 73, 150); | |
159 | } | |
160 | if(strcmp(GraphDaysBytesBarColor,"green") == 0) { | |
161 | color1 = gdImageColorAllocate(im,120,166,129); | |
162 | color2 = gdImageColorAllocate(im,84,113,82); | |
163 | color3 = gdImageColorAllocate(im,158,223,167); | |
164 | } | |
165 | if(strcmp(GraphDaysBytesBarColor,"yellow") == 0) { | |
166 | color1 = gdImageColorAllocate(im,185,185,10); | |
167 | color2 = gdImageColorAllocate(im,111,111,10); | |
168 | color3 = gdImageColorAllocate(im,166,166,10); | |
169 | } | |
170 | if(strcmp(GraphDaysBytesBarColor,"brown") == 0) { | |
171 | color1 = gdImageColorAllocate(im,97,45,27); | |
172 | color2 = gdImageColorAllocate(im,60,30,20); | |
173 | color3 = gdImageColorAllocate(im,88,41,26); | |
174 | } | |
175 | if(strcmp(GraphDaysBytesBarColor,"red") == 0){ | |
176 | color1 = gdImageColorAllocate(im,185,10,10); | |
177 | color2 = gdImageColorAllocate(im,111,10,10); | |
178 | color3 = gdImageColorAllocate(im,166,10,10); | |
179 | } | |
180 | ||
181 | blue = gdImageColorAllocate(im, 0, 0, 255); | |
182 | white = gdImageColorAllocate(im, 255, 255, 255); | |
183 | dimgray = gdImageColorAllocate(im, 105, 105, 105); | |
184 | goldenrod = gdImageColorAllocate(im, 234, 234, 174); | |
185 | goldenrod2 = gdImageColorAllocate(im, 207, 181, 59); | |
186 | ||
187 | num = n; | |
32e71fa4 | 188 | val = 55; |
25697a35 | 189 | for(x=0; x<=366; x++) { |
32e71fa4 | 190 | if(limits[x] >= num) { |
25697a35 GS |
191 | val = 425 - x; |
192 | break; | |
193 | } | |
194 | } | |
25697a35 GS |
195 | |
196 | gdImageFilledRectangle(im, x1, val, x1+11, 425, color3); | |
197 | ||
198 | points[0].x = x1+7; | |
199 | points[0].y = val-5; | |
200 | points[1].x = x1; | |
201 | points[1].y = val; | |
202 | points[2].x = x1+11; | |
203 | points[2].y = val; | |
204 | points[3].x = x1+17; | |
205 | points[3].y = val-5; | |
206 | gdImageFilledPolygon(im, points, 4, color1); | |
207 | ||
208 | gdImageLine(im, x1+8, val-2, x1+8, val-10, dimgray); | |
209 | gdImageFilledRectangle(im, x1-2, val-20, x1+18, val-10, goldenrod); | |
210 | gdImageRectangle(im, x1-2, val-20, x1+18, val-10, goldenrod2); | |
211 | ||
212 | snprintf(v,6,"%s",fixnum(num,0)); | |
213 | ||
214 | SARGgdImageStringFT(im,&brect[0],black,font1,6,0.0,x1-1,val-12,v); | |
215 | ||
216 | points[0].x = x1+17; | |
217 | points[0].y = val-5; | |
218 | points[1].x = x1+11; | |
219 | points[1].y = val; | |
220 | points[2].x = x1+11; | |
221 | points[2].y = 426; | |
222 | points[3].x = x1+17; | |
223 | points[3].y = 420; | |
224 | gdImageFilledPolygon(im, points, 4, color2); | |
225 | ||
226 | #endif | |
227 | return; | |
228 | } | |
229 | ||
32e71fa4 | 230 | void greport_day(const char *user) |
25697a35 GS |
231 | { |
232 | FILE *fp_in, *pngout; | |
d6e703cc | 233 | int x, y; |
25697a35 GS |
234 | int brect[8]; |
235 | char wdirname[MAXLEN]; | |
236 | char graph[MAXLEN]; | |
237 | char wuser[255]; | |
238 | char csort[255]; | |
239 | char data[20]; | |
240 | int count=0; | |
241 | char oday[20]; | |
242 | char day[20]; | |
243 | char bytes[20]; | |
32e71fa4 | 244 | long long int tot=0; |
25697a35 GS |
245 | time_t t; |
246 | struct tm *local; | |
456d78a5 | 247 | int cstatus; |
25697a35 GS |
248 | #ifdef HAVE_GD |
249 | ||
250 | if(strcmp(Graphs,"yes") != 0) { | |
251 | unlink(wdirname); | |
252 | return; | |
253 | } | |
254 | ||
255 | im = gdImageCreate(720, 480); | |
256 | ||
257 | lavender = gdImageColorAllocate(im, 230, 230, 250); | |
258 | white = gdImageColorAllocate(im, 255, 255, 255); | |
259 | gray = gdImageColorAllocate(im, 192, 192, 192); | |
260 | silver = gdImageColorAllocate(im, 211, 211, 211); | |
261 | black = gdImageColorAllocate(im, 0, 0, 0); | |
262 | blue = gdImageColorAllocate(im, 35, 35, 227); | |
263 | dimgray = gdImageColorAllocate(im, 105, 105, 105); | |
264 | darkblue = gdImageColorAllocate(im, 0, 0, 139); | |
265 | ||
266 | gdImageRectangle(im, 0, 0, 719, 479, dimgray); | |
267 | gdImageFilledRectangle(im, 60, 60, 700, 420, silver); | |
268 | ||
269 | points[0].x = 50; | |
270 | points[0].y = 65; | |
271 | points[1].x = 50; | |
272 | points[1].y = 425; | |
273 | points[2].x = 60; | |
274 | points[2].y = 420; | |
275 | points[3].x = 60; | |
276 | points[3].y = 60; | |
277 | gdImageFilledPolygon(im, points, 4, gray); | |
278 | ||
279 | points[0].x = 60; | |
280 | points[0].y = 420; | |
281 | points[1].x = 50; | |
282 | points[1].y = 425; | |
283 | points[2].x = 690; | |
284 | points[2].y = 425; | |
285 | points[3].x = 700; | |
286 | points[3].y = 420; | |
287 | gdImageFilledPolygon(im, points, 4, gray); | |
288 | ||
289 | gdImageLine(im, 50, 65, 50, 430, black); | |
290 | gdImageLine(im, 45, 425, 690, 425, black); | |
291 | gdImageLine(im, 50, 425, 60, 420, black); | |
292 | gdImageLine(im, 60, 420, 60, 60, black); | |
293 | gdImageLine(im, 700, 60, 700, 420, black); | |
294 | gdImageLine(im, 690, 425, 700, 420, black); | |
295 | ||
296 | for(x=415; x>=65; x=x-10) { | |
297 | gdImageLine(im, 50, x, 60, x-5, dimgray); | |
298 | gdImageLine(im, 47, x, 50, x, dimgray); | |
299 | } | |
300 | ||
301 | for(x=60; x<=420; x=x+10) | |
302 | gdImageLine(im, 60, x, 700, x, dimgray); | |
303 | ||
304 | gdImageLine(im, 60, 420, 700, 420, black); | |
305 | ||
306 | for(x=70; x<=680; x=x+20) | |
307 | gdImageLine(im, x, 425, x, 428, dimgray); | |
308 | ||
309 | y=65; | |
310 | for(x=1; x<=31; x++) { | |
311 | sprintf(s,"%02d",x); | |
312 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,y,437,s); | |
313 | y=y+20; | |
314 | } | |
315 | ||
316 | t = time(NULL); | |
317 | local = localtime(&t); | |
318 | if(strcmp(DateFormat,"u") == 0) | |
319 | strftime(ftime, 127, "%b/%d/%Y %H:%M", local); | |
320 | if(strcmp(DateFormat,"e") == 0) | |
321 | strftime(ftime, 127, "%d/%b/%Y-%H:%M", local); | |
322 | ||
94ff9470 GS |
323 | if(dotinuser && strstr(name,"_")) { |
324 | str2=(char *)subs(name,"_","."); | |
325 | strcpy(name,str2); | |
326 | } | |
327 | ||
25697a35 GS |
328 | SARGgdImageStringFT(im,&brect[0],darkblue,font1,7,0.0,620,470,ftime); |
329 | if(strcmp(ShowSargInfo,"yes") == 0) SARGgdImageStringFT(im,&brect[0],darkblue,font1,10,0.0,257,15,"SARG, "); | |
330 | SARGgdImageStringFT(im,&brect[0],darkblue,font1,10,0.0,300,15,Title); | |
d6e703cc | 331 | sprintf(warea,"%s: %s",text[89],period); |
25697a35 GS |
332 | SARGgdImageStringFT(im,&brect[0],darkblue,font1,9,0.0,300,27,warea); |
333 | sprintf(warea,"%s: %s",text[90],name); | |
334 | SARGgdImageStringFT(im,&brect[0],darkblue,font1,9,0.0,300,38,warea); | |
335 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,418," 50K"); | |
336 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,408,"250K"); | |
337 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,398,"500K"); | |
338 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,388," 1M"); | |
339 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,378," 2M"); | |
340 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,368," 3M"); | |
341 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,358," 4M"); | |
342 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,348," 5M"); | |
343 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,338," 6M"); | |
344 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,328," 7M"); | |
345 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,318," 8M"); | |
346 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,308," 9M"); | |
347 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,298," 10M"); | |
348 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,288," 15M"); | |
349 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,278," 20M"); | |
350 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,268," 30M"); | |
351 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,258," 40M"); | |
352 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,248," 50M"); | |
353 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,238," 60M"); | |
354 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,228," 70M"); | |
355 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,218," 80M"); | |
356 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,208," 90M"); | |
357 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,198,"100M"); | |
358 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,188,"200M"); | |
359 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,178,"300M"); | |
360 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,168,"400M"); | |
361 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,158,"500M"); | |
362 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,148,"600M"); | |
363 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,138,"700M"); | |
364 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,128,"800M"); | |
365 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,118,"900M"); | |
366 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,108," 1G"); | |
367 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 98," 2G"); | |
368 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 88," 3G"); | |
369 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 78," 4G"); | |
370 | SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 68," 5G"); | |
371 | SARGgdImageStringFT(im,&brect[0],black,font1,10,3.14/2,20,248,text[93]); | |
372 | SARGgdImageStringFT(im,&brect[0],black,font1,10,0.0,330,460,text[127]); | |
373 | ||
32e71fa4 FM |
374 | if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,user)>=sizeof(graph)) { |
375 | fprintf(stderr, "SARG: user name too long for: %s/%s/graph_day.png\n",dirname,user); | |
376 | exit(1); | |
377 | } | |
378 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,user)>=sizeof(wdirname)) { | |
379 | fprintf(stderr, "SARG: user name too long for: %s/%s.day\n",tmp,user); | |
380 | exit(1); | |
381 | } | |
382 | if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,user)>=sizeof(tmp5)) { | |
383 | fprintf(stderr, "SARG: user name too long for: %s/%s.graph\n",tmp,user); | |
384 | exit(1); | |
385 | } | |
25697a35 GS |
386 | |
387 | if(access(wdirname, R_OK) != 0) | |
388 | return; | |
389 | ||
94ff9470 | 390 | sprintf(csort,"sort -t'/' -k 2,2 -o '%s' '%s'",tmp5,wdirname); |
25697a35 | 391 | if(strcmp(DateFormat,"e") == 0) |
94ff9470 | 392 | sprintf(csort,"sort -t'/' -k 1,1 -o '%s' '%s'",tmp5,wdirname); |
25697a35 | 393 | |
456d78a5 FM |
394 | cstatus=system(csort); |
395 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
396 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
397 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
398 | exit(1); | |
399 | } | |
25697a35 GS |
400 | |
401 | if((fp_in=fopen(tmp5,"r"))==NULL) { | |
402 | fprintf(stderr, "SARG: (grepday) %s: %s\n",text[8],tmp5); | |
403 | exit(1); | |
404 | } | |
405 | ||
406 | if((pngout=fopen(graph,"wb"))==NULL) { | |
407 | fprintf(stderr, "SARG: (grepday) %s: %s\n",text[8],graph); | |
408 | exit(1); | |
409 | } | |
410 | ||
411 | strcpy(wuser,user); | |
412 | if(strstr(wuser,"_") != 0) | |
413 | fixip(wuser); | |
414 | ||
415 | if(strcmp(Ip2Name,"yes") == 0) | |
416 | if((str=(char *) strstr(name, ".")) != (char *) NULL) { | |
417 | if((str=(char *) strstr(str+1, ".")) != (char *) NULL) | |
a1c55d8c | 418 | ip2name(wuser,sizeof(wuser)); |
25697a35 GS |
419 | } |
420 | ||
421 | if(UserTabFile[0] != '\0') { | |
422 | sprintf(warea,":%s:",wuser); | |
423 | if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) { | |
424 | z1=0; | |
425 | str2=(char *) strstr(str+1,":"); | |
426 | str2++; | |
427 | bzero(name, MAXLEN); | |
428 | while(str2[z1] != ':') { | |
429 | name[z1]=str2[z1]; | |
430 | z1++; | |
431 | } | |
432 | } else strcpy(name,wuser); | |
433 | } else strcpy(name,user); | |
434 | ||
435 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
4bcb77cf FM |
436 | if (getword(data,sizeof(data),buf,' ')<0 || getword(day,sizeof(day),data,'/')<0) { |
437 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5); | |
438 | exit(1); | |
439 | } | |
440 | if(strcmp(DateFormat,"u") == 0) { | |
441 | if (getword(day,sizeof(day),data,'/')<0) { | |
442 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5); | |
443 | exit(1); | |
444 | } | |
445 | } | |
25697a35 GS |
446 | if(!count) { |
447 | strcpy(oday,day); | |
448 | count++; | |
449 | } | |
4bcb77cf FM |
450 | if (getword(bytes,sizeof(bytes),buf,' ')<0 || getword(bytes,sizeof(bytes),buf,' ')<0) { |
451 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5); | |
452 | exit(1); | |
453 | } | |
25697a35 GS |
454 | bytes[strlen(bytes)-1]='\0'; |
455 | ||
456 | if(strcmp(oday,day) != 0) { | |
457 | strcpy(warea,oday); | |
458 | x1 = 44 +(atoi(oday) * 20); | |
459 | bar(tot); | |
460 | strcpy(oday,day); | |
461 | tot=0; | |
d6e703cc FM |
462 | } |
463 | tot=tot+my_atoll(bytes); | |
25697a35 GS |
464 | } |
465 | ||
466 | if(tot) { | |
467 | x1 = 44 +(atoi(day) * 20); | |
468 | bar(tot); | |
469 | } | |
470 | ||
471 | gdImagePng(im, pngout); | |
472 | fclose(pngout); | |
473 | gdImageDestroy(im); | |
474 | ||
475 | fclose(fp_in); | |
476 | unlink(wdirname); | |
477 | unlink(tmp5); | |
478 | ||
479 | #endif | |
d6e703cc | 480 | |
25697a35 GS |
481 | return; |
482 | } |