home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / BBS / XDEV_117.ZIP / XLOG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-29  |  12.3 KB  |  483 lines

  1. /* XLOG -- Quick-and-nasty local logon utility for XBBS  */
  2. /* Copyright (c) 1989 by M. Kimes -- All Rights Reserved */
  3.  
  4. #include "msgg.h"
  5.  
  6. void   pascal readconfig (void);
  7. void   pascal prepare (void);
  8. void   pascal userinfo(void);
  9. void   pascal left(char *a,char *b,int x);
  10. char * pascal rstrip (char *a);
  11. char * pascal lstrip (char *a);
  12. ulong  pascal getxbbstime(void);
  13. char * pascal saydate(struct date *);
  14. char * pascal saytime(struct time *);
  15. char * pascal fidodate(void);
  16. char * pascal split (char *,char *);
  17. char * pascal addtolog(char *);
  18.  
  19. word           baud=0;
  20. word           timelimit=60;
  21. struct time    starter;
  22. struct time    timeon;
  23. word           userno=1;
  24. struct _user   user;
  25. char           variable[10][82];
  26. char           pages=0;
  27. struct _mboard mboard;
  28. struct _fboard fboard;
  29. char           age;
  30. char           timer_off=0;
  31. word           hold_time=0;
  32. struct _config conf;
  33. char           nodenumber=1;
  34. struct _events event[10];
  35.  
  36. void cdecl main (int argc,char *argv[]) {
  37.  
  38.  struct ffblk f;
  39.  FILE *fp;
  40.  int handle;
  41.  word timetoevent;
  42.  register word x;
  43.  struct date tempdate;
  44.  struct date dos_date;
  45.  char text[81];
  46.  register word xx;
  47.  char *p;
  48.  char *buffer;
  49.  
  50.  printf("\x1b[0;1;37m\nXLOG copyright (c) 1989 by M. Kimes\n");
  51.  printf("\x1b[0mUsage: XLOG <user#/user_name> <baud> <timetoevent> <nodenumber> <other args>\n");
  52.  
  53.     if(findfirst(searchpath("users.bbs"),&f,0)) {
  54.         printf("\nYou don't have a userfile.\n");
  55.         exit(253);
  56.     }
  57.     timetoevent = 24 * 59;
  58.  
  59.     if (argc>=2) {
  60.         userno=0;
  61.         if (strchr(argv[1],'_')==NULL) userno=(word)atol(argv[1]);
  62.         else {
  63.             p=strchr(strupr(argv[1]),'_');
  64.             *p=' ';
  65.             printf("\nSearching for %s...",argv[1]);
  66.             xx=0;
  67.             if (f.ff_fsize) {
  68.                 if ((handle=_open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  69.                    printf("\nError opening userfile\n");
  70.                    perror("\nERROR");
  71.                    exit(254);
  72.                 }
  73.                 fp=fdopen(handle,"rb");
  74.             }
  75.             buffer=(char *)malloc(sizeof(struct _user)*25);
  76.             if(!buffer) {
  77.                 printf("\nOut of memory!\n");
  78.                 exit(255);
  79.             }
  80.             setvbuf(fp,buffer,_IOFBF,(unsigned int)(sizeof(struct _user)*25));
  81.                rewind(fp);
  82.                while (!feof(fp) && !ferror(fp)) {
  83.                  xx++;
  84.                  if (!(xx%50)) printf(".");
  85.                  if (fread(&user,sizeof(user),1,fp)!=1) break;
  86.                  strupr(user.name);
  87.                  strupr(user.handle);
  88.                  if (!(strcmp(user.name,argv[1])) && (!user.deleted)) break;
  89.                  if (!(strcmp(user.handle,argv[1])) && (!user.deleted)) break;
  90.                }
  91.                if (ferror(fp)) perror("\nERROR");
  92.                if (((strcmp(user.name,argv[1])) && (strcmp(user.handle,argv[1]))) || (user.deleted)) goto notfound;
  93.                if (!user.stat[0]) {
  94.                     fclose(fp);
  95.                     _close(handle);
  96.                     printf("\nUser locked out\n");
  97.                     exit(254);
  98.                }
  99.                userno=(word)(ftell(fp)/(long)sizeof(struct _user));
  100.                fclose(fp);
  101.                _close(handle);
  102.                if(buffer)free(buffer);
  103.                printf("\n%cUser # %d\n",4,userno);
  104.         }
  105.         if (!userno) {
  106. notfound:
  107.             fclose(fp);
  108.             _close(handle);
  109.             printf("\nUser not found.\n");
  110.             exit(253);
  111.         }
  112.     }
  113.     if (argc >= 3) baud = (word)atol(argv[2]);
  114.     if (argc >= 4) timetoevent=(word)atoi(argv[3]);
  115.     if (argc >= 5) nodenumber=(char)atoi(argv[4]);
  116.     if (argc>6) for (x=0;x<(argc-6);x++) strcpy(variable[x],argv[x]);
  117.     gettime(&timeon);
  118.     gettime(&starter);
  119.     timelimit=timetoevent;
  120.  
  121.  
  122.     if ((word)(f.ff_fsize/(long)sizeof(struct _user))<userno) {
  123.         printf("\nRequested user #%u not available.\n",userno);
  124.         exit(254);
  125.     }
  126.     if ((handle=_open(searchpath("USERS.BBS"),O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  127.        printf("\nError opening userfile\n");
  128.        perror("\nERROR");
  129.        exit(254);
  130.     }
  131.     fp=fdopen(handle,"rb");
  132.     if (fseek(fp,(long)((long)(userno-1)*(long)sizeof(struct _user)),SEEK_SET)!=0) {
  133.         printf("\nError seeking user #%u\n",userno);
  134.         perror("\nERROR");
  135.         fclose(fp);
  136.         _close(handle);
  137.         exit(254);
  138.     }
  139.     if (fread(&user,sizeof(user),1,fp)!=1) {
  140.         printf("\nError reading userfile\n");
  141.         perror("\nERROR");
  142.         fclose(fp);
  143.         _close(handle);
  144.         exit(254);
  145.     }
  146.     fclose(fp);
  147.     _close(handle);
  148.  
  149.     for (x=0;x<10;x++) event[x].secsleft=0;
  150.     readconfig();
  151.     mboard=conf.mboard;
  152.     fboard=conf.fboard;
  153.  
  154.    if ((user.stat[0])==0) {
  155.                            printf("\nUser is locked out\n");
  156.                            exit (254);
  157.    }
  158.       getdate(&tempdate);
  159.       if ((tempdate.da_mon!=user.lastdate.da_mon) or (tempdate.da_day!=user.lastdate.da_day)) {
  160.         user.callstoday=0;
  161.         user.timetoday=0;
  162.         user.uktoday=0;
  163.         user.dktoday=0;
  164.       }
  165.     if (user.callsperday!=0) {
  166.       if (user.callstoday>=user.callsperday) {
  167.         printf("\nUser has exceeded number of calls today\n");
  168.         exit(254);
  169.       }
  170.     }
  171.     else {
  172.        if (user.timetoday >= user.totaltime) {
  173.          printf("\nUser has exceeded time limit for today\n");
  174.          exit(254);
  175.        }
  176.     }
  177.     if (user.callsperday != 0) timelimit=user.timepercall;
  178.     else timelimit=(user.totaltime-user.timetoday);
  179.  
  180.     printf("\nCreating XBBS files for %s (%s)\n",user.name,user.handle);
  181.  
  182.     getdate(&user.logondate);
  183.     gettime(&user.logontime);
  184.     if (timetoevent<(timelimit)) {
  185.          printf("\nA system event is scheduled in %u minutes",timetoevent-1);
  186.          timelimit=((timetoevent-1));
  187.     }
  188.     if ((baud>0) && (baud<conf.ansibaud)) user.graphics=0;
  189.     getdate(&dos_date);
  190.     age=((dos_date.da_year-user.birthdate.da_year)-1);
  191.     if (dos_date.da_mon>user.birthdate.da_mon) age++;
  192.     else if ((dos_date.da_mon==user.birthdate.da_mon) && (dos_date.da_day>=user.birthdate.da_day)) age++;
  193.     getdate(&user.logondate);
  194.     gettime(&user.logontime);
  195.     userinfo();
  196.       for (xx=0;xx<76;text[xx]='*',text[xx+1]=0,xx++);
  197.       addtolog(text);
  198.       sprintf(text,"Online: %s @ %u baud",user.name,baud);
  199.       addtolog(text);
  200.     exit(0);
  201. }
  202.  
  203.  
  204.  
  205. void pascal readconfig (void) {
  206.  
  207.  FILE *fp;
  208.  char s[15];
  209.  
  210.     if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
  211.     else strcpy(s,"config.bbs");
  212.  
  213.     if(!(fp=fopen(s,"rb"))) {
  214. Fatal:
  215.        printf("\nFatal Error\n");
  216.        perror("\nCONFIG ERROR");
  217.        exit(254);
  218.     }
  219.   if (fread(&conf,sizeof(conf),1,fp)!=1) goto Fatal;
  220.   fclose(fp);
  221. }
  222.  
  223.  
  224.  
  225. void pascal prepare (void) {
  226.  
  227.   FILE *fp;
  228.   char s[90];
  229.   char numnode[4]="";
  230.  
  231.     if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
  232.     sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
  233.     if(!(fp=fopen(s,"wb"))) perror("ONLINE OPEN");
  234.     else {
  235.       fwrite(&user,sizeof(struct _user),1,fp);
  236.       fwrite(&userno,sizeof(userno),1,fp);
  237.       fwrite(&timelimit,sizeof(timelimit),1,fp);
  238.       fwrite(&timeon,sizeof(timeon),1,fp);
  239.       fwrite(&starter,sizeof(starter),1,fp);
  240.       fwrite(&baud,sizeof(baud),1,fp);
  241.       fwrite(&pages,sizeof(pages),1,fp);
  242.       fwrite(&age,sizeof(age),1,fp);
  243.       fwrite(&timer_off,sizeof(timer_off),1,fp);
  244.       fwrite(&hold_time,sizeof(hold_time),1,fp);
  245.       fwrite(variable,sizeof(variable[0]),10,fp);
  246.       fwrite(&mboard,sizeof(struct _mboard),1,fp);
  247.       fwrite(&fboard,sizeof(struct _fboard),1,fp);
  248.       fwrite(event,sizeof(struct _events),10,fp);
  249.       if (ferror(fp)) perror("ONLINE WRITE");
  250.       fclose(fp);
  251.     }
  252. }
  253.  
  254.  
  255. void pascal userinfo (void) {
  256.  
  257.  FILE *fp,*pf;
  258.  char temp[38],temp2[38];
  259.  char *p=NULL;
  260.  char nodes[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  261.  
  262.      if(!(fp=fopen("userinfo.xbs","w"))) {
  263.        perror("USERINFO OPEN");
  264.        goto Next;
  265.      }
  266.      fprintf(fp,"%s\n%u\n",user.handle,baud);
  267.      fprintf(fp,"%s\n%s\n",saydate(&user.lastdate),saytime(&user.lasttime));
  268.      fprintf(fp,"%s\n%s\n",saydate(&user.logondate),saytime(&user.logontime));
  269.      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);
  270.      fclose(fp);
  271.  
  272. Next:
  273.  
  274.     if(!(fp=fopen("door.sys","w"))) {
  275.        perror("DOOR.SYS OPEN");
  276.        goto Next2;
  277.     }
  278.     baud ? fprintf(fp,"COM%u\r\n",conf.commport+1) : fprintf(fp,"COM0\r\n");
  279.     fprintf(fp,"%u\r\n8\r\n%hu\r\nN\r\nY\r\nN\r\n",baud,nodenumber);
  280.     conf.sysopin ? fprintf(fp,"Y") : fprintf(fp,"N");
  281.     fprintf(fp,"\r\nN\r\n%s\r\n%s, %s\r\n%s\r\n",user.handle,user.city,user.state,user.phone1);
  282.     fprintf(fp,"%s\r\n%s\r\n%u\r\n%hu\r\n",user.phone2,user.password,user.stat[0],user.times);
  283.     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)));
  284.     user.graphics ? fprintf(fp,"GR") : fprintf(fp,"NG");
  285.     fprintf(fp,"\r\n%hu\r\n",user.length);
  286.     user.expert ? fprintf(fp,"Y") : fprintf(fp,"N");
  287.     fprintf(fp,"\r\nABCDEFG\r\n%u\r\n01/01/99\r\n%u\r\nZ\r\n",mboard.number,userno);
  288.     fprintf(fp,"%lu\r\n%lu\r\n%u\r\n%u\r\n999999\r\n",user.upk,user.downk,user.dktoday);
  289.     fclose(fp);
  290.  
  291. Next2:
  292.  
  293.      sprintf(temp,"dorinfo%c.def",nodes[nodenumber%36]);
  294.      unlink(temp);
  295.      *temp='q';
  296.      if(!(fp=fopen(temp,"wt"))) {
  297.        perror("QORINFO? OPEN");
  298.        goto Last;
  299.      }
  300.      *temp='r';
  301.      if(!(pf=fopen(temp,"wt"))) {
  302.         perror("RORINFO? OPEN");
  303.         fclose(fp);
  304.         *temp='q';
  305.         unlink(temp);
  306.         goto Last;
  307.      }
  308.      strcpy(temp,conf.sysop);
  309.      p=split(temp,p);
  310.      fprintf(fp,"%s\n%s\n%s",conf.system,temp,p);
  311.      strupr(temp);
  312.      strupr(p);
  313.      fprintf(pf,"%s\n%s\n%s",conf.system,temp,p);
  314.      if (!baud) {
  315.           fprintf(fp,"\nCOM0\n");
  316.           fprintf(pf,"\nCOM0\n");
  317.      }
  318.      else {
  319.           fprintf(fp,"\nCOM%u\n",conf.commport+1);
  320.           fprintf(pf,"\nCOM%u\n",conf.commport+1);
  321.      }
  322.      if (strchr(user.handle,' ')!=NULL) strcpy(temp,user.handle);
  323.      else strcpy(temp,user.name);
  324.      p=split(temp,p);
  325.      fprintf(fp,"%u BAUD,N,8,1\n0\n%s\n%s\n%s, %s\n",baud,temp,p,user.city,user.state);
  326.      strupr(temp);
  327.      strupr(p);
  328.      if(!baud) fprintf(pf,"9600 BAUD,N,8,1\n0\n%s\n%s\n%s, %s\n",temp,p,user.city,user.state);
  329.      else fprintf(pf,"%u BAUD,N,8,1\n0\n%s\n%s\n%s, %s\n",baud,temp,p,user.city,user.state);
  330.      if(user.graphics) fprintf(pf,"2\n");
  331.      else if(user.hiok) fprintf(pf,"1\n");
  332.      else fprintf(pf,"0\n");
  333.      fprintf(fp,"%hu\n",user.graphics);
  334.      fprintf(fp,"%u\n%u\n",user.stat[0],(word)((long)timelimit-(getxbbstime()/60L)));
  335.      fprintf(pf,"%u\n%u\n",user.stat[0],(word)((long)timelimit-(getxbbstime()/60L)));
  336.      fprintf(pf,"1\n");
  337.      fclose(fp);
  338.      fclose(pf);
  339.      sprintf(temp,"dorinfo%c.def",nodes[nodenumber%36]);
  340.      strcpy(temp2,temp);
  341.      if(conf.RBBSorQBBS) *temp2='r';
  342.      else *temp2='q';
  343.      rename(temp2,temp);
  344.  
  345. Last:
  346.  
  347.   prepare();
  348. }
  349.  
  350.  
  351.  
  352.  
  353. ulong pascal getxbbstime (void) {
  354.  
  355.     int hour;
  356.     int min;
  357.     int sec;
  358.     struct time dos_time;
  359.     char tempause;
  360.     char d[24];
  361.     static ulong xbbs_time;
  362.  
  363.      gettime(&dos_time);
  364.      hour=dos_time.ti_hour-starter.ti_hour;
  365.      min=dos_time.ti_min-starter.ti_min;
  366.      sec=dos_time.ti_sec-starter.ti_sec;
  367.      if (dos_time.ti_hour<starter.ti_hour) hour=hour+24;
  368.      xbbs_time=(long)(hour*3600)+(min*60)+sec;
  369.      return (xbbs_time);
  370. }
  371.  
  372.  
  373.  
  374. char * pascal fidodate (void) {
  375.  
  376.  char months[12][4]={
  377.     "Jan",
  378.     "Feb",
  379.     "Mar",
  380.     "Apr",
  381.     "May",
  382.     "Jun",
  383.     "Jul",
  384.     "Aug",
  385.     "Sep",
  386.     "Oct",
  387.     "Nov",
  388.     "Dec"
  389.  };
  390.  static char fdate[20];
  391.  struct date dos_date;
  392.  struct time dos_time;
  393.  
  394. /* 26 Jul 89  06:23:47 */
  395.  
  396.  getdate(&dos_date);
  397.  gettime(&dos_time);
  398.  
  399.  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);
  400.  return(fdate);
  401.  
  402. }
  403.  
  404.  
  405.  
  406. char * pascal saydate (struct date *a) {
  407.  
  408.     static char xdate[11];
  409.  
  410.  sprintf(xdate,"%02hu/%02hu/%04u",a->da_mon,a->da_day,a->da_year);
  411.  return(xdate);
  412. }
  413.  
  414.  
  415.  
  416. char * pascal saytime (struct time *a) {
  417.  
  418.     static char xtime[9];
  419.  
  420.  sprintf(xtime,"%02u:%02u:%02u",a->ti_hour,a->ti_min,a->ti_sec);
  421.  return(xtime);
  422. }
  423.  
  424.  
  425.  
  426.  
  427. char * pascal split (char *a,char *b) {
  428.  
  429.        b=strchr(a,' ');
  430.        b[0]=0;
  431.        return(++b);
  432. }
  433.  
  434.  
  435.  
  436.  
  437. char * pascal rstrip (char *a) {
  438.  
  439.   register int x;
  440.  
  441.   x=strlen(a);
  442.   while (x && a && a[x-1]==' ') a[--x]=0;
  443.   return a;
  444. }
  445.  
  446.  
  447.  
  448. char * pascal lstrip (char *a) {
  449.  
  450.   register int x;
  451.  
  452.   x=strlen(a);
  453.   while (x && *a==' ') memmove (a,(a+1),x--);
  454.   return (a);
  455. }
  456.  
  457.  
  458.  
  459. char * pascal addtolog (char *text) {  /* WRITE LOGFILE ENTRIES */
  460.  
  461.  int handle;
  462.  char p[127];
  463.  
  464.  if ((handle=_open(conf.logfile,O_RDWR | O_APPEND | O_BINARY | O_DENYNONE))==-1)
  465.     if ((handle=creat(conf.logfile,S_IWRITE))==-1) return text;
  466.  lseek(handle,0,SEEK_END);
  467.  if (text[0]!='*') {
  468.    strcpy(p,fidodate());
  469.    p[16]=0;
  470.    strcat(p,"  ");
  471.    strncat(p,text,126-strlen(p));
  472.    p[126]=0;
  473.  }
  474.  else {
  475.         strncpy(p,text,79);
  476.         p[79]=0;
  477.  }
  478.  _write(handle,p,strlen(p));
  479.  _write(handle,"\r\n",2);
  480.  _close(handle);
  481.  return text;
  482. }
  483.