]> git.ipfire.org Git - thirdparty/sarg.git/blob - grepday.c
Take the length of the label in the locale language into account when placing it...
[thirdparty/sarg.git] / grepday.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
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"
28 #include "include/defs.h"
29
30 #if defined(HAVE_GD)
31
32 #if defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode)
33 #include <iconv.h>
34 #define USE_ICONV 1
35 #endif
36
37 struct GraphDataStruct
38 {
39 #ifdef USE_ICONV
40 iconv_t localtoutf;
41 #endif
42 int lavender;
43 int darkblue;
44 int dimgray;
45 int goldenrod;
46 int goldenrod2;
47 int gray;
48 int silver;
49 int black;
50 int color1;
51 int color2;
52 int color3;
53 gdImage *im;
54 char *string;
55 size_t string_size;
56 };
57
58 enum TextRefPos
59 {
60 TRP_TopLeft,
61 TRP_TopCenter,
62 TRP_TopRight,
63 TRP_BottomLeft,
64 TRP_BottomCenter,
65 TRP_BottomRight,
66 TRP_CenterLeft,
67 TRP_Center,
68 TRP_CenterRight,
69 };
70
71 static char * Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *fontlist,
72 double ptsize, double angle, int x, int y, char *string,enum TextRefPos RefPos)
73 {
74 char *sstring, *retval;
75 int brect[8];
76 int minx,miny,maxx,maxy;
77 int i;
78
79 #ifdef USE_ICONV
80 if (gdata->localtoutf!=(iconv_t)-1) {
81 char *str;
82 char *sstr;
83 size_t slen, sslen;
84
85 slen = strlen(string) + 1; // We must include string termination character
86 sslen = slen * 2; // We assume that UTF8 maximum 2 times large than local
87 if (sslen>gdata->string_size) {
88 sstring = (char *)realloc(gdata->string,sslen);
89 if (!sstring) {
90 debuga(_("realloc error (%zu bytes required)\n"),sslen);
91 exit(EXIT_FAILURE);
92 }
93 gdata->string=sstring;
94 gdata->string_size=sslen;
95 } else {
96 sstring=gdata->string;
97 sslen=gdata->string_size;
98 }
99
100 str = string;
101 sstr = sstring;
102 if (iconv (gdata->localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen)==-1) {
103 debuga(_("(grepday) iconv failed to convert string \"%s\" from %s to UTF-8 - %s\n"),string,CharSet,strerror(errno));
104 sstring=string; //show something sensible on the graph
105 }
106 } else {
107 sstring=string; //show something sensible on the graph
108 }
109 #else
110 sstring=string;
111 #endif
112
113 if (RefPos!=TRP_BottomLeft) {
114 retval = gdImageStringFTEx (NULL, brect, fg, fontlist, ptsize, angle, 0, 0, sstring, gdFTEX_Unicode);
115 if (retval) {
116 debuga(_("libgd failed to calculate the bounding box of the text \"%s\": %s\n"),sstring,retval);
117 exit(EXIT_FAILURE);
118 }
119 /*
120 From libgd documentation, brect contains this without taking into account the angle:
121 0 lower left corner, X position
122 1 lower left corner, Y position
123 2 lower right corner, X position
124 3 lower right corner, Y position
125 4 upper right corner, X position
126 5 upper right corner, Y position
127 6 upper left corner, X position
128 7 upper left corner, Y position
129 */
130 minx=maxx=brect[0];
131 miny=maxy=brect[1];
132 for (i=2 ; i<7 ; i+=2) {
133 if (minx>brect[i]) minx=brect[i];
134 if (maxx<brect[i]) maxx=brect[i];
135 if (miny>brect[i+1]) miny=brect[i+1];
136 if (maxy<brect[i+1]) maxy=brect[i+1];
137 }
138 }
139
140 switch (RefPos)
141 {
142 case TRP_TopLeft:
143 y-=miny;
144 break;
145
146 case TRP_TopCenter:
147 x-=(maxx-minx)/2;
148 y-=miny;
149 break;
150
151 case TRP_TopRight:
152 x-=maxx;
153 y-=miny;
154 break;
155
156 case TRP_BottomLeft:
157 break;
158
159 case TRP_BottomCenter:
160 x-=(maxx-minx)/2;
161 break;
162
163 case TRP_BottomRight:
164 x-=maxx;
165 break;
166
167 case TRP_Center:
168 x-=(maxx-minx)/2;
169 y+=(maxy-miny)/2;
170 break;
171
172 case TRP_CenterLeft:
173 y+=(maxy-miny)/2;
174 break;
175
176 case TRP_CenterRight:
177 x-=maxx;
178 y+=(maxy-miny)/2;
179 break;
180 }
181 retval = gdImageStringFTEx (gdata->im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode);
182 if (retval) {
183 debuga(_("libgd failed to render the text \"%s\": %s\n"),sstring,retval);
184 exit(EXIT_FAILURE);
185 }
186
187 return retval;
188 }
189
190 static void bar(struct GraphDataStruct *gdata,int x1,long long int n)
191 {
192 gdPoint points[4];
193 int val=0, x;
194 long long int num;
195
196 static const long long int limits[400]={0,500,1000,2000,3000,4000,
197 5000,6000,7000,8000,9000,10000,
198 20000,30000,40000,50000,70000,90000,
199 110000,130000,150000,170000,190000,210000,
200 230000,250000,280000,310000,340000,370000,
201 400000,430000,450000,460000,490000,500000,
202 550000,600000,650000,700000,750000,800000,
203 850000,900000,950000,1000000,1100000,1200000,
204 1300000,1400000,1500000,1600000,1700000,1800000,
205 1900000,2000000,2100000,2200000,2300000,2400000,
206 2500000,2600000,2700000,2800000,2900000,3000000,
207 3100000,3200000,3300000,3400000,3500000,3600000,
208 3700000,3800000,3900000,4000000,4100000,4200000,
209 4300000,4400000,4500000,4600000,4700000,4800000,
210 4900000,5000000,5100000,5200000,5300000,5400000,
211 5500000,5600000,5700000,5800000,5900000,6000000,
212 6100000,6200000,6300000,6400000,6500000,6600000,
213 6700000,6800000,6900000,7000000,7100000,7200000,
214 7300000,7400000,7500000,7600000,7700000,7800000,
215 7900000,8000000,8100000,8200000,8300000,8400000,
216 8500000,8600000,8700000,8800000,8900000,9000000,
217 9100000,9200000,9300000,9400000,9500000,9600000,
218 9700000,9800000,9900000,10000000,10500000,11000000,
219 11500000,12000000,12500000,13000000,13500000,14000000,
220 14500000,15000000,15500000,16000000,16500000,17000000,
221 17500000,18000000,18500000,19000000,19500000,20000000,
222 21000000,22000000,23000000,24000000,25000000,26000000,
223 27000000,28000000,29000000,30000000,31000000,32000000,
224 33000000,34000000,35000000,36000000,37000000,38000000,
225 39000000,40000000,41000000,42000000,43000000,44000000,
226 45000000,46000000,47000000,48000000,49000000,50000000,
227 51000000,52000000,53000000,54000000,55000000,56000000,
228 57000000,58000000,59000000,60000000,61000000,62000000,
229 63000000,64000000,65000000,66000000,67000000,68000000,
230 69000000,70000000,71000000,72000000,73000000,74000000,
231 75000000,76000000,77000000,78000000,79000000,80000000,
232 81000000,82000000,83000000,84000000,85000000,86000000,
233 87000000,88000000,89000000,90000000,91000000,92000000,
234 93000000,94000000,95000000,96000000,97000000,98000000,
235 99000000,100000000,110000000,120000000,130000000,140000000,
236 150000000,160000000,170000000,180000000,190000000,200000000,
237 210000000,220000000,230000000,240000000,250000000,260000000,
238 270000000,280000000,290000000,300000000,310000000,320000000,
239 330000000,340000000,350000000,360000000,370000000,380000000,
240 390000000,400000000,410000000,420000000,430000000,440000000,
241 450000000,460000000,470000000,480000000,490000000,500000000,
242 510000000,520000000,530000000,540000000,550000000,560000000,
243 570000000,580000000,590000000,600000000,610000000,620000000,
244 630000000,640000000,650000000,660000000,670000000,680000000,
245 690000000,700000000,710000000,720000000,730000000,740000000,
246 750000000,760000000,770000000,780000000,790000000,800000000,
247 810000000,820000000,830000000,840000000,850000000,860000000,
248 870000000,880000000,890000000,900000000,910000000,920000000,
249 930000000,940000000,950000000,960000000,970000000,980000000,
250 990000000LL,1000000000LL,1100000000LL,1200000000LL,1300000000LL,1400000000LL,
251 1500000000LL,1600000000LL,1700000000LL,1800000000LL,1900000000LL,2000000000LL,
252 2100000000LL,2200000000LL,2300000000LL,2400000000LL,2500000000LL,2600000000LL,
253 2700000000LL,2800000000LL,2900000000LL,3000000000LL,3100000000LL,3200000000LL,
254 3300000000LL,3400000000LL,3500000000LL,3600000000LL,3700000000LL,3800000000LL,
255 3900000000LL,4000000000LL,4100000000LL,4200000000LL,4300000000LL,4400000000LL,
256 4500000000LL,4600000000LL,4700000000LL,4800000000LL,4900000000LL,5000000000LL};
257
258 num = n;
259 val = 55;
260 for(x=0; x<=366; x++) {
261 if(limits[x] >= num) {
262 val = 425 - x;
263 break;
264 }
265 }
266
267 gdImageFilledRectangle(gdata->im, x1, val, x1+11, 425, gdata->color3);
268
269 points[0].x = x1+7;
270 points[0].y = val-5;
271 points[1].x = x1;
272 points[1].y = val;
273 points[2].x = x1+11;
274 points[2].y = val;
275 points[3].x = x1+17;
276 points[3].y = val-5;
277 gdImageFilledPolygon(gdata->im, points, 4, gdata->color1);
278
279 gdImageLine(gdata->im, x1+8, val-2, x1+8, val-10, gdata->dimgray);
280 gdImageFilledRectangle(gdata->im, x1-2, val-20, x1+18, val-10, gdata->goldenrod);
281 gdImageRectangle(gdata->im, x1-2, val-20, x1+18, val-10, gdata->goldenrod2);
282
283 Sarg_gdImageStringFT(gdata,gdata->black,GraphFont,6,0.0,x1+8,val-12,fixnum(num,0),TRP_BottomCenter);
284
285 points[0].x = x1+17;
286 points[0].y = val-5;
287 points[1].x = x1+11;
288 points[1].y = val;
289 points[2].x = x1+11;
290 points[2].y = 426;
291 points[3].x = x1+17;
292 points[3].y = 420;
293 gdImageFilledPolygon(gdata->im, points, 4, gdata->color2);
294
295 return;
296 }
297 #endif //HAVE_GD
298
299 void greport_day(const struct userinfostruct *uinfo)
300 {
301 #ifdef HAVE_GD
302 FILE *fp_in, *pngout;
303 int x, y;
304 int x1;
305 char wdirname[MAXLEN];
306 char graph[MAXLEN];
307 char buf[MAXLEN];
308 char csort[255];
309 char s[15];
310 char tmp5[MAXLEN];
311 int oday=0;
312 int day=0;
313 long long int llday;
314 long long int bytes;
315 char ftime[128];
316 long long int tot=0;
317 time_t t;
318 struct tm *local;
319 int cstatus;
320 long long datapoints[31];
321 gdPoint points[4];
322 struct getwordstruct gwarea;
323 struct GraphDataStruct gdata;
324 const int ImgXSize=720;
325 const int ImgYSize=480;
326 const int LeftMargin=60;
327 const int RightMargin=20;
328 const int TopMargin=60;
329 const int BottomMargin=60;
330 const int TickLength=3;
331 const int ZTickLength=5;
332 int BottomGraph;
333 int RightGraph;
334
335 if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>=sizeof(wdirname)) {
336 debuga(_("user name too long for %s/%s.day\n"),tmp,uinfo->filename);
337 exit(EXIT_FAILURE);
338 }
339 if(access(wdirname, R_OK) != 0) {
340 return;
341 }
342 if(!Graphs || GraphFont[0]=='\0') {
343 unlink(wdirname);
344 return;
345 }
346
347 if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,uinfo->filename)>=sizeof(tmp5)) {
348 debuga(_("user name too long for %s/%s.graph\n"),tmp,uinfo->filename);
349 exit(EXIT_FAILURE);
350 }
351 if(strcmp(DateFormat,"e") == 0)
352 sprintf(csort,"sort -t\"/\" -k 1,1 -o \"%s\" \"%s\"",tmp5,wdirname);
353 else
354 sprintf(csort,"sort -t\"/\" -k 2,2 -o \"%s\" \"%s\"",tmp5,wdirname);
355
356 cstatus=system(csort);
357 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
358 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
359 debuga(_("sort command: %s\n"),csort);
360 exit(EXIT_FAILURE);
361 }
362
363 if((fp_in=fopen(tmp5,"r"))==NULL) {
364 debuga(_("(grepday) Cannot open log file %s\n"),tmp5);
365 exit(EXIT_FAILURE);
366 }
367 unlink(wdirname);
368
369 memset(datapoints,0,sizeof(datapoints));
370 oday=-1;
371 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
372 fixendofline(buf);
373 getword_start(&gwarea,buf);
374 if (getword_atoll(&llday,&gwarea,'/')<0) {
375 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp5);
376 exit(EXIT_FAILURE);
377 }
378 if(DateFormat[0]=='u') {
379 if (getword_atoll(&llday,&gwarea,'/')<0) {
380 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp5);
381 exit(EXIT_FAILURE);
382 }
383 }
384 day=(int)llday;
385 if (day<1 || day>31) continue;
386 if (getword_skip(20,&gwarea,'\t')<0 || getword_skip(20,&gwarea,'\t')<0 || getword_atoll(&bytes,&gwarea,'\t')<0) {
387 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp5);
388 exit(EXIT_FAILURE);
389 }
390
391 if(oday!=day) {
392 if (oday>0) datapoints[oday-1]=tot;
393 oday=day;
394 tot=0;
395 }
396 tot+=bytes;
397 }
398 fclose(fp_in);
399 unlink(tmp5);
400 if (oday>0) datapoints[oday-1]=tot;
401
402 if(access(GraphFont, R_OK) != 0) {
403 debuga(_("(grepday) Fontname %s not found\n"),GraphFont);
404 exit(EXIT_FAILURE);
405 }
406 memset(&gdata,0,sizeof(gdata));
407
408 #ifdef USE_ICONV
409 gdata.localtoutf = iconv_open ("UTF-8", CharSet);
410 if (gdata.localtoutf==(iconv_t)-1) {
411 debuga(_("(grepday) iconv cannot convert from %s to UTF-8 - %s\n"),CharSet,strerror(errno));
412 }
413 #endif
414
415 gdata.im = gdImageCreate(ImgXSize, ImgYSize);
416 BottomGraph=ImgYSize-BottomMargin;
417 RightGraph=ImgXSize-RightMargin;
418
419 // first allocated color is the background
420 gdata.lavender = gdImageColorAllocate(gdata.im, 230, 230, 250);
421 gdata.gray = gdImageColorAllocate(gdata.im, 192, 192, 192);
422 gdata.silver = gdImageColorAllocate(gdata.im, 211, 211, 211);
423 gdata.black = gdImageColorAllocate(gdata.im, 0, 0, 0);
424 gdata.dimgray = gdImageColorAllocate(gdata.im, 105, 105, 105);
425 gdata.darkblue = gdImageColorAllocate(gdata.im, 0, 0, 139);
426 gdata.goldenrod = gdImageColorAllocate(gdata.im, 234, 234, 174);
427 gdata.goldenrod2 = gdImageColorAllocate(gdata.im, 207, 181, 59);
428
429 if(strcmp(GraphDaysBytesBarColor,"orange") == 0) {
430 gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142);
431 gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72);
432 gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107);
433 }
434 else if(strcmp(GraphDaysBytesBarColor,"blue") == 0) {
435 gdata.color1 = gdImageColorAllocate(gdata.im, 62, 80, 167);
436 gdata.color2 = gdImageColorAllocate(gdata.im, 40, 51, 101);
437 gdata.color3 = gdImageColorAllocate(gdata.im, 57, 73, 150);
438 }
439 else if(strcmp(GraphDaysBytesBarColor,"green") == 0) {
440 gdata.color1 = gdImageColorAllocate(gdata.im,120,166,129);
441 gdata.color2 = gdImageColorAllocate(gdata.im,84,113,82);
442 gdata.color3 = gdImageColorAllocate(gdata.im,158,223,167);
443 }
444 else if(strcmp(GraphDaysBytesBarColor,"yellow") == 0) {
445 gdata.color1 = gdImageColorAllocate(gdata.im,185,185,10);
446 gdata.color2 = gdImageColorAllocate(gdata.im,111,111,10);
447 gdata.color3 = gdImageColorAllocate(gdata.im,166,166,10);
448 }
449 else if(strcmp(GraphDaysBytesBarColor,"brown") == 0) {
450 gdata.color1 = gdImageColorAllocate(gdata.im,97,45,27);
451 gdata.color2 = gdImageColorAllocate(gdata.im,60,30,20);
452 gdata.color3 = gdImageColorAllocate(gdata.im,88,41,26);
453 }
454 else if(strcmp(GraphDaysBytesBarColor,"red") == 0){
455 gdata.color1 = gdImageColorAllocate(gdata.im,185,10,10);
456 gdata.color2 = gdImageColorAllocate(gdata.im,111,10,10);
457 gdata.color3 = gdImageColorAllocate(gdata.im,166,10,10);
458 } else {
459 debuga(_("Unknown color \"%s\" requested for the graph. Using orange instead\n"),GraphDaysBytesBarColor);
460 gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142);
461 gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72);
462 gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107);
463 }
464
465 // rectangle around the image
466 gdImageRectangle(gdata.im, 0, 0, ImgXSize-1, ImgYSize-1, gdata.dimgray);
467 // backtround of the graph
468 gdImageFilledRectangle(gdata.im, LeftMargin, TopMargin, RightGraph, BottomGraph, gdata.silver);
469
470 // depth of the left Y axis
471 points[0].x = LeftMargin-10;
472 points[0].y = TopMargin+5;
473 points[1].x = LeftMargin-10;
474 points[1].y = BottomGraph+5;
475 points[2].x = LeftMargin;
476 points[2].y = BottomGraph;
477 points[3].x = LeftMargin;
478 points[3].y = TopMargin;
479 gdImageFilledPolygon(gdata.im, points, 4, gdata.gray);
480
481 // depth of the bottom X axis
482 points[0].x = LeftMargin;
483 points[0].y = BottomGraph;
484 points[1].x = LeftMargin-10;
485 points[1].y = BottomGraph+5;
486 points[2].x = RightGraph-10;
487 points[2].y = BottomGraph+5;
488 points[3].x = RightGraph;
489 points[3].y = BottomGraph;
490 gdImageFilledPolygon(gdata.im, points, 4, gdata.gray);
491
492 // vertical exterior line of the depth
493 gdImageLine(gdata.im, LeftMargin-10, TopMargin+5, LeftMargin-10, BottomGraph+5+ZTickLength, gdata.black);
494 // horizontal exterior line of the depth
495 gdImageLine(gdata.im, LeftMargin-10-ZTickLength, BottomGraph+5, RightGraph-10, BottomGraph+5, gdata.black);
496 // diagonal line between the two depths
497 gdImageLine(gdata.im, LeftMargin-10, BottomGraph+5, LeftMargin, BottomGraph, gdata.black);
498 // vertical left line of the graph
499 gdImageLine(gdata.im, LeftMargin, BottomGraph, LeftMargin, TopMargin, gdata.black);
500 // horizontal bottom line of the graph
501 gdImageLine(gdata.im, LeftMargin, BottomGraph, RightGraph, BottomGraph, gdata.black);
502 // vertical right line of the graph
503 gdImageLine(gdata.im, RightGraph, TopMargin, RightGraph, BottomGraph, gdata.black);
504 // diagonal line to close the right of the bottom depth
505 gdImageLine(gdata.im, RightGraph-10, BottomGraph+5, RightGraph, BottomGraph, gdata.black);
506
507 // Y axis ticks
508 for(x=BottomGraph-10; x>=TopMargin; x=x-10) {
509 gdImageLine(gdata.im, LeftMargin-10, x+5, LeftMargin, x, gdata.dimgray);
510 gdImageLine(gdata.im, LeftMargin-10-TickLength, x+5, LeftMargin-10, x+5, gdata.dimgray);
511 }
512
513 // horizontal background lines
514 for(x=TopMargin; x<=BottomGraph-10; x=x+10)
515 gdImageLine(gdata.im, LeftMargin, x, RightGraph, x, gdata.dimgray);
516
517 // X axis ticks and labels
518 x=LeftMargin-10+20;
519 for(y=1; y<=31; y++) {
520 gdImageLine(gdata.im, x, BottomGraph+5, x, BottomGraph+5+TickLength, gdata.dimgray);
521 sprintf(s,"%02d",y);
522 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,x,BottomGraph+5+TickLength+1,s,TRP_TopCenter);
523 x=x+20;
524 }
525
526 t = time(NULL);
527 local = localtime(&t);
528 if(strcmp(DateFormat,"u") == 0)
529 strftime(ftime, sizeof(ftime), "%b/%d/%Y %H:%M", local);
530 if(strcmp(DateFormat,"e") == 0)
531 strftime(ftime, sizeof(ftime), "%d/%b/%Y-%H:%M", local);
532
533 Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,7,0.0,ImgXSize-10,ImgYSize-10,ftime,TRP_BottomRight);
534 if(ShowSargInfo) Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10,0.0,300,15,_("SARG, "),TRP_BottomRight);
535 Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10,0.0,300,15,Title,TRP_BottomLeft);
536 sprintf(warea,_("Period: %s"),period.text);
537 Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,300,27,warea,TRP_BottomLeft);
538 sprintf(warea,_("User: %s"),uinfo->label);
539 Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,300,38,warea,TRP_BottomLeft);
540
541 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-10+5,"50K",TRP_CenterRight);
542 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-20+5,"250K",TRP_CenterRight);
543 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-30+5,"500K",TRP_CenterRight);
544 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-40+5,"1M",TRP_CenterRight);
545 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-50+5,"2M",TRP_CenterRight);
546 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-60+5,"3M",TRP_CenterRight);
547 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-70+5,"4M",TRP_CenterRight);
548 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-80+5,"5M",TRP_CenterRight);
549 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-90+5,"6M",TRP_CenterRight);
550 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-100+5,"7M",TRP_CenterRight);
551 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-110+5,"8M",TRP_CenterRight);
552 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-120+5,"9M",TRP_CenterRight);
553 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-130+5,"10M",TRP_CenterRight);
554 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-140+5,"15M",TRP_CenterRight);
555 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-150+5,"20M",TRP_CenterRight);
556 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-160+5,"30M",TRP_CenterRight);
557 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-170+5,"40M",TRP_CenterRight);
558 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-180+5,"50M",TRP_CenterRight);
559 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-190+5,"60M",TRP_CenterRight);
560 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-200+5,"70M",TRP_CenterRight);
561 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-210+5,"80M",TRP_CenterRight);
562 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-220+5,"90M",TRP_CenterRight);
563 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-230+5,"100M",TRP_CenterRight);
564 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-240+5,"200M",TRP_CenterRight);
565 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-250+5,"300M",TRP_CenterRight);
566 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-260+5,"400M",TRP_CenterRight);
567 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-270+5,"500M",TRP_CenterRight);
568 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-280+5,"600M",TRP_CenterRight);
569 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-290+5,"700M",TRP_CenterRight);
570 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-300+5,"800M",TRP_CenterRight);
571 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-310+5,"900M",TRP_CenterRight);
572 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-320+5,"1G",TRP_CenterRight);
573 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-330+5,"2G",TRP_CenterRight);
574 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-340+5,"3G",TRP_CenterRight);
575 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-350+5,"4G",TRP_CenterRight);
576 Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-360+5,"5G",TRP_CenterRight);
577 if(strcmp(datetimeby,"bytes") == 0)
578 Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,3.141592/2,20,ImgYSize/2,_("BYTES"),TRP_CenterLeft);
579 else
580 Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,3.141592/2,20,ImgYSize/2,_("ELAPSED TIME"),TRP_CenterLeft);
581 Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,0.0,ImgXSize/2,ImgYSize-20,_("DAYS"),TRP_BottomCenter);
582
583 for (day=0 ; day<31 ; day++) {
584 if (datapoints[day]>0) {
585 x1 = 44 +((day+1) * 20);
586 bar(&gdata,x1,datapoints[day]);
587 }
588 }
589
590 if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",outdirname,uinfo->filename)>=sizeof(graph)) {
591 debuga(_("user name too long for %s/%s/graph_day.png\n"),outdirname,uinfo->filename);
592 exit(EXIT_FAILURE);
593 }
594 if((pngout=fopen(graph,"wb"))==NULL) {
595 debuga(_("(grepday) Cannot open log file %s\n"),graph);
596 exit(EXIT_FAILURE);
597 }
598 gdImagePng(gdata.im, pngout);
599 fclose(pngout);
600 gdImageDestroy(gdata.im);
601
602 if (gdata.string) free(gdata.string);
603 #ifdef USE_ICONV
604 if (gdata.localtoutf!=(iconv_t)-1)
605 iconv_close (gdata.localtoutf);
606 #endif
607
608 #endif //HAVE_GD
609
610 return;
611 }
612
613 void greport_cleanup(void)
614 {
615 #ifdef HAVE_GD
616 gdFontCacheShutdown();
617 #endif
618 }