home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part04 / bbsc1.c.A next >
Text File  |  1992-09-08  |  40KB  |  1,870 lines

  1. /*
  2.  * bbsc.c 
  3.  *
  4.  * BBS (Bulletin Board System) written in xenix system V  "C". 
  5.  *
  6.  * Support files needed: bbscdef.h bbscport.o or bbscport.c bbsclock.o or
  7.  * bbsclock.c bbscfile.o or bbscfile.c bbscmisc.o or bbscmisc.c bbscio.o   or
  8.  * bbscio.c bbscarea.o or bbscarea.c bbscmsga.o or bbscmsga.c bbscqust.o or
  9.  * bbscqust.c bbscbult.o or bbscbult.c bbscadds.o or bbscadds.c bbsclist.o or
  10.  * bbsclist.c bbsczip.o  or bbsczip.c bbscconf.c or bbscconf.o bbscsumm.c or
  11.  * .o 
  12.  *
  13.  *
  14.  *                          Sanford J. Zelkovitz
  15.  *
  16.  */
  17. #include "bbsc12.h"
  18. char *basename();
  19. long difft();
  20. main()
  21. {
  22.     int             i, fd;
  23.     char            ptype[2];
  24.     char            pval[18];
  25.     /*
  26.      * init global variables 
  27.      */
  28.     Zsec = Ztime = sigreturn = 0;
  29.     if ((inbuf = fopen(CONFIG, "r")) == NULL) {
  30.         portsout("\n\rError opening configuration file!\n\r");
  31.         exit(1);
  32.     }
  33.     if ((fgets(WELCOME, 49, inbuf) == NULL))
  34.         error_config();
  35.     strip(WELCOME);
  36.     if ((fgets(BULLETINS, 49, inbuf) == NULL))
  37.         error_config();
  38.     strip(BULLETINS);
  39.     if ((fgets(NEWUSER, 49, inbuf) == NULL))
  40.         error_config();
  41.     strip(NEWUSER);
  42.     if ((fgets(SYSTEM, 49, inbuf) == NULL))
  43.         error_config();
  44.     strip(SYSTEM);
  45.     if ((fgets(CALLERS, 49, inbuf) == NULL))
  46.         error_config();
  47.     strip(CALLERS);
  48.     if ((fgets(LASTCALL, 49, inbuf) == NULL))
  49.         error_config();
  50.     strip(LASTCALL);
  51.     if ((fgets(USERS, 49, inbuf) == NULL))
  52.         error_config();
  53.     strip(USERS);
  54.     if ((fgets(UNIXMSG, 49, inbuf) == NULL))
  55.         error_config();
  56.     strip(UNIXMSG);
  57.     if ((fgets(DLMSG, 49, inbuf) == NULL))
  58.         error_config();
  59.     strip(DLMSG);
  60.     if ((fgets(HUMOR, 49, inbuf) == NULL))
  61.         error_config();
  62.     strip(HUMOR);
  63.     if ((fgets(HELP, 49, inbuf) == NULL))
  64.         error_config();
  65.     strip(HELP);
  66.     if ((fgets(HELPFILE, 49, inbuf) == NULL))
  67.         error_config();
  68.     strip(HELPFILE);
  69.     if ((fgets(HELPMSG, 49, inbuf) == NULL))
  70.         error_config();
  71.     strip(HELPMSG);
  72.     if ((fgets(USERPRIV, 49, inbuf) == NULL))
  73.         error_config();
  74.     strip(USERPRIV);
  75.     if ((fgets(MAINPRIV, 49, inbuf) == NULL))
  76.         error_config();
  77.     strip(MAINPRIV);
  78.     if ((fgets(FILEPRIV, 49, inbuf) == NULL))
  79.         error_config();
  80.     strip(FILEPRIV);
  81.     if ((fgets(QUESTION, 49, inbuf) == NULL))
  82.         error_config();
  83.     strip(QUESTION);
  84.     if ((fgets(ANSWER, 49, inbuf) == NULL))
  85.         error_config();
  86.     strip(ANSWER);
  87.     if ((fgets(ADDITN, 49, inbuf) == NULL))
  88.         error_config();
  89.     strip(ADDITN);
  90.     if ((fgets(LISTFILES, 49, inbuf) == NULL))
  91.         error_config();
  92.     strip(LISTFILES);
  93.     if ((fgets(TODAY, 98, inbuf) == NULL))
  94.         error_config();
  95.     strip(TODAY);
  96.     if ((fgets(ORGPATH, 49, inbuf) == NULL))
  97.         error_config();
  98.     strip(ORGPATH);
  99.     if ((fgets(AREAS, 49, inbuf) == NULL))
  100.         error_config();
  101.     strip(AREAS);
  102.  
  103.     strcpy(SIGS, ORGPATH);
  104.     strcat(SIGS, "sigs.bbs");
  105.  
  106.     if ((fgets(MSGS, 49, inbuf) == NULL))
  107.         error_config();
  108.     strip(MSGS);
  109.     if ((fgets(USRBBS, 49, inbuf) == NULL))
  110.         error_config();
  111.     strip(USRBBS);
  112.     if ((fgets(RB, 49, inbuf) == NULL))
  113.         error_config();
  114.     strip(RB);
  115.     if ((fgets(SB, 49, inbuf) == NULL))
  116.         error_config();
  117.     strip(SB);
  118.     if ((fgets(CRCR, 49, inbuf) == NULL))
  119.         error_config();
  120.     strip(CRCR);
  121.     if ((fgets(CRCS, 49, inbuf) == NULL))
  122.         error_config();
  123.     strip(CRCS);
  124.     if ((fgets(YMDR, 49, inbuf) == NULL))
  125.         error_config();
  126.     strip(YMDR);
  127.     if ((fgets(YMDS, 49, inbuf) == NULL))
  128.         error_config();
  129.     strip(YMDS);
  130.     if ((fgets(YMR, 49, inbuf) == NULL))
  131.         error_config();
  132.     strip(YMR);
  133.     if ((fgets(YMS, 49, inbuf) == NULL))
  134.         error_config();
  135.     strip(YMS);
  136.     if ((fgets(RZ, 49, inbuf) == NULL))
  137.         error_config();
  138.     strip(RZ);
  139.     if ((fgets(SZ, 49, inbuf) == NULL))
  140.         error_config();
  141.     strip(SZ);
  142.     if ((fgets(KS, 49, inbuf) == NULL))
  143.         error_config();
  144.     strip(KS);
  145.     if ((fgets(KRA, 49, inbuf) == NULL))
  146.         error_config();
  147.     strip(KRA);
  148.     if ((fgets(KRE, 49, inbuf) == NULL))
  149.         error_config();
  150.     strip(KRE);
  151.     if ((fgets(SEAR, 49, inbuf) == NULL))
  152.         error_config();
  153.     strip(SEAR);
  154.     if ((fgets(SEAS, 49, inbuf) == NULL))
  155.         error_config();
  156.     strip(SEAS);
  157.     if ((fgets(SYSOP, 49, inbuf) == NULL))
  158.         error_config();
  159.     strip(SYSOP);
  160.     if ((fgets(buf128, 49, inbuf) == NULL))
  161.         error_config();
  162.     strip(buf128);
  163.     LOGTIME = atoi(buf128);
  164.     if ((fgets(buf128, 49, inbuf) == NULL))
  165.         error_config();
  166.     strip(buf128);
  167.     RUNTIME = atoi(buf128);
  168.     if ((fgets(buf128, 49, inbuf) == NULL))
  169.         error_config();
  170.     strip(buf128);
  171.     WAITTIME = atoi(buf128);
  172.     if ((fgets(buf128, 49, inbuf) == NULL))
  173.         error_config();
  174.     strip(buf128);
  175.     NEWPRIV = atoi(buf128);
  176.     if ((fgets(buf128, 49, inbuf) == NULL))
  177.         error_config();
  178.     strip(buf128);
  179.     MAXPRIV = atoi(buf128);
  180.     if ((fgets(buf128, 49, inbuf) == NULL))
  181.         error_config();
  182.     strip(buf128);
  183.     MAXSEC = atoi(buf128);
  184.     if ((fgets(buf128, 49, inbuf) == NULL))
  185.         error_config();
  186.     strip(buf128);
  187.     MAXKBYTE = atoi(buf128);
  188.     if ((fgets(TAR, 49, inbuf) == NULL))
  189.         error_config();
  190.     strip(TAR);
  191.     if ((fgets(ZCAT, 49, inbuf) == NULL))
  192.         error_config();
  193.     strip(ZCAT);
  194. /*
  195.     Starting with version 7.102, the following fgets can just get garbage
  196.        since the arc file lister is now a built-in ( bbscarc.c )
  197. */ 
  198.     if ((fgets(ARC, 49, inbuf) == NULL))
  199.         error_config();
  200.     strip(ARC);
  201.  
  202. /*
  203.     Starting with version 7.102, the following fgets can just get garbage
  204.        since the zip file lister is now a built-in ( bbscunzip.c )
  205. */ 
  206.     if ((fgets(ZIP, 49, inbuf) == NULL))
  207.         error_config();
  208.     strip(ZIP);
  209.  
  210.     if ((fgets(MONITOR, 29, inbuf) == NULL))
  211.         error_config();
  212.     strip(MONITOR);
  213.     if ((fgets(CONSOLE, 29, inbuf) == NULL))
  214.         error_config();
  215.     strip(CONSOLE);
  216.     if ((fgets(SHELL, 29, inbuf) == NULL))
  217.         error_config();
  218.     strip(SHELL);
  219.     if ((fgets(buf128, 49, inbuf) == NULL))
  220.         error_config();
  221.     strip(buf128);
  222.     scan = atoi(buf128);
  223.     if ((fgets(READN, 98, inbuf) == NULL))
  224.         error_config();
  225.     strip(READN);
  226.     if ((fgets(POSTN, 98, inbuf) == NULL))
  227.         error_config();
  228.     strip(POSTN);
  229.     fclose(inbuf);
  230.  
  231.     strcpy(l_m_base, "0");
  232.     strcpy(l_f_base, "0");
  233.     strcpy(xprt_a, "0");
  234.     strcpy(tggl_a, "1");
  235.  
  236.     maxkbyte = MAXKBYTE;
  237.     logtime = LOGTIME;
  238.     Ytime = logtime;
  239.     runtime = RUNTIME;
  240.     waittime = WAITTIME;
  241.     newpriv = NEWPRIV;
  242.     max_priv = MAXPRIV;
  243.     strcpy(callers, CALLERS);
  244.     this_ttyname = ttyname(0);
  245.     strcpy(buf128, this_ttyname);
  246.     i = strlen(buf128);
  247.     i--;
  248.     substr(buf128, pval, i, 2);
  249.     strcat(callers, pval);
  250.     strcpy(port_id, pval);
  251.     strcpy(buf128, "/tmp/conf");
  252.     strcat(buf128, pval);
  253.     (void) unlink(buf128);
  254.     strcpy( buf128, ORGPATH );
  255.     strcat( buf128, "inval_port.bbs");
  256.     inbuf = fopen(buf128, "r" );
  257.     if( inbuf != NULL ) {
  258.         while (1) {
  259.             if( fscanf(inbuf, "%s", buf128) == EOF )
  260.                 break;
  261.             if(strcmp(basename(buf128),basename(this_ttyname))==0){
  262.                 fclose(inbuf);
  263.                 portinit();
  264.                 setmodes();
  265.                 portsout("\n\r\n\rYou called in on a restricted line!\n\r\n\r");
  266.                 restoremodes();
  267.                 portrst();
  268.                 strcpy(buf128, ORGPATH);
  269.                 strcat(buf128, "restricted.bbs");
  270.                 if((inbuf=fopen(buf128,"a")) != NULL) {
  271.                     gettime(ttime);
  272.                     GeTdAtE(mm, dd, yy, month, day, year, date, week);
  273.                     fd = atoi(mm);
  274.                     fd++;
  275.                     sprintf(mm, "%.2d", fd);
  276.                     (void)fprintf(inbuf, "%s/%s/%s  %s    restricted line caller on %s\n", mm,dd,yy,ttime,this_ttyname);
  277.                     fclose(inbuf);
  278.                 }
  279.                 exit(1);
  280.             }
  281.         }
  282.         fclose(inbuf);
  283.     }
  284.     hold_pipe = FALSE;
  285.     debug = FALSE;
  286.     hold_off = FALSE;
  287.     toggle_hold = FALSE;
  288.     first_time_in = TRUE;
  289.     first_msg_in = TRUE;
  290.     chat_in_progress = FALSE;
  291.     stop_chat = FALSE;
  292.     newuzr = FALSE;
  293.     statcnt = 0;
  294.     last_msg_read = 0;
  295.     xpert = FALSE;
  296.     listed_l = FALSE;
  297.     listed_r = FALSE;
  298.     listed_n = FALSE;
  299.     toggle = TRUE;
  300.     active = TRUE;
  301.     reply_sw = FALSE;
  302.     end_msg = FALSE;
  303.     read_flag = FALSE;
  304.     sys_flag = FALSE;
  305.     strcpy(old_upath, AUTHOR);
  306.     new_msg = 0;
  307.     c_pathname[0] = '\0';
  308.     if_monitor = FALSE;
  309.     no_cntrl_k = FALSE;
  310.     resp_flag = FALSE;
  311.     in_the_buffer = 0;
  312.     user_priv = 1;
  313.     read_number = 1;
  314.     extra_time = 0L;
  315.     extra_size = 0L;
  316.     dload_total = 0L;
  317.     max_dload = 0L;
  318.     blocked_m = 0;
  319.     mpA = 1;
  320.     mpB = 1;
  321.     mpE = 1;
  322.     mpG = 1;
  323.     mpK = 1;
  324.     mpP = 1;
  325.     mpN = 1;
  326.     mpQ = 1;
  327.     mpR = 1;
  328.     mpS = 1;
  329.     mpW = 1;
  330.     mpM = 1;
  331.     mpX = 1;
  332.     mpF = 1;
  333.     mpC = 1;
  334.     mpH = 1;
  335.     mpT = 1;
  336.     mpD = 1;
  337.     mpY = 1;
  338.  
  339.     mpUSENET = 1;        /* added for 7.2.1 */
  340.     mpRF = 1;
  341.     mpQUEST = 1;
  342.     mpU = 32767;
  343.     mpMS = 1;
  344.     mpCHAT = 1;
  345.     mpCONF = 1;
  346.     mpL = 1;
  347.     fpL = 1;
  348.     fpU = 1;
  349.     fpD = 1;
  350.     fpM = 1;
  351.     fpG = 1;
  352.     fpR = 1;
  353.  
  354.  
  355.     strcpy(buf128, STDERR);
  356.     strcat(buf128, port_id);
  357.     STDerr = freopen(buf128, "w+", stderr);
  358.     if (IF_MONITOR) {
  359.         mon_handle = open(MONITOR, O_WRONLY);
  360.         if (mon_handle == -1) {
  361.             portsout("\n\rCritical Error --- End BBS\n\r");
  362.             exit(1);
  363.         }
  364.         if_monitor = FALSE;
  365.         i = getpid();
  366.         itoa(buf128, i);
  367.         strcpy(who_am_i, "/tmp/pid");
  368.         strcat(who_am_i, pval);
  369.         inbuf = fopen(who_am_i, "w");
  370.         fprintf(inbuf, "%s", buf128);
  371.         fclose(inbuf);
  372.     }
  373.     if ((inbuf = fopen(MAINPRIV, "r")) == NULL) {
  374.         portsout("\n\rCritical Error!\n\r");
  375.         portsout("Unable to find main privs!\n\r");
  376.         exit(1);
  377.     }
  378.     while (fscanf(inbuf, "%s%s", ptype, pval) != EOF) {
  379.         ptype[1] = '\0';
  380.         *ptype = toupper(*ptype);
  381.         switch (ptype[0]) {
  382.         case ('B'):
  383.             mpB = atoi(pval);
  384.             break;
  385.         case ('E'):
  386.             mpE = atoi(pval);
  387.             break;
  388.         case ('G'):
  389.             mpG = atoi(pval);
  390.             break;
  391.         case ('K'):
  392.             mpK = atoi(pval);
  393.             break;
  394.         case ('N'):
  395.             mpN = atoi(pval);
  396.             break;
  397.         case ('Q'):
  398.             mpQ = atoi(pval);
  399.             break;
  400.         case ('R'):
  401.             mpR = atoi(pval);
  402.             break;
  403.         case ('S'):
  404.             mpS = atoi(pval);
  405.             break;
  406.         case ('W'):
  407.             mpW = atoi(pval);
  408.             break;
  409.         case ('M'):
  410.             mpM = atoi(pval);
  411.             break;
  412.         case ('X'):
  413.             mpX = atoi(pval);
  414.             break;
  415.         case ('F'):
  416.             mpF = atoi(pval);
  417.             break;
  418.         case ('C'):
  419.             mpC = atoi(pval);
  420.             break;
  421.         case ('H'):
  422.             mpH = atoi(pval);
  423.             break;
  424.         case ('T'):
  425.             mpT = atoi(pval);
  426.             break;
  427.         case ('D'):
  428.             mpD = atoi(pval);
  429.             break;
  430.         case ('Y'):
  431.             mpY = atoi(pval);
  432.             break;
  433.         case ('U'):
  434.             mpU = atoi(pval);
  435.             break;
  436.         case ('P'):
  437.             mpP = atoi(pval);
  438.             break;
  439.         case ('A'):
  440.             mpA = atoi(pval);
  441.             break;
  442.         case ('L'):
  443.             mpL = atoi(pval);
  444.             break;
  445.         case ('&'):
  446.             mpMS = atoi(pval);
  447.             break;
  448.         case ('?'):
  449.             mpZ = atoi(pval);
  450.             break;
  451.         case ('~'):
  452.             mpCHAT = atoi(pval);
  453.             break;
  454.         case ('%'):
  455.             mpQUEST = atoi(pval);
  456.             break;
  457.         case ('$'):
  458.             mpRF = atoi(pval);
  459.             break;
  460.         case ('O'):
  461.             mpCONF = atoi(pval);
  462.             break;
  463.         case ('I'):    /* added for 7.2.1 */
  464.             mpUSENET = atoi(pval);
  465.             break;
  466.         default:
  467.             portsout("\n\rBad entry in MAIN PRIV\n\r");
  468.             break;
  469.         }
  470.     }
  471.     fclose(inbuf);
  472.     if ((inbuf = fopen(FILEPRIV, "r")) == NULL) {
  473.         portsout("\n\rCritical Error!\n\r");
  474.         portsout("Unable to find file privs!\n\r");
  475.         exit(1);
  476.     }
  477.     while (fscanf(inbuf, "%s%s", ptype, pval) != EOF) {
  478.         ptype[1] = '\0';
  479.         *ptype = toupper(*ptype);
  480.         switch (ptype[0]) {
  481.         case ('L'):
  482.             fpL = atoi(pval);
  483.             break;
  484.         case ('U'):
  485.             fpU = atoi(pval);
  486.             break;
  487.         case ('D'):
  488.             fpD = atoi(pval);
  489.             break;
  490.         case ('M'):
  491.             fpM = atoi(pval);
  492.             break;
  493.         case ('G'):
  494.             fpG = atoi(pval);
  495.             break;
  496.         case ('R'):
  497.             fpR = atoi(pval);
  498.             break;
  499.         default:
  500.             portsout("\n\rBad entry in FILE PRIV\n\r");
  501.             break;
  502.         }
  503.     }
  504.     fclose(inbuf);
  505.     w_fname[0] = '\0';
  506.     w_lname[0] = '\0';
  507.     strcpy(w_password, "MPK0");
  508.  
  509.     u_fname[0] = '\0';
  510.     u_lname[0] = '\0';
  511.     strcpy(u_password, "MPK0");
  512.     u_time1[0] = '\0';
  513.     u_date1[0] = '\0';
  514.     u_time2[0] = '\0';
  515.     u_date2[0] = '\0';
  516.     u_city[0] = '\0';
  517.  
  518.     mm[0] = '\0';
  519.     dd[0] = '\0';
  520.     yy[0] = '\0';
  521.     month[0] = '\0';
  522.     day[0] = '\0';
  523.     year[0] = '\0';
  524.     date[0] = '\0';
  525.     week[0] = '\0';
  526.     ttime[0] = '\0';
  527.  
  528.     strcpy(msg_delete, "0");
  529.     msg_no[0] = '\0';
  530.     msg_date[0] = '\0';
  531.     msg_date[0] = '\0';
  532.     msg_time[0] = '\0';
  533.     msg_to[0] = '\0';
  534.     msg_from[0] = '\0';
  535.     msg_pass[0] = '\0';
  536.     msg_subject[0] = '\0';
  537.     msg_text[0] = '\0';
  538.     strfill(msg_text, 0, 1482);
  539.  
  540.     stop_that = FALSE;
  541.  
  542.     /* get date and time from the clock      */
  543.  
  544.     gettime(ttime);
  545.     GeTdAtE(mm, dd, yy, month, day, year, date, week);
  546.     substr(month, mnd, 1, 3);
  547.     strcat(mnd, day);
  548.  
  549.     fd = atoi(mm);
  550.     fd++;
  551.     sprintf(mm, "%.2d", fd);
  552.  
  553.     sec = logtime;
  554.     which_timer = 1;
  555.     alarm(sec);
  556.  
  557.     if (signal(SIGALRM, timer) == (int (*) ()) -1)
  558.         exit(1);
  559.     if (signal(SIGUSR1, mon_toggle) == (int (*) ()) -1)
  560.         exit(1);
  561.     if (signal(SIGUSR2, sys_toggle) == (int (*) ()) -1)
  562.         exit(1);
  563.     if (signal(SIGPIPE, chat) == (int (*) ()) -1)
  564.         exit(1);
  565.     if (signal(SIGINT, STOP) == (int (*) ()) -1)
  566.         exit(1);
  567.     if (signal(SIGHUP, hanged) == (int (*) ()) -1)
  568.         exit(1);
  569.  
  570.  
  571.     portinit();        /* init terminal modes */
  572.     setmodes();
  573.     signon();
  574.     driver();
  575.     restoremodes();
  576.     portrst();        /* undo any special modes */
  577.     closer(1);
  578. }
  579. /* end of mainline routine       */
  580.  
  581. driver()
  582. {
  583.     char            linebuf[MAXLINE], buf[128], *bufptr,    /* ptr to buf */
  584.                     usercd[100],    /* user record */
  585.                    *userptr,/* ptr to usercd */
  586.                     cmd[2];
  587.  
  588.     int             cnt, ok_sw, case_sw, i, mpk, result, num0, num1, num2;
  589.     long            vtime;
  590.  
  591.     mpk = mpK;
  592.     cnt = 0;
  593.     ok_sw = TRUE;
  594.     bufptr = buf;
  595.     cmd[0] = '\0';
  596.     if (active) {
  597.  
  598.         sec = runtime;
  599.         vtime = sec;
  600.         vtime += extra_time;
  601.         if (vtime > 32767L)
  602.             vtime = 32767L;
  603.         if (vtime < 60L)
  604.             vtime = 60L;
  605.         sec = vtime;
  606.         Ytime = sec;
  607.         max_dload = ((long) (maxkbyte)) * 1024L;
  608.         max_dload += extra_size;
  609.         alarm(sec);
  610.         which_timer = 2;
  611.         change_bult();
  612.         today_msg();
  613.         if (scan) {
  614.             if (!newuzr) {
  615.                 portsout("\n\rLast time you were on the system: ");
  616.                 portsout(z_date);
  617.                 portsout(" at ");
  618.                 portsout(z_time);
  619.                 portsout("\n\r\n\r");
  620.                 portsout("\n\rDo you wish to check to see if you have any messages? (Y/n): ");
  621.                 portsin(cmd, 1);
  622.                 portsout(CRLF);
  623.                 if (cmd[0] == 'N' || cmd[0] == 'n')
  624.                     check_msga_n();
  625.                 else
  626.                     check_msga();
  627.                 cmd[0] = '\0';
  628.             } else {
  629.                 portsout(CRLF);
  630.                 portsout("Since you are a new user, the scan for messages will not be performed.\n\r");
  631.                 portsout("The next time that you call, all message bases will be scanned.\n\r\n\r");
  632.                 check_msga_n();
  633.                 portsout("Since you are a new user, you will be asked to fill out our questionnaire.\n\r");
  634.                 portsout("Please take the time and fill it out. Thank you.\n\r");
  635.                 question(1);
  636.             }
  637.         } else
  638.             check_msga_n();
  639.     }
  640.     while (active) {
  641.         stop_that = FALSE;    /* reset switch */
  642.         portsout(CRLF);
  643.         signal(SIGALRM, timer);
  644.         signal(SIGUSR1, mon_toggle);
  645.         signal(SIGUSR2, sys_toggle);
  646.         signal(SIGPIPE, chat);
  647.         signal(SIGINT, STOP);
  648.         signal(SIGHUP, hanged);
  649.         cmd_t();
  650.         sigreturn = 0;
  651.         bbsmenu(1,0);
  652.         portsin(cmd, 1);
  653.         portsout(CRLF);
  654.  
  655.         *cmd = toupper(*cmd);
  656.  
  657.         switch (cmd[0]) {
  658.         case ('V'):
  659.             portsout("\n\r\n\rVersion: ");
  660.             portsout(VERSION);
  661.             portsout("    ");
  662.             portsout(LASTDATE);
  663.             portsout("\n\r\n\r");
  664.             break;
  665.         case ('U'):
  666.             if (!privmsg(mpU))
  667.                 break;
  668.             cmd_p(UNIXMSG);
  669.             if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  670.                                      * append */
  671.                 portsout(CRLF);
  672.                 portsout("Can't open/create callers file!");
  673.                 portsout(CRLF);
  674.                 return;
  675.             }
  676.             result = fprintf(inbuf, "%s", "   Going into Xenix/Unix");
  677.             if (result < 0) {
  678.                 portsout(CRLF);
  679.                 portsout("Caller file has problem writing");
  680.                 portsout(CRLF);
  681.             } else {
  682.                 fputs("\n", inbuf);
  683.             }
  684.             fclose(inbuf);
  685.             restoremodes();
  686.             portrst();
  687.             STDerr = freopen("/dev/tty", "w+", stderr);
  688.             result = system(SHELL);
  689.             strcpy(buf128, STDERR);
  690.             strcat(buf128, port_id);
  691.             STDerr = freopen(buf128, "w+", stderr);
  692.             signal(SIGALRM, timer);
  693.             signal(SIGHUP, hanged);
  694.             signal(SIGUSR1, mon_toggle);
  695.             signal(SIGUSR2, sys_toggle);
  696.             signal(SIGPIPE, chat);
  697.             signal(SIGINT, STOP);
  698.             portinit();
  699.             setmodes();
  700.             break;
  701.         case ('G'):    /* goodby */
  702.             if (!privmsg(mpG))
  703.                 break;
  704.             cmd_c();
  705.             break;
  706.         case ('L'):
  707.             if (!privmsg(mpL))
  708.                 break;
  709.             who_is_there();
  710.             break;
  711.         case ('Z'):
  712.             if (!privmsg(mpY))
  713.                 break;
  714.             cmd_z();
  715.             break;
  716.         case ('R'):
  717.             if (!privmsg(mpRF))
  718.                 break;
  719.             file_list();
  720.             break;
  721.         case ('C'):
  722.             if (!privmsg(mpCHAT))
  723.                 break;
  724.             sigchat();
  725.             break;
  726.         case ('O'):
  727.             if (!privmsg(mpCONF))
  728.                 break;
  729.             conf();
  730.             break;
  731.         case ('E'):
  732.             if (!privmsg(mpCONF))
  733.                 break;
  734.             portsout("\n\r\n\rThe following users are presently in conference\n\r");
  735.             no_cntrl_k = 1;
  736.             strcpy(buf128, "ls /tmp/conf* > /tmp/inconf.");
  737.             strcat(buf128, port_id);
  738.             (void) system(buf128);
  739.             strcpy(buf128, "/tmp/inconf.");
  740.             strcat(buf128, port_id);
  741.             if ((otbuf = fopen(buf128, "r")) == NULL) {
  742.                 portsout("\n\rError opening list file!\n\r");
  743.                 exit(1);
  744.             }
  745.             while (fscanf(otbuf, "%s", who_am_i) != EOF)
  746.                 cmd_p(who_am_i);
  747.             fclose(otbuf);
  748.             no_cntrl_k = 0;
  749.             break;
  750.         case ('I'):        /* No need to check privs since
  751.                                            each command has access privs */
  752.             sig_access();
  753.             break;
  754.         case ('Q'):
  755.             if (!privmsg(mpQUEST))
  756.                 break;
  757.             question(0);
  758.             break;
  759.         case ('A'):
  760.             if (!privmsg(mpA))
  761.                 break;
  762.             additional(ADDITN);
  763.             break;
  764.         case ('D'):
  765.             if (!privmsg(mpD))
  766.                 break;
  767.             strcpy(buf128, TODAY);
  768.             strcat(buf128, port_id);
  769.             result = system(buf128);
  770.             strcpy(buf128, "/tmp/today");
  771.             strcat(buf128, port_id);
  772.             cmd_p(buf128);
  773.             break;
  774.         case ('P'):
  775.             if (!privmsg(mpP))
  776.                 break;
  777.             ch_password();
  778.             break;
  779.         case ('X'):    /* expert toggle */
  780.             if (!privmsg(mpX))
  781.                 break;
  782.             cmd_x();
  783.             rewritx();
  784.             break;
  785.         case ('N'):    /* print new-user stuff */
  786.             if (!privmsg(mpN))
  787.                 break;
  788.             cmd_p(NEWUSER);
  789.             break;
  790.         case ('W'):    /* print welcome file */
  791.             if (!privmsg(mpW))
  792.                 break;
  793.             cmd_p(WELCOME);
  794.             break;
  795.         case ('B'):    /* print bulletins */
  796.             if (!privmsg(mpB))
  797.                 break;
  798.             change_bult();
  799.             break;
  800.         case ('H'):    /* print humor file */
  801.             if (!privmsg(mpH))
  802.                 break;
  803.             cmd_p(HUMOR);
  804.             break;
  805.         case ('F'):
  806.             if (!privmsg(mpF))
  807.                 break;
  808.             cmd_f();
  809.             break;
  810.         case ('M'):
  811.             if (!privmsg(mpMS))
  812.                 break;
  813.             msg_section(mpk);
  814.             break;
  815.         case ('T'):
  816.             if (!privmsg(mpT))
  817.                 break;
  818.             toggle = !toggle;
  819.             rewritx();
  820.             if (toggle) {
  821.                 portsout("\n\rStop Mode\n\r");
  822.             } else {
  823.                 portsout("\n\rContinuous Mode\n\r");
  824.             }
  825.             break;
  826.         case ('?'):    /* help */
  827.             if (!privmsg(mpZ))
  828.                 break;
  829.             cmd_p(HELP);
  830.             break;
  831.         case ('S'):    /* added for 7.2.1  USENET ACCESS */
  832.             if (!privmsg(mpUSENET))
  833.                 break;
  834.             usenet();
  835.             break;
  836.         default:
  837.             break;
  838.         }
  839.  
  840.     }
  841. }
  842. /* end of function               */
  843. sigchat()
  844. {
  845.     char           *ttyzz;
  846.     char            tb[80];
  847.     int             result, handle;
  848.     static char     bell = '\007';
  849.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  850.                              * append */
  851.         portsout(CRLF);
  852.         portsout("Can't open/create callers file!");
  853.         portsout(CRLF);
  854.         return;
  855.     }
  856.     result = fprintf(inbuf, "%s", "   Requesting a chat");
  857.     if (result < 0) {
  858.         portsout(CRLF);
  859.         portsout("Caller file has problem writing");
  860.         portsout(CRLF);
  861.     } else {
  862.         fputs("\n", inbuf);
  863.     }
  864.     fclose(inbuf);
  865.     result = stat(SYSTTY, &statbuf);
  866.     if (!result) {
  867.         strcpy(buf128, "\n\r\n\r");
  868.         strcat(buf128, SYSOP);
  869.         strcat(buf128, " is already engaged in a chat or has turned it off.\n\r\n\r");
  870.         portsout(buf128);
  871.         return;
  872.     }
  873.     handle = open(CONSOLE, O_WRONLY);
  874.     if (handle == -1) {
  875.         portsout("\n\rError opening console driver!\n\r");
  876.         exit(1);
  877.     }
  878.     ttyzz = ttyname(1);
  879.     strcpy(tb, "\n\rChat requested by ");
  880.     strcat(tb, w_fname);
  881.     strcat(tb, " ");
  882.     strcat(tb, w_lname);
  883.     strcat(tb, " on ");
  884.     strcat(tb, ttyzz);
  885.     strcat(tb, "\n\r");
  886.     write(handle, tb, (strlen(tb)));
  887.     Xsec = 0;
  888.     stop_chat = FALSE;
  889.     portsout("\n\rPaging: ");
  890.     for (result = 0; result <= 30; result++) {
  891. sigloop:
  892.         if (stop_chat) {
  893.             portsout(CRLF);
  894.             close(handle);
  895.             return;
  896.         }
  897.         Sec = alarm(0);
  898.         hold_pipe = TRUE;
  899.         alarm(Sec);
  900.         hold_pipe = FALSE;
  901.         if (Sec != Xsec) {
  902.             if (stop_chat) {
  903.                 portsout(CRLF);
  904.                 close(handle);
  905.                 return;
  906.             }
  907.             Xsec = Sec;
  908.             portsout(". ");
  909.             write(handle, &bell, 1);
  910.         } else
  911.             goto sigloop;
  912.     }
  913.     strcpy(buf128, "\n\rI am sorry; however, ");
  914.     strcat(buf128, SYSOP);
  915.     strcat(buf128, " is unavailable to chat with you.\n\r");
  916.     portsout(buf128);
  917.     close(handle);
  918. }
  919.  
  920. ch_password()
  921. {
  922.     int             result, char_in_passwd;
  923.     char           *pptr;
  924.     while (1) {
  925. in_passx:
  926.         portsout(CRLF);
  927.         portsout("Ok, now I need a 4  to 10 character password ===> ");
  928.         portsinz(u_password, 10);
  929.         portsout(CRLF);
  930.         char_in_passwd = strlen(u_password);
  931.         if (char_in_passwd < 4) {
  932.             portsout("\n\rPassword was NOT changed!\n\r");
  933.             return;
  934.         }
  935.         pptr = strchr(u_password, '~');
  936.         if (pptr != NULL) {
  937.             portsout("\n\rInvalid password   try again!\n\r");
  938.             goto in_passx;
  939.         }
  940.         pptr = strchr(u_password, ' ');
  941.         if (pptr != NULL) {
  942.             portsout("\n\rInvalid password   try again!\n\r");
  943.             goto in_passx;
  944.         }
  945.         portsout("Just to make sure, enter it again ===> ");
  946.         portsinz(w_password, 10);
  947.         result = strlen(w_password);
  948.         if (result != char_in_passwd)
  949.             goto passwx_loop;
  950.         portsout(CRLF);
  951.  
  952.         if (strcmp(u_password, w_password) == 0) {
  953.             result = 10 - result;
  954.             while (result) {
  955.                 strcat(u_password, " ");
  956.                 result--;
  957.             }
  958.             break;    /* get it right twice, then get out */
  959.         }
  960. passwx_loop:
  961.         portsout(CRLF);
  962.         portsout("hmmmm, one of us forgot it already");
  963.         portsout(CRLF);
  964.         portsout("      let's try it again!!");
  965.         portsout(CRLF);
  966.         portsout(CRLF);
  967.     }
  968.     if ((inbuf = fopen(USERS, "r+")) == NULL) {
  969.         portsout("\n\rError opening users file!\n\r");
  970.         exit(1);
  971.     }
  972.     fds = fileno(inbuf);
  973.     rewind(inbuf);
  974.     locking(fds, LK_LOCK, 0L);
  975.     result = fseek(inbuf, save_d_pos, 0);
  976.     rewrtuser(inbuf);
  977.     rewind(inbuf);
  978.     locking(fds, LK_UNLCK, 0L);
  979.     fclose(inbuf);
  980. }
  981.  
  982. msg_section(mpk)
  983.     int             mpk;
  984. {
  985.     char            cmd[81];
  986.     char        tmp_cmd[80];
  987.     char        *cmd_ptr, *tmp_cmd_ptr;
  988.     int             result, tmp_number;
  989.     char           *file_ptr_x;
  990.     if (first_msg_in) {
  991.         result = atoi(l_m_base);
  992.         change_msga(result);
  993.         check_mail();
  994.     }
  995.     first_msg_in = FALSE;
  996. msg_looper:
  997.     signal(SIGALRM, timer);
  998.     signal(SIGHUP, hanged);
  999.     signal(SIGUSR1, mon_toggle);
  1000.     signal(SIGUSR2, sys_toggle);
  1001.     signal(SIGPIPE, chat);
  1002.     signal(SIGINT, STOP);
  1003.     stop_that = FALSE;
  1004.     cmd_t();
  1005.     portsout("\n\rCurrent message area = ");
  1006.     strcpy(buf128, m_pathname);
  1007.     file_ptr_x = strrchr(buf128, '/');
  1008.     *file_ptr_x = '\0';
  1009.     file_ptr_x = strrchr(buf128, '/');
  1010.     *file_ptr_x++;
  1011.     strcpy(who_am_i, file_ptr_x);
  1012.     portsout(who_am_i);
  1013.     portsout(CRLF);
  1014.     portsout(CRLF);
  1015.     bbsmenu(2,mpk);
  1016.     portsin_cmp(cmd, 80, "KkQqSsRrYyCcEeNnMmGgXxTt?");
  1017.     portsout(CRLF);
  1018.  
  1019.     if(cmd[0] != 'B' && cmd[0] != 'b')
  1020.         fix_name(cmd);
  1021.  
  1022.     switch (cmd[0]) {
  1023.     case ('E'):        /* enter msg */
  1024.         if (!privmsg(mpE))
  1025.             goto msg_looper;
  1026.         cmd_e();
  1027.         goto msg_looper;
  1028.     case ('N'):        /*Enter BLOCKED message */
  1029.         if(!privmsg(mpE))
  1030.             goto msg_looper;
  1031.         blocked_m = 1;
  1032.         cmd_e();
  1033.         blocked_m = 0;
  1034.         goto msg_looper;
  1035.     case ('G'):        /* goodby */
  1036.         if (!privmsg(mpG))
  1037.             goto msg_looper;
  1038.         cmd_c();
  1039.         break;
  1040.     case ('T'):
  1041.         if (!privmsg(mpT))
  1042.             goto msg_looper;
  1043.         toggle = !toggle;
  1044.         rewritx();
  1045.         if (toggle) {
  1046.             portsout("\n\rStop Mode\n\r");
  1047.         } else {
  1048.             portsout("\n\rContinuous Mode\n\r");
  1049.         }
  1050.         goto msg_looper;
  1051.     case ('X'):
  1052.         if (!privmsg(mpX))
  1053.             goto msg_looper;
  1054.         cmd_x();
  1055.         rewritx();
  1056.         goto msg_looper;
  1057.     case ('K'):
  1058.         if (!privmsg(mpk))
  1059.             goto msg_looper;
  1060.         cmd_k();
  1061.         goto msg_looper;
  1062.     case ('Q'):        /* quick scan */
  1063.         if (!privmsg(mpQ))
  1064.             goto msg_looper;
  1065.         cmd_q();
  1066.         goto msg_looper;
  1067.     case ('R'):        /* read msg */
  1068.         if (!privmsg(mpR))
  1069.             goto msg_looper;
  1070.         cmd_r();
  1071.         goto msg_looper;
  1072.     case ('B'):
  1073.     case ('b'):
  1074.         if(!privmsg(mpR))
  1075.             goto msg_looper;
  1076.         cmd_ptr = cmd;
  1077.         cmd_ptr++;
  1078.         tmp_number=strlen(cmd_ptr);
  1079.         if(!tmp_number)
  1080.             {
  1081.             portsout("\n\r\n\rNo messages selected in batch command!\n\r\n\r");
  1082.             goto msg_looper;
  1083.             }
  1084.         digit(cmd_ptr);
  1085.         while(*cmd_ptr)
  1086.             {
  1087.             tmp_cmd_ptr = tmp_cmd;
  1088.             if(*cmd_ptr == (char) ' ')
  1089.                 {
  1090.                 cmd_ptr++;
  1091.                 continue;
  1092.                 }
  1093.             while(*cmd_ptr != (char) ' ')
  1094.                 {
  1095.                 if(*cmd_ptr == (char) '\0')
  1096.                     break;
  1097.                 *tmp_cmd_ptr++ = *cmd_ptr++;
  1098.                 }
  1099.             *tmp_cmd_ptr = (char)'\0';
  1100.             read_number = atoi(tmp_cmd);
  1101.             read_flag = TRUE;
  1102.             cmd_r();
  1103.             read_flag = FALSE;
  1104.             portsout(CRLF);
  1105.             portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  1106.             jnk[0] = portin();
  1107.             if (jnk[0] == CTL_K || stop_that)
  1108.                 {
  1109.                 stop_that = FALSE;
  1110.                 goto msg_looper;
  1111.                 }
  1112.                 
  1113.             }
  1114.         goto msg_looper;
  1115.             
  1116.         
  1117.     case ('Y'):
  1118.         if (!privmsg(mpY))
  1119.             goto msg_looper;
  1120.         cmd_y();
  1121.         goto msg_looper;
  1122.     case ('S'):        /* scan msg */
  1123.         if (!privmsg(mpS))
  1124.             goto msg_looper;
  1125.         cmd_s();
  1126.         goto msg_looper;
  1127.     case ('C'):
  1128.         if (!privmsg(mpC))
  1129.             goto msg_looper;
  1130.         check_mail();
  1131.         goto msg_looper;
  1132.     case ('M'):
  1133.         break;
  1134.     case ('?'):        /* help */
  1135.         if (!privmsg(mpZ))
  1136.             goto msg_looper;
  1137.         cmd_p(HELPMSG);
  1138.         goto msg_looper;
  1139.     case ('A'):
  1140.         result = strlen(cmd);
  1141.         result--;
  1142.         if (!result)
  1143.             change_msga(0);
  1144.         else {
  1145.             substr(cmd, buf128, 2, result);
  1146.             digit(buf128);
  1147.             result = atoi(buf128);
  1148.             change_msga(result);
  1149.         }
  1150.         check_mail();
  1151.         goto msg_looper;
  1152.     default:
  1153.         goto msg_looper;
  1154.     }
  1155. }
  1156.  
  1157. privmsg(priv)
  1158.     int             priv;
  1159. {
  1160.     if (user_priv >= priv)
  1161.         return (TRUE);
  1162.     portsout("\n\rI'm sorry, your privilege level is not high enough to use that option.\n\r");
  1163.     return (FALSE);
  1164. }
  1165. cmd_c()
  1166. {                /* go to the operating system level */
  1167.     char            well[3];
  1168.     int             length;
  1169.     if (resp_flag) {
  1170.         portsout("\n\r\n\rAre you sure you want to exit? (Y/n): ");
  1171.         portsin(well, 1);
  1172.         portsout(CRLF);
  1173.         if (well[0] == 'N' || well[0] == 'n')
  1174.             return;
  1175.     }
  1176.     length = strlen(c_pathname);
  1177.     if (resp_flag && length > 0) {
  1178.         portsout(CRLF);
  1179.         strcpy(buf128, "Would you like to leave a private message for ");
  1180.         strcat(buf128, SYSOP);
  1181.         strcat(buf128, "? (y/N): ");
  1182.         portsout(buf128);
  1183.         portsin(well, 1);
  1184.         portsout(CRLF);
  1185.         if (well[0] == 'y' || well[0] == 'Y') {
  1186.             portsout("\n\rDo you wish to use blocked (right justified) format?  (y/N: ");
  1187.             portsin(well, 1);
  1188.             portsout(CRLF);
  1189.             if (well[0] == 'y' || well[0] == 'Y') 
  1190.                 blocked_m = 1;
  1191.             else
  1192.                 blocked_m = 0;
  1193.             strcpy(m_pathname, c_pathname);
  1194.             hdrread();
  1195.             reply_sw = TRUE;
  1196.             strcpy(msg_to, SYSOP);
  1197.             strcpy(msg_subject, "Departure Message");
  1198.             end_msg = TRUE;
  1199.             cmd_e();
  1200.             reply_sw = FALSE;
  1201.         }
  1202.     }
  1203.     if ((inbuf = fopen(SYSTEM, "r")) == NULL) {
  1204.         portsout("\n\rError opening system file!\n\r");
  1205.         exit(1);
  1206.     } else {
  1207.         no_cntrl_k = TRUE;
  1208.         porttype(inbuf);/* type a file to port */
  1209.         fclose(inbuf);
  1210.     }
  1211.     active = FALSE;
  1212. }
  1213. /* end of function               */
  1214. cmd_t()
  1215. {
  1216.     int             minutes, seconds;
  1217.     xsec = alarm(0);
  1218.     sec = xsec;
  1219.     alarm(sec);
  1220.     minutes = xsec / 60;
  1221.     seconds = xsec - (minutes * 60);
  1222.     portsout(CRLF);
  1223.     portsout("Time left = ");
  1224.     itoa(bufy, minutes);
  1225.     strcpy(bufx, bufy);
  1226.     strcat(bufx, " minutes and ");
  1227.     itoa(bufy, seconds);
  1228.     strcat(bufx, bufy);
  1229.     strcat(bufx, " seconds");
  1230.     portsout(bufx);
  1231.     portsout(CRLF);
  1232. }
  1233.  
  1234. cmd_tt(tt) int tt;
  1235. {
  1236.     int             minutes, seconds;
  1237.     long        tottime;
  1238.     tottime = difft();
  1239.     minutes = (int)tottime / 60L;
  1240.     seconds = (int)tottime - (long)(minutes * 60);
  1241.     itoa(bufy, minutes);
  1242.     strcpy(bufx, bufy);
  1243.     strcat(bufx, " minutes and ");
  1244.     itoa(bufy, seconds);
  1245.     strcat(bufx, bufy);
  1246.     strcat(bufx, " seconds");
  1247. }
  1248.  
  1249. int
  1250. timer()
  1251. {
  1252.     portsout(CRLF);
  1253.     if (which_timer == 1)
  1254.         portsout("Your login time limit has been reached!");
  1255.     if (which_timer == 2)
  1256.         portsout("Your usage time limit has been reached!");
  1257.     if (which_timer == 3)
  1258.         portsout("Your response time limit has been reached!");
  1259.     portsout(CRLF);
  1260.     restoremodes();
  1261.     portrst();        /* undo any special modes */
  1262.     closer(2);
  1263.     exit(1);
  1264. }
  1265. int
  1266. hanged()
  1267. {
  1268.     restoremodes();
  1269.     portrst();
  1270.     closer(3);
  1271.     exit(1);
  1272. }
  1273.  
  1274. closer(typeclose)
  1275. int typeclose;
  1276. {
  1277.     int result;
  1278.     if(typeclose == 2)
  1279.         cmd_tt(0);
  1280.     else
  1281.         cmd_tt(1);
  1282.     if ((inbuf = fopen(callers, "a")) == NULL)
  1283.         exit(1);
  1284.     result = fprintf(inbuf, "Time used on the system = %s\n",bufx);
  1285.     if (result < 0)
  1286.         exit(1);
  1287.     switch(typeclose) {
  1288.     case (1): fprintf(inbuf, "Normal exit .....\n");
  1289.             break;
  1290.     case (2): fprintf(inbuf, "Limit exit .....");
  1291.             switch (which_timer) {
  1292.             case(1): fprintf(inbuf, "logon\n");
  1293.                 break;
  1294.             case(2): fprintf(inbuf, "usage\n");
  1295.                 break;
  1296.             case(3): fprintf(inbuf, "response\n");
  1297.                 break;
  1298.             }
  1299.             break;
  1300.     case (3): fprintf(inbuf, "The user just hung up! .....\n");
  1301.             break;
  1302.     case (4): fprintf(inbuf, "The user forgot his password! .....\n");
  1303.             break;
  1304.     default:  fprintf(inbuf, "Ooooops .... This exit is not known! .....\n");
  1305.             break;
  1306.     }
  1307.  
  1308.     fprintf(inbuf,"\n\n");
  1309.     fclose(inbuf);
  1310. }
  1311. int
  1312. mon_toggle()
  1313. {
  1314.     signal(SIGUSR1, mon_toggle);
  1315.     if (!chat_in_progress)
  1316.         if_monitor = !if_monitor;
  1317.     else
  1318.         chat_in_progress = !chat_in_progress;
  1319. }
  1320. int
  1321. STOP()
  1322. {
  1323.     signal(SIGINT, STOP);
  1324.     stop_that = TRUE;
  1325. }
  1326. int
  1327. chat()
  1328. {
  1329.     FILE           *dev;
  1330.     int             result, handle;
  1331.     char            byte, byten, byter, bytes, device[30];
  1332.     signal(SIGPIPE, chat);
  1333.     byten = (char) '\n';
  1334.     byter = (char) '\r';
  1335.     bytes = (char) ' ';
  1336.     chat_in_progress = TRUE;
  1337.     stop_chat = TRUE;
  1338.     if (hold_pipe) {
  1339.         alarm(Sec);
  1340.         hold_pipe = FALSE;
  1341.     }
  1342.     Xsec = alarm(0);
  1343.     if ((dev = fopen(SYSTTY, "r")) == NULL) {
  1344.         portsout_chat("\n\rError finding sysop's device driver!\n\r");
  1345.         exit(1);
  1346.     }
  1347.     if ((fgets(device, 29, dev) == NULL)) {
  1348.         portsout_chat("\n\rError reading sysop's device driver name!\n\r");
  1349.         exit(1);
  1350.     }
  1351.     fclose(dev);
  1352.     strip(device);
  1353.     handle = open(device, O_WRONLY);
  1354.     if (handle == -1) {
  1355.         portsout_chat("\n\rError opening sysop's device driver!\n\r");
  1356.         exit(1);
  1357.     }
  1358.     portsout_chat(CRLF);
  1359.     portsout_chat(CRLF);
  1360.     portsout_chat(CRLF);
  1361.     portsout_chat("********** THE SYSOP HAS STARTED CHAT MODE ********");
  1362.     portsout_chat(CRLF);
  1363.     portsout_chat("*** Your usage time has stopped during the chat ***");
  1364.     portsout_chat(CRLF);
  1365.     portsout_chat(CRLF);
  1366.     portsout_chat(CRLF);
  1367.     while (chat_in_progress) {
  1368.         byte = portin_chat();
  1369.         if (byte == 127)
  1370.             byte = '\b';
  1371.         portout_chat(byte);
  1372.         if (byte == '\n')
  1373.             portout_chat(byter);
  1374.         if (byte == '\r')
  1375.             portout_chat(byten);
  1376.         write(handle, &byte, 1);
  1377.         if (byte == '\n')
  1378.             write(handle, &byter, 1);
  1379.         if (byte == '\r')
  1380.             write(handle, &byten, 1);
  1381.         if (byte == '\b') {
  1382.             write(handle, &bytes, 1);
  1383.             portout_chat(bytes);
  1384.             write(handle, &byte, 1);
  1385.             portout_chat(byte);
  1386.         }
  1387.     }
  1388.     close(handle);
  1389.     portsout_chat(CRLF);
  1390.     portsout_chat(CRLF);
  1391.     portsout_chat(CRLF);
  1392.     portsout_chat("********** THE SYSOP HAS STOPPED CHAT MODE **********");
  1393.     portsout_chat(CRLF);
  1394.     portsout_chat(CRLF);
  1395.     portsout_chat(CRLF);
  1396.     alarm(Xsec);
  1397. }
  1398.  
  1399. int
  1400. sys_toggle()
  1401. {
  1402.     signal(SIGUSR2, sys_toggle);
  1403.     if (!toggle_hold && hold_off) {
  1404.         toggle_hold = TRUE;
  1405.         return;
  1406.     }
  1407.     toggle_hold = FALSE;
  1408.     if (!sys_flag) {
  1409.         old_priv = user_priv;
  1410.         user_priv = max_priv;
  1411.         if (max_priv != MAXPRIV) {
  1412.             sprintf(buf128, "\n\rCompiler error max=%d  MAX=%d\n\r", max_priv, MAXPRIV);
  1413.             portsout(buf128);
  1414.             exit(1);
  1415.         }
  1416.         strcpy(old_upath, u_pathname);
  1417.         strcpy(old_fpath, f_pathname);
  1418.         strcpy(old_mpath, m_pathname);
  1419.         old_sec = alarm(0);
  1420.         alarm(MAXSEC);
  1421.     } else {
  1422.         user_priv = old_priv;
  1423.         strcpy(u_pathname, old_upath);
  1424.         strcpy(f_pathname, old_fpath);
  1425.         strcpy(m_pathname, old_mpath);
  1426.         if (!first_msg_in)
  1427.             hdrread();
  1428.         delta_time = old_sec;
  1429.         delta_time = delta_time - (MAXSEC - alarm(0));
  1430.         if (delta_time < 0L || delta_time > 32767L)
  1431.             delta_time = 5L;
  1432.         sec = delta_time;
  1433.         alarm(sec);
  1434.     }
  1435.     sys_flag = !sys_flag;
  1436. }
  1437. cmd_f()
  1438. {
  1439.     char            choice[6];
  1440.     char           *file_ptr_x;
  1441.     long            bytes_left;
  1442.     int             result;
  1443.     listed_l = FALSE;
  1444.     listed_r = FALSE;
  1445.     listed_n = FALSE;
  1446.     if (first_time_in) {
  1447.         result = atoi(l_f_base);
  1448.         change_area(result);
  1449.     }
  1450.     first_time_in = FALSE;
  1451. ffile:
  1452.     portsout(CRLF);
  1453.     portsout(CRLF);
  1454.     signal(SIGALRM, timer);
  1455.     signal(SIGHUP, hanged);
  1456.     signal(SIGUSR1, mon_toggle);
  1457.     signal(SIGUSR2, sys_toggle);
  1458.     signal(SIGPIPE, chat);
  1459.     signal(SIGINT, STOP);
  1460.     cmd_t();
  1461.     portsout("\n\rCurrent download area = ");
  1462.     strcpy(buf128, f_pathname);
  1463.     file_ptr_x = strrchr(buf128, '/');
  1464.     *file_ptr_x = '\0';
  1465.     file_ptr_x = strrchr(buf128, '/');
  1466.     *file_ptr_x++;
  1467.     strcpy(who_am_i, file_ptr_x);
  1468.     portsout(who_am_i);
  1469.     portsout("\n\rCurrent upload area = ");
  1470.     strcpy(buf128, u_pathname);
  1471.     file_ptr_x = strrchr(buf128, '/');
  1472.     *file_ptr_x = '\0';
  1473.     file_ptr_x = strrchr(buf128, '/');
  1474.     *file_ptr_x++;
  1475.     strcpy(who_am_i, file_ptr_x);
  1476.     portsout(who_am_i);
  1477.     portsout(CRLF);
  1478.     bytes_left = max_dload - dload_total;
  1479.     strcpy(buf128, "Allowable daily download limit = ");
  1480.     sprintf(who_am_i, "%ld", bytes_left);
  1481.     strcat(buf128, who_am_i);
  1482.     strcat(buf128, " bytes\n\r");
  1483.     portsout(buf128);
  1484.     stop_that = FALSE;
  1485.     bbsmenu(3,0);
  1486.     portsin_cmp(choice, 5, "FfLlUuDdMmXxTtGgCcRrNnSsZz?");
  1487.     portsout(CRLF);
  1488.     fix_name(choice);
  1489.     switch (choice[0]) {
  1490.     case ('S'):
  1491.         if (!privmsg(fpL))
  1492.             goto ffile;
  1493.         summary();
  1494.         goto ffile;
  1495.     case ('L'):
  1496.         if (!privmsg(fpL))
  1497.             goto ffile;
  1498.         listed_r = FALSE;
  1499.         listed_n = FALSE;
  1500.         listed_l = FALSE;
  1501.         file_loc( NULL );
  1502.         goto ffile;
  1503.     case ('F'):
  1504.         if (!privmsg(fpL))
  1505.             goto ffile;
  1506.         listed_r = FALSE;
  1507.         listed_n = FALSE;
  1508.         file_l();
  1509.         listed_l = TRUE;
  1510.         goto ffile;
  1511.     case ('N'):
  1512.         if (!privmsg(fpL))
  1513.             goto ffile;
  1514.         listed_r = FALSE;
  1515.         listed_l = FALSE;
  1516.         file_n();
  1517.         listed_n = TRUE;
  1518.         goto ffile;
  1519.     case ('Z'):
  1520.         if (!privmsg(fpL))
  1521.             goto ffile;
  1522.         listed_r = FALSE;
  1523.         listed_l = FALSE;
  1524.         listed_n = FALSE;
  1525.         allnew();
  1526.         goto ffile;
  1527.     case ('?'):        /* help */
  1528.         if (!privmsg(mpZ))
  1529.             goto ffile;
  1530.         cmd_p(HELPFILE);
  1531.         goto ffile;
  1532.     case ('R'):
  1533.         if (!privmsg(fpR))
  1534.             goto ffile;
  1535.         listed_l = FALSE;
  1536.         listed_n = FALSE;
  1537.         file_r();
  1538.         listed_r = TRUE;
  1539.         goto ffile;
  1540.     case ('C'):
  1541.         if (!privmsg(fpL))
  1542.             goto ffile;
  1543.         listed_l = FALSE;
  1544.         listed_r = FALSE;
  1545.         listed_n = FALSE;
  1546.         file_c();
  1547.         goto ffile;
  1548.     case ('T'):
  1549.         if (!privmsg(mpT))
  1550.             goto ffile;
  1551.         toggle = !toggle;
  1552.         rewritx();
  1553.         if (toggle) {
  1554.             portsout("\n\rStop Mode\n\r");
  1555.         } else {
  1556.             portsout("\n\rContinuous Mode\n\r");
  1557.         }
  1558.         goto ffile;
  1559.     case ('A'):
  1560.         result = strlen(choice);
  1561.         result--;
  1562.         if (!result)
  1563.             change_area(0);
  1564.         else {
  1565.             substr(choice, buf128, 2, result);
  1566.             digit(buf128);
  1567.             result = atoi(buf128);
  1568.             change_area(result);
  1569.         }
  1570.         listed_r = FALSE;
  1571.         listed_l = FALSE;
  1572.         listed_n = FALSE;
  1573.         goto ffile;
  1574.     case ('X'):
  1575.         if (!privmsg(mpX))
  1576.             goto ffile;
  1577.         cmd_x();
  1578.         rewritx();
  1579.         goto ffile;
  1580.     case ('U'):
  1581.         if (!privmsg(fpU))
  1582.             goto ffile;
  1583.         file_u();
  1584.         listed_r = FALSE;
  1585.         listed_l = FALSE;
  1586.         listed_n = FALSE;
  1587.         goto ffile;
  1588.     case ('D'):
  1589.         if (!privmsg(fpD))
  1590.             goto ffile;
  1591.         file_d();
  1592.         goto ffile;
  1593.     case ('M'):
  1594.         if (!privmsg(fpM))
  1595.             goto ffile;
  1596.         listed_l = FALSE;
  1597.         listed_r = FALSE;
  1598.         listed_n = FALSE;
  1599.         break;
  1600.     case ('G'):
  1601.         if (!privmsg(fpG))
  1602.             goto ffile;
  1603.         cmd_c();
  1604.         break;
  1605.     default:
  1606.         goto ffile;
  1607.     }
  1608. }
  1609. file_c()
  1610. {
  1611.     int             result, zcat;
  1612.     char           *ptr, temp[16];
  1613.     zcat = 0;
  1614.     portsout("\n\r\n\rArchive Contents Listing Option for .tar(.Z), .zip  or .arc files\n\r\n\r");
  1615.     portsout("Input archive file name to list ====> ");
  1616.     portsin(x_filename, 15);
  1617.     portsout(CRLF);
  1618.     if (strlen(x_filename) < 1)
  1619.         return;
  1620.     strcpy(x_pathandfile, f_pathname);
  1621.     strcat(x_pathandfile, x_filename);
  1622.     ptr = strrchr(x_pathandfile, '.');
  1623.     if (ptr == NULL) {
  1624.         portsout("\n\rImproper file extension\n\r");
  1625.         return;
  1626.     }
  1627.     *ptr++;
  1628.     strcpy(temp, ptr);
  1629.     if (strcmp(temp, "Z") == 0) {
  1630.         zcat = 1;
  1631.         strcpy(buf128, x_pathandfile);
  1632.         ptr = strrchr(buf128, '.');
  1633.         if (ptr == NULL) {
  1634.             portsout("\n\rImproper file extension\n\r");
  1635.             return;
  1636.         }
  1637.         *ptr = '\0';
  1638.         ptr = strrchr(buf128, '.');
  1639.         if (ptr == NULL) {
  1640.             portsout("\n\rImproper file extension\n\r");
  1641.             return;
  1642.         }
  1643.         *ptr++;
  1644.         strcpy(temp, ptr);
  1645.     }
  1646.     if ((strcmp(temp, "arc") == 0) || (strcmp(temp, "ARC") == 0) || (strcmp(temp, "tar") == 0) || (strcmp(temp,"zip") == 0) || (strcmp(temp,"ZIP") ==0)) {
  1647.         result = stat(x_pathandfile, &statbuf);
  1648.         if (result != 0) {
  1649.             portsout("\n\r\n\rThe requested file was not found!\n\r\n\r");
  1650.             return;
  1651.         }
  1652.         if ((strcmp(temp, "arc") == 0 || strcmp(temp, "ARC") == 0)) {
  1653.             listarc(x_pathandfile, port_id);
  1654. /*
  1655.             strcpy(buf128, ARC);
  1656.             strcat(buf128, x_pathandfile);
  1657.             strcat(buf128, " > ");
  1658.             strcat(buf128, TMPFILE);
  1659.             strcat(buf128, port_id);
  1660.             (void) system(buf128);
  1661. */
  1662.  
  1663.             strcpy(buf128, "/tmp/arclst.");
  1664.             strcat(buf128, port_id);
  1665.  
  1666.             portsout("\n\r\n\r");
  1667. /*
  1668.             strcpy(buf128, TMPFILE);
  1669.             strcat(buf128, port_id);
  1670. */
  1671.             cmd_p(buf128);
  1672.             portsout("\n\r\n\r");
  1673.             return;
  1674.         }
  1675.         if ((strcmp(temp, "zip") == 0 || strcmp(temp, "ZIP") == 0)) {
  1676.  
  1677.             listzip( x_pathandfile, port_id);
  1678. /*
  1679.             strcpy(buf128, ZIP);
  1680.             strcat(buf128, x_pathandfile);
  1681.             strcat(buf128, " > ");
  1682.             strcat(buf128, TMPFILE);
  1683.             strcat(buf128, port_id);
  1684.             (void) system(buf128);
  1685. */
  1686.  
  1687.             strcpy(buf128, "/tmp/ziplst.");
  1688.             strcat(buf128, port_id);
  1689.  
  1690.             portsout("\n\r\n\r");
  1691. /*
  1692.             strcpy(buf128, TMPFILE);
  1693.             strcat(buf128, port_id);
  1694. */
  1695.             cmd_p(buf128);
  1696.             portsout("\n\r\n\r");
  1697.             return;
  1698.         }
  1699.         if (strcmp(temp, "tar") == 0) {
  1700.             if (!zcat) {
  1701.                 strcpy(buf128, TAR);
  1702.                 strcat(buf128, x_pathandfile);
  1703.             } else {
  1704.                 strcpy(buf128, ZCAT);
  1705.                 strcat(buf128, x_pathandfile);
  1706.                 strcat(buf128, " | ");
  1707.                 strcat(buf128, TAR);
  1708.                 strcat(buf128, "-");
  1709.             }
  1710.  
  1711.             strcat(buf128, " > ");
  1712.             strcat(buf128, TMPFILE);
  1713.             strcat(buf128, port_id);
  1714.             portsout("\n\rOne moment please ....");
  1715.             (void) system(buf128);
  1716.             portsout("\n\r\n\r");
  1717.             strcpy(buf128, TMPFILE);
  1718.             strcat(buf128, port_id);
  1719.             cmd_p(buf128);
  1720.             portsout("\n\r\n\r");
  1721.             return;
  1722.         }
  1723.     }
  1724.     portsout("\n\r\n\rIllegal file extension!\n\r\n\r");
  1725. }
  1726. file_r()
  1727. {
  1728.     int             result;
  1729.     if (!listed_r) {
  1730.         portsout("\n\rOne moment please ....");
  1731.         strcpy(buf128, "ls -l ");
  1732.         strcat(buf128, f_pathname);
  1733.         strcat(buf128, " > ");
  1734.         strcat(buf128, TMPFILE);
  1735.         strcat(buf128, port_id);
  1736.         (void) system(buf128);
  1737.     }
  1738.     portsout("\n\r\n\r");
  1739.     strcpy(buf128, TMPFILE);
  1740.     strcat(buf128, port_id);
  1741.     cmd_p(buf128);
  1742.     portsout("\n\r\n\r");
  1743. }
  1744. msgck()
  1745. {
  1746.     portsout("A control-k will terminate the listing\n");
  1747. }
  1748. file_l()
  1749. {
  1750.     int             result;
  1751.     int             zz;
  1752.     char            timeptr[30];
  1753.     char           *fileptr;
  1754.     int             lnctx, xp;
  1755.     lnctx = 1;
  1756.     if (xpert)
  1757.         xp = 10;
  1758.     else
  1759.         xp = 5;
  1760.     xyy = atol(yy);
  1761.     strcpy(buf128, f_pathname);
  1762.     strcat(buf128, FILES);
  1763.     if ((rdstatbuf = fopen(buf128, "r")) == NULL) {
  1764.         portsout("\n\rThe are NO files available!\n\r");
  1765.         return;
  1766.     }
  1767.     msgck();
  1768.     portsout(CRLF);
  1769.     strcpy(buf128, TMPFILE);
  1770.     strcat(buf128, port_id);
  1771.     while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  1772.         zz = 0;
  1773.         if (x_filename[0] == '~') {
  1774.             goto finis;    /* Special case so that that
  1775.                      * following files are not displayed
  1776.                      * - can be used to disallow uploads
  1777.                      * from being shown until they are
  1778.                      * validated. */
  1779.         }
  1780.         if (x_filename[0] == '+') {
  1781.             fileptr = x_filename + 1;
  1782.             strcpy(work_msg, fileptr);
  1783.             (void) fgets(buf128, 80, rdstatbuf);
  1784.             strcat(work_msg, buf128);
  1785.             strip(work_msg);
  1786.             goto arond;
  1787.         }
  1788.         if (x_filename[0] == '.') {
  1789.             strcpy(x_filename, "   ");
  1790.             strcpy(who_am_i, "   ");
  1791.             strcpy(who_am_I, "   ");
  1792.             zz++;
  1793.         }
  1794.         if (result = fgets(buf128, 55, rdstatbuf) == NULL) {
  1795.             if (!zz)
  1796.                 strcpy(buf128, " ***** No description on file *****");
  1797.         }
  1798.         strip(buf128);
  1799.         if (!zz)
  1800.             term_space(buf128);
  1801.         result = strlen(buf128);
  1802.         if (result == 0) {
  1803.             if (!zz)
  1804.                 strcpy(buf128, " ***** No description on file *****");
  1805.         }
  1806.         if (!zz) {
  1807.             strcpy(x_pathandfile, f_pathname);
  1808.             strcat(x_pathandfile, x_filename);
  1809.             result = stat(x_pathandfile, &statbuf);
  1810.             if (result != 0) {
  1811.                 strcpy(who_am_i, "OFFLINE");
  1812.                 strcpy(who_am_I, "    ");
  1813.                 goto around;
  1814.             }
  1815.             xmm = statbuf.st_size;
  1816.             sprintf(who_am_i, "%6ld", xmm);
  1817.             xmm = statbuf.st_mtime;
  1818.             strcpy(timeptr, ctime(&xmm));
  1819.             substr(timeptr, bufx, 5, 6);
  1820.             substr(timeptr, z_dd, 23, 2);
  1821.             xmm = atol(z_dd);
  1822.             if (xyy > xmm) {
  1823.                 substr(timeptr, bufx, 5, 3);
  1824.                 strcat(bufx, "-");
  1825.                 strcat(bufx, z_dd);
  1826.             }
  1827.             strcpy(who_am_I, bufx);
  1828.         }
  1829. around:
  1830.         sprintf(work_msg, "%-15s%-7s%-6s%-50s", x_filename, who_am_i, who_am_I, buf128);
  1831. arond:
  1832.         strip(work_msg);
  1833.         term_space(work_msg);
  1834.  
  1835.         sprintf(buf128, "%s\n\r", work_msg);
  1836.         portsout(buf128);
  1837.         if (stop_that) {
  1838.             fclose(rdstatbuf);
  1839.             stop_that = FALSE;
  1840.             return;
  1841.         }
  1842.         if (toggle) {
  1843.             lnctx++;
  1844.             if (lnctx == 23) {
  1845.                 portsout(CRLF);
  1846.                 portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  1847.                 jnk[0] = portin();
  1848.                 if (jnk[0] == CTL_K || stop_that) {
  1849.                     stop_that = FALSE;
  1850.                     fclose(rdstatbuf);
  1851.                     return;
  1852.                 }
  1853.                 portsout(CRLF);
  1854.                 lnctx = 1;
  1855.             }
  1856.         }
  1857.     }
  1858. finis:
  1859.     fclose(rdstatbuf);
  1860. finisl:
  1861.     if (toggle && lnctx > xp) {
  1862.         portsout(CRLF);
  1863.         portsout("*** Depress a key to continue ........ ");
  1864.         jnk[0] = portin();
  1865.         portsout(CRLF);
  1866.     }
  1867.     portsout(CRLF);
  1868.     portsout(CRLF);
  1869. }
  1870.