#if defined(HAVE_GD)
-static int blue;
-static int white;
-static int lavender;
-static int darkblue;
-static int dimgray;
-static int goldenrod;
-static int goldenrod2;
-static int gray;
-static int silver;
-static int black;
-
#if defined(HAVE_ICONV_H) && defined(gdFTEX_Unicode)
#include <iconv.h>
-#define SARGgdImageStringFT I18NgdImageStringFT
+#define USE_ICONV 1
+#endif
-static char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
- double ptsize, double angle, int x, int y, char *string)
+struct GraphDataStruct
{
+#ifdef USE_ICONV
iconv_t localtoutf;
- char *sstring, *str, *sstr, *retval;
- size_t slen, sslen;
-
- slen = strlen(string) + 1; // We must include string termination character
- sslen = slen * 2; // We assume that UTF8 maximum 2 times large than local
- sstring = (char *)malloc(sslen);
- if (!sstring) {
- debuga(_("malloc error (%zu bytes required)\n"),sslen);
- exit(EXIT_FAILURE);
- }
-
- str = (char *) string;
- sstr = (char *) sstring;
+#endif
+ int lavender;
+ int darkblue;
+ int dimgray;
+ int goldenrod;
+ int goldenrod2;
+ int gray;
+ int silver;
+ int black;
+ int color1;
+ int color2;
+ int color3;
+ gdImage *im;
+ char *string;
+ size_t string_size;
+};
+
+enum TextRefPos
+{
+ TRP_TopLeft,
+ TRP_TopCenter,
+ TRP_TopRight,
+ TRP_BottomLeft,
+ TRP_BottomCenter,
+ TRP_BottomRight,
+ TRP_CenterLeft,
+ TRP_Center,
+ TRP_CenterRight,
+};
+
+static char * Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *fontlist,
+ double ptsize, double angle, int x, int y, char *string,enum TextRefPos RefPos)
+{
+ char *sstring, *retval;
+ int brect[8];
+ int minx,miny,maxx,maxy;
+ int i;
+
+#ifdef USE_ICONV
+ if (gdata->localtoutf!=(iconv_t)-1) {
+ char *str;
+ char *sstr;
+ size_t slen, sslen;
+
+ slen = strlen(string) + 1; // We must include string termination character
+ sslen = slen * 2; // We assume that UTF8 maximum 2 times large than local
+ if (sslen>gdata->string_size) {
+ sstring = (char *)realloc(gdata->string,sslen);
+ if (!sstring) {
+ debuga(_("realloc error (%zu bytes required)\n"),sslen);
+ exit(EXIT_FAILURE);
+ }
+ gdata->string=sstring;
+ gdata->string_size=sslen;
+ } else {
+ sstring=gdata->string;
+ sslen=gdata->string_size;
+ }
- localtoutf = iconv_open ("UTF-8", CharSet);
- if (localtoutf==(iconv_t)-1) {
- debuga(_("(grepday) iconv cannot convert from %s to UTF-8 - %s\n"),CharSet,strerror(errno));
- strcpy(sstring,string); //show something sensible on the graph
- }
- else {
- if (iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen)==-1) {
+ str = string;
+ sstr = sstring;
+ if (iconv (gdata->localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen)==-1) {
debuga(_("(grepday) iconv failed to convert string \"%s\" from %s to UTF-8 - %s\n"),string,CharSet,strerror(errno));
- strcpy(sstring,string); //show something sensible on the graph
+ sstring=string; //show something sensible on the graph
+ }
+ } else {
+ sstring=string; //show something sensible on the graph
+ }
+#else
+ sstring=string;
+#endif
+
+ if (RefPos!=TRP_BottomLeft) {
+ retval = gdImageStringFTEx (NULL, brect, fg, fontlist, ptsize, angle, 0, 0, sstring, gdFTEX_Unicode);
+ if (retval) {
+ debuga(_("libgd failed to calculate the bounding box of the text \"%s\": %s\n"),sstring,retval);
+ exit(EXIT_FAILURE);
+ }
+ /*
+ From libgd documentation, brect contains this without taking into account the angle:
+ 0 lower left corner, X position
+ 1 lower left corner, Y position
+ 2 lower right corner, X position
+ 3 lower right corner, Y position
+ 4 upper right corner, X position
+ 5 upper right corner, Y position
+ 6 upper left corner, X position
+ 7 upper left corner, Y position
+ */
+ minx=maxx=brect[0];
+ miny=maxy=brect[1];
+ for (i=2 ; i<7 ; i+=2) {
+ if (minx>brect[i]) minx=brect[i];
+ if (maxx<brect[i]) maxx=brect[i];
+ if (miny>brect[i+1]) miny=brect[i+1];
+ if (maxy<brect[i+1]) maxy=brect[i+1];
}
- iconv_close (localtoutf);
}
- retval = gdImageStringFTEx (im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode);
- free(sstring);
+ switch (RefPos)
+ {
+ case TRP_TopLeft:
+ y-=miny;
+ break;
+
+ case TRP_TopCenter:
+ x-=(maxx-minx)/2;
+ y-=miny;
+ break;
+
+ case TRP_TopRight:
+ x-=maxx;
+ y-=miny;
+ break;
+
+ case TRP_BottomLeft:
+ break;
+
+ case TRP_BottomCenter:
+ x-=(maxx-minx)/2;
+ break;
+
+ case TRP_BottomRight:
+ x-=maxx;
+ break;
+
+ case TRP_Center:
+ x-=(maxx-minx)/2;
+ y+=(maxy-miny)/2;
+ break;
+
+ case TRP_CenterLeft:
+ y+=(maxy-miny)/2;
+ break;
+
+ case TRP_CenterRight:
+ x-=maxx;
+ y+=(maxy-miny)/2;
+ break;
+ }
+ retval = gdImageStringFTEx (gdata->im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode);
+ if (retval) {
+ debuga(_("libgd failed to render the text \"%s\": %s\n"),sstring,retval);
+ exit(EXIT_FAILURE);
+ }
return retval;
}
-#else
-#define SARGgdImageStringFT gdImageStringFT
-#endif
-static void bar(int x1,long long int n)
+static void bar(struct GraphDataStruct *gdata,int x1,long long int n)
{
gdPoint points[4];
- int brect[8];
int val=0, x;
long long int num;
- char v[15];
static const long long int limits[400]={0,500,1000,2000,3000,4000,
5000,6000,7000,8000,9000,10000,
3900000000LL,4000000000LL,4100000000LL,4200000000LL,4300000000LL,4400000000LL,
4500000000LL,4600000000LL,4700000000LL,4800000000LL,4900000000LL,5000000000LL};
- if(strcmp(GraphDaysBytesBarColor,"orange") == 0) {
- color1 = gdImageColorAllocate(im, 255, 233, 142);
- color2 = gdImageColorAllocate(im, 220, 163, 72);
- color3 = gdImageColorAllocate(im, 255, 198, 107);
- }
- if(strcmp(GraphDaysBytesBarColor,"blue") == 0) {
- color1 = gdImageColorAllocate(im, 62, 80, 167);
- color2 = gdImageColorAllocate(im, 40, 51, 101);
- color3 = gdImageColorAllocate(im, 57, 73, 150);
- }
- if(strcmp(GraphDaysBytesBarColor,"green") == 0) {
- color1 = gdImageColorAllocate(im,120,166,129);
- color2 = gdImageColorAllocate(im,84,113,82);
- color3 = gdImageColorAllocate(im,158,223,167);
- }
- if(strcmp(GraphDaysBytesBarColor,"yellow") == 0) {
- color1 = gdImageColorAllocate(im,185,185,10);
- color2 = gdImageColorAllocate(im,111,111,10);
- color3 = gdImageColorAllocate(im,166,166,10);
- }
- if(strcmp(GraphDaysBytesBarColor,"brown") == 0) {
- color1 = gdImageColorAllocate(im,97,45,27);
- color2 = gdImageColorAllocate(im,60,30,20);
- color3 = gdImageColorAllocate(im,88,41,26);
- }
- if(strcmp(GraphDaysBytesBarColor,"red") == 0){
- color1 = gdImageColorAllocate(im,185,10,10);
- color2 = gdImageColorAllocate(im,111,10,10);
- color3 = gdImageColorAllocate(im,166,10,10);
- }
-
- blue = gdImageColorAllocate(im, 0, 0, 255);
- white = gdImageColorAllocate(im, 255, 255, 255);
- dimgray = gdImageColorAllocate(im, 105, 105, 105);
- goldenrod = gdImageColorAllocate(im, 234, 234, 174);
- goldenrod2 = gdImageColorAllocate(im, 207, 181, 59);
-
num = n;
val = 55;
for(x=0; x<=366; x++) {
}
}
- gdImageFilledRectangle(im, x1, val, x1+11, 425, color3);
+ gdImageFilledRectangle(gdata->im, x1, val, x1+11, 425, gdata->color3);
points[0].x = x1+7;
points[0].y = val-5;
points[2].y = val;
points[3].x = x1+17;
points[3].y = val-5;
- gdImageFilledPolygon(im, points, 4, color1);
-
- gdImageLine(im, x1+8, val-2, x1+8, val-10, dimgray);
- gdImageFilledRectangle(im, x1-2, val-20, x1+18, val-10, goldenrod);
- gdImageRectangle(im, x1-2, val-20, x1+18, val-10, goldenrod2);
+ gdImageFilledPolygon(gdata->im, points, 4, gdata->color1);
- snprintf(v,6,"%s",fixnum(num,0));
+ gdImageLine(gdata->im, x1+8, val-2, x1+8, val-10, gdata->dimgray);
+ gdImageFilledRectangle(gdata->im, x1-2, val-20, x1+18, val-10, gdata->goldenrod);
+ gdImageRectangle(gdata->im, x1-2, val-20, x1+18, val-10, gdata->goldenrod2);
- SARGgdImageStringFT(im,&brect[0],black,GraphFont,6,0.0,x1-1,val-12,v);
+ Sarg_gdImageStringFT(gdata,gdata->black,GraphFont,6,0.0,x1+8,val-12,fixnum(num,0),TRP_BottomCenter);
points[0].x = x1+17;
points[0].y = val-5;
points[2].y = 426;
points[3].x = x1+17;
points[3].y = 420;
- gdImageFilledPolygon(im, points, 4, color2);
+ gdImageFilledPolygon(gdata->im, points, 4, gdata->color2);
return;
}
FILE *fp_in, *pngout;
int x, y;
int x1;
- int brect[8];
char wdirname[MAXLEN];
char graph[MAXLEN];
char buf[MAXLEN];
char csort[255];
- char data[20];
char s[15];
char tmp5[MAXLEN];
- int count=0;
int oday=0;
int day=0;
long long int llday;
time_t t;
struct tm *local;
int cstatus;
+ long long datapoints[31];
+ gdPoint points[4];
struct getwordstruct gwarea;
- struct getwordstruct gwarea1;
+ struct GraphDataStruct gdata;
+ const int ImgXSize=720;
+ const int ImgYSize=480;
+ const int LeftMargin=60;
+ const int RightMargin=20;
+ const int TopMargin=60;
+ const int BottomMargin=60;
+ const int TickLength=3;
+ const int ZTickLength=5;
+ int BottomGraph;
+ int RightGraph;
- if(!Graphs || GraphFont[0]=='\0') {
- unlink(wdirname);
- return;
- }
- if(access(GraphFont, R_OK) != 0) {
- debuga(_("(grepday) Fontname %s not found\n"),GraphFont);
+ if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>=sizeof(wdirname)) {
+ debuga(_("user name too long for %s/%s.day\n"),tmp,uinfo->filename);
exit(EXIT_FAILURE);
}
-
- im = gdImageCreate(720, 480);
-
- lavender = gdImageColorAllocate(im, 230, 230, 250);
- white = gdImageColorAllocate(im, 255, 255, 255);
- gray = gdImageColorAllocate(im, 192, 192, 192);
- silver = gdImageColorAllocate(im, 211, 211, 211);
- black = gdImageColorAllocate(im, 0, 0, 0);
- blue = gdImageColorAllocate(im, 35, 35, 227);
- dimgray = gdImageColorAllocate(im, 105, 105, 105);
- darkblue = gdImageColorAllocate(im, 0, 0, 139);
-
- gdImageRectangle(im, 0, 0, 719, 479, dimgray);
- gdImageFilledRectangle(im, 60, 60, 700, 420, silver);
-
- points[0].x = 50;
- points[0].y = 65;
- points[1].x = 50;
- points[1].y = 425;
- points[2].x = 60;
- points[2].y = 420;
- points[3].x = 60;
- points[3].y = 60;
- gdImageFilledPolygon(im, points, 4, gray);
-
- points[0].x = 60;
- points[0].y = 420;
- points[1].x = 50;
- points[1].y = 425;
- points[2].x = 690;
- points[2].y = 425;
- points[3].x = 700;
- points[3].y = 420;
- gdImageFilledPolygon(im, points, 4, gray);
-
- gdImageLine(im, 50, 65, 50, 430, black);
- gdImageLine(im, 45, 425, 690, 425, black);
- gdImageLine(im, 50, 425, 60, 420, black);
- gdImageLine(im, 60, 420, 60, 60, black);
- gdImageLine(im, 700, 60, 700, 420, black);
- gdImageLine(im, 690, 425, 700, 420, black);
-
- for(x=415; x>=65; x=x-10) {
- gdImageLine(im, 50, x, 60, x-5, dimgray);
- gdImageLine(im, 47, x, 50, x, dimgray);
+ if(access(wdirname, R_OK) != 0) {
+ return;
}
-
- for(x=60; x<=420; x=x+10)
- gdImageLine(im, 60, x, 700, x, dimgray);
-
- gdImageLine(im, 60, 420, 700, 420, black);
-
- for(x=70; x<=680; x=x+20)
- gdImageLine(im, x, 425, x, 428, dimgray);
-
- y=65;
- for(x=1; x<=31; x++) {
- sprintf(s,"%02d",x);
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,y,437,s);
- y=y+20;
+ if(!Graphs || GraphFont[0]=='\0') {
+ unlink(wdirname);
+ return;
}
- t = time(NULL);
- local = localtime(&t);
- if(strcmp(DateFormat,"u") == 0)
- strftime(ftime, sizeof(ftime), "%b/%d/%Y %H:%M", local);
- if(strcmp(DateFormat,"e") == 0)
- strftime(ftime, sizeof(ftime), "%d/%b/%Y-%H:%M", local);
-
- SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,7,0.0,620,470,ftime);
- if(ShowSargInfo) SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,257,15,"SARG, ");
- SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,300,15,Title);
- sprintf(warea,_("Period: %s"),period.text);
- SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,27,warea);
- sprintf(warea,_("User: %s"),uinfo->label);
- SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,38,warea);
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,418," 50K");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,408,"250K");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,398,"500K");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,388," 1M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,378," 2M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,368," 3M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,358," 4M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,348," 5M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,338," 6M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,328," 7M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,318," 8M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,308," 9M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,298," 10M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,288," 15M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,278," 20M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,268," 30M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,258," 40M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,248," 50M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,238," 60M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,228," 70M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,218," 80M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,208," 90M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,198,"100M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,188,"200M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,178,"300M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,168,"400M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,158,"500M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,148,"600M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,138,"700M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,128,"800M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,118,"900M");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,108," 1G");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 98," 2G");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 88," 3G");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 78," 4G");
- SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23, 68," 5G");
- if(strcmp(datetimeby,"bytes") == 0)
- SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,3.14/2,20,248,_("BYTES"));
- else
- SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,3.14/2,20,248,_("ELAPSED TIME"));
- SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,0.0,330,460,_("DAYS"));
-
- if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",outdirname,uinfo->filename)>=sizeof(graph)) {
- debuga(_("user name too long for %s/%s/graph_day.png\n"),outdirname,uinfo->filename);
- exit(EXIT_FAILURE);
- }
- if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>=sizeof(wdirname)) {
- debuga(_("user name too long for %s/%s.day\n"),tmp,uinfo->filename);
- exit(EXIT_FAILURE);
- }
if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,uinfo->filename)>=sizeof(tmp5)) {
debuga(_("user name too long for %s/%s.graph\n"),tmp,uinfo->filename);
exit(EXIT_FAILURE);
}
-
- if(access(wdirname, R_OK) != 0) {
- gdImageDestroy(im);
- return;
- }
-
if(strcmp(DateFormat,"e") == 0)
sprintf(csort,"sort -t\"/\" -k 1,1 -o \"%s\" \"%s\"",tmp5,wdirname);
else
debuga(_("(grepday) Cannot open log file %s\n"),tmp5);
exit(EXIT_FAILURE);
}
+ unlink(wdirname);
- if((pngout=fopen(graph,"wb"))==NULL) {
- debuga(_("(grepday) Cannot open log file %s\n"),graph);
- exit(EXIT_FAILURE);
- }
-
+ memset(datapoints,0,sizeof(datapoints));
+ oday=-1;
while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
fixendofline(buf);
getword_start(&gwarea,buf);
- if (getword(data,sizeof(data),&gwarea,'\t')<0) {
+ if (getword_atoll(&llday,&gwarea,'/')<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp5);
exit(EXIT_FAILURE);
}
- getword_start(&gwarea1,data);
- if (getword_atoll(&llday,&gwarea1,'/')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp5);
- exit(EXIT_FAILURE);
- }
- if(strcmp(DateFormat,"u") == 0) {
- if (getword_atoll(&llday,&gwarea1,'/')<0) {
+ if(DateFormat[0]=='u') {
+ if (getword_atoll(&llday,&gwarea,'/')<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp5);
exit(EXIT_FAILURE);
}
}
day=(int)llday;
- if(!count) {
- oday=day;
- count++;
- }
- if (getword_skip(20,&gwarea,'\t')<0 || getword_atoll(&bytes,&gwarea,'\t')<0) {
+ if (day<1 || day>31) continue;
+ if (getword_skip(20,&gwarea,'\t')<0 || getword_skip(20,&gwarea,'\t')<0 || getword_atoll(&bytes,&gwarea,'\t')<0) {
debuga(_("Maybe you have a broken record or garbage in your %s file\n"),tmp5);
exit(EXIT_FAILURE);
}
if(oday!=day) {
- x1 = 44 +(oday * 20);
- bar(x1,tot);
+ if (oday>0) datapoints[oday-1]=tot;
oday=day;
tot=0;
}
tot+=bytes;
}
+ fclose(fp_in);
+ unlink(tmp5);
+ if (oday>0) datapoints[oday-1]=tot;
+
+ if(access(GraphFont, R_OK) != 0) {
+ debuga(_("(grepday) Fontname %s not found\n"),GraphFont);
+ exit(EXIT_FAILURE);
+ }
+ memset(&gdata,0,sizeof(gdata));
+
+#ifdef USE_ICONV
+ gdata.localtoutf = iconv_open ("UTF-8", CharSet);
+ if (gdata.localtoutf==(iconv_t)-1) {
+ debuga(_("(grepday) iconv cannot convert from %s to UTF-8 - %s\n"),CharSet,strerror(errno));
+ }
+#endif
+
+ gdata.im = gdImageCreate(ImgXSize, ImgYSize);
+ BottomGraph=ImgYSize-BottomMargin;
+ RightGraph=ImgXSize-RightMargin;
+
+ // first allocated color is the background
+ gdata.lavender = gdImageColorAllocate(gdata.im, 230, 230, 250);
+ gdata.gray = gdImageColorAllocate(gdata.im, 192, 192, 192);
+ gdata.silver = gdImageColorAllocate(gdata.im, 211, 211, 211);
+ gdata.black = gdImageColorAllocate(gdata.im, 0, 0, 0);
+ gdata.dimgray = gdImageColorAllocate(gdata.im, 105, 105, 105);
+ gdata.darkblue = gdImageColorAllocate(gdata.im, 0, 0, 139);
+ gdata.goldenrod = gdImageColorAllocate(gdata.im, 234, 234, 174);
+ gdata.goldenrod2 = gdImageColorAllocate(gdata.im, 207, 181, 59);
+
+ if(strcmp(GraphDaysBytesBarColor,"orange") == 0) {
+ gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142);
+ gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72);
+ gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107);
+ }
+ else if(strcmp(GraphDaysBytesBarColor,"blue") == 0) {
+ gdata.color1 = gdImageColorAllocate(gdata.im, 62, 80, 167);
+ gdata.color2 = gdImageColorAllocate(gdata.im, 40, 51, 101);
+ gdata.color3 = gdImageColorAllocate(gdata.im, 57, 73, 150);
+ }
+ else if(strcmp(GraphDaysBytesBarColor,"green") == 0) {
+ gdata.color1 = gdImageColorAllocate(gdata.im,120,166,129);
+ gdata.color2 = gdImageColorAllocate(gdata.im,84,113,82);
+ gdata.color3 = gdImageColorAllocate(gdata.im,158,223,167);
+ }
+ else if(strcmp(GraphDaysBytesBarColor,"yellow") == 0) {
+ gdata.color1 = gdImageColorAllocate(gdata.im,185,185,10);
+ gdata.color2 = gdImageColorAllocate(gdata.im,111,111,10);
+ gdata.color3 = gdImageColorAllocate(gdata.im,166,166,10);
+ }
+ else if(strcmp(GraphDaysBytesBarColor,"brown") == 0) {
+ gdata.color1 = gdImageColorAllocate(gdata.im,97,45,27);
+ gdata.color2 = gdImageColorAllocate(gdata.im,60,30,20);
+ gdata.color3 = gdImageColorAllocate(gdata.im,88,41,26);
+ }
+ else if(strcmp(GraphDaysBytesBarColor,"red") == 0){
+ gdata.color1 = gdImageColorAllocate(gdata.im,185,10,10);
+ gdata.color2 = gdImageColorAllocate(gdata.im,111,10,10);
+ gdata.color3 = gdImageColorAllocate(gdata.im,166,10,10);
+ } else {
+ debuga(_("Unknown color \"%s\" requested for the graph. Using orange instead\n"),GraphDaysBytesBarColor);
+ gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142);
+ gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72);
+ gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107);
+ }
+
+ // rectangle around the image
+ gdImageRectangle(gdata.im, 0, 0, ImgXSize-1, ImgYSize-1, gdata.dimgray);
+ // backtround of the graph
+ gdImageFilledRectangle(gdata.im, LeftMargin, TopMargin, RightGraph, BottomGraph, gdata.silver);
+
+ // depth of the left Y axis
+ points[0].x = LeftMargin-10;
+ points[0].y = TopMargin+5;
+ points[1].x = LeftMargin-10;
+ points[1].y = BottomGraph+5;
+ points[2].x = LeftMargin;
+ points[2].y = BottomGraph;
+ points[3].x = LeftMargin;
+ points[3].y = TopMargin;
+ gdImageFilledPolygon(gdata.im, points, 4, gdata.gray);
+
+ // depth of the bottom X axis
+ points[0].x = LeftMargin;
+ points[0].y = BottomGraph;
+ points[1].x = LeftMargin-10;
+ points[1].y = BottomGraph+5;
+ points[2].x = RightGraph-10;
+ points[2].y = BottomGraph+5;
+ points[3].x = RightGraph;
+ points[3].y = BottomGraph;
+ gdImageFilledPolygon(gdata.im, points, 4, gdata.gray);
+
+ // vertical exterior line of the depth
+ gdImageLine(gdata.im, LeftMargin-10, TopMargin+5, LeftMargin-10, BottomGraph+5+ZTickLength, gdata.black);
+ // horizontal exterior line of the depth
+ gdImageLine(gdata.im, LeftMargin-10-ZTickLength, BottomGraph+5, RightGraph-10, BottomGraph+5, gdata.black);
+ // diagonal line between the two depths
+ gdImageLine(gdata.im, LeftMargin-10, BottomGraph+5, LeftMargin, BottomGraph, gdata.black);
+ // vertical left line of the graph
+ gdImageLine(gdata.im, LeftMargin, BottomGraph, LeftMargin, TopMargin, gdata.black);
+ // horizontal bottom line of the graph
+ gdImageLine(gdata.im, LeftMargin, BottomGraph, RightGraph, BottomGraph, gdata.black);
+ // vertical right line of the graph
+ gdImageLine(gdata.im, RightGraph, TopMargin, RightGraph, BottomGraph, gdata.black);
+ // diagonal line to close the right of the bottom depth
+ gdImageLine(gdata.im, RightGraph-10, BottomGraph+5, RightGraph, BottomGraph, gdata.black);
+
+ // Y axis ticks
+ for(x=BottomGraph-10; x>=TopMargin; x=x-10) {
+ gdImageLine(gdata.im, LeftMargin-10, x+5, LeftMargin, x, gdata.dimgray);
+ gdImageLine(gdata.im, LeftMargin-10-TickLength, x+5, LeftMargin-10, x+5, gdata.dimgray);
+ }
+
+ // horizontal background lines
+ for(x=TopMargin; x<=BottomGraph-10; x=x+10)
+ gdImageLine(gdata.im, LeftMargin, x, RightGraph, x, gdata.dimgray);
+
+ // X axis ticks and labels
+ x=LeftMargin-10+20;
+ for(y=1; y<=31; y++) {
+ gdImageLine(gdata.im, x, BottomGraph+5, x, BottomGraph+5+TickLength, gdata.dimgray);
+ sprintf(s,"%02d",y);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,x,BottomGraph+5+TickLength+1,s,TRP_TopCenter);
+ x=x+20;
+ }
+
+ t = time(NULL);
+ local = localtime(&t);
+ if(strcmp(DateFormat,"u") == 0)
+ strftime(ftime, sizeof(ftime), "%b/%d/%Y %H:%M", local);
+ if(strcmp(DateFormat,"e") == 0)
+ strftime(ftime, sizeof(ftime), "%d/%b/%Y-%H:%M", local);
+
+ Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,7,0.0,ImgXSize-10,ImgYSize-10,ftime,TRP_BottomRight);
+ if(ShowSargInfo) Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10,0.0,300,15,_("SARG, "),TRP_BottomRight);
+ Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10,0.0,300,15,Title,TRP_BottomLeft);
+ sprintf(warea,_("Period: %s"),period.text);
+ Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,300,27,warea,TRP_BottomLeft);
+ sprintf(warea,_("User: %s"),uinfo->label);
+ Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,300,38,warea,TRP_BottomLeft);
+
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-10+5,"50K",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-20+5,"250K",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-30+5,"500K",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-40+5,"1M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-50+5,"2M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-60+5,"3M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-70+5,"4M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-80+5,"5M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-90+5,"6M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-100+5,"7M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-110+5,"8M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-120+5,"9M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-130+5,"10M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-140+5,"15M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-150+5,"20M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-160+5,"30M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-170+5,"40M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-180+5,"50M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-190+5,"60M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-200+5,"70M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-210+5,"80M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-220+5,"90M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-230+5,"100M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-240+5,"200M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-250+5,"300M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-260+5,"400M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-270+5,"500M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-280+5,"600M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-290+5,"700M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-300+5,"800M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-310+5,"900M",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-320+5,"1G",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-330+5,"2G",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-340+5,"3G",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-350+5,"4G",TRP_CenterRight);
+ Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,LeftMargin-10-TickLength,BottomGraph-360+5,"5G",TRP_CenterRight);
+ if(strcmp(datetimeby,"bytes") == 0)
+ Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,3.141592/2,20,ImgYSize/2,_("BYTES"),TRP_CenterLeft);
+ else
+ Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,3.141592/2,20,ImgYSize/2,_("ELAPSED TIME"),TRP_CenterLeft);
+ Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,0.0,ImgXSize/2,ImgYSize-20,_("DAYS"),TRP_BottomCenter);
- if(tot) {
- x1 = 44 +(day * 20);
- bar(x1,tot);
+ for (day=0 ; day<31 ; day++) {
+ if (datapoints[day]>0) {
+ x1 = 44 +((day+1) * 20);
+ bar(&gdata,x1,datapoints[day]);
+ }
}
- gdImagePng(im, pngout);
+ if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",outdirname,uinfo->filename)>=sizeof(graph)) {
+ debuga(_("user name too long for %s/%s/graph_day.png\n"),outdirname,uinfo->filename);
+ exit(EXIT_FAILURE);
+ }
+ if((pngout=fopen(graph,"wb"))==NULL) {
+ debuga(_("(grepday) Cannot open log file %s\n"),graph);
+ exit(EXIT_FAILURE);
+ }
+ gdImagePng(gdata.im, pngout);
fclose(pngout);
- gdImageDestroy(im);
+ gdImageDestroy(gdata.im);
- fclose(fp_in);
- unlink(wdirname);
- unlink(tmp5);
+ if (gdata.string) free(gdata.string);
+#ifdef USE_ICONV
+ if (gdata.localtoutf!=(iconv_t)-1)
+ iconv_close (gdata.localtoutf);
+#endif
#endif //HAVE_GD