- FILE *fp_in, *pngout;
- int x, y;
- int x1;
- int brect[8];
- char wdirname[MAXLEN];
- char graph[MAXLEN];
- char buf[MAXLEN];
- char wuser[255];
- char csort[255];
- char data[20];
- int count=0;
- int oday=0;
- int day=0;
- long long int llday;
- long long int bytes;
- char ftime[128];
- long long int tot=0;
- time_t t;
- struct tm *local;
- int cstatus;
- char s[15];
- struct getwordstruct gwarea;
- struct getwordstruct gwarea1;
-
- if(!Graphs) {
- unlink(wdirname);
- return;
- }
-
- 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);
- }
-
- 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,font1,7,0.0,y,437,s);
- y=y+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);
-
- if(dotinuser && strchr(name,'_')) {
- subs(name,sizeof(name),"_",".");
- }
-
- SARGgdImageStringFT(im,&brect[0],darkblue,font1,7,0.0,620,470,ftime);
- if(ShowSargInfo) SARGgdImageStringFT(im,&brect[0],darkblue,font1,10,0.0,257,15,"SARG, ");
- SARGgdImageStringFT(im,&brect[0],darkblue,font1,10,0.0,300,15,Title);
- sprintf(warea,"%s: %s",text[89],period);
- SARGgdImageStringFT(im,&brect[0],darkblue,font1,9,0.0,300,27,warea);
- sprintf(warea,"%s: %s",text[90],name);
- SARGgdImageStringFT(im,&brect[0],darkblue,font1,9,0.0,300,38,warea);
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,418," 50K");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,408,"250K");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,398,"500K");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,388," 1M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,378," 2M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,368," 3M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,358," 4M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,348," 5M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,338," 6M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,328," 7M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,318," 8M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,308," 9M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,298," 10M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,288," 15M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,278," 20M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,268," 30M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,258," 40M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,248," 50M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,238," 60M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,228," 70M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,218," 80M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,208," 90M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,198,"100M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,188,"200M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,178,"300M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,168,"400M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,158,"500M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,148,"600M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,138,"700M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,128,"800M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,118,"900M");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23,108," 1G");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 98," 2G");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 88," 3G");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 78," 4G");
- SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 68," 5G");
- if(strcmp(datetimeby,"bytes") == 0)
- SARGgdImageStringFT(im,&brect[0],black,font1,10,3.14/2,20,248,text[93]);
- else
- SARGgdImageStringFT(im,&brect[0],black,font1,10,3.14/2,20,248,text[94]);
- SARGgdImageStringFT(im,&brect[0],black,font1,10,0.0,330,460,text[127]);
-
- if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,user)>=sizeof(graph)) {
- fprintf(stderr, "SARG: user name too long for: %s/%s/graph_day.png\n",dirname,user);
- exit(1);
- }
- if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,user)>=sizeof(wdirname)) {
- fprintf(stderr, "SARG: user name too long for: %s/%s.day\n",tmp,user);
- exit(1);
- }
- if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,user)>=sizeof(tmp5)) {
- fprintf(stderr, "SARG: user name too long for: %s/%s.graph\n",tmp,user);
- exit(1);
- }
-
- 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
- sprintf(csort,"sort -t\"/\" -k 2,2 -o \"%s\" \"%s\"",tmp5,wdirname);
-
- cstatus=system(csort);
- if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
- fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
- fprintf(stderr, "SARG: sort command: %s\n",csort);
- exit(1);
- }
-
- if((fp_in=fopen(tmp5,"r"))==NULL) {
- fprintf(stderr, "SARG: (grepday) %s: %s\n",text[8],tmp5);
- exit(1);
- }
-
- if((pngout=fopen(graph,"wb"))==NULL) {
- fprintf(stderr, "SARG: (grepday) %s: %s\n",text[8],graph);
- exit(1);
- }
-
- strcpy(wuser,user);
- if(strstr(wuser,"_") != 0)
- fixip(wuser);
-
- if(Ip2Name)
- if((str=(char *) strstr(name, ".")) != (char *) NULL) {
- if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
- ip2name(wuser,sizeof(wuser));
- }
-
- user_find(name, sizeof(name), wuser);
-
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- fixendofline(buf);
- getword_start(&gwarea,buf);
- if (getword(data,sizeof(data),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
- exit(1);
- }
- getword_start(&gwarea1,data);
- if (getword_atoll(&llday,&gwarea1,'/')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
- exit(1);
- }
- if(strcmp(DateFormat,"u") == 0) {
- if (getword_atoll(&llday,&gwarea1,'/')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
- exit(1);
- }
- }
- day=(int)llday;
- if(!count) {
- oday=day;
- count++;
- }
- if (getword_skip(20,&gwarea,'\t')<0 || getword_atoll(&bytes,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp5);
- exit(1);
- }
-
- if(oday!=day) {
- x1 = 44 +(oday * 20);
- bar(x1,tot);
- oday=day;
- tot=0;
- }
- tot+=bytes;
- }
-
- if(tot) {
- x1 = 44 +(day * 20);
- bar(x1,tot);
- }
-
- gdImagePng(im, pngout);
- fclose(pngout);
- gdImageDestroy(im);
-
- fclose(fp_in);
- unlink(wdirname);
- unlink(tmp5);