home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
xdev_118.arj
/
XLOG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-28
|
13KB
|
494 lines
/* 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];
int cdecl main (int argc,char *argv[]) {
struct stat f;
FILE *fp;
int handle;
word timetoevent;
register word x;
struct date tempdate;
struct date dos_date;
char text[81],spin[] = "-\|/",*sp = spin;
register word xx;
char *p;
printf("\x1b[0;1;37m\nXLOG copyright (c) 1989/91 by M. Kimes\n");
printf("\x1b[0mUsage: XLOG <user#/user_name> <baud> <timetoevent> <nodenumber> <other args>\n");
if(stat(searchpath("users.bbs"),&f)) {
fprintf(stderr,"\n**You don't have a userfile.\n");
return(253);
}
timetoevent = 24 * 59;
if (argc >= 2) {
userno = 0;
if (strchr(argv[1],' ') == NULL && strchr(argv[1],'_') == NULL)
userno = atoi(argv[1]);
else {
p = strchr(strupr(argv[1]),'_');
*p = ' ';
printf("\n\04Searching for %s...",argv[1]);
xx = 0;
if (f.st_size) {
if ((handle = _open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE)) == -1) {
fprintf(stderr,"\n**Error opening userfile\n");
perror("\nERROR");
return(254);
}
}
fp = fdopen(handle,"rb");
setvbuf(fp,NULL,_IOFBF,sizeof(struct _user) * 33);
rewind(fp);
printf("%c\b",*sp++);
while (!feof(fp)) {
xx++;
if(!(xx % 25)) {
printf("%c\b",*sp++);
if(!*sp) sp = spin;
}
if(fread(&user,sizeof(user),1,fp) != 1) break;
if(user.deleted) continue;
if(!stricmp(user.name,argv[1]) || !stricmp(user.handle,argv[1])) break;
}
printf(" \b");
if((stricmp(user.name,argv[1]) && stricmp(user.handle,argv[1])) ||
user.deleted) goto NotFound;
if (!user.stat[0]) {
fclose(fp);
fprintf(stderr,"\n**User locked out\n");
return(254);
}
userno = (word)(ftell(fp) / (long)sizeof(struct _user));
fclose(fp);
_close(handle);
printf("\n\04User #%d\n",userno);
}
if (!userno) {
NotFound:
fclose(fp);
fprintf(stderr,"\n**User not found.\n");
return(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.st_size / (long)sizeof(struct _user)) < userno) {
fprintf(stderr,"\n**Requested user #%u not available.\n",userno);
printf("\nUSERS.BBS = %ld bytes, sizeof(user) = %u\n",f.st_size,sizeof(struct _user));
return(254);
}
if ((handle = _open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
fprintf(stderr,"\n**Error opening userfile\n");
perror("\nERROR");
return(254);
}
if (lseek(handle,(long)((long)(userno - 1) * (long)sizeof(struct _user)),SEEK_SET) == -1L) {
fprintf(stderr,"\n**Error seeking user #%u\n",userno);
perror("\nERROR");
_close(handle);
return(254);
}
if (_read(handle,&user,sizeof(user)) != sizeof(user)) {
fprintf(stderr,"\n**Error reading userfile\n");
perror("\nERROR");
_close(handle);
return(254);
}
_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");
return (254);
}
getdate(&tempdate);
if ((tempdate.da_mon != user.lastdate.da_mon) || (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) {
fprintf(stderr,"\n**User has exceeded number of calls today\n");
return(254);
}
}
else {
if (user.timetoday >= user.totaltime) {
fprintf(stderr,"\n**User has exceeded time limit for today\n");
return(254);
}
}
if (user.callsperday != 0) timelimit = user.timepercall;
else timelimit = (user.totaltime - user.timetoday);
printf("\n\04Creating XBBS files for %s (%s)\n",user.name,user.handle);
getdate(&user.logondate);
gettime(&user.logontime);
if (timetoevent<(timelimit)) {
printf("\n\04A 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);
return(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")) == NULL) {
Fatal:
fprintf(stderr,"\n**Fatal Config 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")) == NULL) 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(nodenumber == 1) strcpy(temp,"userinfo.xbs");
else {
if(nodes[nodenumber % 36] == 'S') {
strcpy(temp,"userinfo.xb!");
}
else sprintf(temp,"userinfo.xb%c",nodes[nodenumber % 36]);
}
if((fp = fopen(temp,"wt")) == NULL) {
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(nodenumber == 1) strcpy(temp,"door.sys");
else sprintf(temp,"door%c.sys",nodes[nodenumber % 36]);
fp = fopen(temp,"wt");
if(fp == NULL) {
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")) == NULL) {
perror("QORINFO? OPEN");
goto Last;
}
*temp = 'r';
if((pf = fopen(temp,"wt")) == NULL) {
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;
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;
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;
}