home *** CD-ROM | disk | FTP | other *** search
/ Share Gallery 1 / share_gal_1.zip / share_gal_1 / CO / CO018.ZIP / TLX312-2.ZIP / HOST.SLT < prev    next >
Text File  |  1990-04-30  |  22KB  |  958 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //   H O S T . S L T
  4. //
  5. //   Copyright (C) 1988 PTel and Colin Sampaleanu
  6. //
  7. //   This is a Host Mode for Telix, written as a script file.
  8. //   Ton configure Host Mode parameters such as passwords, run the 'HCONFIG'
  9. //   script. That script is run automatically if the Host Mode ocnfiguration
  10. //   file 'HOST.CNF' is missing.
  11. //
  12. //   This script will only work with Hayes compatible modems, but may be
  13. //   modified for operation with othe rmodems.
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16.  
  17. // Parameters which can be configured
  18.  
  19. str pass1[8] = "pass1",                 // The level 1 pass
  20.     pass2[8] = "pass2",                 // The level 2 (Sysop) pass
  21.     shellpass[8] = "shell",             // the pass to enter the Remote Shell
  22.     shutpass[8] = "shut",               // the pass to shut down the Host Mode
  23.     host_downloads[64],                 // where users may download from
  24.     host_uploads[64];                   // where uploaded files go
  25. int direct_connect = 0;
  26.  
  27. str current_caller[31],                 // storage of current caller's name
  28.     conn300[] = "CONNECT^M",            // modem result messages for bauds
  29.     conn1200[] = "CONNECT 1200",
  30.     conn2400[] = "CONNECT 2400",
  31.     conn9600[] = "CONNECT 9600",
  32.     conn19200[] = "CONNECT 19200";
  33. int finished_caller,                    // set to TRUE when must return to top
  34.     local_mode,                         // set to TRUE when local test mode
  35.     access_level,                       // access level of current caller
  36.     carrier_counts = 1,                 // TRUE if should watch Carrier signal
  37.     already_connected = 0,
  38.     exit_requested = 0,                 // set to TRUE if Sysop has pressed Esc
  39.     connection_lost = 0,                // set to TRUE when carrier lost
  40.     kill_user = 0;                      // set to TRUE when user must be purged
  41.  
  42. int old_scr_chk_key,                    // storage for some system variables
  43.     old_cisb_auto,                      // which we have to modify and put
  44.     old_zmod_auto,                      // back to what they were when done
  45.     old_sound;
  46. str old_down_dir[64],
  47.     old_up_dir[64];
  48.  
  49. //////////////////////////////////////////////////////////////////////////////
  50. //////////////////////////////////////////////////////////////////////////////
  51.  
  52. main()
  53.  
  54. {
  55.  int c;
  56.  
  57.  clear_scr();
  58.  
  59.  if (read_host_config_file() == -1)
  60.   {
  61.    prints("Unable to read HOST.CNF...");
  62.    prints("Running HCONFIG, the Host Mode configuration script.^M^J");
  63.    call("HCONFIG");
  64.    if (read_host_config_file() == -1)
  65.     {
  66.      prints("Still unable to read HOST.CNF. Aborting Host Mode.^M^J");
  67.      return -1;
  68.     }
  69.   }
  70.  
  71.  if (!check_directories())
  72.   {
  73.    prints("Either the upload or download directory as defined in the HOST.CNF file");
  74.    prints("doesn't exist. Either create the missing directory with the DOS 'MKDIR'");
  75.    prints("command, or run the HCONFIG script to redefine what directories to use.");
  76.    prints("Aborting Host Mode.");
  77.    return -1;
  78.   }
  79.  
  80.  old_scr_chk_key = _scr_chk_key;
  81.  _scr_chk_key = 0;
  82.  old_cisb_auto = _cisb_auto;
  83.  _cisb_auto = 0;
  84.  old_zmod_auto = _zmod_auto;
  85.  _zmod_auto = 0;
  86.  old_sound = _sound_on;
  87.  _sound_on = 0;
  88.  old_down_dir = _down_dir;
  89.  _down_dir = host_uploads;   // these are reversed because we are now the Host
  90.  old_up_dir = _up_dir;
  91.  _up_dir = host_downloads;   // these are reversed because we are now the Host
  92.  
  93.  usagelog("HOST.LOG");
  94.  
  95.  if (direct_connect)
  96.   carrier_counts = 0;
  97.  else
  98.   carrier_counts = 1;
  99.  
  100.  if (!direct_connect && carrier())
  101.   already_connected = 1;
  102.  
  103.  
  104.  while (1)
  105.   {
  106.    if (!direct_connect && !already_connected)
  107.     {
  108.      prints("Sending Modem Init string...");
  109.      cputs_tr(_mdm_init_str);
  110.      delay(10);
  111.      prints("Sending Auto-Answer string...");
  112.      cputs_tr(_auto_ans_str);
  113.     }
  114.  
  115.    finished_caller = kill_user = 0;
  116.  
  117.    if (direct_connect)
  118.     carrier_counts = 0;
  119.    else
  120.     carrier_counts = 1;
  121.  
  122.    if (!direct_connect)
  123.     {
  124.      prints("^M^JHost Mode: Waiting for call...");
  125.      prints("(Press Esc to exit, or 'L' for local test mode).^M^J");
  126.  
  127.      do
  128.       {
  129.        if (carrier())
  130.         {
  131.          local_mode = 0;
  132.          break;
  133.         }
  134.  
  135.        c = inkey();
  136.        if (c)
  137.         {
  138.          if (c == 27)
  139.           {
  140.            exit_requested = 1;
  141.            break;
  142.           }
  143.          else if (c == 'l' || c == 'L')               // local teswt mode
  144.           {
  145.            prints("Local test mode entered");
  146.            local_mode = 1;
  147.            carrier_counts = 0;
  148.           }
  149.         }
  150.       }
  151.      while (toupper(c) != 'L');
  152.     }
  153.  
  154.    if (!exit_requested)
  155.     {
  156.      prints("Incoming call. Sysop: press Esc to exit, or END to terminate user.");
  157.  
  158.      do_one_caller();
  159.      if ((connection_lost || kill_user) && carrier_counts && carrier())
  160.       hangup();             // make sure nobody sneaks in
  161.     }
  162.    already_connected = 0;
  163.    if (exit_requested)
  164.     {
  165.      if (!carrier() && !direct_connect)
  166.       {
  167.        prints("Sending Modem Init string...");
  168.        cputs_tr(_mdm_init_str);
  169.       }
  170.      _scr_chk_key = old_scr_chk_key;
  171.      _cisb_auto = old_cisb_auto;
  172.      _zmod_auto = old_zmod_auto;
  173.      _sound_on = old_sound;
  174.      _down_dir = old_down_dir;
  175.      _up_dir = old_up_dir;
  176.      prints("^M^JHost mode script finished.");
  177.      usagelog("*CLOSE*");
  178.      return 1;
  179.     }
  180.   }
  181. }
  182.  
  183. //////////////////////////////////////////////////////////////////////////////
  184.  
  185. do_one_caller()
  186.  
  187. {
  188.  str strn[80],
  189.      fname[64];
  190.  int option,
  191.      status,
  192.      c, i, i2, f;
  193.  
  194.  access_level = 1;
  195.  
  196.  if (already_connected)
  197.   prints("Already connected, or modem Carrier Detect switch improperly set!");
  198.  else if (carrier_counts)
  199.   {
  200.    if (!determine_baud())
  201.     ;                          // do something else here if this is a problem
  202.   }
  203.  
  204.  delay(10);
  205.  type_file("LOGO.MSG");
  206.  
  207.  flushbuf();
  208.  while (1)
  209.   {
  210.    host_send("Please enter your full name: ");
  211.    host_input_strn(current_caller, 30);
  212.    host_send("^M^J");
  213.  
  214.    if (finished_caller)
  215.     return;
  216.  
  217.    if (strlen(current_caller) >= 5)
  218.     break;
  219.   }
  220.  
  221.  access_level = ask_for_pass(3, pass1, pass2);
  222.  
  223.  if (access_level)
  224.   ustamp("Logon by ", 1, 0);
  225.  else
  226.   ustamp("Failed logon attempt by ", 1, 0);
  227.  ustamp(current_caller, 0, 1);
  228.  
  229.  if (!access_level)
  230.   {
  231.    host_send("Goodbye!^M^J");
  232.    if (carrier_counts)
  233.     {
  234.      delay(10);
  235.      hangup();
  236.     }
  237.    return;
  238.   }
  239.  
  240.  type_file("WELCOME.MSG");
  241.  
  242.  while (1)
  243.   {
  244.    if (finished_caller)
  245.     return;
  246.  
  247.    host_send("^M^JFiles  Type  Upload  Download  Shell  Chat  Goodbye ? ");
  248.    host_input_strn(strn, 1);
  249.    option = toupper(subchr(strn, 0));
  250.    host_send("^M^J");
  251.  
  252.    if (option == 'F')                 // Files directory
  253.     {
  254.      if (access_level == 2)
  255.       {
  256.        host_send("Enter 'filespec' or press Return for *.*,^M^J: ");
  257.        host_input_strn(fname, 64);
  258.        host_send("^M^J");
  259.  
  260.        if (just_filename(fname))
  261.         {
  262.          strn = host_downloads;
  263.          strcat(strn, fname);
  264.         }
  265.        else
  266.         strn = fname;
  267.       }
  268.      else
  269.       {
  270.        strn = host_downloads;
  271.        strcat(strn, "*.*");
  272.       }
  273.        
  274.      if (local_mode)
  275.       show_directory(strn, 0, carrier_counts);
  276.      else
  277.       show_directory(strn, 1, carrier_counts);
  278.      host_send("^M^J");
  279.     }
  280.    else if (option == 'T')            // Type a file
  281.     {
  282.      host_send("Type what file? ");
  283.      host_input_strn(strn, 64);
  284.      host_send("^M^J");
  285.      if (access_level != 2)             // if access 1, name and ext only
  286.       fnstrip(strn, 3, fname);
  287.      else
  288.       fname = strn;
  289.  
  290.      if (just_filename(fname))
  291.       {
  292.        strn = host_downloads;
  293.        strcat(strn, fname);
  294.        fname = strn;
  295.       }
  296.  
  297.      if (!filefind(fname, 0, strn))
  298.       {
  299.        host_send("Unable to find ");
  300.        host_send(fname);
  301.        continue;
  302.       }
  303.  
  304.      type_file(fname);
  305.     }
  306.    else if (option == 'G')            // Goodbye (Hang-up)
  307.     {
  308.      host_send("^M^JGoodbye!^M^J");
  309.      ustamp("User logged off.", 1, 1);
  310.      if (carrier_counts)
  311.       {
  312.        delay(10);
  313.        hangup();
  314.       }
  315.      return;
  316.     }
  317.    else if (option == 'C')            // Chat mode
  318.     {
  319.      prints("Sysop: Press Space to chat, any other key not to.^M^J");
  320.      c = 0;
  321.      _sound_on = 1;
  322.      for (i = 8; i && !c; --i)
  323.       {
  324.        if (carrier_counts && !carrier())
  325.         {
  326.          prints("^M^JConnection has been lost, call terminated.^M^J");
  327.          connection_lost = 1;
  328.          finished_caller = 1;
  329.          break;
  330.         }
  331.        cputc('^G');
  332.        tone(523, 20);
  333.        tone(659, 20);
  334.        tone(523, 20);
  335.        tone(659, 20);
  336.        tone(523, 20);
  337.        tone(659, 20);
  338.        for (i2 = 30; i2 && (c = inkey()) == 0; --i2)
  339.         delay(1);
  340.       }
  341.      _sound_on = 0;
  342.      if (finished_caller)
  343.       continue;
  344.      if (c != ' ' || !c)
  345.       {
  346.        host_send("Sorry, the Sysop is unavailable^M^J");
  347.        continue;
  348.       }
  349.      host_send("The sysop is here!^M^J");
  350.      chatmode(1);
  351.     }
  352.    else if (option == 'U')            // User upload
  353.     {
  354.      option = host_get_prot();
  355.      if (!option)
  356.       continue;
  357.  
  358.      status = 1;
  359.      if (option == 'T' || option == 'M' || option == 'S' ||
  360.          option == 'Y' || option == 'Z' || option == 'E')
  361.       {
  362.        send_transfer_msg();
  363.        status = receive(option, "");
  364.       }
  365.      else
  366.       {
  367.        host_send("Upload what file? ");
  368.        host_input_strn(strn, 48);
  369.        host_send("^M^J");
  370.        if (!strn)
  371.         continue;
  372.        if (access_level != 2)             // if access 1, name and ext only
  373.         fnstrip(strn, 3, fname);
  374.        else
  375.         fname = strn;
  376.  
  377.        if (just_filename(fname))
  378.         {
  379.          strn = host_uploads;
  380.          strcat(strn, fname);
  381.          fname = strn;
  382.         }
  383.  
  384.        if (filefind(fname, 23, strn))
  385.         host_send("File already exists!^M^J");
  386.        else
  387.         {
  388.          send_transfer_msg();
  389.          status = receive(option, fname);
  390.         }
  391.       }
  392.      if (status == -2)                        // Carrier lost
  393.       connection_lost = finished_caller = 1;
  394.      else if (status == -1)
  395.       host_send("^GOne or more files not received!^M^J");
  396.     }
  397.    else if (option == 'D')            // User download
  398.     {
  399.      option = host_get_prot();
  400.      if (!option)
  401.       continue;
  402.      host_send("Download what file(s)? ");
  403.      host_input_strn(strn, 48);
  404.      host_send("^M^J");
  405.      if (!strn)
  406.       continue;
  407.      if (access_level != 2)      // if not level 2, keep only name & ext
  408.       fnstrip(strn, 3, fname);
  409.      else
  410.       fname = strn;
  411.  
  412.      if (just_filename(fname))
  413.       {
  414.        strn = host_downloads;
  415.        strcat(strn, fname);
  416.        fname = strn;
  417.       }
  418.  
  419.      if (!filefind(fname, 0, strn))
  420.       {
  421.        host_send("Unable to find any matching file(s)!^M^J");
  422.        continue;
  423.       }
  424.  
  425.      status = 1;
  426.      send_transfer_msg();
  427.      status = send(option, fname);
  428.      if (status == -2)                        // Carrier lost
  429.       connection_lost = finished_caller = 1;
  430.      else if (status == -1)
  431.       host_send("^GOne or more files not received!^M^J");
  432.     }
  433.    else if (option == 'S')            // Remote shell
  434.     {
  435.      if (ask_for_pass(3, shellpass, shellpass) != 0)
  436.       {
  437.        host_send("Type EXIT and then press Enter to come back.^M^J");
  438.        if (get_baud() == 300)
  439.         delay(10);
  440.        if (local_mode)
  441.         dos("", 0);
  442.                  // See if user has prepared a custom file for shell operation
  443.                  // and call that if it exists
  444.        else if (filefind("RSHELL.BAT", 0, strn))
  445.         dos("RSHELL.BAT", 0);
  446.        else   // otherwise make our own temporary batch file for redirection
  447.         {
  448.          // now want to make a temporary batch file which will be called
  449.          // to redirect DOS input and output, then shell to another copy
  450.          // of COMMAND.COM
  451.          f = fopen("HOSTTEMP.BAT", "w");
  452.          if (f)
  453.           {
  454.            if (get_port() != 1 && get_port() != 2)
  455.             {
  456.              host_send("Remote Shell not supported on this comm port due to DOS limits!^M^J");
  457.              continue;
  458.             }
  459.  
  460.            strn = "COMx";
  461.            setchr(strn, 3, get_port() + '0'); // get right name to redirect
  462.  
  463.            fputs("CTTY ", f);           // write to batch file
  464.            fputs(strn, f);
  465.            fputs("^M^JCOMMAND^M^J", f);
  466.            fputs("CTTY CON^M^J", f);
  467.            fputs("EXIT^M^J", f);
  468.  
  469.            fclose(f);                   // close the file
  470.  
  471.            if (!local_mode)             // call batch file
  472.             dos("HOSTTEMP.BAT", 0);
  473.           }
  474.          else
  475.           host_send("Can't open temporary batch file!^M^J");
  476.         }
  477.       }
  478.     }
  479.    else if (option == '^Z')            // Shut down Host Mode
  480.     {
  481.      host_send("Shut down Host mode. ");
  482.      if (!ask_for_pass(3, shutpass, shutpass))
  483.       continue;
  484.      host_send("Goodbye!^M^J");
  485.      if (carrier_counts)
  486.       hangup();
  487.      ustamp("User shut down Host Mode.", 1, 1);
  488.      finished_caller = 1;
  489.      exit_requested = 1;
  490.     }
  491.   }
  492. }
  493.  
  494. //////////////////////////////////////////////////////////////////////////////
  495.  
  496. host_get_prot()
  497.  
  498. {
  499.  str prot[1];
  500.  
  501.  host_send("^M^JModem7  SEAlink  Xmodem  1k-Xmodem  G-1k-Xmodem  Ymodem  YmodEm-g  Zmodem^M^J");
  502.  host_send("Which protocol? ");
  503.  host_input_strn(prot, 1);
  504.  host_send("^M^J");
  505.  
  506.  if (strposi("MSX1GYEZ", prot, 0) == -1)     // if illegal prot
  507.   prot = "";                                 // return 0
  508.  
  509.  return (toupper(subchr(prot, 0)));
  510.  
  511. }
  512.  
  513. //////////////////////////////////////////////////////////////////////////////
  514.  
  515. send_transfer_msg()
  516.  
  517. {
  518.  host_send("Ready to transfer file(s)... Press Ctrl-X at least twice to abort^M^J");
  519. }
  520.  
  521. //////////////////////////////////////////////////////////////////////////////
  522. // Determine the baud rate once a Carrier Detect Signal has been detected
  523. // Since no characters were read, the 'CONNECT' string should still be
  524. // in the receive buffer.
  525.  
  526. determine_baud()
  527.  
  528. {
  529.  int t3, t12, t24, t96, t192;
  530.  int tmark, stat;
  531.  int new_baud = 0;
  532.  
  533.  printsc("Determining baud... ");
  534.  
  535.  track_free(0);                // clear all existing tracks
  536.  
  537.  t3 = track(conn300, 0);       // check for connect strings
  538.  t12 = track(conn1200, 0);
  539.  t24 = track(conn2400, 0);
  540.  t96 = track(conn9600, 0);
  541.  t192 = track(conn19200, 0);
  542.  
  543.  tmark = timer_start(30);      // wait up to 3 seconds for string
  544.                              
  545.  while (!time_up(tmark))
  546.   {
  547.    if (!carrier())
  548.     {
  549.      track_free(0);            // clear all existing tracks
  550.      return 0;
  551.     }
  552.  
  553.    if (cinp_cnt())
  554.     track_addchr(cgetc());
  555.  
  556.    stat = track_hit(0);
  557.    if (stat == 0)
  558.     continue;
  559.  
  560.    if (stat == t3)
  561.     new_baud = 300;
  562.    else if (stat == t24)
  563.     new_baud = 2400;
  564.    else if (stat == t96)
  565.     new_baud = 9600;
  566.    else if (stat == t192)
  567.     new_baud = 19200;
  568.    else
  569.     new_baud = 1200;
  570.  
  571.    break;                      // have baud rate, get out
  572.   }
  573.  
  574.  if (!new_baud)                // time-up without CONNECT string
  575.   {
  576.    prints("Failed!");
  577.    track_free(0);              // clear all existing tracks
  578.    return 0;     
  579.   }
  580.  
  581.  printn(new_baud);
  582.  prints("");
  583.  set_cparams(new_baud, get_parity(), get_datab(), get_stopb());
  584.  
  585.  track_free(0);                // clear all existing tracks
  586.  return 1;                     // indicate success
  587.  
  588. }
  589.  
  590. //////////////////////////////////////////////////////////////////////////////
  591.  
  592. type_file(str fname)
  593.  
  594. {
  595.  int f;
  596.  str buf[100];
  597.  int ichar, lines_sent = 0;
  598.  
  599.  f = fopen(fname, "r");
  600.  if (!f)
  601.   return -1;
  602.  
  603.  host_send("^M^J");
  604.  
  605.  while (1)
  606.   {
  607.    if (carrier_counts)
  608.     if (!carrier())
  609.      {
  610.       connection_lost = 1;
  611.       finished_caller = 1;
  612.       fclose(f);
  613.       return 0;
  614.      }
  615.  
  616.    if (fgets(buf, 80, f) == -1)
  617.     {
  618.      fclose(f);
  619.      return 1;
  620.     }
  621.  
  622.    host_send(buf);
  623.    host_send("^M^J");
  624.    ++lines_sent;
  625.  
  626.    if (lines_sent >= 22)
  627.     {
  628.      lines_sent = 0;
  629.      host_send("[More]");
  630.      host_input();
  631.  
  632.      if (finished_caller)         // if user inactivity
  633.       {
  634.        fclose(f);
  635.        return 0;
  636.       }
  637.  
  638.      host_send("^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H");
  639.     }
  640.  
  641.    while (cinp_cnt())
  642.     {
  643.      ichar = cgetc();
  644.      if (ichar == '^C' || ichar == '^K')
  645.       {
  646.        host_send("^M^J");
  647.        fclose(f);
  648.        return 1;
  649.       }
  650.     }
  651.   }
  652. }
  653.  
  654. //////////////////////////////////////////////////////////////////////////////
  655.  
  656. host_send(str outstr)
  657.  
  658. {
  659.  
  660.  printsc(outstr);
  661.  if (!local_mode)
  662.   cputs(outstr);
  663.  
  664. }
  665.  
  666. //////////////////////////////////////////////////////////////////////////////
  667.  
  668. host_send_c(int chr)
  669.  
  670. {
  671.  
  672.  printc(chr);
  673.  if (!local_mode)
  674.   cputc(chr);
  675.  
  676. }
  677.  
  678. //////////////////////////////////////////////////////////////////////////////
  679.  
  680. host_input_strn(str buf, int maximum)
  681.  
  682. {
  683.  int i = 0, key;
  684.  
  685.  while (1)
  686.   {
  687.    key = host_input();
  688.    if (!key)                 // timeout or user disconnect
  689.     {
  690.      setchr(buf, 0, 0);      // set string to empty
  691.      return 0;               // indicate there is a problem
  692.     }
  693.  
  694.    if (key == '^M')
  695.     break;
  696.    if (key == 127 || key == 8)
  697.     {
  698.      if (i)
  699.       {
  700.        --i;
  701.        host_send_c(key);
  702.       }
  703.      continue;
  704.     }
  705.    if (i < maximum)
  706.     {
  707.      setchr(buf, i, key);
  708.      i = i + 1;
  709.     }
  710.    else
  711.     i = i + 1;
  712.   }
  713.  
  714.  if (i > maximum)
  715.   i = maximum;
  716.  
  717.  setchr(buf, i, '^0');
  718.  
  719.  if (subchr(buf, 0))
  720.   return 1;
  721.  else
  722.   return 0;
  723.  
  724. }
  725.  
  726. //////////////////////////////////////////////////////////////////////////////
  727.  
  728. host_input()
  729.  
  730. {
  731.  int c;
  732.  int t;
  733.  
  734.  t = timer_start(2400);         // 4 minutes inactivity allowed
  735.  
  736.  while (1)
  737.   {
  738.    if (time_up(t) && !direct_connect)
  739.     {
  740.      host_send("^M^J^M^JInactivity period too long. Connection terminated!^M^J");
  741.      if (carrier_counts)
  742.       hangup();
  743.      finished_caller = 1;
  744.      kill_user = 1;
  745.      return 0;
  746.     }
  747.  
  748.    if (carrier_counts)
  749.     if (!carrier())
  750.       {
  751.        prints("^M^JConnection has been lost, call terminated.^M^J");
  752.        connection_lost = 1;
  753.        finished_caller = 1;
  754.        return 0;
  755.       }
  756.  
  757.    if ((c = inkey()) != 0)
  758.     {
  759.      if (c == 27)               // ESC key, sysop wants to exit
  760.       {
  761.        finished_caller = 1;
  762.        exit_requested = 1;
  763.        return 0;
  764.       }
  765.      else if (c == 0x4f00)      // END key, temrinate user
  766.       {
  767.        prints("^M^JUser terminated!");
  768.        ustamp("User terminated!", 1, 1);
  769.        if (carrier_counts)
  770.         hangup();
  771.  
  772.        finished_caller = 1;
  773.        kill_user = 1;
  774.        return 0;
  775.       }
  776.  
  777.      else if (c <= 255)
  778.       {
  779.        if (c != 8 && c != 127)   
  780.         host_send_c(c);
  781.        return c;
  782.       }
  783.     }
  784.  
  785.    if (!local_mode)
  786.     if (cinp_cnt())
  787.      {
  788.       c = cgetc();
  789.       if (c != 8 && c != 127)
  790.        host_send_c(c);
  791.       return c;
  792.      }
  793.   }
  794. }
  795.  
  796. //////////////////////////////////////////////////////////////////////////////
  797.  
  798. ask_for_pass(int maxtries, str pass1, str pass2)
  799.  
  800. {
  801.  int i;
  802.  str strn[8];
  803.  
  804.  for (i = 0; i < maxtries; ++i)
  805.   {
  806.    if (i)
  807.     host_send("Wrong! Try again.^M^J");
  808.    host_send("Password: ");
  809.    host_input_strn(strn, 8);
  810.    host_send("^M^J");
  811.  
  812.    if (finished_caller)
  813.     return 0;
  814.  
  815.    if (!strcmpi(strn, pass1))
  816.     return 1;
  817.  
  818.    if (!strcmpi(strn, pass2))
  819.     return 2;
  820.   }
  821.  
  822.  host_send("No more chances. Access denied.^M^J");
  823.  
  824.  return 0;
  825.  
  826. }
  827.  
  828. //////////////////////////////////////////////////////////////////////////////
  829.  
  830. read_host_config_file()
  831.  
  832. {
  833.  str s[80];
  834.  int f, stat;
  835.  
  836.  s = _telix_dir;
  837.  strcat(s, "HOST.CNF");
  838.  
  839.  f = fopen(s, "r");
  840.  if (!f)
  841.   {
  842.    printsc("Can't open ");
  843.    prints(s);
  844.    return -1;
  845.   }
  846.  
  847.  stat = fgets(s, 80, f);
  848.  if (stat == -1)
  849.   goto got_error;
  850.  pass1 = s;
  851.  
  852.  stat = fgets(s, 80, f);
  853.  if (stat == -1)
  854.   goto got_error;
  855.  pass2 = s;
  856.  
  857.  stat = fgets(s, 80, f);
  858.  if (stat == -1)
  859.   goto got_error;
  860.  shellpass = s;
  861.  
  862.  stat = fgets(s, 80, f);
  863.  if (stat == -1)
  864.   goto got_error;
  865.  shutpass = s;
  866.  
  867.  stat = fgets(s, 80, f);
  868.  if (stat == -1)
  869.   goto got_error;
  870.  host_downloads = s;
  871.  
  872.  stat = fgets(s, 80, f);
  873.  if (stat == -1)
  874.   goto got_error;
  875.  host_uploads = s;
  876.  
  877.  stat = fgets(s, 80, f);
  878.  if (stat == -1)
  879.   goto got_error;
  880.  direct_connect = (toupper(subchr(s, 0)) == 'D');
  881.  
  882.  fclose(f);
  883.  return 1;
  884.  
  885. // jump here if error
  886.  
  887.  got_error:
  888.   fclose(f);
  889.   return -1;
  890.  
  891. }
  892.  
  893. //////////////////////////////////////////////////////////////////////////////
  894.  
  895. check_directories()
  896.  
  897. {
  898.  str s[80];
  899.  int i, a;
  900.  
  901.  // first remove trailing slashes
  902.  
  903.  s = host_uploads;
  904.  i = strlen(s);
  905.  if (i > 0)
  906.   if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  907.    setchr(s, i - 1, 0);
  908.  if (s && !(strlen(s) == 2 && subchr(s, 1) == ':'))
  909.   {
  910.    a = fileattr(s);
  911.    if (a == -1 || !(a & 16))
  912.     return 0;                  // not a directory or doesn't exist
  913.   }
  914.  
  915.  s = host_downloads;
  916.  i = strlen(s);
  917.  if (i > 0)
  918.   if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  919.    setchr(s, i - 1, 0);
  920.  if (s && !(strlen(s) == 2 && subchr(s, 1) == ':'))
  921.   {
  922.    a = fileattr(s);
  923.    if (a == -1 || !(a & 16))
  924.     return 0;                  // not a directory or doesn't exist
  925.   }
  926.  
  927.  return 1;
  928.  
  929. }
  930.  
  931. //////////////////////////////////////////////////////////////////////////////
  932. // returns TRUE if passed filespec is just a filename. Also handles the
  933. // forward slash as a path separator.
  934.  
  935. just_filename(str filespec)
  936.  
  937. {
  938.  int slash, space;
  939.  
  940.  if (strpos(filespec, ":", 0) != -1)
  941.   return 0;
  942.  if (strpos(filespec, "\", 0) != -1)
  943.   return 0;
  944.  if ((slash = strpos(filespec, "/")) == -1)
  945.   return 1;
  946.  
  947.  space = strpos(filespec, " ");
  948.  if (space == -1)
  949.   return 0;
  950.  if (space < slash)
  951.   return 1;
  952.  
  953.  return 0;
  954.  
  955. }
  956.  
  957. //////////////////////////////////////////////////////////////////////////////
  958.