home *** CD-ROM | disk | FTP | other *** search
- #define PROGNAME "Last10Callers"
-
-
- #include "bbs:bgcheck/bgcheck.h"
- #include "bbs:bgcheck/express.h"
- #include "env:timedate.h"
-
-
- static const char VersionTag[] = "\0$VER: "PROGNAME" "REVISION" ("REVDATE")";
-
- struct Callers
- {
- int Node;
- char logintime[10],
- logindate[10],
- logofftime[10],
- logoffdate[10],
- datetoday[10],
- Handle[32],
- Location[32];
- long days,
- hours,
- minutes,
- connect;
- ULONG upbytes,
- downbytes,
- upfiles,
- downfiles,
- todaybytes,
- todayfiles;
- BOOL losscarrier,
- upfailed,
- downfailed,
- hack,
- paged,
- newuser,
- locallogin;
- char space[48];
- };
-
- struct Top
- {
- char day[10];
- ULONG upbytestoday,
- upfilestoday,
- downbytestoday,
- downfilestoday,
- upbytesyest,
- upfilesyest,
- downbytesyest,
- downfilesyest,
- topupfiles,
- topupbytes,
- topdownfiles,
- topdownbytes,
- callers,
- callersyest,
- callerstop,
- minstoday,
- hourstoday,
- minsyest,
- hoursyest,
- topmins,
- tophours;
- };
-
- void main( int argc, char *argv[] )
- {
- BOOL losscarrier=FALSE,
- hack=FALSE,paged=FALSE,newuser=FALSE,locallogin=FALSE,
- nolocal=FALSE,nosysop=FALSE,nodefound=FALSE,out=FALSE,notadding=FALSE,
- logofft=FALSE,notop=FALSE;
- char buffer[255],buffer2[255],*p=NULL,**filenames=NULL,logintime[15]="",
- logindate[15]="",logofftime[15]="",logoffdate[15]="",
- lc='-',uf='-',df='-',ha='-',pa='-',new='-',
- connectstr[10]="",outfile[100]="",programdir[100]="",
- downstring[20]="",upstring[20]="";
- BPTR fh=NULL,lock=0,writefh=NULL;
- long position=0,upfiles=0,downfiles=0,connect=0,pos=0,
- downfailed=0,upfailed=0,usernumber=0,size=0,days=0,hours=0,minutes=0;
- ULONG upbytes=0,downbytes=0;
- struct User *user=NULL;
- struct DateTime *time=NULL,*time2=NULL;
- struct DateStamp *loginstmp=NULL,*logoffstmp=NULL;
- int nodenr=0,listnumber=10;
- struct Callers *caller=NULL,*caller2=NULL;
- struct Top *top=NULL;
-
- if (argc==1 || strcmp(argv[1],"?")==0 )
- {
- printf("LastCallers ©1996 by Joe Cool\n");
- printf("`-> Usage: LastCallers <Nodenumber> [options]\n");
- printf("Options:\n");
- printf("NOLOCAL Don`t add Local Calls to LastCallers\n");
- printf("NOSYSOP Don`t add Sysop Calls to Lastcallers\n");
- printf("Node <nr> Nodenumber\n");
- printf("Number <nr> Number of LastCallers\n");
- printf("Bull <path+filename> Output the Data to file\n");
- exit(0);
- }
-
- top=(struct Top *)AllocMem(sizeof(struct Top),MEMF_PUBLIC|MEMF_CLEAR);
- user=(struct User *) AllocMem(sizeof (struct User),MEMF_PUBLIC|MEMF_CLEAR);
- caller=(struct Callers *) AllocMem(sizeof (struct Callers),MEMF_PUBLIC|MEMF_CLEAR);
- caller2=(struct Callers *) AllocMem(sizeof (struct Callers),MEMF_PUBLIC|MEMF_CLEAR);
- exit(0);
- for(pos=1;pos<argc;pos++)
- {
- strcpy(buffer,argv[pos]);
- upperstring(buffer);
- if (strcmp(buffer,"NOLOCAL")==0) nolocal=TRUE;
- if (strcmp(buffer,"NOSYSOP")==0) nosysop=TRUE;
- if (strcmp(buffer,"NODE")==0)
- {
- if (argc>pos+1)
- {
- nodenr=atoi(argv[pos+1]);
- nodefound=TRUE;
- }
- }
- if (strcmp(buffer,"NUMBER")==0)
- {
- if (argc>pos+1)
- {
- listnumber=atoi(argv[pos+1]);
- if (!listnumber) listnumber=10;
- }
- }
- if (strcmp(buffer,"BULL")==0)
- {
- if (argc>pos+1)
- {
- strcpy(outfile,argv[pos+1]);
- out=TRUE;
- }
- }
- }
-
- if (!nodefound) exit(0);
-
-
- lock=GetProgramDir();
- if (lock)
- {
- NameFromLock(lock,programdir,100);
- UnLock(lock);
- }
-
- sprintf(buffer,"bbs:node%d/Callerslog",nodenr);
- fh=Open(buffer,MODE_OLDFILE);
- if (!fh) exit(0);
-
- position=Seek(fh,-15000,OFFSET_END);
-
- while(FGets(fh,buffer,254))
- {
- if (strncmp(buffer,"**********",10)==0)
- {
- position=Seek(fh,0,OFFSET_CURRENT);
- }
- }
-
- Seek(fh,position,OFFSET_BEGINNING);
- while(FGets(fh,buffer,254))
- {
- if (buffer[2]=='-' && buffer[5]=='-' && buffer[8]==' ' && buffer[9]=='(' && buffer[12]==':' && buffer[15]==':' && buffer[18]==')')
- {
- if (logintime[0]=='\0')
- {
- strncpy(logintime,buffer+10,8);
- logintime[8]='\0';
- strncpy(logindate,buffer,8);
- logindate[8]='\0';
- }
- else
- {
- logofft=TRUE;
- strncpy(logofftime,buffer+10,8);
- logofftime[8]='\0';
- strncpy(logoffdate,buffer,8);
- logoffdate[8]='\0';
- }
- }
-
- if (!connect)
- {
- strcpy(buffer2,buffer);
- upperstring(buffer2);
- p=strstr(buffer2,"CONNECT");
- if (p)
- {
- p+=8;
- connect=atoi(p);
- locallogin=FALSE;
- }
- p=strstr(buffer2,"(SYSOP_LO");
- if (p)
- {
- connect=1;
- locallogin=TRUE;
- }
- p=strstr(buffer2,"(F2_LOCAL");
- if (p)
- {
- connect=1;
- locallogin=TRUE;
- }
- }
- if (!usernumber)
- {
- if (strlen(buffer) >23)
- {
- if (buffer[2]=='-' & buffer[5]=='-' && buffer[9]=='(' && buffer[12]==':' && buffer[15]==':' && buffer[18]==')')
- {
- if (buffer[20]=='[')
- {
- usernumber=atoi(buffer+21);
- }
- if (buffer[20]=='N' && buffer[21]=='E' && buffer[22]=='W')
- {
- usernumber=atoi(buffer+25);
- newuser=TRUE;
- }
- }
- }
- }
-
-
-
- if (strstr(buffer,"Uploading") && strstr(buffer,"bytes"))
- {
- p=strstr(buffer,"Uploading");
- for (pos=10;p[pos]!=' ';pos++);
- upbytes+=atoi(p+pos+1);
- upfiles++;
- upfailed=FALSE;
- }
- if (strstr(buffer,"Downloading") && strstr(buffer,"bytes"))
- {
- p=strstr(buffer,"Downloading");
- for (pos=12;p[pos]!=' ';pos++);
- downbytes+=atoi(p+pos+1);
- downfiles++;
- downfailed=FALSE;
- }
- if (strstr(buffer,"Download Failed")) downfailed=TRUE;
- if (strstr(buffer,"Upload Failed")) upfailed=TRUE;
- if (strstr(buffer,"Off Loss Carrier")) losscarrier=TRUE;
- if (strstr(buffer,"Password Failure")) hack=TRUE;
- if (strstr(buffer,"Operator Paged")) paged=TRUE;
- }
-
- if (fh) Close(fh);
- if (nolocal && locallogin) notadding=TRUE;
- if (nosysop && usernumber==1) notadding=TRUE;
-
- if (!notadding)
- {
-
- fh=Open("bbs:user.data",MODE_OLDFILE);
- Seek(fh,(usernumber-1)*sizeof(struct User),OFFSET_BEGINNING);
- Read(fh,user,sizeof(struct User));
- Close(fh);
-
- if (logofft &&logofftime[0]!=0 && logoffdate[0]!=0 && logintime[0]!=0 && logindate[0]!=0)
- {
- time=(struct DateTime *) malloc (sizeof(struct DateTime));
- time2=(struct DateTime *) malloc (sizeof(struct DateTime));
-
- time->dat_Format=FORMAT_USA;
- time->dat_Flags=DTF_SUBST;
- time->dat_StrDay=NULL;
- time->dat_StrDate=logindate;
- time->dat_StrTime=logintime;
-
- StrToDate(time);
-
- time2->dat_Format=FORMAT_USA;
- time2->dat_Flags=DTF_SUBST;
- time2->dat_StrDay=NULL;
- time2->dat_StrDate=logoffdate;
- time2->dat_StrTime=logofftime;
-
- StrToDate(time2);
-
- loginstmp=&time->dat_Stamp;
- logoffstmp=&time2->dat_Stamp;
-
- days=logoffstmp->ds_Days-loginstmp->ds_Days;
- minutes=logoffstmp->ds_Minute-loginstmp->ds_Minute;
- if (!minutes) minutes=1;
- if (minutes<0)
- {
- minutes+=(24*60);
- days--;
- }
-
-
- if (minutes>60)
- {
- hours=minutes/60;
- minutes=minutes%60;
- }
-
- free(time);
- free(time2);
- }
- else
- {
- days=0;
- hours=0;
- minutes=0;
- }
-
- caller->Node=nodenr;
- caller->connect=connect;
- strcpy(caller->Handle,user->Name);
- strcpy(caller->Location,user->Location);
- caller->upfiles=upfiles;
- caller->upbytes=upbytes;
- caller->downfiles=downfiles;
- caller->downbytes=downbytes;
- caller->losscarrier=losscarrier;
- caller->upfailed=upfailed;
- caller->downfailed=downfailed;
- caller->hack=hack;
- caller->paged=paged;
- caller->newuser=newuser;
- strcpy(caller->logintime,logintime);
- strcpy(caller->logindate,logindate);
- strcpy(caller->logofftime,logofftime);
- strcpy(caller->logoffdate,logoffdate);
- caller->days=days;
- caller->hours=hours;
- caller->minutes=minutes;
- caller->locallogin=locallogin;
-
-
- sprintf(buffer,"%s/lastcallers.data",programdir);
- fh=Open(buffer,MODE_READWRITE);
- if (!fh) fh=Open(buffer,MODE_NEWFILE);
- if (!fh) exit(0);
- if (fh)
- {
- Seek(fh,0,OFFSET_END);
- size=Seek(fh,0,OFFSET_CURRENT);
-
- if ((size/sizeof(struct Callers))<listnumber)
- {
- if ((size/sizeof(struct Callers))<1)
- {
- Write(fh,caller,sizeof(struct Callers));
- }
- else
- {
- Seek(fh,0,OFFSET_END);
- Write(fh,caller,sizeof(struct Callers));
- for (pos=0;pos<(size/sizeof(struct Callers));pos++)
- {
- Seek(fh,(-1)*(pos+2)*sizeof(struct Callers),OFFSET_END);
- Read(fh,caller2,sizeof(struct Callers));
- Seek(fh,(-1)*(pos+1)*sizeof(struct Callers),OFFSET_END);
- Write(fh,caller2,sizeof(struct Callers));
- }
- Seek(fh,0,OFFSET_BEGINNING);
- Write(fh,caller,sizeof(struct Callers));
- }
- }
- else
- {
- for (pos=0;pos<(size/sizeof(struct Callers));pos++)
- {
- Seek(fh,(-1)*(pos+2)*sizeof(struct Callers),OFFSET_END);
- Read(fh,caller2,sizeof(struct Callers));
- Seek(fh,(-1)*(pos+1)*sizeof(struct Callers),OFFSET_END);
- Write(fh,caller2,sizeof(struct Callers));
- }
- Seek(fh,0,OFFSET_BEGINNING);
- Write(fh,caller,sizeof(struct Callers));
- }
- if (fh) Close(fh);
- }
- }
-
- sprintf(buffer,"%s/lastcallers.top",programdir);
- fh=Open(buffer,MODE_READWRITE);
- pos=0;
- while (!fh && pos<60)
- {
- pos++;
- fh=Open(buffer,MODE_READWRITE);
- if (!fh) Delay(30);
- }
- if (!Read(fh,top,sizeof(struct Top))) notop=TRUE;
-
- if (notop)
- {
- strcpy(top->day,logoffdate);
- top->upbytestoday=0;
- top->upfilestoday=0;
- top->downbytestoday=0;
- top->downfilestoday=0;
- top->upbytesyest=0;
- top->upfilesyest=0;
- top->downbytesyest=0;
- top->downfilesyest=0;
- top->topupfiles=0;
- top->topupbytes=0;
- top->topdownfiles=0;
- top->topdownbytes=0;
- top->callers=0;
- top->callersyest=0;
- top->callerstop=0;
- top->minstoday=0;
- top->hourstoday=0;
- top->minsyest=0;
- top->hoursyest=0;
- top->topmins=0;
- top->tophours=0;
- }
- if (0==strcmp(top->day,logoffdate))
- {
- if (!notadding)
- {
- top->upbytestoday+=upbytes;
- top->upfilestoday+=upfiles;
- top->downbytestoday+=downbytes;
- top->downfilestoday+=downfiles;
- top->callers++;
- top->minstoday+=(top->hourstoday)*60;
- top->minstoday+=minutes+(60*hours);
- top->hourstoday=top->minstoday/60;
- top->minstoday=top->minstoday%60;
- }
-
- if (top->upbytestoday>top->topupbytes) top->topupbytes=top->upbytestoday;
- if (top->upfilestoday>top->topupfiles) top->topupfiles=top->upfilestoday;
- if (top->downbytestoday>top->topdownbytes) top->topdownbytes=top->downbytestoday;
- if (top->downfilestoday>top->topdownfiles) top->topdownfiles=top->downfilestoday;
- if (top->callerstop<top->callers) top->callerstop=top->callers;
- if ((((top->tophours)*60)+top->topmins)<((top->hourstoday*60)+top->minstoday))
- {
- top->tophours=top->hourstoday;
- top->topmins=top->minstoday;
- }
- }
- else
- {
- top->upbytesyest=top->upbytestoday;
- top->upfilesyest=top->upfilestoday;
- top->downbytesyest=top->downbytestoday;
- top->downfilesyest=top->downfilestoday;
- top->callersyest=top->callers;
- top->minsyest=top->minstoday;
- top->hoursyest=top->hourstoday;
-
- top->upbytestoday=upbytes;
- top->upfilestoday=upfiles;
- top->downbytestoday=downbytes;
- top->downfilestoday=downfiles;
- top->minstoday=minutes;
- top->hourstoday=hours;
-
- strcpy(top->day,caller->logoffdate);
- top->callers=1;
- }
- Seek(fh,0,OFFSET_BEGINNING);
- Write(fh,top,sizeof(struct Top));
- Close(fh);
-
- if (out)
- {
- writefh=NULL;
- fh=NULL;
-
- sprintf(buffer,"%s/lastcallers.data",programdir);
- fh=Open(buffer,MODE_READWRITE);
- if (fh)
- {
- writefh=Open(outfile,MODE_NEWFILE);
- if (!writefh)
- {
- Close(fh);
- exit(0);
- }
- FPuts(writefh,"c\n");
- FPuts(writefh,"================.=====.========================.============.================\n");
- FPuts(writefh,"___ _j\\_________|\\ /|______ ____ _________/| ___ _______)\\ ______ .___\n");
- FPuts(writefh,"7 7 7 . 7 _(__ __) (__ __)__) 7 : __) . 7 : 7 7 7 __) _ ) ___7 | 7\n");
- FPuts(writefh,": l_j ` :._ 7 7 7 7 7| _)j l | | (__l ` : l_l l_| _)j \\____ | l__:\n");
- FPuts(writefh,"l___)_;_j___j l_j l_jl___)_j_j l___ )_!_j___)___)___)__\\__) ___j l__j\n");
- FPuts(writefh,".----------------------------Y---------|/--------Y-------------\\(------------.\n");
- FPuts(writefh,"[BD][N][USERNAME] [LOCATION] ` [LOGON][OT][FLAGS] [UL-KB][DL-KB]\n");
-
- while(Read(fh,caller,sizeof(struct Callers)))
- {
- lc='-';uf='-';df='-';ha='-';pa='-';new=' ';
- if (caller->losscarrier) lc='C';
- if (caller->upfailed) uf='u';
- if (caller->downfailed) df='d';
- if (caller->hack) ha='H';
- if (caller->paged) pa='O';
- if (caller->newuser) new='*';
- if ((!caller->upfailed) && (caller->upfiles)) uf='U';
- if ((!caller->downfailed)&&(caller->downfiles)) df='D';
- if (caller->locallogin) strcpy(connectstr,"locl");
- else sprintf(connectstr,"%4.1f",(float)(caller->connect/1000.0));
-
- if (caller->upbytes) sprintf(upstring,"%db",caller->upbytes);
- else strcpy(upstring,"");
-
- if (caller->upbytes>1024)
- {
- sprintf(upstring,"%3dk",caller->upbytes/1024);
- caller->upbytes/=1024;
- }
- if (caller->upbytes>1024)
- {
- sprintf(upstring,"%-3.1fm",caller->upbytes/1024.0);
- caller->upbytes/=1024;
- }
-
- if (caller->downbytes) sprintf(downstring,"%db",caller->downbytes);
- else strcpy(downstring,"");
-
- if (caller->downbytes>1024)
- {
- sprintf(downstring,"%3dk",caller->downbytes/1024);
- caller->downbytes/=1024;
- }
- if (caller->downbytes>1024)
- {
- sprintf(downstring,"%-3.1fm",caller->downbytes/1024.0);
- caller->downbytes/=1024;
- }
-
-
- sprintf(buffer,"%4.4s %d%c%-18.18s %-18.18s %5.5s%2d:%2.2d[%c%c%c%c%c] %6.6s %6.6s\n",connectstr,caller->Node,new,caller->Handle,caller->Location,caller->logintime,caller->hours,caller->minutes,lc,uf,df,ha,pa,upstring,downstring);
- FPuts(writefh,buffer);
-
-
- }
- if (writefh)
- {
- FPuts(writefh,"------------------------------------------------CALLERS-O-RADO by jOE cOOL---'\n");
- sprintf(buffer," today Call: %4d up: %4d/%4dmB down: %4d/%4dmb time:%3d:%2.2d\n",top->callers,top->upfilestoday,top->upbytestoday/1024/1024,top->downfilestoday,top->downbytestoday/1024/1024,top->hourstoday,top->minstoday);
- FPuts(writefh,buffer);
- sprintf(buffer," yesterday Call: %4d up: %4d/%4dmB down: %4d/%4dmb time:%3d:%2.2d\n",top->callersyest,top->upfilesyest,top->upbytesyest/1024/1024,top->downfilesyest,top->downbytesyest/1024/1024,top->hoursyest,top->minsyest);
- FPuts(writefh,buffer);
- sprintf(buffer," top Call: %4d up: %4d/%4dmB down: %4d/%4dmb time:%3d:%2.2d\n",top->callerstop,top->topupfiles,top->topupbytes/1024/1024,top->topdownfiles,top->topdownbytes/1024/1024,top->tophours,top->topmins);
- FPuts(writefh,buffer);
- FPuts(writefh,"`----------------------------------------------------------------------------'\n\n");
- Close(writefh);
-
- }
- printf("Close\n");
- Close(fh);
- }
-
- }
-
- FreeMem(user,sizeof(struct User));
- FreeMem(caller,sizeof(struct Callers));
- FreeMem(caller2,sizeof(struct Callers));
- FreeMem(top,sizeof(struct Top));
- }