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