home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TELIX.ZIP / TELIX351.DAT / QDHOST.SLT < prev    next >
Text File  |  1996-05-01  |  29KB  |  1,103 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //   Q D H O S T . S L T
  4. //
  5. //   Copyright (C) 1988-1992 deltaComm Development.
  6. //
  7. //   - Written by Colin Sampaleanu.
  8. //   - Modifications by Jeff Woods, Feb '91, to add help function and support
  9. //     for locked modems.
  10. //   - Modifications by Dan Horn, Nov '92, fixed 'floating' timer bug.
  11. //   - Modifications by Bernd Giesen (ELSA), Apr '96, added 'fclose(f)'
  12. //     at line 575 to free file handle in case of error.
  13. //
  14. //
  15. //   This is a Host Mode for Telix, written as a script file.
  16. //   To configure Host Mode parameters such as passwords, run the 'QDCONFIG'
  17. //   script. That script is run automatically if the Host Mode configuration
  18. //   file 'QDHOST.CNF' is missing.
  19. //
  20. //   This script will only work with Hayes compatible modems, but may be
  21. //   modified for operation with other modems.
  22. //
  23. //////////////////////////////////////////////////////////////////////////////
  24.  
  25. // Parameters which can be configured
  26.  
  27. str pass1[8] = "pass1",                 // The level 1 pass
  28.     pass2[8] = "pass2",                 // The level 2 (Sysop) pass
  29.     shellpass[8] = "shell",             // the pass to enter the Remote Shell
  30.     shutpass[8] = "shut",               // the pass to shut down the Host Mode
  31.     host_downloads[64],                 // where users may download from
  32.     host_uploads[64];                   // where uploaded files go
  33. int direct_connect = 0,
  34.     modem_lock = 0;
  35.  
  36. str current_caller[31],                 // storage of current caller's name
  37.     conn300[] = "CONNECT^M",            // modem result messages for bauds
  38.     conn1200[] = "CONNECT 1200",
  39.     conn2400[] = "CONNECT 2400",
  40.     conn9600[] = "CONNECT 9600",
  41.     conn19200[] = "CONNECT 19200";
  42.  
  43. int finished_caller,                    // set to TRUE when must return to top
  44.     local_mode,                         // set to TRUE when local test mode
  45.     access_level,                       // access level of current caller
  46.     carrier_counts = 1,                 // TRUE if should watch Carrier signal
  47.     already_connected = 0,
  48.     exit_requested = 0,                 // set to TRUE if Sysop has pressed Esc
  49.     connection_lost = 0,                // set to TRUE when carrier lost
  50.     kill_user = 0;                      // set to TRUE when user must be purged
  51.  
  52. int old_scr_chk_key,                    // storage for some system variables
  53.     old_cisb_auto,                      // which we have to modify and put
  54.     old_zmod_auto,                      // back to what they were when done
  55.     old_sound;
  56. str old_down_dir[64],
  57.     old_up_dir[64],
  58.     old_usage_fname[64];
  59.  
  60. //////////////////////////////////////////////////////////////////////////////
  61. //////////////////////////////////////////////////////////////////////////////
  62.  
  63. main()
  64.  
  65. {
  66.  int c;
  67.  
  68.  clear_scr();
  69.  
  70.  if (read_host_config_file() == -1)
  71.   {
  72.    prints("Unable to read QDHOST.CNF...");
  73.    prints("Running QDCONFIG, the Host Mode configuration script.^M^J");
  74.    call("QDCONFIG");
  75.    if (read_host_config_file() == -1)
  76.     {
  77.      prints("Still unable to read QDHOST.CNF. Aborting Host Mode.^M^J");
  78.      return -1;
  79.     }
  80.   }
  81.  
  82.  if (!check_directories())
  83.   {
  84.    prints("Either the upload or download directory as defined in the QDHOST.CNF file");
  85.    prints("doesn't exist. Either create the missing directory with the DOS 'MKDIR'");
  86.    prints("command, or run the QDCONFIG script to redefine what directories to use.");
  87.    prints("Aborting Host Mode.");
  88.    return -1;
  89.   }
  90.  
  91.  old_scr_chk_key = _scr_chk_key;
  92.  _scr_chk_key = 0;
  93.  old_cisb_auto = _cisb_auto;
  94.  _cisb_auto = 0;
  95.  old_zmod_auto = _zmod_auto;
  96.  _zmod_auto = 0;
  97.  old_sound = _sound_on;
  98.  _sound_on = 0;
  99.  old_down_dir = _down_dir;
  100.  _down_dir = host_uploads;   // these are reversed because we are now the Host
  101.  old_up_dir = _up_dir;
  102.  _up_dir = host_downloads;   // these are reversed because we are now the Host
  103.  old_usage_fname = _usage_fname;
  104.  
  105.  usagelog("QDHOST.LOG");
  106.  
  107.  if (direct_connect)
  108.   carrier_counts = 0;
  109.  else
  110.   carrier_counts = 1;
  111.  
  112.  if (!direct_connect && carrier())
  113.   already_connected = 1;
  114.  
  115.  
  116.  while (1)
  117.   {
  118.    if (!direct_connect && !already_connected)
  119.     {
  120.      if (!modem_lock)
  121.         set_cparams(modem_lock, 0, 8, 1);
  122.      delay(3);
  123.      prints("Sending Modem Init string...");
  124.      cputs_tr(_mdm_init_str);
  125.      delay(10);
  126.      prints("Sending Auto-Answer string...");
  127.      cputs_tr(_auto_ans_str);
  128.     }
  129.  
  130.    finished_caller = kill_user = 0;
  131.  
  132.    if (direct_connect)
  133.     carrier_counts = 0;
  134.    else
  135.     carrier_counts = 1;
  136.  
  137.    if (!direct_connect)
  138.     {
  139.      prints("^M^JQDHost Mode: Waiting for call...");
  140.      prints("(Press Esc to exit, or 'L' for local test mode).^M^J");
  141.  
  142.      do
  143.       {
  144.        if (carrier())
  145.         {
  146.          local_mode = 0;
  147.          break;
  148.         }
  149.  
  150.        c = inkey();
  151.        if (c)
  152.         {
  153.          if (c == 27)
  154.           {
  155.            exit_requested = 1;
  156.            break;
  157.           }
  158.          else if (c == 'l' || c == 'L')               // local teswt mode
  159.           {
  160.            prints("Local test mode entered");
  161.            local_mode = 1;
  162.            carrier_counts = 0;
  163.           }
  164.         }
  165.       }
  166.      while (toupper(c) != 'L');
  167.     }
  168.  
  169.    if (!exit_requested)
  170.     {
  171.      prints("Incoming call. Sysop: press Esc to exit, or END to terminate user.");
  172.  
  173.      do_one_caller();
  174.      if ((connection_lost || kill_user) && carrier_counts && carrier())
  175.       hangup();             // make sure nobody sneaks in
  176.     }
  177.    already_connected = 0;
  178.    if (exit_requested)
  179.     {
  180.      if (!carrier() && !direct_connect)
  181.       {
  182.        prints("Sending Modem Init string...");
  183.        cputs_tr(_mdm_init_str);
  184.       }
  185.      _scr_chk_key = old_scr_chk_key;
  186.      _cisb_auto = old_cisb_auto;
  187.      _zmod_auto = old_zmod_auto;
  188.      _sound_on = old_sound;
  189.      _down_dir = old_down_dir;
  190.      _up_dir = old_up_dir;
  191.      prints("^M^JQDHost mode script finished.");
  192.      usagelog("*CLOSE*");
  193.      _usage_fname = old_usage_fname;
  194.      return 1;
  195.     }
  196.   }
  197. }
  198.  
  199. //////////////////////////////////////////////////////////////////////////////
  200.  
  201. HelpOn(int option)
  202.  
  203. {
  204.    if (option == 'H')
  205.     {
  206.      host_send("^M^JHelp on Help^M^J");
  207.      host_send("^M^JTo use the help, simply type the first letter of one of the following:");
  208.      host_send("^M^J^M^J<H>elp <F>iles <T>ype <U>pload <D>ownload <S>hell <C>hat <G>oodbye");
  209.      Host_send("^M^J");
  210.     }
  211.    if (option == 'F')
  212.     {
  213.      host_send("^M^JHelp on Files^M^J");
  214.      host_send("^M^JThe 'Files' option allows the caller to list the files in the");
  215.      host_send("^M^Jcurrent disk directory. The caller must press a key after each");
  216.      host_send("^M^Jscreen. The output is not echoed on the local screen. If the");
  217.      host_send("^M^Jcaller has access level two s/he is prompted for a filespec,");
  218.      host_send("^M^Jwhich may include the * and ? wildcard characters (see your");
  219.      host_send("^M^JDOS manual), so that the contents of other directories than");
  220.      host_send("^M^Jthe 'Host download dir' may be listed.");
  221.      Host_send("^M^J");
  222.     }
  223.    if (option == 'T')
  224.     {
  225.      host_send("^M^JHelp on Type^M^J");
  226.      host_send("^M^JThe 'Type' option allows the caller to view any ASCII file in");
  227.      host_send("^M^Jthe Host Download Directory, or in any directory for access");
  228.      host_send("^M^JLevel 2 callers.   Simply give the name (or full path and name)");
  229.      host_send("^M^Jof the system file you wish to view:    ie. C:\TELIX\TELIX.IMG");
  230.      Host_send("^M^J");
  231.     }
  232.    if (option == 'U')
  233.     {
  234.      host_send("^M^JHelp on Uploading^M^J");
  235.      host_send("^M^JThe 'Upload' option allows the caller to send a file to the");
  236.      host_send("^M^Jhost. The caller is shown the a menu of protocols.   He/she");
  237.      host_send("^M^Jshould select the appropriate protocol by its first letter");
  238.      host_send("^M^J(or 'E' for Ymodem-g). If appropriate the caller is also asked");
  239.      host_send("^M^Jfor the filename.  The transfer is then initiated by QDHOST.  The");
  240.      host_send("^M^Jcaller must then initiate the upload on THEIR side by giving");
  241.      host_send("^M^Jtheir comm program an upload instruction, choosing the same");
  242.      host_send("^M^Jprotocol as they told host, and giving the filename again,");
  243.      host_send("^M^Jwithin 60 seconds of telling QDHOST the same information.");
  244.      Host_send("^M^J");
  245.     }
  246.    if (option == 'D')
  247.     {
  248.      host_send("^M^JHelp on Downloading^M^J");
  249.      host_send("^M^JThe 'Download' command allows a caller to receive a file from");
  250.      host_send("^M^Jthe host. The caller must select the protocol after giving the");
  251.      host_send("^M^Jdownload command to QDHOST, and then must tell QDHOST what files");
  252.      host_send("^M^Jto send.    Some protocols like ZModem will start automatically");
  253.      host_send("^M^Jafter this.   Others, like XModem, require the caller to start");
  254.      host_send("^M^Ja download in their comm program at this point (usually Pg-Dn)");
  255.      host_send("^M^Jand will be asked by the comm program for a file name again.  The");
  256.      host_send("^M^Jtransfer is then initiated.");
  257.      Host_send("^M^J");
  258.     }
  259.    if (option == 'S')
  260.     {
  261.      host_send("^M^JHelp on Shelling^M^J");
  262.      host_send("^M^JThe 'Shell' command is a very powerful but also very dangerous");
  263.      host_send("^M^Jcommand. It allows the caller to run a DOS shell on the sys-");
  264.      host_send("^M^Jtem, except that the caller receives the output, and the");
  265.      host_send("^M^Jcaller enters the keystrokes.   The caller has complete control");
  266.      host_send("^M^Jof the HOST system at the DOS level.   Shell is a password");
  267.      host_send("^M^Jprotected feature of QDHOST.  The caller sees program output only");
  268.      host_send("^M^Jif the programs use standard DOS output. Programs that write");
  269.      host_send("^M^Jdirectly to the video screen will work, but will not be seen");
  270.      host_send("^M^Jby the remote caller. As well, programs that use non-DOS meth-");
  271.      host_send("^M^Jods of getting keystrokes will not receive the callers");
  272.      host_send("^M^Jkeystrokes. Finally, under some systems, if the caller presses");
  273.      host_send("^M^JBackspace at the DOS prompt when the current line is empty,");
  274.      host_send("^M^JDOS will hang on the Host machine. As these are functions of");
  275.      host_send("^M^JDOS, there is nothing that can be done about these limits.");
  276.      Host_send("^M^J");
  277.     }
  278.    if (option == 'C')
  279.     {
  280.      host_send("^M^JHelp on Chatting^M^J");
  281.      host_send("^M^JThe 'Chat' command allows the caller to chat with the host op-");
  282.      host_send("^M^Jerator. When the caller presses 'C' the host operator is paged");
  283.      host_send("^M^Jfor 20 seconds.    If the host operator responds, you will see");
  284.      host_send("^M^Jhim/her typing on your screen.    If you can, place yourself in");
  285.      host_send("^M^JChat Mode, by using your comm program's chat mode (Telix's is");
  286.      host_send("^M^JAlt-Y).   You will then see what you type on half of the screen");
  287.      host_send("^M^Jand the operator's words on the other half.");
  288.      Host_send("^M^J");
  289.     }
  290.    if (option == 'G')
  291.     {
  292.      host_send("^M^JHelp on Goodbye^M^J");
  293.      host_send("^M^JThe 'Goodbye' command allows the caller to log off the host");
  294.      Host_send("^M^J");
  295.     }
  296. }
  297.  
  298. //////////////////////////////////////////////////////////////////////////////
  299.  
  300. do_one_caller()
  301.  
  302. {
  303.  str strn[80],
  304.      fname[64];
  305.  int option,
  306.      status,
  307.      c, i, i2, f;
  308.  
  309.  access_level = 1;
  310.  
  311.  if (already_connected)
  312.   prints("Already connected, or modem Carrier Detect switch improperly set!");
  313.  else if (carrier_counts)
  314.   {
  315.    if (!modem_lock)
  316.     if (!determine_baud())
  317.     ;                          // do something else here if this is a problem
  318.   }
  319.  
  320.  delay(10);
  321.  type_file("LOGO.MSG");
  322.  
  323.  flushbuf();
  324.  while (1)
  325.   {
  326.    host_send("Please enter your full name: ");
  327.    host_input_strn(current_caller, 30, 1);
  328.    host_send("^M^J");
  329.  
  330.    if (finished_caller)
  331.     return;
  332.  
  333.    if (strlen(current_caller) >= 5)
  334.     break;
  335.   }
  336.  
  337.  access_level = ask_for_pass(3, pass1, pass2);
  338.  
  339.  if (access_level)
  340.   ustamp("Logon by ", 1, 0);
  341.  else
  342.   ustamp("Failed logon attempt by ", 1, 0);
  343.  ustamp(current_caller, 0, 1);
  344.  
  345.  if (!access_level)
  346.   {
  347.    host_send("Goodbye!^M^J");
  348.    if (carrier_counts)
  349.     {
  350.      delay(10);
  351.      hangup();
  352.     }
  353.    return;
  354.   }
  355.  
  356.  type_file("WELCOME.MSG");
  357.  
  358.  while (1)
  359.   {
  360.    if (finished_caller)
  361.     return;
  362.  
  363.    host_send("^M^JCommand: <H>elp <F>iles <T>ype <U>pload <D>ownload <S>hell <C>hat <G>oodbye ? ");
  364.    host_input_strn(strn, 1, 1);
  365.    option = toupper(subchr(strn, 0));
  366.    host_send("^M^J");
  367.  
  368.    if (option == 'H')
  369.     {
  370.      host_send("^M^J^M^JWhich item above do you wish help on? ");
  371.      host_input_strn(strn, 1, 1);
  372.      Option = toupper(subchr(strn, 0));
  373.      Host_send("^M^J");
  374.      HelpOn(Option);
  375.      Option = 'H';
  376.     }
  377.    if (option == 'F')                 // Files directory
  378.     {
  379.      if (access_level == 2)
  380.       {
  381.        host_send("Enter 'filespec' or press Return for *.*,^M^J: ");
  382.        host_input_strn(fname, 64, 1);
  383.        host_send("^M^J");
  384.  
  385.        if (just_filename(fname))
  386.         {
  387.          strn = host_downloads;
  388.          strcat(strn, fname);
  389.         }
  390.        else
  391.         strn = fname;
  392.       }
  393.      else
  394.       {
  395.        strn = host_downloads;
  396.        strcat(strn, "*.*");
  397.       }
  398.  
  399.      if (local_mode)
  400.       show_directory(strn, 0, carrier_counts);
  401.      else
  402.       show_directory(strn, 1, carrier_counts);
  403.      host_send("^M^J");
  404.     }
  405.    else if (option == 'T')            // Type a file
  406.     {
  407.      host_send("Type what file? ");
  408.      host_input_strn(strn, 64, 1);
  409.      host_send("^M^J");
  410.      if (access_level != 2)             // if access 1, name and ext only
  411.       fnstrip(strn, 3, fname);
  412.      else
  413.       fname = strn;
  414.  
  415.      if (just_filename(fname))
  416.       {
  417.        strn = host_downloads;
  418.        strcat(strn, fname);
  419.        fname = strn;
  420.       }
  421.  
  422.      if (!filefind(fname, 0, strn))
  423.       {
  424.        host_send("Unable to find ");
  425.        host_send(fname);
  426.        continue;
  427.       }
  428.  
  429.      type_file(fname);
  430.     }
  431.    else if (option == 'G')            // Goodbye (Hang-up)
  432.     {
  433.      host_send("^M^JGoodbye!^M^J");
  434.      ustamp("User logged off.", 1, 1);
  435.      if (carrier_counts)
  436.       {
  437.        delay(10);
  438.        hangup();
  439.       }
  440.      return;
  441.     }
  442.    else if (option == 'C')            // Chat mode
  443.     {
  444.      prints("Sysop: Press <Space> to chat, any other key not to.^M^J");
  445.      c = 0;
  446.      _sound_on = 1;
  447.      for (i = 8; i && !c; --i)
  448.       {
  449.        if (carrier_counts && !carrier())
  450.         {
  451.          prints("^M^JConnection has been lost, call terminated.^M^J");
  452.          connection_lost = 1;
  453.          finished_caller = 1;
  454.          break;
  455.         }
  456.        cputc('^G');
  457.        tone(523, 20);
  458.        tone(659, 20);
  459.        tone(523, 20);
  460.        tone(659, 20);
  461.        tone(523, 20);
  462.        tone(659, 20);
  463.        for (i2 = 30; i2 && (c = inkey()) == 0; --i2)
  464.         delay(1);
  465.       }
  466.      _sound_on = 0;
  467.      if (finished_caller)
  468.       continue;
  469.      if (c != ' ' || !c)
  470.       {
  471.        host_send("Sorry, the Sysop is unavailable^M^J");
  472.        continue;
  473.       }
  474.      host_send("The sysop is here!^M^J");
  475.      chatmode(1);
  476.     }
  477.    else if (option == 'U')            // User upload
  478.     {
  479.      option = host_get_prot();
  480.      if (!option)
  481.       continue;
  482.  
  483.      status = 1;
  484.      if (option == 'T' || option == 'M' || option == 'S' ||
  485.          option == 'Y' || option == 'Z' || option == 'E')
  486.       {
  487.        send_transfer_msg();
  488.        status = receive(option, "");
  489.       }
  490.      else
  491.       {
  492.        host_send("Upload what file? ");
  493.        host_input_strn(strn, 48, 1);
  494.        host_send("^M^J");
  495.        if (!strn)
  496.         continue;
  497.        if (access_level != 2)             // if access 1, name and ext only
  498.         fnstrip(strn, 3, fname);
  499.        else
  500.         fname = strn;
  501.  
  502.        if (just_filename(fname))
  503.         {
  504.          strn = host_uploads;
  505.          strcat(strn, fname);
  506.          fname = strn;
  507.         }
  508.  
  509.        if (filefind(fname, 23, strn))
  510.         host_send("File already exists!^M^J");
  511.        else
  512.         {
  513.          send_transfer_msg();
  514.          status = receive(option, fname);
  515.         }
  516.       }
  517.      if (status == -2)                        // Carrier lost
  518.       connection_lost = finished_caller = 1;
  519.      else if (status == -1)
  520.       host_send("^GOne or more files not received!^M^J");
  521.     }
  522.    else if (option == 'D')            // User download
  523.     {
  524.      option = host_get_prot();
  525.      if (!option)
  526.       continue;
  527.      host_send("Download what file(s)? ");
  528.      host_input_strn(strn, 48, 1);
  529.      host_send("^M^J");
  530.      if (!strn)
  531.       continue;
  532.      if (access_level != 2)      // if not level 2, keep only name & ext
  533.       fnstrip(strn, 3, fname);
  534.      else
  535.       fname = strn;
  536.  
  537.      if (just_filename(fname))
  538.       {
  539.        strn = host_downloads;
  540.        strcat(strn, fname);
  541.        fname = strn;
  542.       }
  543.  
  544.      if (!filefind(fname, 0, strn))
  545.       {
  546.        host_send("Unable to find any matching file(s)!^M^J");
  547.        continue;
  548.       }
  549.  
  550.      status = 1;
  551.      send_transfer_msg();
  552.      status = send(option, fname);
  553.      if (status == -2)                        // Carrier lost
  554.       connection_lost = finished_caller = 1;
  555.      else if (status == -1)
  556.       host_send("^GOne or more files not received!^M^J");
  557.     }
  558.    else if (option == 'S')            // Remote shell
  559.     {
  560.      if (ask_for_pass(3, shellpass, shellpass) != 0)
  561.       {
  562.        host_send("Type EXIT and then press Enter to come back.^M^J");
  563.        if (get_baud() == 300)
  564.         delay(10);
  565.        if (local_mode)
  566.         dos("", 0);
  567.                  // See if user has prepared a custom file for shell operation
  568.                  // and call that if it exists
  569.        else if (filefind("RSHELL.BAT", 0, strn))
  570.         dos("RSHELL.BAT", 0);
  571.        else   // otherwise make our own temporary batch file for redirection
  572.         {
  573.          // now want to make a temporary batch file which will be called
  574.          // to redirect DOS input and output, then shell to another copy
  575.          // of COMMAND.COM
  576.          f = fopen("HOSTTEMP.BAT", "w");
  577.          if (f)
  578.           {
  579.            if (get_port() != 1 && get_port() != 2)
  580.             {
  581.              host_send("Remote Shell not supported on this comm port due to DOS limits!^M^J");
  582.              fclose(f);
  583.              continue;
  584.             }
  585.  
  586.            strn = "COMx";
  587.            setchr(strn, 3, get_port() + '0'); // get right name to redirect
  588.  
  589.            fputs("CTTY ", f);           // write to batch file
  590.            fputs(strn, f);
  591.            fputs("^M^JCOMMAND^M^J", f);
  592.            fputs("CTTY CON^M^J", f);
  593.            fputs("EXIT^M^J", f);
  594.  
  595.            fclose(f);                   // close the file
  596.  
  597.            if (!local_mode)             // call batch file
  598.             dos("HOSTTEMP.BAT", 0);
  599.           }
  600.          else
  601.           host_send("Can't open temporary batch file!^M^J");
  602.         }
  603.       }
  604.     }
  605.    else if (option == '^Z')            // Shut down Host Mode
  606.     {
  607.      host_send("Shut down QDHost mode. ");
  608.      if (!ask_for_pass(3, shutpass, shutpass))
  609.       continue;
  610.      host_send("Goodbye!^M^J");
  611.      if (carrier_counts)
  612.       hangup();
  613.      ustamp("User shut down QDHost Mode.", 1, 1);
  614.      finished_caller = 1;
  615.      exit_requested = 1;
  616.     }
  617.   }
  618. }
  619.  
  620. //////////////////////////////////////////////////////////////////////////////
  621.  
  622. host_get_prot()
  623.  
  624. {
  625.  str prot[1];
  626.  
  627.  host_send("^M^JModem7  SEAlink  Xmodem  1k-Xmodem  G-1k-Xmodem  Ymodem  YmodEm-g  Zmodem^M^J");
  628.  host_send("Which protocol? ");
  629.  host_input_strn(prot, 1, 1);
  630.  host_send("^M^J");
  631.  
  632.  if (strposi("MSX1GYEZ", prot, 0) == -1)     // if illegal prot
  633.   prot = "";                                 // return 0
  634.  
  635.  return (toupper(subchr(prot, 0)));
  636.  
  637. }
  638.  
  639. //////////////////////////////////////////////////////////////////////////////
  640.  
  641. send_transfer_msg()
  642.  
  643. {
  644.  host_send("Ready to transfer file(s)... Press Ctrl-X at least twice to abort^M^J");
  645. }
  646.  
  647. //////////////////////////////////////////////////////////////////////////////
  648. // Determine the baud rate once a Carrier Detect Signal has been detected
  649. // Since no characters were read, the 'CONNECT' string should still be
  650. // in the receive buffer.
  651.  
  652. determine_baud()
  653.  
  654. {
  655.  int t3, t12, t24, t96, t192;
  656.  int tmark, stat;
  657.  int new_baud = 0;
  658.  
  659.  printsc("Determining baud... ");
  660.  
  661.  track_free(0);                // clear all existing tracks
  662.  
  663.  t3 = track(conn300, 0);       // check for connect strings
  664.  t12 = track(conn1200, 0);
  665.  t24 = track(conn2400, 0);
  666.  t96 = track(conn9600, 0);
  667.  t192 = track(conn19200, 0);
  668.  
  669.  tmark = timer_start(30);      // wait up to 3 seconds for string
  670.  
  671.  while (!time_up(tmark))
  672.   {
  673.    if (!carrier())
  674.     {
  675.      track_free(0);            // clear all existing tracks
  676.      timer_free(tmark);        // free existing timer
  677.      return 0;
  678.     }
  679.  
  680.    if (cinp_cnt())
  681.     track_addchr(cgetc());
  682.  
  683.    stat = track_hit(0);
  684.    if (stat == 0)
  685.     continue;
  686.  
  687.    if (stat == t3)
  688.     new_baud = 300;
  689.    else if (stat == t24)
  690.     new_baud = 2400;
  691.    else if (stat == t96)
  692.     new_baud = 9600;
  693.    else if (stat == t192)
  694.     new_baud = 19200;
  695.    else
  696.     new_baud = 1200;
  697.  
  698.    break;                      // have baud rate, get out
  699.   }
  700.  
  701.  track_free(0);                // clear all existing tracks
  702.  timer_free(tmark);            // free existing timer
  703.  
  704.  if (!new_baud)                // time-up without CONNECT string
  705.   {
  706.    prints("Failed!");
  707.    return 0;
  708.   }
  709.  
  710.  printn(new_baud);
  711.  prints("");
  712.  set_cparams(new_baud, get_parity(), get_datab(), get_stopb());
  713.  
  714.  return 1;                     // indicate success
  715.  
  716. }
  717.  
  718. //////////////////////////////////////////////////////////////////////////////
  719.  
  720. type_file(str fname)
  721.  
  722. {
  723.  int f;
  724.  str buf[100];
  725.  int ichar, lines_sent = 0;
  726.  
  727.  f = fopen(fname, "r");
  728.  if (!f)
  729.   return -1;
  730.  
  731.  host_send("^M^J");
  732.  
  733.  while (1)
  734.   {
  735.    if (carrier_counts)
  736.     if (!carrier())
  737.      {
  738.       connection_lost = 1;
  739.       finished_caller = 1;
  740.       fclose(f);
  741.       return 0;
  742.      }
  743.  
  744.    if (fgets(buf, 80, f) == -1)
  745.     {
  746.      fclose(f);
  747.      return 1;
  748.     }
  749.  
  750.    host_send(buf);
  751.    host_send("^M^J");
  752.    ++lines_sent;
  753.  
  754.    if (lines_sent >= 22)
  755.     {
  756.      lines_sent = 0;
  757.      host_send("[More]");
  758.      host_input(1);
  759.  
  760.      if (finished_caller)         // if user inactivity
  761.       {
  762.        fclose(f);
  763.        return 0;
  764.       }
  765.  
  766.      host_send("^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H");
  767.     }
  768.  
  769.    while (cinp_cnt())
  770.     {
  771.      ichar = cgetc();
  772.      if (ichar == '^C' || ichar == '^K')
  773.       {
  774.        host_send("^M^J");
  775.        fclose(f);
  776.        return 1;
  777.       }
  778.     }
  779.   }
  780. }
  781.  
  782. //////////////////////////////////////////////////////////////////////////////
  783.  
  784. host_send(str outstr)
  785.  
  786. {
  787.  
  788.  printsc(outstr);
  789.  if (!local_mode)
  790.   cputs(outstr);
  791.  
  792. }
  793.  
  794. //////////////////////////////////////////////////////////////////////////////
  795.  
  796. host_send_c(int chr)
  797.  
  798. {
  799.  
  800.  printc(chr);
  801.  if (!local_mode)
  802.   cputc(chr);
  803.  
  804. }
  805.  
  806. //////////////////////////////////////////////////////////////////////////////
  807.  
  808. host_input_strn(str buf, int maximum, int echoable)
  809.  
  810. {
  811.  int i = 0, key;
  812.  
  813.  while (1)
  814.   {
  815.    key = host_input(echoable);
  816.    if (!key)                 // timeout or user disconnect
  817.     {
  818.      setchr(buf, 0, 0);      // set string to empty
  819.      return 0;               // indicate there is a problem
  820.     }
  821.  
  822.    if (key == '^M')
  823.     break;
  824.    if (key == 127 || key == 8)
  825.     {
  826.      if (i)
  827.       {
  828.        --i;
  829.          host_send_c(key);
  830.       }
  831.      continue;
  832.     }
  833.    if (i < maximum)
  834.     {
  835.      setchr(buf, i, key);
  836.      i = i + 1;
  837.     }
  838.    else
  839.     i = i + 1;
  840.   }
  841.  
  842.  if (i > maximum)
  843.   i = maximum;
  844.  
  845.  setchr(buf, i, '^0');
  846.  
  847.  if (subchr(buf, 0))
  848.   return 1;
  849.  else
  850.   return 0;
  851.  
  852. }
  853.  
  854. //////////////////////////////////////////////////////////////////////////////
  855.  
  856. host_input(int echoable)
  857.  
  858. {
  859.  int c;
  860.  int t;
  861.  
  862.  t = timer_start(2400);         // 4 minutes inactivity allowed
  863.  
  864.  while (1)
  865.   {
  866.    if (time_up(t) && !direct_connect)
  867.     {
  868.      host_send("^M^J^M^JInactivity period too long. Connection terminated!^M^J");
  869.      if (carrier_counts)
  870.       hangup();
  871.      finished_caller = 1;
  872.      kill_user = 1;
  873.      break;
  874.     }
  875.  
  876.    if (carrier_counts)
  877.     if (!carrier())
  878.       {
  879.        prints("^M^JConnection has been lost, call terminated.^M^J");
  880.        connection_lost = 1;
  881.        finished_caller = 1;
  882.        break;
  883.       }
  884.  
  885.    if ((c = inkey()) != 0)
  886.     {
  887.      if (c == 27)               // ESC key, sysop wants to exit
  888.       {
  889.        finished_caller = 1;
  890.        exit_requested = 1;
  891.        break;
  892.       }
  893.      else if (c == 0x4f00)      // END key, temrinate user
  894.       {
  895.        prints("^M^JUser terminated!");
  896.        ustamp("User terminated!", 1, 1);
  897.        if (carrier_counts)
  898.         hangup();
  899.  
  900.        finished_caller = 1;
  901.        kill_user = 1;
  902.        break;
  903.       }
  904.  
  905.      else if (c <= 255)
  906.       {
  907.        if (c != 8 && c != 127)
  908.         if (!echoable)
  909.          host_send_c('*');
  910.         else
  911.          host_send_c(c);
  912.        break;
  913.       }
  914.     }
  915.  
  916.    if (!local_mode)
  917.     if (cinp_cnt())
  918.      {
  919.       c = cgetc();
  920.       if (c != 8 && c != 127)
  921.        if (!echoable)
  922.         host_send_c('*');
  923.        else
  924.         host_send_c(c);
  925.       break;
  926.      }
  927.   }
  928.  
  929.  timer_free(t);                 // free existing timer
  930.  if (finished_caller)
  931.    return 0;                    // return 0 - no character
  932.  
  933.  return c;                      // return received/pressed character
  934. }
  935.  
  936. //////////////////////////////////////////////////////////////////////////////
  937.  
  938. ask_for_pass(int maxtries, str pass1, str pass2)
  939.  
  940. {
  941.  int i;
  942.  str strn[8];
  943.  
  944.  for (i = 0; i < maxtries; ++i)
  945.   {
  946.    if (i)
  947.     host_send("Wrong! Try again.^M^J");
  948.    host_send("Password: ");
  949.    host_input_strn(strn, 8, 0);
  950.    host_send("^M^J");
  951.  
  952.    if (finished_caller)
  953.     return 0;
  954.  
  955.    if (!strcmpi(strn, pass1))
  956.     return 1;
  957.  
  958.    if (!strcmpi(strn, pass2))
  959.     return 2;
  960.   }
  961.  
  962.  host_send("No more chances. Access denied.^M^J");
  963.  
  964.  return 0;
  965.  
  966. }
  967.  
  968. //////////////////////////////////////////////////////////////////////////////
  969.  
  970. read_host_config_file()
  971.  
  972. {
  973.  str s[80];
  974.  int f, stat;
  975.  
  976.  s = _telix_dir;
  977.  strcat(s, "QDHOST.CNF");
  978.  
  979.  f = fopen(s, "r");
  980.  if (!f)
  981.   {
  982.    printsc("Can't open ");
  983.    prints(s);
  984.    return -1;
  985.   }
  986.  
  987.  stat = fgets(s, 80, f);
  988.  if (stat == -1)
  989.   goto got_error;
  990.  pass1 = s;
  991.  
  992.  stat = fgets(s, 80, f);
  993.  if (stat == -1)
  994.   goto got_error;
  995.  pass2 = s;
  996.  
  997.  stat = fgets(s, 80, f);
  998.  if (stat == -1)
  999.   goto got_error;
  1000.  shellpass = s;
  1001.  
  1002.  stat = fgets(s, 80, f);
  1003.  if (stat == -1)
  1004.   goto got_error;
  1005.  shutpass = s;
  1006.  
  1007.  stat = fgets(s, 80, f);
  1008.  if (stat == -1)
  1009.   goto got_error;
  1010.  host_downloads = s;
  1011.  
  1012.  stat = fgets(s, 80, f);
  1013.  if (stat == -1)
  1014.   goto got_error;
  1015.  host_uploads = s;
  1016.  
  1017.  stat = fgets(s, 80, f);
  1018.  if (stat == -1)
  1019.   goto got_error;
  1020.  direct_connect = (toupper(subchr(s, 0)) == 'D');
  1021.  
  1022.  stat = fgets(s, 80, f);
  1023.  if (stat == -1)
  1024.   goto got_error;
  1025.  modem_lock = stoi(s);
  1026.  
  1027.  fclose(f);
  1028.  return 1;
  1029.  
  1030. // jump here if error
  1031.  
  1032.  got_error:
  1033.   fclose(f);
  1034.   return -1;
  1035.  
  1036. }
  1037.  
  1038. //////////////////////////////////////////////////////////////////////////////
  1039.  
  1040. check_directories()
  1041.  
  1042. {
  1043.  str s[80];
  1044.  int i, a;
  1045.  
  1046.  // first remove trailing slashes
  1047.  
  1048.  s = host_uploads;
  1049.  i = strlen(s);
  1050.  if (i > 0)
  1051.   if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  1052.    setchr(s, i - 1, 0);
  1053.  if (s && !(strlen(s) == 2 && subchr(s, 1) == ':'))
  1054.   {
  1055.    a = fileattr(s);
  1056.    if (a == -1 || !(a & 16))
  1057.     return 0;                  // not a directory or doesn't exist
  1058.   }
  1059.  
  1060.  s = host_downloads;
  1061.  i = strlen(s);
  1062.  if (i > 0)
  1063.   if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  1064.    setchr(s, i - 1, 0);
  1065.  if (s && !(strlen(s) == 2 && subchr(s, 1) == ':'))
  1066.   {
  1067.    a = fileattr(s);
  1068.    if (a == -1 || !(a & 16))
  1069.     return 0;                  // not a directory or doesn't exist
  1070.   }
  1071.  
  1072.  return 1;
  1073.  
  1074. }
  1075.  
  1076. //////////////////////////////////////////////////////////////////////////////
  1077. // returns TRUE if passed filespec is just a filename. Also handles the
  1078. // forward slash as a path separator.
  1079.  
  1080. just_filename(str filespec)
  1081.  
  1082. {
  1083.  int slash, space;
  1084.  
  1085.  if (strpos(filespec, ":", 0) != -1)
  1086.   return 0;
  1087.  if (strpos(filespec, "\", 0) != -1)
  1088.   return 0;
  1089.  if ((slash = strpos(filespec, "/")) == -1)
  1090.   return 1;
  1091.  
  1092.  space = strpos(filespec, " ");
  1093.  if (space == -1)
  1094.   return 0;
  1095.  if (space < slash)
  1096.   return 1;
  1097.  
  1098.  return 0;
  1099.  
  1100. }
  1101.  
  1102. //////////////////////////////////////////////////////////////////////////////
  1103.