home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / XBBS7200.ZIP / XBBS7200.TAR / bbsc1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-15  |  81.6 KB  |  3,671 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. file_loc( strg )
  1871. char *strg;
  1872. {
  1873.     int             result;
  1874.     int             i;
  1875.     int             zz;
  1876.     int             outok;
  1877.     int             len_in, len_file, times;
  1878.     long            foo;
  1879.     char            timeptr[30];
  1880.     char           *fileptr;
  1881.     char            temp[15];
  1882.     char            string_loc[20];
  1883.     int             lnctx, xp;
  1884.     
  1885.     if (xpert)
  1886.         xp = 10;
  1887.     else
  1888.         xp = 5;
  1889.  
  1890.  
  1891.     lnctx = 1;
  1892.     substr(z_date, z_mm, 1, 2);
  1893.     substr(z_date, z_dd, 4, 2);
  1894.     substr(z_date, z_yy, 7, 2);
  1895.     xmm = atol(z_mm);
  1896.     xdd = atol(z_dd);
  1897.     xyy = atol(z_yy);
  1898.     foo = atol(yy);
  1899.     outok = FALSE;
  1900.     old_long_date = (xyy * 10000L) + (xmm * 100L) + xdd;
  1901.     if( strg == NULL) {
  1902.         portsout("\n\r\n\rInput file name substring (max 14 characters): ");
  1903.         portsin(string_loc, 14);
  1904.         portsout(CRLF);
  1905.         fileptr = strchr(string_loc, '*');
  1906.         if( fileptr != NULL ) {
  1907.             portsout("\n\rDo not use an asterisk as part of the string.\n\r\n\r");
  1908.             return;
  1909.         }
  1910.     } else {
  1911.         strcpy(string_loc, strg );
  1912.     }
  1913.     len_in = strlen(string_loc);
  1914.     if (!len_in)
  1915.         return;
  1916.     strcpy(buf128, f_pathname);
  1917.     strcat(buf128, FILES);
  1918.     if ((rdstatbuf = fopen(buf128, "r")) == NULL) {
  1919.         portsout("\n\rThe are NO files available!\n\r");
  1920.         return;
  1921.     }
  1922.     msgck();
  1923.     portsout("\n\rSearching for a comparison\n\r\n\r");
  1924.     while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  1925.         zz = 0;
  1926.         if (x_filename[0] == '~') {
  1927.             goto finisx;    /* Special case so that that
  1928.                      * following files are not displayed
  1929.                      * - can be used to disallow uploads
  1930.                      * from being shown until they are
  1931.                      * validated. */
  1932.         }
  1933.         if (x_filename[0] == '+') {
  1934.             fileptr = x_filename + 1;
  1935.             strcpy(work_msg, fileptr);
  1936.             (void) fgets(buf128, 80, rdstatbuf);
  1937.             goto xend;
  1938.         }
  1939.         if (x_filename[0] == '.') {
  1940.             strcpy(x_filename, "   ");
  1941.             strcpy(who_am_i, "   ");
  1942.             strcpy(who_am_I, "   ");
  1943.             zz++;
  1944.         }
  1945.         if (result = fgets(buf128, 55, rdstatbuf) == NULL) {
  1946.             if (!zz)
  1947.                 strcpy(buf128, " ***** No description on file *****");
  1948.         }
  1949.         strip(buf128);
  1950.         if (!zz)
  1951.             term_space(buf128);
  1952.         result = strlen(buf128);
  1953.         if (result == 0) {
  1954.             if (!zz)
  1955.                 strcpy(buf128, " ***** No description on file *****");
  1956.         }
  1957.         if (!zz) {
  1958.             len_file = strlen(x_filename);
  1959.             if (len_file < len_in) {
  1960.                 outok = FALSE;
  1961.                 goto xend;
  1962.             }
  1963.             strcpy(x_pathandfile, f_pathname);
  1964.             strcat(x_pathandfile, x_filename);
  1965.             result = stat(x_pathandfile, &statbuf);
  1966.             if (result != 0) {
  1967.                 strcpy(who_am_i, "OFFLINE");
  1968.                 strcpy(who_am_I, "    ");
  1969.                 outok = FALSE;
  1970.                 goto xend;
  1971.             }
  1972.             xmm = statbuf.st_size;
  1973.             sprintf(who_am_i, "%6ld", xmm);
  1974.             xmm = statbuf.st_mtime;
  1975.             strcpy(timeptr, ctime(&xmm));
  1976.             substr(timeptr, bufx, 5, 6);
  1977.             strcpy(who_am_I, bufx);
  1978.             substr(timeptr, bufx, 5, 3);
  1979.             substr(timeptr, z_dd, 9, 2);
  1980.             substr(timeptr, z_yy, 23, 2);
  1981.             xdd = atol(z_dd);
  1982.             xyy = atol(z_yy);
  1983.             if (foo > xyy) {
  1984.                 strcpy(who_am_I, bufx);
  1985.                 strcat(who_am_I, "-");
  1986.                 strcat(who_am_I, z_yy);
  1987.             }
  1988.             times = len_file - len_in + 1;
  1989.             outok = FALSE;
  1990.             for (result = 1; result <= times; result++) {
  1991.                 substr(x_filename, temp, result, len_in);
  1992.                 if (strcmp(temp, string_loc) == 0) {
  1993.                     outok = TRUE;
  1994.                     break;
  1995.                 }
  1996.             }
  1997.         }
  1998.         if (!outok)
  1999.             goto xend;
  2000.         sprintf(work_msg, "%-15s%-7s%-6s%-50s", x_filename, who_am_i, who_am_I, buf128);
  2001.         strip(work_msg);
  2002.         term_space(work_msg);
  2003.  
  2004.         sprintf(buf128, "%s\n\r", work_msg);
  2005.         portsout(buf128);
  2006.         if (stop_that) {
  2007.             fclose(rdstatbuf);
  2008.             stop_that = FALSE;
  2009.             return;
  2010.         }
  2011.         if (toggle) {
  2012.             lnctx++;
  2013.             if (lnctx == 23) {
  2014.                 portsout(CRLF);
  2015.                 portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  2016.                 jnk[0] = portin();
  2017.                 if (jnk[0] == CTL_K || stop_that) {
  2018.                     stop_that = FALSE;
  2019.                     fclose(rdstatbuf);
  2020.                     return;
  2021.                 }
  2022.                 portsout(CRLF);
  2023.                 lnctx = 1;
  2024.             }
  2025.         }
  2026. xend:
  2027.         ;
  2028.     }
  2029. finisx:
  2030.     fclose(rdstatbuf);
  2031.     if (toggle && lnctx > xp) {
  2032.         portsout(CRLF);
  2033.         portsout("*** Depress a key to continue ........ ");
  2034.         jnk[0] = portin();
  2035.         portsout(CRLF);
  2036.     }
  2037.     portsout(CRLF);
  2038.     portsout(CRLF);
  2039. }
  2040. file_n()
  2041. {
  2042.     int             result;
  2043.     int             i;
  2044.     int             zz;
  2045.     int             outok;
  2046.     long            foo;
  2047.     char            timeptr[30];
  2048.     char           *fileptr;
  2049.     int             lnctx, xp;
  2050.     static char    *dates[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  2051.                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",};
  2052.     substr(z_date, z_mm, 1, 2);
  2053.     substr(z_date, z_dd, 4, 2);
  2054.     substr(z_date, z_yy, 7, 2);
  2055.     lnctx = 1;
  2056.     if (xpert)
  2057.         xp = 10;
  2058.     else
  2059.         xp = 5;
  2060.     xmm = atol(z_mm);
  2061.     xdd = atol(z_dd);
  2062.     xyy = atol(z_yy);
  2063.     foo = atol(yy);
  2064.     outok = FALSE;
  2065.     old_long_date = (xyy * 10000L) + (xmm * 100L) + xdd;
  2066.     strcpy(buf128, f_pathname);
  2067.     strcat(buf128, FILES);
  2068.     if ((rdstatbuf = fopen(buf128, "r")) == NULL) {
  2069.         portsout("\n\rThe are NO files available!\n\r");
  2070.         return;
  2071.     }
  2072.     strcpy(buf128, TMPFILE);
  2073.     strcat(buf128, port_id);
  2074.     msgck();
  2075.     portsout("\n\rStarting the new file search.\n\r\n\r");
  2076.     while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  2077.         zz = 0;
  2078.         if (x_filename[0] == '~') {
  2079.             goto finisn;    /* Special case so that that
  2080.                      * following files are not displayed
  2081.                      * - can be used to disallow uploads
  2082.                      * from being shown until they are
  2083.                      * validated. */
  2084.         }
  2085.         if (x_filename[0] == '+') {
  2086.             fileptr = x_filename + 1;
  2087.             strcpy(work_msg, fileptr);
  2088.             (void) fgets(buf128, 80, rdstatbuf);
  2089.             goto nend;
  2090.         }
  2091.         if (x_filename[0] == '.') {
  2092.             strcpy(x_filename, "   ");
  2093.             strcpy(who_am_i, "   ");
  2094.             strcpy(who_am_I, "   ");
  2095.             zz++;
  2096.         }
  2097.         if (result = fgets(buf128, 55, rdstatbuf) == NULL) {
  2098.             if (!zz)
  2099.                 strcpy(buf128, " ***** No description on file *****");
  2100.         }
  2101.         strip(buf128);
  2102.         if (!zz)
  2103.             term_space(buf128);
  2104.         result = strlen(buf128);
  2105.         if (result == 0) {
  2106.             if (!zz)
  2107.                 strcpy(buf128, " ***** No description on file *****");
  2108.         }
  2109.         if (!zz) {
  2110.             strcpy(x_pathandfile, f_pathname);
  2111.             strcat(x_pathandfile, x_filename);
  2112.             result = stat(x_pathandfile, &statbuf);
  2113.             if (result != 0) {
  2114.                 strcpy(who_am_i, "OFFLINE");
  2115.                 strcpy(who_am_I, "    ");
  2116.                 outok = FALSE;
  2117.                 goto nend;
  2118.             }
  2119.             xmm = statbuf.st_size;
  2120.             sprintf(who_am_i, "%6ld", xmm);
  2121.             xmm = statbuf.st_mtime;
  2122.             strcpy(timeptr, ctime(&xmm));
  2123.             substr(timeptr, bufx, 5, 6);
  2124.             strcpy(who_am_I, bufx);
  2125.             substr(timeptr, bufx, 5, 3);
  2126.             substr(timeptr, z_dd, 9, 2);
  2127.             substr(timeptr, z_yy, 23, 2);
  2128.             xdd = atol(z_dd);
  2129.             xyy = atol(z_yy);
  2130.             if (foo > xyy) {
  2131.                 strcpy(who_am_I, bufx);
  2132.                 strcat(who_am_I, "-");
  2133.                 strcat(who_am_I, z_yy);
  2134.             }
  2135.             for (result = 0; result < 12; result++) {
  2136.                 i = strcmp(bufx, dates[result]);
  2137.                 if (!i) {
  2138.                     xmm = (long) result + 1;
  2139.                     new_long_date = (xyy * 10000L) + (xmm * 100L) + xdd;
  2140.                     if (new_long_date < old_long_date) {
  2141.                         outok = FALSE;
  2142.                         goto nend;
  2143.                     }
  2144.                     outok = TRUE;
  2145.                     break;
  2146.                 }
  2147.             }
  2148.  
  2149.         }
  2150.         if (!outok)
  2151.             goto nend;
  2152. aroundn:
  2153.         sprintf(work_msg, "%-15s%-7s%-6s%-50s", x_filename, who_am_i, who_am_I, buf128);
  2154. arondn:
  2155.         strip(work_msg);
  2156.         term_space(work_msg);
  2157.  
  2158.         sprintf(buf128, "%s\n\r", work_msg);
  2159.         portsout(buf128);
  2160.         if (stop_that) {
  2161.             fclose(rdstatbuf);
  2162.             stop_that = FALSE;
  2163.             return;
  2164.         }
  2165.         if (toggle) {
  2166.             lnctx++;
  2167.             if (lnctx == 23) {
  2168.                 portsout(CRLF);
  2169.                 portsout("*** Depress a key to continue ( control-k to quit ) ........ ");
  2170.                 jnk[0] = portin();
  2171.                 if (jnk[0] == CTL_K || stop_that) {
  2172.                     stop_that = FALSE;
  2173.                     fclose(rdstatbuf);
  2174.                     return;
  2175.                 }
  2176.                 portsout(CRLF);
  2177.                 lnctx = 1;
  2178.             }
  2179.         }
  2180. nend:
  2181.         ;
  2182.     }
  2183. finisn:
  2184.     fclose(rdstatbuf);
  2185. finisln:
  2186.     if (toggle && lnctx > xp) {
  2187.         portsout(CRLF);
  2188.         portsout("*** Depress a key to continue ........ ");
  2189.         jnk[0] = portin();
  2190.         portsout(CRLF);
  2191.     }
  2192.     portsout(CRLF);
  2193.     portsout(CRLF);
  2194. }
  2195. file_u()
  2196. {
  2197.     char            choic1[2], *str_result;
  2198.     FILE           *storbuff;
  2199.     int             result, tryit, tryit1, code;
  2200. fileu:
  2201.     tryit = FALSE;
  2202.     tryit1 = FALSE;
  2203.     if_kermit = 0;
  2204.     portsout("\n\rYour usage time will be STOPPED during uploads and \n\r");
  2205.     portsout("the size of the file(s) will be added to your limit.\n\r");
  2206.     portsout(CRLF);
  2207.     portsout("Input filename for upload:  ");
  2208.     portsin(x_filename, 15);
  2209.     if (strlen(x_filename) < 1)
  2210.         return;
  2211.     if (x_filename[0] == '.' || x_filename[0] == '/' || x_filename[0] == ' ') {
  2212.         portsout("\n\r\n\rIllegal Filename!\n\r");
  2213.         return;
  2214.     }
  2215.     code = strlen(x_filename);
  2216.     code--;
  2217.     if (x_filename[code] == '.' || x_filename[code] == '/' || x_filename[code] == ' ') {
  2218.         portsout("\n\r\n\rIllegal Filename! \n\r");
  2219.         return;
  2220.     }
  2221.     code = strcmp(x_filename, "files.bbs");
  2222.     if (code == 0) {
  2223.         portsout("\n\r\n\rIllegal Filename! \n\r");
  2224.         return;
  2225.     }
  2226.     code = legalname("|`><!;:", x_filename);
  2227.     if (code == 0) {
  2228.         portsout("\n\r\n\rIllegal Filename! \n\r");
  2229.         return;
  2230.     }
  2231.     portsout(CRLF);
  2232.     str_result = strchr(x_filename, '*');
  2233.     if (str_result != NULL)
  2234.         tryit = TRUE;
  2235.     strcpy(x_pathandfile, u_pathname);
  2236.     strcat(x_pathandfile, x_filename);
  2237.     if (!tryit) {
  2238.         result = stat(x_pathandfile, &statbuf);
  2239.         if (result == 0) {
  2240.             portsout("That file already exists!\n\r");
  2241.             return;
  2242.         }
  2243.     }
  2244.     portsout(CRLF);
  2245.     if ( tryit ) {
  2246.         portsout("Options: K(ermit),  B(atch ymodem),  Z(modem),\n\r\n\r");
  2247.         portsout("Commands: K,B,Z  ===> ");
  2248.     }
  2249.     else {
  2250.         portsout("Options: X(modem), C(rc xmodem), B(atch ymodem), Y(modem), Z(modem),\n\r");
  2251.         portsout("         K(ermit), S(EAlink),    A(scii)\n\r\n\r");
  2252.         portsout("Commands: X,C,B,Y,Z,K,S,A  ===> ");
  2253.     }
  2254.     portsin(choic1, 1);
  2255.     portsout(CRLF);
  2256.     *choic1 = toupper(*choic1);
  2257.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  2258.                              * append */
  2259.         portsout(CRLF);
  2260.         portsout("Can't open/create callers file!");
  2261.         portsout(CRLF);
  2262.         return;
  2263.     }
  2264.     code = fprintf(inbuf, "%s %s  ", "   UPLOAD  ", x_filename);
  2265.     if (code < 0) {
  2266.         portsout(CRLF);
  2267.         portsout("Caller file has problem writing");
  2268.         portsout(CRLF);
  2269.     } 
  2270.     fclose(inbuf);
  2271.     if (choic1[0] == 'K' || choic1[0] == 'B' || choic1[0] == 'Z')
  2272.         tryit1 = TRUE;
  2273.     if (tryit && !tryit1) {
  2274.         portsout("\n\rIllegal use of wildcards - Must be KERMIT, YMODEM BATCH, or ZMODEM\n\r");
  2275.         typexfr(11);
  2276.         return;
  2277.     }
  2278.     switch (choic1[0]) {
  2279.     case ('X'):
  2280.         strcpy(x_pathandfile, RB);
  2281.         strcat(x_pathandfile, u_pathname);
  2282.         strcat(x_pathandfile, x_filename);
  2283.         typexfr(5);
  2284.         uploadtime();
  2285.         result = system(x_pathandfile);
  2286.         restoresig();
  2287.         updatef();
  2288.         enabletime();
  2289.         break;
  2290.     case ('Y'):
  2291.         strcpy(x_pathandfile, YMDR);
  2292.         strcat(x_pathandfile, u_pathname);
  2293.         strcat(x_pathandfile, x_filename);
  2294.         typexfr(3);
  2295.         uploadtime();
  2296.         result = system(x_pathandfile);
  2297.         restoresig();
  2298.         updatef();
  2299.         enabletime();
  2300.         break;
  2301.     case ('C'):
  2302.         strcpy(x_pathandfile, CRCR);
  2303.         strcat(x_pathandfile, u_pathname);
  2304.         strcat(x_pathandfile, x_filename);
  2305.         typexfr(4);
  2306.         uploadtime();
  2307.         result = system(x_pathandfile);
  2308.         restoresig();
  2309.         updatef();
  2310.         enabletime();
  2311.         break;
  2312.     case ('S'):
  2313.         strcpy(x_pathandfile, SEAR);
  2314.         strcat(x_pathandfile, u_pathname);
  2315.         strcat(x_pathandfile, x_filename);
  2316.         typexfr(7);
  2317.         uploadtime();
  2318.         result = system(x_pathandfile);
  2319.         restoresig();
  2320.         updatef();
  2321.         enabletime();
  2322.         break;
  2323.     case ('A'):
  2324.         strcpy(x_pathandfile, u_pathname);
  2325.         strcat(x_pathandfile, x_filename);
  2326.         typexfr(8);
  2327.         if ((storbuff = fopen(x_pathandfile, "w")) == NULL) {
  2328.             portsout("\n\rError opening upload file!\n\r");
  2329.             break;
  2330.         }
  2331.         fds = fileno(storbuff);
  2332.         rewind(storbuff);
  2333.         locking(fds, LK_LOCK, 0L);
  2334.         portsout("\n\rTerminate the ASCII upload with a control d ( ^d )");
  2335.         portsout("\n\rReady to receive ASCII upload....\n\r");
  2336.         uploadtime();
  2337.  
  2338.         restoremodes();
  2339.         portrst();
  2340.  
  2341.         while ((fgets(buf128, 132, stdin)) != NULL) {
  2342.             result = fputs(buf128, storbuff);
  2343.         }
  2344.         rewind(storbuff);
  2345.         locking(fds, LK_UNLCK, 0L);
  2346.         fclose(storbuff);
  2347.  
  2348.         portinit();
  2349.         setmodes();
  2350.  
  2351.         updatef();
  2352.         enabletime();
  2353.         break;
  2354.     case ('B'):
  2355.         strcpy(x_pathandfile, YMR);
  2356.         portsout("Please start your YMODEM transfer");
  2357.         portsout(CRLF);
  2358.         if_kermit = 1;
  2359.         typexfr(2);
  2360.         uploadtime();
  2361.         result = system(x_pathandfile);
  2362.         restoresig();
  2363.         strcpy(x_pathandfile, KRE);
  2364.         result = system(x_pathandfile);
  2365.         if ((rdstatbuf = fopen(FLIST, "r")) == NULL) {
  2366.             portsout("\n\rERROR: Unable to update!\n\r");
  2367.             exit(1);
  2368.         }
  2369.         while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  2370.             strcpy(x_pathandfile, u_pathname);
  2371.             strcat(x_pathandfile, x_filename);
  2372.             result = stat(x_pathandfile, &statbuf);
  2373.             if (result != 0) {
  2374.                 updatef();
  2375.             } else {
  2376.                 portsout(CRLF);
  2377.                 portsout(x_filename);
  2378.                 portsout(":  Duplicate file deleted!\n\r");
  2379.                 strcpy(x_pathandfile, USRBBS);
  2380.                 strcat(x_pathandfile, x_filename);
  2381.                 result = unlink(x_pathandfile);
  2382.             }
  2383.         }
  2384.         enabletime();
  2385.         fclose(rdstatbuf);
  2386.         break;
  2387.     case ('K'):
  2388.         strcpy(x_pathandfile, KRA);
  2389.         portsout("Please start your KERMIT transfer");
  2390.         portsout(CRLF);
  2391.         if_kermit = 1;
  2392.         typexfr(6);
  2393.         uploadtime();
  2394.         result = system(x_pathandfile);
  2395.         restoresig();
  2396.         strcpy(x_pathandfile, KRE);
  2397.         result = system(x_pathandfile);
  2398.         if ((rdstatbuf = fopen(FLIST, "r")) == NULL) {
  2399.             portsout("\n\rERROR: Unable to update!\n\r");
  2400.             exit(1);
  2401.         }
  2402.         while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  2403.             strcpy(x_pathandfile, u_pathname);
  2404.             strcat(x_pathandfile, x_filename);
  2405.             result = stat(x_pathandfile, &statbuf);
  2406.             if (result != 0) {
  2407.                 updatef();
  2408.             } else {
  2409.                 portsout(CRLF);
  2410.                 portsout(x_filename);
  2411.                 portsout(":  Duplicate file deleted!\n\r");
  2412.                 strcpy(x_pathandfile, USRBBS);
  2413.                 strcat(x_pathandfile, x_filename);
  2414.                 result = unlink(x_pathandfile);
  2415.             }
  2416.         }
  2417.         enabletime();
  2418.         fclose(rdstatbuf);
  2419.         break;
  2420.     case ('Z'):
  2421.         strcpy(x_pathandfile, RZ);
  2422.         portsout("Please start your ZMODEM transfer");
  2423.         portsout(CRLF);
  2424.         if_kermit = 1;
  2425.         typexfr(1);
  2426.         uploadtime();
  2427.         result = system(x_pathandfile);
  2428.         restoresig();
  2429.         strcpy(x_pathandfile, KRE);
  2430.         result = system(x_pathandfile);
  2431.         if ((rdstatbuf = fopen(FLIST, "r")) == NULL) {
  2432.             portsout("\n\rERROR: Unable to update!\n\r");
  2433.             exit(1);
  2434.         }
  2435.         while (fscanf(rdstatbuf, "%14s", x_filename) != EOF) {
  2436.             strcpy(x_pathandfile, u_pathname);
  2437.             strcat(x_pathandfile, x_filename);
  2438.             result = stat(x_pathandfile, &statbuf);
  2439.             if (result != 0) {
  2440.                 updatef();
  2441.             } else {
  2442.                 portsout(CRLF);
  2443.                 portsout(x_filename);
  2444.                 portsout(":  Duplicate file deleted!\n\r");
  2445.                 strcpy(x_pathandfile, USRBBS);
  2446.                 strcat(x_pathandfile, x_filename);
  2447.                 result = unlink(x_pathandfile);
  2448.             }
  2449.         }
  2450.         enabletime();
  2451.         fclose(rdstatbuf);
  2452.         break;
  2453.     default:
  2454.         portsout("Illegal option");
  2455.         portsout(CRLF);
  2456.         typexfr(11);
  2457.         break;
  2458.     }
  2459.     portsout(CRLF);
  2460. }
  2461. uploadtime()
  2462. {
  2463.     xsec = alarm(0);
  2464.     Ztime = xsec;
  2465.     alarm(32767);
  2466. }
  2467. enabletime()
  2468. {
  2469.     sec = xsec;
  2470.     alarm(sec);
  2471. }
  2472. digit(datr) char *
  2473.                     datr;
  2474. {
  2475.     int             res;
  2476.     char           *datr1;
  2477.     datr1 = datr;
  2478.     while (*datr1) {
  2479.         res = *datr1;
  2480.         if (!isdigit(res))
  2481.             *datr1 = ' ';
  2482.         datr1++;
  2483.     }
  2484. }
  2485.  
  2486.  
  2487. updatef()
  2488. {
  2489.     /*
  2490.      * The following modifications to "updatef()" allow you to have
  2491.      * MAX_DEC_LINES lines of description for uploaded files instead of
  2492.      * just one. 
  2493.      */
  2494. #define MAX_DESC_LINES  5
  2495.     int             code;
  2496.     int             index, index2;
  2497.     char            buf50[MAX_DESC_LINES][51], tmp[51];
  2498.  
  2499.     if (if_kermit == 0) {
  2500.         strcpy(buf128, u_pathname);
  2501.     } else {
  2502.         strcpy(buf128, USRBBS);
  2503.     }
  2504.     strcat(buf128, x_filename);
  2505.     (void) stat(buf128, &statbuf);
  2506.     if (statbuf.st_size == ((off_t) 0)) {
  2507.         unlink(buf128);
  2508.         return;
  2509.     }
  2510.     max_dload += statbuf.st_size;
  2511.     set_upd(-statbuf.st_size);
  2512.     portsout(CRLF);
  2513.     portsout("Please describe ");
  2514.     portsout(x_filename);
  2515.     sprintf(tmp, "    ( max of 50 characters on %d lines ) ", MAX_DESC_LINES);
  2516.     portsout(tmp);
  2517.     portsout(CRLF);
  2518.     portsout("NOTE: NO WORD WRAP.  Please watch how long your lines are!!");
  2519.     portsout(CRLF);
  2520.     portsout("Start with a / on line 1 for SYSOP ONLY!");
  2521.     portsout(CRLF);
  2522.     portsout("  ---------1---------2---------3---------4---------5");
  2523.     portsout(CRLF);
  2524.     index = 1;
  2525.     sprintf(tmp, "%1d:", index);
  2526.     portsout(tmp);
  2527.     portsin(buf50[0], 50);
  2528.     portsout(CRLF);
  2529.     while ((buf50[(index - 1)][0] != '\0') && (index < MAX_DESC_LINES)) {
  2530.         index++;
  2531.         sprintf(tmp, "%1d:", index);
  2532.         portsout(tmp);
  2533.         portsin(buf50[(index - 1)], 50);
  2534.         portsout(CRLF);
  2535.     }
  2536.     if (buf50[0][0] == '/') {
  2537.         portsout(CRLF);
  2538.         portsout(x_filename);
  2539.         portsout(" will NOT be logged\n\r");
  2540.         if ((inbuf = fopen(callers, "a")) == NULL) {
  2541.             portsout(CRLF);
  2542.             portsout("Can't open/create callers.bbs!");
  2543.             portsout(CRLF);
  2544.             return;
  2545.         }
  2546.         code = fprintf(inbuf, "%s %s", x_filename, buf50[0]);
  2547.         if (code < 0) {
  2548.             portsout(CRLF);
  2549.             portsout("Callers file has problem writing");
  2550.             portsout(CRLF);
  2551.         } else {
  2552.             fputs("\n", inbuf);
  2553.         }
  2554.         index2 = 1;
  2555.         while (index2 < index) {
  2556.             fprintf(inbuf, ". %s\n", buf50[index2]);
  2557.             index2++;
  2558.         }
  2559.         if( index == MAX_DESC_LINES )
  2560.             fprintf(inbuf, ".\n");
  2561.         fclose(inbuf);
  2562.         if (if_kermit == 0) {
  2563.             strcpy(x_pathandfile, u_pathname);
  2564.         } else {
  2565.             strcpy(x_pathandfile, USRBBS);
  2566.         }
  2567.         strcat(x_pathandfile, x_filename);
  2568.         strcpy(buf128, ORGPATH);
  2569.         strcat(buf128, x_filename);
  2570.         code = link(x_pathandfile, buf128);
  2571.         if( code == -1) {
  2572.             strcpy(buf128, "mv ");
  2573.             strcat(buf128, x_pathandfile);
  2574.             strcat(buf128, " ");
  2575.             strcat(buf128, ORGPATH);
  2576.             strcat(buf128, x_filename);
  2577.             (void)system(buf128);
  2578.             portsout("\n\r\n\rPlease leave a message to the sysop advising him that the\n");
  2579.             portsout("bbs users' home directory is NOT in the same filesystem as the upload path.\n\r\n\r");
  2580.         }
  2581.             
  2582.         (void)unlink(x_pathandfile);
  2583.         return;
  2584.     }
  2585.     strcpy(who_am_i, u_pathname);
  2586.     strcat(who_am_i, FILES);
  2587.     if ((inbuf = fopen(who_am_i, "a")) == NULL) {    /* create or open for
  2588.                              * append */
  2589.         portsout(CRLF);
  2590.         portsout("Can't open/create files.bbs!");
  2591.         portsout(CRLF);
  2592.         return;
  2593.     }
  2594.     fds = fileno(inbuf);
  2595.     rewind(inbuf);
  2596.     locking(fds, LK_LOCK, 0L);
  2597.     code = fprintf(inbuf, "%s %s", x_filename, buf50[0]);
  2598.     if (code < 0) {
  2599.         portsout(CRLF);
  2600.         portsout("List file has problem writing");
  2601.         portsout(CRLF);
  2602.     } else {
  2603.         fputs("\n", inbuf);    /* put lf on end of each record */
  2604.     }
  2605.     index2 = 1;
  2606.     while (index2 < index) {
  2607.         fprintf(inbuf, ". %s\n", buf50[index2]);
  2608.         index2++;
  2609.     }
  2610.     if( index == MAX_DESC_LINES )
  2611.         fprintf(inbuf, ".\n");
  2612.     rewind(inbuf);
  2613.     locking(fds, LK_UNLCK, 0L);
  2614.     fclose(inbuf);
  2615.     if (if_kermit != 0) {
  2616.         strcpy(x_pathandfile, USRBBS);
  2617.         strcat(x_pathandfile, x_filename);
  2618.         strcpy(buf128, u_pathname);
  2619.         strcat(buf128, x_filename);
  2620.         code = link(x_pathandfile, buf128);
  2621.         if( code == -1) {
  2622.             strcpy(buf128, "mv ");
  2623.             strcat(buf128, x_pathandfile);
  2624.             strcat(buf128, " ");
  2625.             strcat(buf128, u_pathname);
  2626.             strcat(buf128, x_filename);
  2627.             (void)system(buf128);
  2628.             portsout("\n\r\n\rPlease leave a message to the sysop advising him that the\n");
  2629.             portsout("bbs users' home directory is NOT in the same filesystem as the upload path.\n\r\n\r");
  2630.         }
  2631.             
  2632.         code = unlink(x_pathandfile);
  2633.     }
  2634. }
  2635. enough_time()
  2636. {
  2637.     long            lsec, lspeed;
  2638.     int             size, speed, code, result, astptr;
  2639.     static int      baud[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  2640.     char            data_buffer[600];
  2641.     char         *ppr, *locptr;
  2642.     locptr = strchr(x_pathandfile, '*');
  2643.     if( locptr == NULL )
  2644.         astptr = 0;
  2645.     else
  2646.         astptr = 1;
  2647.     strcpy(data_buffer, "ls ");
  2648.     strcat(data_buffer, x_pathandfile);
  2649.     strcat(data_buffer, " > /tmp/wild");
  2650.     strcat(data_buffer, port_id);
  2651.     code = system(data_buffer);
  2652.     if( !astptr )
  2653.         x_pathandfile[0] = '\0';
  2654.     code = 0;
  2655.     sum_size = 0L;
  2656.     sum_lsec = 0L;
  2657.     strcpy(data_buffer, "/tmp/wild");
  2658.     strcat(data_buffer, port_id);
  2659.     portsout("\n\rThe following files will be sent:\n\r");
  2660.     if ((inbuf = fopen(data_buffer, "r")) == NULL)
  2661.         return (FALSE);
  2662.     while (fscanf(inbuf, "%s", data_buffer) != EOF) {
  2663.         result = stat(data_buffer, &statbuf);
  2664.         if( !astptr ) {
  2665.             strcat(x_pathandfile, data_buffer);
  2666.             strcat(x_pathandfile, " ");
  2667.         }
  2668.         ppr = strrchr(data_buffer, '/');
  2669.         if (ppr == NULL)
  2670.             ppr = data_buffer;
  2671.         else
  2672.             ppr++;
  2673.         if (result != 0) {
  2674.             fclose(inbuf);
  2675.             strcpy(data_buffer, "/tmp/wild");
  2676.             strcat(data_buffer, port_id);
  2677.             result = unlink(data_buffer);
  2678.             return (FALSE);
  2679.         }
  2680.         result = strcmp(ppr, "files.bbs");
  2681.         if( result == 0 ) {
  2682.             portsout("\n\rIllegal file request\n\r");
  2683.             return(FALSE);
  2684.         }
  2685.         portsout(ppr);
  2686.         portsout(CRLF);
  2687.         size = (statbuf.st_size / 128) + 1;
  2688.         ioctl(0, TCGETA, &ttyhold);
  2689.         speed = baud[ttyhold.c_cflag & 017];
  2690.         lspeed = speed;
  2691.         lsec = size;
  2692.         sum_lsec = sum_lsec + (lsec * 128L * 11L / lspeed);
  2693.         sum_size = sum_size + statbuf.st_size;
  2694.         code++;
  2695.     }
  2696.     if( ! astptr ) {
  2697.         ppr = strrchr( x_pathandfile, ' ');
  2698.         if( ppr != NULL )
  2699.             *ppr = '\0';
  2700.     }
  2701.     fclose(inbuf);
  2702.     strcpy(data_buffer, "/tmp/wild");
  2703.     strcat(data_buffer, port_id);
  2704.     result = unlink(data_buffer);
  2705.     strcpy(buf128, "\n\rTotal number of files = ");
  2706.     itoa(data_buffer, code);
  2707.     strcat(buf128, data_buffer);
  2708.     strcat(buf128, "\n\r");
  2709.     portsout(buf128);
  2710.     strcpy(buf128, "Total number of bytes = ");
  2711.     sprintf(data_buffer, "%ld", sum_size);
  2712.     strcat(buf128, data_buffer);
  2713.     portsout(buf128);
  2714.     strcpy(buf128, "\n\rTotal download time = ");
  2715.     sprintf(data_buffer, "%ld", sum_lsec);
  2716.     strcat(buf128, data_buffer);
  2717.     strcat(buf128, " seconds\n\r");
  2718.     portsout(buf128);
  2719.     xsec = alarm(0);
  2720.     Ztime = xsec;
  2721.     sec = xsec;
  2722.     alarm(sec);
  2723.     if (sum_lsec > xsec)
  2724.         return (FALSE);
  2725.     if ((sum_size + dload_total) > max_dload)
  2726.         return (FALSE);
  2727.     if( sum_size == 0L )
  2728.         return (FALSE);
  2729.     return (TRUE);
  2730. }
  2731. file_d()
  2732. {
  2733.     FILE        *zipp;
  2734.     char            choic2[2], *str_result, *ptr, *ptr1;
  2735.     long            lsec, hold_sec, jsec, ksec;
  2736.     unsigned        start_sec, stop_sec;
  2737.     long            var_sec;
  2738.     int             result, tryit, tryit1, size, speed, default_flag, code;
  2739.     int        mult;
  2740.     static int      baud[15] = {0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200};
  2741. filed:
  2742.     result = stat(DLMSG, &statbuf);
  2743.     if (!result) {
  2744.         portsout(CRLF);
  2745.         no_cntrl_k = TRUE;
  2746.         cmd_p(DLMSG);
  2747.         no_cntrl_k = FALSE;
  2748.         portsout(CRLF);
  2749.     }
  2750.     tryit = FALSE;
  2751.     tryit1 = FALSE;
  2752.     mult = FALSE;
  2753.     portsout(CRLF);
  2754.     portsout("Input file name(s) to download:  ");
  2755.     portsin(x_filename, 98);
  2756.     if (strlen(x_filename) < 1)
  2757.         return;
  2758.     if (x_filename[0] == '.' || x_filename[0] == '/' || x_filename[0] == ' ') {
  2759.         portsout("\n\r\n\rIllegal Filename! \n\r");
  2760.         return;
  2761.     }
  2762.     code = strlen(x_filename);
  2763.     code--;
  2764.     if (x_filename[code] == '.' || x_filename[code] == '/' || x_filename[code] == ' ') {
  2765.         portsout("\n\r\n\rIllegal Filename! \n\r");
  2766.         return;
  2767.     }
  2768.     code = strcmp(x_filename, "files.bbs");
  2769.     if (code == 0) {
  2770.         portsout("\n\r\n\rIllegal Filename! \n\r");
  2771.         return;
  2772.     }
  2773.     str_result = strchr(x_filename, '*');
  2774.     if (str_result != NULL)
  2775.         tryit = TRUE;
  2776.  
  2777.     str_result = strchr(x_filename, ' ');
  2778.     if (str_result != NULL) {
  2779.         tryit = TRUE;
  2780.         mult = TRUE;
  2781.     }
  2782.  
  2783.     portsout(CRLF);
  2784.     code = legalname("|`><!;:", x_filename);
  2785.     if (code == 0) {
  2786.         portsout("\n\r\n\rIllegal Filename! \n\r");
  2787.         return;
  2788.     }
  2789.     if( mult ) {
  2790.         ptr = x_filename;
  2791.         x_pathandfile[0] = '\0';
  2792.         while(1) {
  2793.             ptr1 = strchr(ptr, ' ');
  2794.             if(ptr1 == NULL)
  2795.                 break;    
  2796.             *ptr1 = '\0';
  2797.             strcat(x_pathandfile, f_pathname);
  2798.             strcat(x_pathandfile, ptr);
  2799.             strcat(x_pathandfile, " ");
  2800.             *ptr1 = (char)' ';
  2801.             ptr = ptr1 + 1;
  2802.         }
  2803.         strcat(x_pathandfile, f_pathname);
  2804.         strcat(x_pathandfile, ptr);
  2805.     } else {
  2806.         strcpy(x_pathandfile, f_pathname);
  2807.         strcat(x_pathandfile, x_filename);
  2808.     }
  2809.     if (!tryit) {
  2810.         result = stat(x_pathandfile, &statbuf);
  2811.         if (result != 0) {
  2812.             portsout("\n\rThat file does not exist!\n\r");
  2813.             portsout("Remember that file names are CASE sensitive.\n\r");
  2814.             return;
  2815.         }
  2816.         size = (statbuf.st_size / 128) + 1;
  2817.         ioctl(0, TCGETA, &ttyhold);
  2818.         speed = baud[ttyhold.c_cflag & 017];
  2819.         lsec = size;
  2820.         lsec = lsec * 128L * 11L / speed;
  2821.         sum_size = statbuf.st_size;
  2822.         xsec = alarm(0);
  2823.         Ztime = xsec;
  2824.         sec = xsec;
  2825.         alarm(sec);
  2826.         hold_sec = lsec;
  2827.         if (lsec > xsec) {
  2828.             portsout("\n\rYou don't have enough time left to download that file.\n\r");
  2829.             return;
  2830.         }
  2831.         if ((statbuf.st_size + dload_total) > max_dload) {
  2832.             portsout("\n\rThis download will overrun your download limit.");
  2833.             portsout("\n\rUploads will increase your limit.\n\r");
  2834.             return;
  2835.         }
  2836.     } else {
  2837.         if (!enough_time()) {
  2838.             portsout("\n\rYou don't have enough time/bytes or an error was detected.\n\r");
  2839.             return;
  2840.         }
  2841.         hold_sec = sum_lsec;
  2842.     }
  2843.     hold_sec /= 2L;
  2844.     portsout(CRLF);
  2845.     if ( tryit ) 
  2846.         portsout("Multi-file options: Z(modem),  B(atch ymodem), K(ermit)");
  2847.     else {
  2848.         portsout("Options: Z(modem),  C(rc xmodem), X(modem), B(atch ymodem), Y(modem),\n\r");
  2849.         portsout("         K(ermit),  S(EAlink),    A(scii),  T(ype)");
  2850.     }
  2851.     portsout(CRLF);
  2852.     portsout(CRLF);
  2853.     if ( tryit )
  2854.         portsout("Commands: Z,B,K  ===> ");
  2855.     else
  2856.         portsout("Commands: Z,C,X,B,Y,K,S,A,T  ===> ");
  2857.     portsin(choic2, 1);
  2858.     portsout(CRLF);
  2859.     default_flag = 1;
  2860.     *choic2 = toupper(*choic2);
  2861.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  2862.                              * append */
  2863.         portsout(CRLF);
  2864.         portsout("Can't open/create callers file!");
  2865.         portsout(CRLF);
  2866.         return;
  2867.     }
  2868.     code = fprintf(inbuf, "%s %s  ", "   DNLOAD  ", x_filename);
  2869.     if (code < 0) {
  2870.         portsout(CRLF);
  2871.         portsout("Caller file has problem writing");
  2872.         portsout(CRLF);
  2873.     } 
  2874.     fclose(inbuf);
  2875.     if (choic2[0] == 'K' || choic2[0] == 'B' || choic2[0] == 'Z')
  2876.         tryit1 = TRUE;
  2877.     if (tryit && !tryit1) {
  2878.         portsout("\n\rIllegal use of wildcards - Must be KERMIT, YMODEM BATCH, or ZMODEM\n\r");
  2879.         typexfr(11);
  2880.         return;
  2881.     }
  2882.     start_sec = stop_sec = 0;
  2883.     xsec = alarm(0);
  2884.     alarm(32767);
  2885.     switch (choic2[0]) {
  2886.     case ('T'):
  2887.         portsout("\n\r\n\rOne moment please while an ascii check is done on the file ......  ");
  2888.         if(!asciicheck(x_pathandfile)) {
  2889.             portsout("Sorry.\n\rEither the file does not exist or it is not printable ascii.\n\r\n\r");
  2890.             typexfr(10);
  2891.             return;
  2892.         }
  2893.         portsout("ok.\n\r\n\r");
  2894.         cmd_p(x_pathandfile);
  2895.         typexfr(9);
  2896.         break;
  2897.     case ('A'):
  2898.         strcpy(x_pathandfile, f_pathname);
  2899.         strcat(x_pathandfile, x_filename);
  2900.         portsout("\n\r\n\rOne moment please while an ascii check is done on the file ......  ");
  2901.         if(!asciicheck(x_pathandfile)) {
  2902.             portsout("Sorry.\n\rEither the file does not exist or it is not printable ascii.\n\r\n\r");
  2903.             typexfr(10);
  2904.             return;
  2905.         }
  2906.         portsout("ok.\n\r\n\r");
  2907.         typexfr(8);
  2908.         portsout("\n\rOnce the transfer starts, you may terminate it by typing a Control-K");
  2909.         portsout("\n\rType a character to start the transfer when you are ready ===>  ");
  2910.         portsin(choic2, 1);
  2911.         portsout(CRLF);
  2912.         no_cntrl_k = TRUE;
  2913.         if (!toggle) {
  2914.             cmd_p(x_pathandfile);
  2915.         } else {
  2916.             toggle = FALSE;
  2917.             cmd_p(x_pathandfile);
  2918.             toggle = TRUE;
  2919.         }
  2920.         no_cntrl_k = FALSE;
  2921.         sleep(3);
  2922.         break;
  2923.     case ('X'):
  2924.         strcpy(x_pathandfile, SB);
  2925.         strcat(x_pathandfile, f_pathname);
  2926.         strcat(x_pathandfile, x_filename);
  2927.         typexfr(5);
  2928.         result = system(x_pathandfile);
  2929.         restoresig();
  2930.         start_sec = result;
  2931.         sleep(1);
  2932.         break;
  2933.     case ('Y'):
  2934.         strcpy(x_pathandfile, YMDS);
  2935.         strcat(x_pathandfile, f_pathname);
  2936.         strcat(x_pathandfile, x_filename);
  2937.         typexfr(3);
  2938.         result = system(x_pathandfile);
  2939.         restoresig();
  2940.         start_sec = result;
  2941.         sleep(1);
  2942.         break;
  2943.     case ('C'):
  2944.         strcpy(x_pathandfile, CRCS);
  2945.         strcat(x_pathandfile, f_pathname);
  2946.         strcat(x_pathandfile, x_filename);
  2947.         typexfr(4);
  2948.         result = system(x_pathandfile);
  2949.         restoresig();
  2950.         start_sec = result;
  2951.         sleep(1);
  2952.         break;
  2953.     case ('S'):
  2954.         strcpy(x_pathandfile, SEAS);
  2955.         strcat(x_pathandfile, f_pathname);
  2956.         strcat(x_pathandfile, x_filename);
  2957.         typexfr(7);
  2958.         result = system(x_pathandfile);
  2959.         restoresig();
  2960.         start_sec = result;
  2961.         sleep(1);
  2962.         break;
  2963.     case ('Z'):
  2964.         strcpy(msg_text, SZ);
  2965.         strcat(msg_text, x_pathandfile);
  2966.         typexfr(1);
  2967.         result = system(msg_text);
  2968.         restoresig();
  2969.         start_sec = result;
  2970.         sleep(1);
  2971.         break;
  2972.     case ('B'):
  2973.         strcpy(msg_text, YMS);
  2974.         strcat(msg_text, x_pathandfile);
  2975.         typexfr(2);
  2976.         result = system(msg_text);
  2977.         restoresig();
  2978.         start_sec = result;
  2979.         sleep(1);
  2980.         break;
  2981.     case ('K'):
  2982.         strcpy(msg_text, KS);
  2983.         strcat(msg_text, x_pathandfile);
  2984.         typexfr(6);
  2985.         portsout("Ready to start KERMIT transfer");
  2986.         portsout(CRLF);
  2987.         result = system(msg_text);
  2988.         restoresig();
  2989.         start_sec = result;
  2990.         break;
  2991.     default:
  2992.         portsout("Illegal option");
  2993.         typexfr(11);
  2994.         default_flag = 0;
  2995.         portsout(CRLF);
  2996.         break;
  2997.     }
  2998.     sec = alarm(0);
  2999.     jsec = 32767L - (long) sec;
  3000.     ksec = (long) xsec;
  3001.     ksec -= jsec;
  3002.     if (ksec <= 2L)
  3003.         ksec = 2L;
  3004.     xsec = (unsigned int) ksec;
  3005.     code = 0;
  3006.     if (default_flag) {
  3007.         if ((zipp = fopen(callers, "a")) == NULL) {    /* create or open for
  3008.                                  * append */
  3009.             portsout(CRLF);
  3010.             portsout("Can't open/create callers file!");
  3011.             portsout(CRLF);
  3012.             return;
  3013.         }
  3014.         if (start_sec == 0) {
  3015.             dload_total += sum_size;
  3016.             set_upd(sum_size);
  3017.             code = fprintf(zipp, "      Transfer seems to be OK.\n");
  3018.         } else 
  3019.             code = fprintf(zipp, "      Transfer seems to have failed.\n");
  3020.         if (code < 0) {
  3021.             portsout(CRLF);
  3022.             portsout("Caller file has problem writing");
  3023.             portsout(CRLF);
  3024.         } 
  3025.         fclose(zipp);
  3026.  
  3027.     }
  3028.     alarm(xsec);
  3029.     portsout(CRLF);
  3030. }
  3031. typexfr(typex)  int typex;
  3032. {
  3033.     int code;
  3034.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  3035.                              * append */
  3036.         portsout(CRLF);
  3037.         portsout("Can't open/create callers file!");
  3038.         portsout(CRLF);
  3039.         return;
  3040.     }
  3041.     switch (typex) {
  3042.         case (1): code = fprintf(inbuf, " using ZMODEM\n");
  3043.             break;
  3044.         case (2): code = fprintf(inbuf, " using BATCH YMODEM\n");
  3045.             break;
  3046.         case (3): code = fprintf(inbuf, " using YMODEM\n");
  3047.             break;
  3048.         case (4): code = fprintf(inbuf, " using XMODEM-CRC\n");
  3049.             break;
  3050.         case (5): code = fprintf(inbuf, " using XMODEM-CHECKSUM\n");
  3051.             break;
  3052.         case (6): code = fprintf(inbuf, " using KERMIT\n");
  3053.             break;
  3054.         case (7): code = fprintf(inbuf, " using SEALINK\n");
  3055.             break;
  3056.         case (8): code = fprintf(inbuf, " using ASCII\n");
  3057.             break;
  3058.         case (9): code = fprintf(inbuf, " using TYPE\n");
  3059.             break;
  3060.         case (10): code = fprintf(inbuf, " NOT printable ASCII\n");
  3061.             break;
  3062.         default:  code = fprintf(inbuf, " ......... illegal option!\n");
  3063.             break;
  3064.     }
  3065.     if (code < 0) {
  3066.         portsout(CRLF);
  3067.         portsout("Caller file has problem writing");
  3068.         portsout(CRLF);
  3069.     }
  3070.     fclose(inbuf);
  3071. }
  3072.  
  3073. cmd_e()
  3074. {                /* enter a message */
  3075.     int             entering, editing, char_cnt, temp_int, temp_int1;
  3076.     char            l_cnt[3], type[2], ans[2];
  3077.     char           *char_ptr;
  3078.     char            tmp[80];
  3079.  
  3080.     entering = editing = TRUE;
  3081.     cnt1 = 0;
  3082.     strcpy(l_cnt, "00");
  3083.     msg_text[0] = '\0';    /* init message text area */
  3084.     portsout(CRLF);
  3085.     portsout("This will be message # ");
  3086.     portsout(h_act_msg);
  3087.     portsout(CRLF);
  3088.     if (!reply_sw) {
  3089.         entr_name();
  3090.         entr_subj();
  3091.     }
  3092.     if (!end_msg)
  3093.         entr_priv();
  3094.     if (end_msg)
  3095.         strcpy(pubpriv, "5");
  3096.  
  3097.     portsout(CRLF);
  3098.     sprintf(tmp, "A line can contain 72 characters, up to %d lines.", MAX_MSG_LINES);
  3099.     portsout(tmp);
  3100.     portsout(CRLF);
  3101.     portsout("To end, enter a carriage return on an empty line.");
  3102.     portsout(CRLF);
  3103.     if(blocked_m)
  3104.         portsout("The lines will automatically word wrap and block.");
  3105.     else
  3106.         portsout("The lines will automatically word wrap.");
  3107.     portsout(CRLF);
  3108. Enter:
  3109.     portsout(CRLF);
  3110.     portsout("    .___.____1____.____2____.____3____.____4____.____5____.____6____.____7__");
  3111.     portsout(CRLF);
  3112.  
  3113.     char_cnt = 72;
  3114.     work_msg[0] = '\0';
  3115.     while (entering) {    /* get the text of the message */
  3116.         linecnt(l_cnt);    /* calc line count */
  3117.  
  3118.         portsout(l_cnt);/* show line count */
  3119.         portsout("> ");    /* and prompt */
  3120.         portsout(work_msg);
  3121.         strcpy(buf128, work_msg);
  3122.         in_the_buffer = strlen(buf128);
  3123.         work_msg[0] = '\0';
  3124.         portsinm(x_pathandfile, char_cnt, buf128);
  3125.         char_ptr = strrchr(x_pathandfile, ' ');
  3126.         temp_int = strlen(x_pathandfile);
  3127.         if (temp_int >= char_cnt) {
  3128.             if (x_pathandfile[temp_int - 1] == '\n' || x_pathandfile[temp_int - 1] == '\r' || x_pathandfile[temp_int - 1] == ' ') {
  3129.                 char_cnt = 72;
  3130.                 goto enter1;
  3131.             }
  3132.             if (char_ptr != NULL) {
  3133.                 *char_ptr = '\0';
  3134.                 char_ptr++;
  3135.                 strcpy(work_msg, char_ptr);
  3136.                 temp_int = strlen(work_msg);
  3137.                 for (temp_int1 = 1; temp_int1 <= temp_int; temp_int1++)
  3138.                     portsout("\b");
  3139.                 for (temp_int1 = 1; temp_int1 <= temp_int; temp_int1++)
  3140.                     portsout(" ");
  3141.                 char_cnt = 72 - temp_int;
  3142.  
  3143.             } else {
  3144.                 char_cnt = 72;
  3145.             }
  3146.         } else {
  3147.             char_cnt = 72;
  3148.             work_msg[0] = '\0';
  3149.  
  3150.         }
  3151. enter1:
  3152.         strcat(buf128, x_pathandfile);
  3153.         portsout(CRLF);
  3154.  
  3155.         strcat(buf128, "\n");    /* put a <lf> on each line */
  3156.         if(blocked_m) {
  3157.             strcpy(x_pathandfile, buf128);
  3158.             block_text();
  3159.         }
  3160.  
  3161.         if (strlen(buf128) < 2) {    /* count cr too */
  3162.             entering = FALSE;    /* all done */
  3163.         } else {
  3164.             strcat(msg_text, buf128);    /* append each line to
  3165.                              * text */
  3166.         }
  3167.         if ((++cnt1) > MAX_MSG_LINES) {    /* only allow 20 lines */
  3168.             entering = FALSE;    /* all done */
  3169.         }
  3170.     }
  3171.  
  3172.     while (editing) {    /* save it, fix it, list it, or get out */
  3173.         portsout(CRLF);
  3174.         portsout("(S)ave,    (L)ist,     (C)ontinue, or (Q)uit");
  3175.         portsout(CRLF);
  3176.         portsout("ce(N)ter,  (B)lock,    (D)elete,      (I)nsert,    (R)eplace,  or (E)dit line");
  3177.         portsout(CRLF);
  3178.         portsout("Change     sub(J)ect,  recei(V)er, or (P)rivilege ==> ");
  3179.         portsin(ans, 1);/* get a byte */
  3180.         portsout(CRLF);
  3181.  
  3182.         *ans = toupper(*ans);
  3183.  
  3184.         switch (ans[0]) {    /* get 1 byte */
  3185.         case ('S'):    /* save message */
  3186.             new_msg = atoi(h_act_msg);
  3187.             savemsg();
  3188.             editing = FALSE;    /* get out of while */
  3189.             break;
  3190.         case ('E'):    /* edit message */
  3191.         case ('I'):    /* edit message */
  3192.         case ('D'):    /* edit message */
  3193.         case ('R'):
  3194.         case ('N'):
  3195.         case ('B'):
  3196.             editmsg(*ans);
  3197.             break;
  3198.         case ('P'):
  3199.             if (end_msg) {
  3200.                 portsout("\n\rCannot change the privilege on a log off message\n\r");
  3201.                 break;
  3202.             }
  3203.             entr_priv();
  3204.             portsout(CRLF);
  3205.             break;
  3206.         case ('J'):
  3207.             if (end_msg) {
  3208.                 portsout("\n\rCannot change the subject on a log off message\n\r");
  3209.                 break;
  3210.             }
  3211.             if (reply_sw) {
  3212.                 portsout("\n\rCannot change the subject on a reply to a message\n\r");
  3213.                 break;
  3214.             }
  3215.             portsout(CRLF);
  3216.             entr_subj();
  3217.             portsout(CRLF);
  3218.             break;
  3219.         case ('V'):
  3220.             if (end_msg) {
  3221.                 portsout("\n\rCannot change the name of the receiver on a log off message\n\r");
  3222.                 break;
  3223.             }
  3224.             if (reply_sw) {
  3225.                 portsout("\n\rCannot change the receiver's name on a message reply\n\r");
  3226.                 break;
  3227.             }
  3228.             entr_name();
  3229.             break;
  3230.         case ('L'):    /* list message */
  3231.             listmsg();
  3232.             break;
  3233.         case ('Q'):    /* get out w/out saving */
  3234.             portsout("\n\r\n\rAre you sure you want to quit? (Y/n): ");
  3235.             portsin(ans, 1);
  3236.             portsout(CRLF);
  3237.             if (ans[0] == 'N' || ans[0] == 'n')
  3238.                 break;
  3239.             editing = FALSE;    /* get out of while */
  3240.             break;
  3241.         case ('C'):
  3242.             if (cnt1 == MAX_MSG_LINES) {
  3243.                 sprintf(tmp, "\n\rMessage is already %d lines!\n\r", MAX_MSG_LINES);
  3244.                 portsout(tmp);
  3245.                 break;
  3246.             }
  3247.             entering = TRUE;
  3248.             cnt1--;
  3249.             itoa(l_cnt, cnt1);
  3250.             goto Enter;
  3251.             break;
  3252.         default:
  3253.             portsout(CRLF);
  3254.             portsout("Shall we try that one again?\r\n");
  3255.             break;
  3256.         }
  3257.     }
  3258.  
  3259. }
  3260. /* end of function               */
  3261. entr_name()
  3262. {
  3263.     char            z_fname[11], z_lname[16], z_full[22];
  3264.     int             length, length1;
  3265.     char            firstz[20], lastz[20];
  3266.     char            priv[6];
  3267.     char            etime[9];
  3268.     char            esize[9];
  3269. enter_it_again:
  3270.     length1 = 0;
  3271.     portsout(CRLF);
  3272.     portsout("                                           ____.____1\r\n");
  3273.     portsout("Enter the FIRST NAME of the receiver ===>  ");
  3274.     portsin(z_fname, 10);
  3275.     length = strlen(z_fname);
  3276.     if (!length) {
  3277.         strcpy(z_fname, "All");
  3278.         z_lname[0] = '\0';
  3279.         goto bobble;
  3280.     }
  3281.     portsout(CRLF);
  3282.     portsout("                                           ____.____1____.\r\n");
  3283.     portsout("Enter the LAST NAME of the receiver ====>  ");
  3284.     portsin(z_lname, 15);
  3285.     length1 = strlen(z_lname);
  3286. bobble:
  3287.     portsout(CRLF);
  3288.     fix_name(z_fname);
  3289.     fix_name(z_lname);
  3290.     length += length1;
  3291.     if (length > 20) {
  3292.         portsout("\n\rI'm sorry; however, the name is TOO long to be posted!\n\r");
  3293.         goto enter_it_again;
  3294.     }
  3295.     strcpy(z_full, z_fname);
  3296.     strcat(z_full, " ");
  3297.     strcat(z_full, z_lname);
  3298.     strcpy(msg_to, z_full);
  3299.     portsout(CRLF);
  3300.     if ((inbuf = fopen(USERPRIV, "r")) == NULL) {
  3301.         portsout(CRLF);
  3302.         portsout("Can't open user priv file!");
  3303.         portsout(CRLF);
  3304.         exit(1);
  3305.     }
  3306.     while (fscanf(inbuf, "%s%s%s%s%s", firstz, lastz, priv, etime, esize) != EOF) {
  3307.         if ((strcmp(firstz, z_fname) == 0) &&
  3308.             (strcmp(lastz, z_lname) == 0)) {
  3309.             return;
  3310.         }
  3311.     }
  3312.     fclose(inbuf);
  3313.     if( strcmp(z_fname, "Sysop") == 0 ) {
  3314.         strcpy(msg_to, SYSOP);
  3315.         return;
  3316.     }
  3317.     if( strcmp(z_fname, "All") == 0 ) {
  3318.         strcpy(msg_to, "All Users");
  3319.         return;
  3320.     }
  3321.     portsout("\n\rWarning: there is no user on this system by that name.\n\r");
  3322.     portsout("Do you still wish to use it? (Y/n): ");
  3323.     portsin(etime, 1);
  3324.     portsout(CRLF);
  3325.     if( etime[0] == 'N' || etime[0] == 'n' )
  3326.         goto enter_it_again;
  3327. }
  3328.  
  3329. entr_subj()
  3330. {
  3331.     int             length;
  3332.     portsout("                             ____.____1____.____2\n\r");
  3333.     portsout("What is the subject     ===> ");
  3334.     portsin(msg_subject, 20);
  3335.     length = strlen(msg_subject);
  3336.     if (!length) {
  3337.         strcpy(msg_subject, "*** NO SUBJECT ***");
  3338.     }
  3339. }
  3340. entr_priv()
  3341. {
  3342.     char            type[2];
  3343.     portsout(CRLF);
  3344.     portsout("Do you wish the message to be P(ublic) or pri(V)ate) (P/V) ?  ");
  3345.     portsin(type, 1);
  3346.     *type = toupper(*type);
  3347.     switch (type[0]) {
  3348.     case ('P'):
  3349.         strcpy(pubpriv, "0");
  3350.         break;
  3351.     case ('V'):
  3352.         strcpy(pubpriv, "5");
  3353.         break;
  3354.     default:
  3355.         portsout("\n\rDefaulting to public!\n\r");
  3356.         strcpy(pubpriv, "0");
  3357.         break;
  3358.     }
  3359. }
  3360. linecnt(lcnt)            /* 2 byte string of line numbers */
  3361.     char           *lcnt;
  3362. {
  3363.     int             icnt;
  3364.     char            xcnt[4];
  3365.  
  3366.     icnt = atoi(lcnt);
  3367.     if (++icnt < 10) {
  3368.         strcpy(lcnt, "0");
  3369.         itoa(xcnt, icnt);
  3370.         strcat(lcnt, xcnt);
  3371.     } else {
  3372.         itoa(xcnt, icnt);
  3373.         strcpy(lcnt, xcnt);
  3374.     }
  3375.     return;
  3376. }
  3377. /* end of function               */
  3378.  
  3379. savemsg()
  3380. {                /* save a message */
  3381.     int             fd;
  3382.  
  3383.     portsout("Saving...\r\n");
  3384.  
  3385.     strcpy(msg_delete, pubpriv);    /* delete byte */
  3386.     strcpy(msg_date, mm);
  3387.     strcat(msg_date, "/");
  3388.     strcat(msg_date, dd);
  3389.     strcat(msg_date, "/");
  3390.     strcat(msg_date, yy);
  3391.  
  3392.     strcpy(msg_time, ttime);/* and the time */
  3393.  
  3394.     strcpy(msg_from, w_fname);    /* and the from name */
  3395.     strcat(msg_from, " ");
  3396.     strcat(msg_from, w_lname);
  3397.     if ((inbuf = fopen(callers, "a")) == NULL) {    /* create or open for
  3398.                              * append */
  3399.         portsout(CRLF);
  3400.         portsout("Can't open/create callers file!");
  3401.         portsout(CRLF);
  3402.         return;
  3403.     }
  3404.     fd = fprintf(inbuf, "%s%s", "   Message being sent to ", msg_to);
  3405.     if (fd < 0) {
  3406.         portsout(CRLF);
  3407.         portsout("Caller file has problem writing");
  3408.         portsout(CRLF);
  3409.     } else {
  3410.         fputs("\n", inbuf);    /* put lf on end of each record */
  3411.     }
  3412.     fclose(inbuf);
  3413.     hdrread();        /* Guarantee proper header and table */
  3414.     if ((fd = msgopen(2)) == ERROR) {    /* open i/o */
  3415.         return (ERROR);
  3416.     }
  3417.     msgwrt(fd);        /* write the message */
  3418.     msgclose(fd);
  3419.  
  3420.     strcpy(h_date, msg_date);
  3421.     hdrwrt();        /* update the header file */
  3422. }
  3423. /* end of function               */
  3424.  
  3425.  
  3426. listmsg()
  3427. {
  3428.     char           *ptr, byte, lcnt[3];
  3429.     int             i;
  3430.  
  3431.     ptr = msg_text;        /* ptr points to start of text */
  3432.     strcpy(lcnt, "00");
  3433.  
  3434.     portsout(CRLF);
  3435.     while (*ptr != 0) {
  3436.         linecnt(lcnt);
  3437.         portsout(lcnt);    /* put out line number */
  3438.         portsout(">");
  3439.         while (byte = *ptr++) {
  3440.             if (byte == '\n') {    /* we dont save <cr>, so add *//* i
  3441.                          * t here when find a <cr> */
  3442.                 portsout(CRLF);
  3443.                 break;
  3444.             } else
  3445.                 portout(byte);
  3446.         }
  3447.     }
  3448. }
  3449. /* end of function               */
  3450.  
  3451. editmsg(tflag) char
  3452.     tflag;
  3453. {
  3454.     char            ans[3];
  3455.     int             lnum;    /* line number to edit */
  3456.     char            tmp[80];
  3457.  
  3458.     while (1) {
  3459.         portsout(CRLF);
  3460.         portsout("Enter line number to ");
  3461.         if (tflag == 'E')
  3462.             portsout("edit,");
  3463.         else if (tflag == 'D')
  3464.             portsout("delete,");
  3465.         else if (tflag == 'I')
  3466.             portsout("insert after,");
  3467.         else if (tflag == 'R')
  3468.             portsout("replace,");
  3469.         else if (tflag == 'N')
  3470.             portsout("center,");
  3471.         else if (tflag == 'B')
  3472.             portsout("block,");
  3473.         else
  3474.             return;
  3475.         portsout(CRLF);
  3476.         portsout("   or RETURN to exit ==> ");
  3477.         portsin(ans, 2);/* only MAX_MSG_LINES lines possible */
  3478.         portsout(CRLF);
  3479.         if (tflag == 'I' && cnt1 == MAX_MSG_LINES) {
  3480.             sprintf(tmp, "\n\rMessage is already %d lines!\n\r", MAX_MSG_LINES);
  3481.             portsout(tmp);
  3482.             return;
  3483.         }
  3484.         lnum = atoi(ans);
  3485.         if (lnum <= 0) {
  3486.             break;    /* out of while and return */
  3487.         }
  3488.         if ((lnum < MAX_MSG_LINES) || ((lnum == MAX_MSG_LINES) && (tflag != 'I'))) {
  3489.             editline(lnum, tflag);
  3490.             break;
  3491.         } else {    /* else slap on hand and loop around */
  3492.             sprintf(tmp, "Aw come on, there can only be %d lines!", MAX_MSG_LINES);
  3493.             portsout(tmp);
  3494.             portsout(CRLF);
  3495.             portsout("Shall we try that again?");
  3496.             portsout(CRLF);
  3497.         }
  3498.     }
  3499. }
  3500. /* end of function               */
  3501.  
  3502. usenet()
  3503. {                /* added for 7.2.1 USENET access */
  3504.  
  3505.  
  3506. #ifdef  SYSV
  3507. #define logname getlogin
  3508. #endif
  3509.  
  3510.     char           *logname();
  3511.  
  3512.     static char     shell[] = "SHELL=/bin/sh";
  3513.     static char     home[150];
  3514.     static char     logn[50];
  3515.     char            cmd[512];
  3516.     char            news[520];
  3517.     char            tmp[512];
  3518.     FILE           *newsf;
  3519.     int             mask;
  3520.     char            term;
  3521.  
  3522.     strcpy(home, "HOME=");
  3523.     strcpy(logn,"LOGNAME=");
  3524.     strcat(home, ORGPATH);
  3525.     strcat(home, "usenet/");
  3526.     strcat(home, u_fname);
  3527.     strcat(home, "/");
  3528.     strcat(home, u_lname);
  3529.     strcat(logn, logname());
  3530.  
  3531.     sprintf(news, "%susenet/%s/%s/.newsrc", ORGPATH, u_fname, u_lname);
  3532.     if (access(news, 00) == -1) {
  3533.         mask = umask(0000);
  3534.         portsout("creating necessary news files\n\r");
  3535.         portsout("\n\r");
  3536.         sprintf(tmp, "/bin/mkdir %susenet/%s", ORGPATH, u_fname);
  3537.         system(tmp);
  3538.         strcat(tmp, "/");
  3539.         strcat(tmp, u_lname);
  3540.         system(tmp);
  3541.         if ((newsf = fopen(news, "w")) == NULL) {
  3542.             portsout("open of .newsrc failed\n\r");
  3543.             exit(-1);
  3544.         }
  3545.         fprintf(newsf, "");
  3546.         fclose(newsf);
  3547.         umask(mask);
  3548.     }
  3549. menu:
  3550.     portsout("\n\rWhich type of terminal do you have:\n\r");
  3551.     portsout("1) Ansi Standard Monitor\n\r");
  3552.     portsout("2) ANSI.SYS for MS-DOS\n\r");
  3553.     portsout("3) VT100\n\r");
  3554.     portsout("4) Macintosh MacTerm in VT-100 mode\n\r");
  3555.     portsout("5) VT52 Terminal\n\r");
  3556.     portsout("6) Televideo 925\n\r");
  3557.     portsout("7) Televideo 910\n\r");
  3558.     portsout("8) Tandy DT-100\n\r");
  3559.     portsout("9) Dumb  - Use this when nothing else works correctly.\n\r");
  3560.     portsout("           Instead of the normal \"- MORE -\" inbetween pages\n\r");
  3561.     portsout("           You will see nothing, BUT you will hear a beep.\n\r");
  3562.     portsout("           This is the same thing. \"?\" is for help\n\r");
  3563.     portsout("\n\rQ) Return to main menu\n\r");
  3564.     portsout("===> ");
  3565.     term = portin();
  3566.     portsout("\n\r");
  3567.     switch (term) {
  3568.     case ('1'):
  3569.         putenv("TERM=ansi");
  3570.         break;
  3571.     case ('2'):
  3572.         putenv("TERM=dosansi");
  3573.         break;
  3574.     case ('3'):
  3575.         putenv("TERM=vt100");
  3576.         break;
  3577.     case ('4'):
  3578.         putenv("TERM=macterm");
  3579.         break;
  3580.     case ('5'):
  3581.         putenv("TERM=vt52so");
  3582.         break;
  3583.     case ('6'):
  3584.         putenv("TERM=tvi925co");
  3585.         break;
  3586.     case ('7'):
  3587.         putenv("TERM=tvi910");
  3588.         break;
  3589.     case ('8'):
  3590.         putenv("TERM=dt100");
  3591.         break;
  3592.     case ('9'):
  3593.         putenv("TERM=dumb");
  3594.         break;
  3595.     case ('Q'):
  3596.     case ('q'):
  3597.         portsout("\n\r");
  3598.         return (0);
  3599.         break;
  3600.     default:
  3601.         portsout("\n\rYou have selected an unsupported type. Please try again\n\r");
  3602.         goto menu;
  3603.         break;
  3604.     }
  3605.  
  3606.     putenv(shell);
  3607.     putenv(home);
  3608.     putenv(logn);
  3609. choose:
  3610.     portsout("\n\rDo you wish to:\n\r");
  3611.     portsout("1) Readnews\n\r");
  3612.     portsout("2) Postnews\n\r");
  3613.     portsout("\n\rQ) Return to main menu\n\r");
  3614.     portsout("===>");
  3615.     term = portin();
  3616.     portsout("\n\r");
  3617.     switch (term) {
  3618.     case ('1'):
  3619.         restoremodes();
  3620.         portrst();
  3621.         STDerr = freopen("/dev/tty", "w+", stderr);
  3622.         sprintf(cmd, "%s -n all",READN);
  3623.         system(cmd);
  3624.         break;
  3625.     case ('2'):
  3626.         restoremodes();
  3627.         portrst();
  3628.         STDerr = freopen("/dev/tty", "w+", stderr);
  3629.         sprintf(cmd, "%s",POSTN);
  3630.         system(cmd);
  3631.         break;
  3632.     case ('Q'):
  3633.     case ('q'):
  3634.         portsout("\n\r");
  3635.         strcpy(home, "HOME=");
  3636.         strcpy(logn, "LOGNAME=");
  3637.         cmd[0] = '\0';
  3638.         news[0] = '\0';
  3639.         tmp[0] = '\0';
  3640.         return (0);
  3641.         break;
  3642.     default:
  3643.         portsout("Please try again\n\r");
  3644.         goto choose;
  3645.         break;
  3646.     }
  3647.  
  3648.     strcpy(home, "HOME=");
  3649.     strcpy(logn, "LOGNAME=");
  3650.     cmd[0] = '\0';
  3651.     news[0] = '\0';
  3652.     tmp[0] = '\0';
  3653.  
  3654.     strcpy(buf128, STDERR);
  3655.     strcat(buf128, port_id);
  3656.     STDerr = freopen(buf128, "w+", stderr);
  3657.     portinit();
  3658.     setmodes();
  3659.     restoresig();
  3660.  
  3661. }
  3662. restoresig()
  3663. {
  3664.     signal(SIGALRM, timer);
  3665.     signal(SIGHUP, hanged);
  3666.     signal(SIGUSR1, mon_toggle);
  3667.     signal(SIGUSR2, sys_toggle);
  3668.     signal(SIGPIPE, chat);
  3669.  
  3670. }
  3671.