home *** CD-ROM | disk | FTP | other *** search
- /* XLOG -- Quick-and-nasty local logon utility for XBBS */
- /* Copyright (c) 1989 by M. Kimes -- All Rights Reserved */
-
- #include "msgg.h"
-
- void pascal readconfig (void);
- void pascal prepare (void);
- void pascal userinfo(void);
- void pascal left(char *a,char *b,int x);
- char * pascal rstrip (char *a);
- char * pascal lstrip (char *a);
- ulong pascal getxbbstime(void);
- char * pascal saydate(struct date *);
- char * pascal saytime(struct time *);
- char * pascal fidodate(void);
- char * pascal split (char *,char *);
- char * pascal addtolog(char *);
-
- word baud=0;
- word timelimit=60;
- struct time starter;
- struct time timeon;
- word userno=1;
- struct _user user;
- char variable[10][82];
- char pages=0;
- struct _mboard mboard;
- struct _fboard fboard;
- char age;
- char timer_off=0;
- word hold_time=0;
- struct _config conf;
- char nodenumber=1;
- struct _events event[10];
-
- void cdecl main (int argc,char *argv[]) {
-
- struct ffblk f;
- FILE *fp;
- int handle;
- word timetoevent;
- register word x;
- struct date tempdate;
- struct date dos_date;
- char text[81];
- register word xx;
- char *p;
- char *buffer;
-
- printf("\x1b[0;1;37m\nXLOG copyright (c) 1989 by M. Kimes\n");
- printf("\x1b[0mUsage: XLOG <user#/user_name> <baud> <timetoevent> <nodenumber> <other args>\n");
-
- if(findfirst(searchpath("users.bbs"),&f,0)) {
- printf("\nYou don't have a userfile.\n");
- exit(253);
- }
- timetoevent = 24 * 59;
-
- if (argc>=2) {
- userno=0;
- if (strchr(argv[1],'_')==NULL) userno=(word)atol(argv[1]);
- else {
- p=strchr(strupr(argv[1]),'_');
- *p=' ';
- printf("\nSearching for %s...",argv[1]);
- xx=0;
- if (f.ff_fsize) {
- if ((handle=_open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- printf("\nError opening userfile\n");
- perror("\nERROR");
- exit(254);
- }
- fp=fdopen(handle,"rb");
- }
- buffer=(char *)malloc(sizeof(struct _user)*25);
- if(!buffer) {
- printf("\nOut of memory!\n");
- exit(255);
- }
- setvbuf(fp,buffer,_IOFBF,(unsigned int)(sizeof(struct _user)*25));
- rewind(fp);
- while (!feof(fp) && !ferror(fp)) {
- xx++;
- if (!(xx%50)) printf(".");
- if (fread(&user,sizeof(user),1,fp)!=1) break;
- strupr(user.name);
- strupr(user.handle);
- if (!(strcmp(user.name,argv[1])) && (!user.deleted)) break;
- if (!(strcmp(user.handle,argv[1])) && (!user.deleted)) break;
- }
- if (ferror(fp)) perror("\nERROR");
- if (((strcmp(user.name,argv[1])) && (strcmp(user.handle,argv[1]))) || (user.deleted)) goto notfound;
- if (!user.stat[0]) {
- fclose(fp);
- _close(handle);
- printf("\nUser locked out\n");
- exit(254);
- }
- userno=(word)(ftell(fp)/(long)sizeof(struct _user));
- fclose(fp);
- _close(handle);
- if(buffer)free(buffer);
- printf("\n%cUser # %d\n",4,userno);
- }
- if (!userno) {
- notfound:
- fclose(fp);
- _close(handle);
- printf("\nUser not found.\n");
- exit(253);
- }
- }
- if (argc >= 3) baud = (word)atol(argv[2]);
- if (argc >= 4) timetoevent=(word)atoi(argv[3]);
- if (argc >= 5) nodenumber=(char)atoi(argv[4]);
- if (argc>6) for (x=0;x<(argc-6);x++) strcpy(variable[x],argv[x]);
- gettime(&timeon);
- gettime(&starter);
- timelimit=timetoevent;
-
-
- if ((word)(f.ff_fsize/(long)sizeof(struct _user))<userno) {
- printf("\nRequested user #%u not available.\n",userno);
- exit(254);
- }
- if ((handle=_open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
- printf("\nError opening userfile\n");
- perror("\nERROR");
- exit(254);
- }
- fp=fdopen(handle,"rb");
- if (fseek(fp,(long)((long)(userno-1)*(long)sizeof(struct _user)),SEEK_SET)!=0) {
- printf("\nError seeking user #%u\n",userno);
- perror("\nERROR");
- fclose(fp);
- _close(handle);
- exit(254);
- }
- if (fread(&user,sizeof(user),1,fp)!=1) {
- printf("\nError reading userfile\n");
- perror("\nERROR");
- fclose(fp);
- _close(handle);
- exit(254);
- }
- fclose(fp);
- _close(handle);
-
- for (x=0;x<10;x++) event[x].secsleft=0;
- readconfig();
- mboard=conf.mboard;
- fboard=conf.fboard;
-
- if ((user.stat[0])==0) {
- printf("\nUser is locked out\n");
- exit (254);
- }
- getdate(&tempdate);
- if ((tempdate.da_mon!=user.lastdate.da_mon) or (tempdate.da_day!=user.lastdate.da_day)) {
- user.callstoday=0;
- user.timetoday=0;
- user.uktoday=0;
- user.dktoday=0;
- }
- if (user.callsperday!=0) {
- if (user.callstoday>=user.callsperday) {
- printf("\nUser has exceeded number of calls today\n");
- exit(254);
- }
- }
- else {
- if (user.timetoday >= user.totaltime) {
- printf("\nUser has exceeded time limit for today\n");
- exit(254);
- }
- }
- if (user.callsperday != 0) timelimit=user.timepercall;
- else timelimit=(user.totaltime-user.timetoday);
-
- printf("\nCreating XBBS files for %s (%s)\n",user.name,user.handle);
-
- getdate(&user.logondate);
- gettime(&user.logontime);
- if (timetoevent<(timelimit)) {
- printf("\nA system event is scheduled in %u minutes",timetoevent-1);
- timelimit=((timetoevent-1));
- }
- if ((baud>0) && (baud<conf.ansibaud)) user.graphics=0;
- getdate(&dos_date);
- age=((dos_date.da_year-user.birthdate.da_year)-1);
- if (dos_date.da_mon>user.birthdate.da_mon) age++;
- else if ((dos_date.da_mon==user.birthdate.da_mon) && (dos_date.da_day>=user.birthdate.da_day)) age++;
- getdate(&user.logondate);
- gettime(&user.logontime);
- userinfo();
- for (xx=0;xx<76;text[xx]='*',text[xx+1]=0,xx++);
- addtolog(text);
- sprintf(text,"Online: %s @ %u baud",user.name,baud);
- addtolog(text);
- exit(0);
- }
-
-
-
- void pascal readconfig (void) {
-
- FILE *fp;
- char s[15];
-
- if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
- else strcpy(s,"config.bbs");
-
- if(!(fp=fopen(s,"rb"))) {
- Fatal:
- printf("\nFatal Error\n");
- perror("\nCONFIG ERROR");
- exit(254);
- }
- if (fread(&conf,sizeof(conf),1,fp)!=1) goto Fatal;
- fclose(fp);
- }
-
-
-
- void pascal prepare (void) {
-
- FILE *fp;
- char s[90];
- char numnode[4]="";
-
- if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
- sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
- if(!(fp=fopen(s,"wb"))) perror("ONLINE OPEN");
- else {
- fwrite(&user,sizeof(struct _user),1,fp);
- fwrite(&userno,sizeof(userno),1,fp);
- fwrite(&timelimit,sizeof(timelimit),1,fp);
- fwrite(&timeon,sizeof(timeon),1,fp);
- fwrite(&starter,sizeof(starter),1,fp);
- fwrite(&baud,sizeof(baud),1,fp);
- fwrite(&pages,sizeof(pages),1,fp);
- fwrite(&age,sizeof(age),1,fp);
- fwrite(&timer_off,sizeof(timer_off),1,fp);
- fwrite(&hold_time,sizeof(hold_time),1,fp);
- fwrite(variable,sizeof(variable[0]),10,fp);
- fwrite(&mboard,sizeof(struct _mboard),1,fp);
- fwrite(&fboard,sizeof(struct _fboard),1,fp);
- fwrite(event,sizeof(struct _events),10,fp);
- if (ferror(fp)) perror("ONLINE WRITE");
- fclose(fp);
- }
- }
-
-
- void pascal userinfo (void) {
-
- FILE *fp,*pf;
- char temp[38],temp2[38];
- char *p=NULL;
- char nodes[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-
- if(!(fp=fopen("userinfo.xbs","w"))) {
- perror("USERINFO OPEN");
- goto Next;
- }
- fprintf(fp,"%s\n%u\n",user.handle,baud);
- fprintf(fp,"%s\n%s\n",saydate(&user.lastdate),saytime(&user.lasttime));
- fprintf(fp,"%s\n%s\n",saydate(&user.logondate),saytime(&user.logontime));
- fprintf(fp,"%lu\n%u\n%u\n%hu\n%u\n%hu\n",user.times,(user.graphics),(word)((long)timelimit-(getxbbstime()/60L)),pages,(word)user.credit,user.length);
- fclose(fp);
-
- Next:
-
- if(!(fp=fopen("door.sys","w"))) {
- perror("DOOR.SYS OPEN");
- goto Next2;
- }
- baud ? fprintf(fp,"COM%u\r\n",conf.commport+1) : fprintf(fp,"COM0\r\n");
- fprintf(fp,"%u\r\n8\r\n%hu\r\nN\r\nY\r\nN\r\n",baud,nodenumber);
- conf.sysopin ? fprintf(fp,"Y") : fprintf(fp,"N");
- fprintf(fp,"\r\nN\r\n%s\r\n%s, %s\r\n%s\r\n",user.handle,user.city,user.state,user.phone1);
- fprintf(fp,"%s\r\n%s\r\n%u\r\n%hu\r\n",user.phone2,user.password,user.stat[0],user.times);
- fprintf(fp,"%02hu/%02hu/%04u\r\n%lu\r\n%lu\r\n",user.lastdate.da_mon,user.lastdate.da_day,user.lastdate.da_year,((long)timelimit-(getxbbstime()/60L))*60L,((long)timelimit-(getxbbstime()/60L)));
- user.graphics ? fprintf(fp,"GR") : fprintf(fp,"NG");
- fprintf(fp,"\r\n%hu\r\n",user.length);
- user.expert ? fprintf(fp,"Y") : fprintf(fp,"N");
- fprintf(fp,"\r\nABCDEFG\r\n%u\r\n01/01/99\r\n%u\r\nZ\r\n",mboard.number,userno);
- fprintf(fp,"%lu\r\n%lu\r\n%u\r\n%u\r\n999999\r\n",user.upk,user.downk,user.dktoday);
- fclose(fp);
-
- Next2:
-
- sprintf(temp,"dorinfo%c.def",nodes[nodenumber%36]);
- unlink(temp);
- *temp='q';
- if(!(fp=fopen(temp,"wt"))) {
- perror("QORINFO? OPEN");
- goto Last;
- }
- *temp='r';
- if(!(pf=fopen(temp,"wt"))) {
- perror("RORINFO? OPEN");
- fclose(fp);
- *temp='q';
- unlink(temp);
- goto Last;
- }
- strcpy(temp,conf.sysop);
- p=split(temp,p);
- fprintf(fp,"%s\n%s\n%s",conf.system,temp,p);
- strupr(temp);
- strupr(p);
- fprintf(pf,"%s\n%s\n%s",conf.system,temp,p);
- if (!baud) {
- fprintf(fp,"\nCOM0\n");
- fprintf(pf,"\nCOM0\n");
- }
- else {
- fprintf(fp,"\nCOM%u\n",conf.commport+1);
- fprintf(pf,"\nCOM%u\n",conf.commport+1);
- }
- if (strchr(user.handle,' ')!=NULL) strcpy(temp,user.handle);
- else strcpy(temp,user.name);
- p=split(temp,p);
- fprintf(fp,"%u BAUD,N,8,1\n0\n%s\n%s\n%s, %s\n",baud,temp,p,user.city,user.state);
- strupr(temp);
- strupr(p);
- if(!baud) fprintf(pf,"9600 BAUD,N,8,1\n0\n%s\n%s\n%s, %s\n",temp,p,user.city,user.state);
- else fprintf(pf,"%u BAUD,N,8,1\n0\n%s\n%s\n%s, %s\n",baud,temp,p,user.city,user.state);
- if(user.graphics) fprintf(pf,"2\n");
- else if(user.hiok) fprintf(pf,"1\n");
- else fprintf(pf,"0\n");
- fprintf(fp,"%hu\n",user.graphics);
- fprintf(fp,"%u\n%u\n",user.stat[0],(word)((long)timelimit-(getxbbstime()/60L)));
- fprintf(pf,"%u\n%u\n",user.stat[0],(word)((long)timelimit-(getxbbstime()/60L)));
- fprintf(pf,"1\n");
- fclose(fp);
- fclose(pf);
- sprintf(temp,"dorinfo%c.def",nodes[nodenumber%36]);
- strcpy(temp2,temp);
- if(conf.RBBSorQBBS) *temp2='r';
- else *temp2='q';
- rename(temp2,temp);
-
- Last:
-
- prepare();
- }
-
-
-
-
- ulong pascal getxbbstime (void) {
-
- int hour;
- int min;
- int sec;
- struct time dos_time;
- char tempause;
- char d[24];
- static ulong xbbs_time;
-
- gettime(&dos_time);
- hour=dos_time.ti_hour-starter.ti_hour;
- min=dos_time.ti_min-starter.ti_min;
- sec=dos_time.ti_sec-starter.ti_sec;
- if (dos_time.ti_hour<starter.ti_hour) hour=hour+24;
- xbbs_time=(long)(hour*3600)+(min*60)+sec;
- return (xbbs_time);
- }
-
-
-
- char * pascal fidodate (void) {
-
- char months[12][4]={
- "Jan",
- "Feb",
- "Mar",
- "Apr",
- "May",
- "Jun",
- "Jul",
- "Aug",
- "Sep",
- "Oct",
- "Nov",
- "Dec"
- };
- static char fdate[20];
- struct date dos_date;
- struct time dos_time;
-
- /* 26 Jul 89 06:23:47 */
-
- getdate(&dos_date);
- gettime(&dos_time);
-
- sprintf(fdate,"%02hu %s %02d %02hu:%02hu:%02hu",dos_date.da_day,months[dos_date.da_mon-1],dos_date.da_year%100,dos_time.ti_hour,dos_time.ti_min,dos_time.ti_sec);
- return(fdate);
-
- }
-
-
-
- char * pascal saydate (struct date *a) {
-
- static char xdate[11];
-
- sprintf(xdate,"%02hu/%02hu/%04u",a->da_mon,a->da_day,a->da_year);
- return(xdate);
- }
-
-
-
- char * pascal saytime (struct time *a) {
-
- static char xtime[9];
-
- sprintf(xtime,"%02u:%02u:%02u",a->ti_hour,a->ti_min,a->ti_sec);
- return(xtime);
- }
-
-
-
-
- char * pascal split (char *a,char *b) {
-
- b=strchr(a,' ');
- b[0]=0;
- return(++b);
- }
-
-
-
-
- char * pascal rstrip (char *a) {
-
- register int x;
-
- x=strlen(a);
- while (x && a && a[x-1]==' ') a[--x]=0;
- return a;
- }
-
-
-
- char * pascal lstrip (char *a) {
-
- register int x;
-
- x=strlen(a);
- while (x && *a==' ') memmove (a,(a+1),x--);
- return (a);
- }
-
-
-
- char * pascal addtolog (char *text) { /* WRITE LOGFILE ENTRIES */
-
- int handle;
- char p[127];
-
- if ((handle=_open(conf.logfile,O_RDWR | O_APPEND | O_BINARY | O_DENYNONE))==-1)
- if ((handle=creat(conf.logfile,S_IWRITE))==-1) return text;
- lseek(handle,0,SEEK_END);
- if (text[0]!='*') {
- strcpy(p,fidodate());
- p[16]=0;
- strcat(p," ");
- strncat(p,text,126-strlen(p));
- p[126]=0;
- }
- else {
- strncpy(p,text,79);
- p[79]=0;
- }
- _write(handle,p,strlen(p));
- _write(handle,"\r\n",2);
- _close(handle);
- return text;
- }