home *** CD-ROM | disk | FTP | other *** search
/ 1st Canadian Shareware Disc / 1st_Canadian_Shareware_Disc_1991.ISO / comms / dbbs_12 / dbbs1.slt < prev    next >
Text File  |  1989-02-21  |  38KB  |  1,148 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //   D B B S . 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. //   To 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. // Revised by Jon Fleming to use individual
  18. //     passwords, let anyone with level 3 access get at the shell or shut
  19. //     down host mode, and not display the shell option on the menu to those
  20. //     who don't have the access level to use it.
  21. // * DBBS VERSION 1.1 *
  22. // Revised By Dennis Seaton, made about 1000 little changes such as:
  23. //     Real menus!, Messages To sysop, Sysop can see what the user
  24. //     is doing in dos, More files can be displayed, just made it
  25. //     look 60% better by doing little things.
  26. //
  27. // * DBBS VERSION 1.2 *
  28. //     I was Pissed off at some people for stealing my ideas, So Im
  29. //     stealin some of theirs! Now with: User Status, Sysop functions,
  30. //     Batch Files, More Security, and again, tons of little changes.
  31. //
  32.  
  33. // Parameters which can be configured
  34.  
  35. str password[16],                                  //caller's password
  36.     host_downloads[64],                 // where users may download from
  37.     host_uploads[64];                   // where uploaded files go
  38. int direct_connect = 0;
  39.  
  40. str current_caller[31],                 // storage of current caller's name
  41.     conn300[] = "CONNECT^M",            // modem result messages for bauds
  42.     conn1200[] = "CONNECT 1200",
  43.     conn2400[] = "CONNECT 2400",
  44.     conn9600[] = "CONNECT 9600",
  45.     conn19200[] = "CONNECT 19200";
  46. int finished_caller,                    // set to TRUE when must return to top
  47.     local_mode,                         // set to TRUE when local test mode
  48.     access_level,                       // access level of current caller
  49.     we_care_about_carrier = 1,                 // TRUE if should watch Carrier signal
  50.     already_connected = 0,
  51.     exit_requested = 0,                 // set to TRUE if Sysop has pressed Esc
  52.     connection_lost = 0,                // set to TRUE when carrier lost
  53.     kill_user = 0,                      // set to TRUE when user must be purged
  54.     min_user_name = 2;                      // Minimum length of a user name
  55.  
  56. int old_scr_chk_key,                    // storage for some system variables
  57.     old_cisb_auto,                      // which we have to modify and put
  58.     old_zmod_auto,                      // back to what they were when done
  59.     old_sound;
  60. str old_down_dir[64],
  61.     old_up_dir[64];
  62.  
  63. //////////////////////////////////////////////////////////////////////////////
  64. //////////////////////////////////////////////////////////////////////////////
  65.  
  66. main() {
  67.  
  68.    int c;
  69.  
  70.    clear_scr();
  71.  
  72.    if (read_host_config_file() == -1) {
  73.        prints("Unable to read HOST2.CNF...");
  74.        prints("Running DCONFIG, the Host Mode configuration script.^M^J");
  75.        call("DCONFIG");
  76.        if (read_host_config_file() == -1) {
  77.            prints("Still unable to read HOST2.CNF. Aborting Host Mode.^M^J");
  78.            return -1;
  79.        }
  80.    }
  81.  
  82.    if (!check_directories()) {
  83.        prints("Either the upload or download directory as defined in the HOST2.CNF file");
  84.        prints("doesn't exist. Either create the missing directory with the DOS 'MKDIR'");
  85.        prints("command, or run the DCONFIG script to redefine what directories to use.");
  86.        prints("Aborting Host Mode.");
  87.        return -1;
  88.    }
  89.  
  90.    old_scr_chk_key = _scr_chk_key;
  91.    _scr_chk_key = 0;
  92.    old_cisb_auto = _cisb_auto;
  93.    _cisb_auto = 0;
  94.    old_zmod_auto = _zmod_auto;
  95.    _zmod_auto = 0;
  96.    old_sound = _sound_on;
  97.    _sound_on = 0;
  98.    old_down_dir = _down_dir;
  99.    _down_dir = host_uploads;   // these are reversed because we are now the Host
  100.    old_up_dir = _up_dir;
  101.    _up_dir = host_downloads;   // these are reversed because we are now the Host
  102.  
  103.    usagelog("B:DBBS.LOG");
  104.  
  105.    if (direct_connect)
  106.        we_care_about_carrier = 0;
  107.    else
  108.        we_care_about_carrier = 1;
  109.  
  110.    if (!direct_connect && carrier())
  111.        already_connected = 1;
  112.  
  113.    if (!direct_connect && !already_connected) {
  114.        prints("Initializing modem");
  115.        cputs_tr(_auto_ans_str);
  116.    }
  117.  
  118.    while (1) {
  119.        finished_caller = kill_user = 0;
  120.  
  121.        if (direct_connect)
  122.            we_care_about_carrier = 0;
  123.        else
  124.            we_care_about_carrier = 1;
  125.  
  126.        if (!direct_connect) {
  127.            prints("^M^J* DBBS 1.2 *   Waiting for someone to call...");
  128.            prints("Press Esc to exit, or 'L'  for local test.^M^J");
  129.  
  130.            do {
  131.                if (carrier()) {
  132.                    local_mode = 0;
  133.                    break;
  134.                }
  135.  
  136.                c = inkey();
  137.                if (c) {
  138.                    if (c == 27) {
  139.                        exit_requested = 1;
  140.                        break;
  141.                    }
  142.                    else if (c == 'l' || c == 'L') {            // local test mode
  143.                        prints("Local test mode entered");
  144.                        local_mode = 1;
  145.                        we_care_about_carrier = 0;
  146.                    }
  147.                }
  148.            }
  149.            while (toupper(c) != 'L');
  150.        }
  151.  
  152.        if (!exit_requested) {
  153.            host_send("^LDBBS Version 1.2   -   By Dennis Seaton^G^M^J^M^J");
  154.            prints("*  Sysop: Press Esc to exit, END to terminate user, Home for Dos Functions  *");
  155.            _sound_on=1;
  156.            tone(500, 10);
  157.            tone(900, 10);
  158.            tone(500, 10);
  159.            tone(900, 10);
  160.            tone(500, 10);
  161.            tone(900, 10);
  162.            tone(500, 10);
  163.            do_one_caller();
  164.            if ((connection_lost || kill_user) && we_care_about_carrier && carrier())
  165.                hangup();             // make sure nobody sneaks in
  166.        }
  167.        already_connected = 0;
  168.        if (exit_requested) {
  169.            if (!carrier() && !direct_connect)
  170.                cputs_tr(_mdm_init_str);
  171.            _scr_chk_key = old_scr_chk_key;
  172.            _cisb_auto = old_cisb_auto;
  173.            _zmod_auto = old_zmod_auto;
  174.            _sound_on = old_sound;
  175.            _down_dir = old_down_dir;
  176.            _up_dir = old_up_dir;
  177.            prints("^M^JHost mode script finished.");
  178.            usagelog("B:DBBS.LOG");
  179.            return 1;
  180.        }
  181.    }
  182. }
  183. //////////////////////////////////////////////////////////////////////////////
  184.  
  185. do_one_caller() {
  186.  
  187.    str strn[80], fname[64], temporary[1];
  188.    str stuff[78];
  189.    int option, status, c, i, i2;
  190.  
  191.    access_level = 1;
  192.  
  193.    if (already_connected)
  194.        prints("Already Connected!");
  195.    else if (we_care_about_carrier) {
  196.        if (!determine_baud())
  197.            ;                       // do something else here if this is a problem
  198.    }
  199.  
  200.    delay(10);
  201.    type_file("B:FIRST.MSG");
  202.  
  203.    flushbuf();
  204.    while (1) {
  205.        host_send("Please Enter Your Alias -> ");
  206.        host_input_strn(current_caller, 30, 0);
  207.        host_send("^M^J");
  208.  
  209.        if (finished_caller)
  210.            return;
  211.  
  212.        if (strlen(current_caller) >= min_user_name) {
  213.            host_send ("^"");
  214.            host_send (current_caller);
  215.            host_send ("^", correct? (Y/N) -> ");
  216.            host_input_strn (temporary, 30, 0);
  217.            host_send ("^M^J");
  218.  
  219.            if (strcmpi (temporary, "y") == 0)
  220.                break;
  221.        }
  222.        else
  223.            host_send ("^M^JVery Funny...^G^M^J^M^J");
  224.    }
  225.  
  226.    if (access_level = ask_for_pass(3)) {
  227.        ustamp("Logon by ", 1, 0);
  228.        ustamp(current_caller, 0, 1);
  229.    }
  230.    else {
  231.        host_send("^G^M^JGoodbye!^G^M^J");
  232.        if (we_care_about_carrier) {
  233.            delay(10);
  234.            hangup();
  235.        }
  236.        ustamp("Failed logon attempt by ", 1, 0);
  237.        ustamp(current_caller, 0, 1);
  238.        return;
  239.    }
  240.  
  241.    type_file("B:BULLETIN.MSG");
  242.    host_send("- More -");
  243.    host_input_strn(stuff,1,0);
  244.    while (1) {
  245.        if (finished_caller)
  246.            return;
  247.        printsc("^M^J->   User: ");
  248.        printsc(current_caller);
  249.        printsc("   Access Level: ");
  250.        printc(access_level+48);
  251.        printsc("   <-");
  252.        if (access_level <= 1) {
  253.        type_file("B:NEWMENU.MSG");                 // New user Menu
  254.        host_send("                                   -> ");
  255.        }
  256.        else {
  257.        type_file("B:MENU.MSG");                               // Normal Menu
  258.        host_send("                                   -> ");
  259.        }
  260.        host_input_strn(strn, 1, 0);
  261.        option = toupper(subchr(strn, 0));
  262.        host_send("^M^J");
  263.  
  264.           if (option == 'R') {                 // Files directory
  265.            if (access_level >= 2) {
  266.                host_send("^LRaw Files Directory^M^J");
  267.                host_send("===================^M^J^M^J");
  268.                host_send("Enter filespec or Return for *.* -> ");
  269.                host_input_strn(fname, 64, 0);
  270.                host_send("^M^J");
  271.  
  272.                if (just_filename(fname)) {
  273.                    strn = host_downloads;
  274.                    strcat(strn, fname);
  275.                }
  276.                else
  277.                strn = fname;
  278.            }
  279.            else {
  280.                strn = host_downloads;
  281.                strcat(strn, "*.*");
  282.            }
  283.  
  284.            if (local_mode)
  285.                show_directory(strn, 0, we_care_about_carrier);
  286.            else
  287.                show_directory(strn, 1, we_care_about_carrier);
  288.  
  289.        host_input_strn(stuff,1,0);
  290.        }
  291.  
  292.        else if (option == 'T') {           // Type a file
  293.            host_send("^LType File^M^J");
  294.            host_send("=========^M^J^M^J");
  295.            host_send("Type what file -> ");
  296.            host_input_strn(strn, 64, 0);
  297.            host_send("^M^J");
  298.            if (access_level == 1) {           // if access 1, name and ext only
  299.                host_send("^M^J^G* Your Access Level Is Too Low *^G^M^J");
  300.                ustamp("Level 1 User Attempted To TYPE a File.",1,1);
  301.                strn = stuff;
  302.             }
  303.            else {
  304.               fname = strn;
  305.             }
  306.            if (just_filename(fname)) {
  307.                strn = host_downloads;
  308.                strcat(strn, fname);
  309.                fname = strn;
  310.            }
  311.  
  312.            if (!filefind(fname, 0, strn)) {
  313.                host_send("^GUnable to find ");
  314.                host_send(fname);
  315.                continue;
  316.            }
  317.  
  318.            type_file(fname);
  319.            host_send("^M^J- More -");
  320.            host_input_strn(stuff,1,0);
  321.        }
  322.  
  323.        else if (option == 'L') {           // Goodbye (Hang-up)
  324.            type_file("B:LAST.MSG");
  325.            ustamp("User logged off.", 1, 1);
  326.            if (we_care_about_carrier) {
  327.                delay(10);
  328.                hangup();
  329.            }
  330.            return;
  331.        }
  332.  
  333.        else if (option == 'Y') {           // Chat mode
  334.            host_send("^LChat Mode^M^J");
  335.            host_send("=========^M^J^M^J");
  336.            printsc("->  User: ");
  337.            printsc(current_caller);
  338.            printsc("   Access Level: ");
  339.            printc(access_level+48);
  340.            printsc("  <-");
  341.            host_send("^M^JPaging Sysop, You may leave a message if he is not in.^M^J");
  342.            c = 0;
  343.            _sound_on = 1;
  344.            for (i = 4; i && !c; --i) {
  345.                if (we_care_about_carrier && !carrier()) {
  346.                    prints("^M^JConnection has been lost, call terminated.^M^J");
  347.                    connection_lost = 1;
  348.                    finished_caller = 1;
  349.                    break;
  350.                }
  351.                cputc('^G');
  352.                tone(475, 10);
  353.                tone(925, 10);
  354.                tone(475, 10);
  355.                tone(925, 10);
  356.                tone(475, 10);
  357.                tone(925, 10);
  358.                for (i2 = 30; i2 && (c = inkey()) == 0; --i2)
  359.                    delay(1);
  360.            }
  361.            _sound_on = 0;
  362.            if (finished_caller)
  363.                continue;
  364.            if (c != ' ' || !c) {
  365.                host_send("^LSorry The Sysop Is Unavaliable!^M^J^M^J");
  366.                host_send("But Leave Him A Short Message (5 Lines)^M^J");
  367.                ustamp("^G ** Message To Sysop ** ",0,1);
  368.                host_send("^M^J1>");
  369.                host_input_strn(stuff,78,0);
  370.                ustamp(stuff,0,1);
  371.                host_send("^M^J2>");
  372.                host_input_strn(stuff,78,0);
  373.                ustamp(stuff,0,1);
  374.                host_send("^M^J3>");
  375.                host_input_strn(stuff,78,0);
  376.                ustamp(stuff,0,1);
  377.                host_send("^M^J4>");
  378.                host_input_strn(stuff,78,0);
  379.                ustamp(stuff,0,1);
  380.                host_send("^M^J^G5>");
  381.                host_input_strn(stuff,78,0);
  382.                ustamp(stuff,0,1);
  383.                continue;
  384.            }
  385.            host_send("^M^JHi, how can I help you?^M^J^M^J");
  386.            chatmode(1);
  387.        }
  388.       else if (option == 'F')    // Files List
  389.        {
  390.       if (access_level >= 2) {
  391.       type_file ("B:FILES.BBS");
  392.       host_send("- More -");
  393.       host_input_strn(stuff,1,0);
  394.        }
  395.       else {
  396.       host_send("^M^J^G* Your Access Level Is Too Low *^G^M^J");
  397.       ustamp("Level 1 User Attempted To View FILES LIST.",1,1);
  398.       }
  399.        }
  400.       else if (option == 'B')
  401.       {
  402.       type_file ("B:BULLETIN.MSG");
  403.       host_send("- More -");
  404.       host_input_strn(stuff,1,0);
  405.       }
  406.       else if (option == 'I')
  407.       {
  408.       if (access_level >= 2) {
  409.       type_file("B:BBSNUM.LST");
  410.       host_send("- More -");
  411.       host_input_strn(stuff,1,0);
  412.       }
  413.       else {
  414.       host_send("^G* Your Access Level Is Too Low *^G^M^J");
  415.       ustamp("Level 1 User Attempted To View BBS LIST",1,1);
  416.        }
  417.       }
  418.       else if (option == '*')
  419.       {
  420.       if (access_level == 3) {
  421.       type_file("B:DBBS.LOG");
  422.       host_send("- More -");
  423.       host_input_strn(stuff,1,0);
  424.       }
  425.       else {
  426.       host_send("^G* Your Access Level Is Too Low *^G^M^J");
  427.       ustamp("User Attempted To View DBBS.LOG",1,1);
  428.        }
  429.       }
  430.       else if (option == 'N')
  431.       {
  432.       type_file("B:NEWUSER.IFO");
  433.       host_send("- More -");
  434.       host_input_strn(stuff,1,0);
  435.       }
  436.       else if (option == 'A') {
  437.        if (access_level >= 2) {
  438.        dos("B:DBBS.BAT", 0);
  439.        ustamp("User ran DBBS.BAT.",1,1);
  440.        }
  441.        else {
  442.         host_send("^M^J^G* Your Access Level Is Too Low *^G^M^J");
  443.         ustamp("Level 1 User Attempted To Run DBBS.BAT",1,1);
  444.  
  445.         }
  446.       }
  447.       else if (option == 'E')
  448.       {
  449.       type_file ("B:EXTRA.IFO");
  450.       host_send("- More -");
  451.       host_input_strn(stuff,1,0);
  452.       }
  453.        else if (option == 'U') {           // User upload
  454.            if (! (option = host_get_prot()))
  455.                continue;
  456.  
  457.            status = 1;
  458.            if (option == 'T' || option == 'M' || option == 'S' ||
  459.                    option == 'Y' || option == 'Z' || option == 'E') {
  460.                send_transfer_msg();
  461.                status = receive(option, "");
  462.            }
  463.            else {
  464.                host_send("Upload what file -> ");
  465.                host_input_strn(strn, 48, 0);
  466.                host_send("^M^J");
  467.                if (!strn)
  468.                    continue;
  469.                if (access_level == 1)             // if access 1, name and ext only
  470.                    fnstrip(strn, 3, fname);
  471.                else
  472.                    fname = strn;
  473.  
  474.                if (just_filename(fname)) {
  475.                    strn = host_uploads;
  476.                    strcat(strn, fname);
  477.                    fname = strn;
  478.                }
  479.  
  480.                if (filefind(fname, 23, strn))
  481.                    host_send("Thanks, but I've got that file already!^G^M^J");
  482.                else {
  483.                    send_transfer_msg();
  484.                    status = receive(option, fname);
  485.                }
  486.            }
  487.            if (status == -2)                        // Carrier lost
  488.                connection_lost = finished_caller = 1;
  489.            else if (status == -1)
  490.                host_send("^G-> One or more files not received! <-^M^J");
  491.        }
  492.  
  493.        else if (option == 'D') {           // User download
  494.            if (access_level >= 2) {
  495.            if (! (option = host_get_prot()))
  496.                continue;
  497.            host_send("^M^JAnother download leech eh?^M^J");
  498.            host_send("Download what file(s) -> ");
  499.            host_input_strn(strn, 48, 0);
  500.            host_send("^M^J");
  501.            if (!strn)
  502.                continue;
  503.            if (access_level == 1)      // if level 1, keep only name & ext
  504.                fnstrip(strn, 3, fname);
  505.            else
  506.                fname = strn;
  507.  
  508.            if (just_filename(fname)) {
  509.                strn = host_downloads;
  510.                strcat(strn, fname);
  511.                fname = strn;
  512.            }
  513.  
  514.            if (!filefind(fname, 0, strn)) {
  515.                host_send("^G* I dont have that file! *^M^J");
  516.                continue;
  517.            }
  518.  
  519.            status = 1;
  520.            send_transfer_msg();
  521.            status = send(option, fname);
  522.            if (status == -2)                        // Carrier lost
  523.                connection_lost = finished_caller = 1;
  524.            else if (status == -1)
  525.                host_send("^G * One or more files not received! *^M^J");
  526.        }
  527.         else {
  528.         host_send("^M^J^G* Your Access Level Is Too Low *^G^M^J");
  529.         ustamp("Level 1 User Attempted To Download",1,1);
  530.          }
  531.         }
  532.        else if (option == 'S') {           // Remote shell
  533.            if (get_port() != 1 && get_port() != 2) {
  534.                host_send("Remote Shell not supported on this comm port due to DOS limits!^M^J");
  535.                continue;
  536.            }
  537.  
  538.            if (access_level == 3) {            // Need access level 3 to shell
  539.                host_send("^LDos Shell^M^J");
  540.                host_send("=========^M^J^M^J");
  541.                host_send(" - Please, do not delete anything!^M^J");
  542.                host_send(" - Type EXIT to return to DBBS ^M^J");
  543.                if (get_baud() == 300)
  544.                    delay(10);
  545.  
  546.                strn = "GATE1";     // THE GATEWAY DRIVER IS NEEDED CHANGE GATE1 TO STRN
  547.                setchr("GATE1", 3, get_port() + '0'); // AND TAKE OUT QUOTES ON THIS LINE
  548.                                                   // TO MAKE IT WORK WITH OUT GATEWAY. THIS IS
  549.                if (!local_mode)                  // SET UP FOR COM1 RIGHT NOW.
  550.                    if (redirect_dos("GATE1") == -1)    // redirect DOS input and output
  551.                        continue;
  552.  
  553.                dos("", 0);                    // actually call the shell
  554.  
  555.                    if (!local_mode)
  556.                        redirect_dos("");         // very important to put things back to norm
  557.            }
  558.            else {
  559.                host_send ("^G^G * Your Access Level Is Too Low *^M^J");
  560.            }
  561.        }
  562.  
  563.        else if (option == '^Z') {            // Shut down Host Mode
  564.            if (access_level == 3) {
  565.                host_send("Shutting down DBBS.  Goodbye!^M^J");
  566.                if (we_care_about_carrier)
  567.                    hangup();
  568.                ustamp("User shut down Host Mode.", 1, 1);
  569.                finished_caller = 1;
  570.                exit_requested = 1;
  571.            }
  572.            else {
  573.                host_send ("^G^G * Your Access Level Is Too Low *^M^J");
  574.            }
  575.        }
  576.    }
  577. }
  578.  
  579. //////////////////////////////////////////////////////////////////////////////
  580.  
  581. host_get_prot() {
  582.  
  583.    str prot[1];
  584.    host_send("^L            File Transfer^M^J");
  585.    host_send("            =============^M^J^M^J");
  586.    host_send("    [Z]modem          [S]ealink^M^J");
  587.    host_send("    [X]modem          [1]k-Xmodem^M^J");
  588.    host_send("    [G]-1k-Xmodem     [Y]modem^M^J");
  589.    host_send("^M^J    Which protocol -> ");
  590.    host_input_strn(prot, 1, 0);
  591.    host_send("^M^J");
  592.  
  593.    if (strposi("MSX1GYEZ", prot, 0) == -1)     // if illegal prot
  594.        prot = "";                                 // return 0
  595.  
  596.    return (toupper(subchr(prot, 0)));
  597.  
  598. }
  599.  
  600. //////////////////////////////////////////////////////////////////////////////
  601.  
  602. send_transfer_msg() {
  603.  
  604.    host_send("-> Ready to transfer file(s)... Slam on Ctrl-X to abort <-^M^J");
  605. }
  606.  
  607. //////////////////////////////////////////////////////////////////////////////
  608. // Determine the baud rate once a Carrier Detect Signal has been detected
  609. // Since no characters were read, the 'CONNECT' string should still be
  610. // in the receive buffer.
  611.  
  612. determine_baud() {
  613.  
  614.    int t3, t12, t24, t96, t192;
  615.    int tmark, stat;
  616.    int new_baud = 0;
  617.  
  618.    printsc("Determining baud... ");
  619.  
  620.    track_free(0);                // clear all existing tracks
  621.  
  622.    t3 = track(conn300, 0);       // check for connect strings
  623.    t12 = track(conn1200, 0);
  624.    t24 = track(conn2400, 0);
  625.    t96 = track(conn9600, 0);
  626.    t192 = track(conn19200, 0);
  627.  
  628.    tmark = timer_start(30);      // wait up to 3 seconds for string
  629.  
  630.    while (!time_up(tmark)) {
  631.        if (!carrier()) {
  632.            track_free(0);            // clear all existing tracks
  633.            return 0;
  634.        }
  635.  
  636.    if (cinp_cnt())
  637.        track_addchr(cgetc());
  638.  
  639.    stat = track_hit(0);
  640.    if (stat == 0)
  641.        continue;
  642.  
  643.    if (stat == t3)
  644.        new_baud = 300;
  645.    else if (stat == t24)
  646.        new_baud = 2400;
  647.    else if (stat == t96)
  648.        new_baud = 9600;
  649.    else if (stat == t192)
  650.        new_baud = 19200;
  651.    else
  652.        new_baud = 1200;
  653.  
  654.    break;                      // have baud rate, get out
  655.    }
  656.  
  657.    if (!new_baud) {               // time-up without CONNECT string
  658.        prints("Failed!");
  659.        track_free(0);              // clear all existing tracks
  660.        return 0;
  661.    }
  662.  
  663.    printn(new_baud);
  664.    prints("");
  665.    set_cparams(new_baud, get_parity(), get_datab(), get_stopb());
  666.  
  667.    track_free(0);                // clear all existing tracks
  668.    return 1;                     // indicate success
  669.  
  670. }
  671.  
  672. //////////////////////////////////////////////////////////////////////////////
  673.  
  674. type_file(str fname) {
  675.  
  676.    int f, control_z_loc;
  677.    str buf[100];
  678.    int ichar, lines_sent = 0;
  679.  
  680.    if (not (f = fopen(fname, "r")))
  681.        return -1;
  682.  
  683.    host_send("^M^J");
  684.  
  685.    while (1) {
  686.        if (we_care_about_carrier) {
  687.            if (!carrier()) {
  688.                connection_lost = 1;
  689.                finished_caller = 1;
  690.                fclose(f);
  691.                return 0;
  692.            }
  693.        }
  694.  
  695.        if (fgets(buf, 80, f) == -1) {
  696.            fclose(f);
  697.            return 1;
  698.        }
  699.  
  700.        if ((control_z_loc = strpos (buf, "^Z", 0)) >= 0) {
  701.            if (control_z_loc == 0) {
  702.                fclose (f);
  703.                return 1;
  704.            }
  705.            else {
  706.                setchr (buf, control_z_loc, 0);
  707.            }
  708.        }
  709.  
  710.        host_send(buf);
  711.        host_send("^M^J");
  712.        ++lines_sent;
  713.  
  714.        if (lines_sent >= 22222) {
  715.            lines_sent = 0;
  716.            host_send("- More -");
  717.            host_input(0);
  718.  
  719.            if (finished_caller) {        // if user inactivity
  720.                fclose(f);
  721.                return 0;
  722.            }
  723.  
  724.            host_send("^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H^H ^H");
  725.        }
  726.  
  727.        while (cinp_cnt()) {
  728.            ichar = cgetc();
  729.            if (ichar == '^C' || ichar == '^K') {
  730.                host_send("^M^J");
  731.                fclose(f);
  732.                return 1;
  733.            }
  734.        }
  735.    }
  736. }
  737.  
  738. //////////////////////////////////////////////////////////////////////////////
  739.  
  740. host_send(str outstr) {
  741.  
  742.    printsc(outstr);
  743.    if (!local_mode)
  744.        cputs(outstr);
  745.  
  746. }
  747.  
  748. //////////////////////////////////////////////////////////////////////////////
  749.  
  750. host_send_c(int chr) {
  751.  
  752.    printc(chr);
  753.    if (!local_mode)
  754.        cputc(chr);
  755.  
  756. }
  757.  
  758. //////////////////////////////////////////////////////////////////////////////
  759.  
  760. host_input_strn(str buf, int maximum, int echo_asterisk) {
  761.  
  762. //Rev 11/25/88 by Jon Fleming to echo a string of asterisks if
  763. //     "echo_asterisk" is non-zero, echo the input string if "echo_asterisk"
  764. //     is zero.
  765.  
  766.    int i = 0, key;
  767.  
  768.    while (1) {
  769.        key = host_input(echo_asterisk);
  770.        if (!key) {                // timeout or user disconnect
  771.            setchr(buf, 0, 0);      // set string to empty
  772.            return 0;               // indicate there is a problem
  773.        }
  774.  
  775.        if (key == '^M')
  776.            break;
  777.        if (key == 127 || key == 8) {
  778.            if (i) {
  779.                --i;
  780.                host_send_c(key);
  781.            }
  782.            continue;
  783.        }
  784.        if (i < maximum) {
  785.            setchr(buf, i, key);
  786.            i = i + 1;
  787.        }
  788.        else
  789.            i = i + 1;
  790.    }
  791.  
  792.    if (i > maximum)
  793.        i = maximum;
  794.  
  795.    setchr(buf, i, '^0');
  796.  
  797.    if (subchr(buf, 0))
  798.        return 1;
  799.    else
  800.        return 0;
  801.  
  802. }
  803.  
  804. //////////////////////////////////////////////////////////////////////////////
  805.  
  806. host_input(int echo_asterisk) {
  807.  
  808. // Rev 11/25 88 by Jon Fleming to echo asterisk if "echo_asterisk" is
  809. //     non-zero, to echo the input character if "echo_asterisk" is zero.
  810.  
  811.    int c, t;
  812.  
  813.    t = timer_start(3000);         // 4 minutes inactivity allowed
  814.  
  815.    while (1) {
  816.        if (time_up(t) && !direct_connect) {
  817.            host_send("^L^M^J^M^J^G^G^GInactivity period too long! Goodbye!^M^J");
  818.            if (we_care_about_carrier)
  819.                hangup();
  820.            finished_caller = 1;
  821.            kill_user = 1;
  822.            return 0;
  823.        }
  824.  
  825.        if (we_care_about_carrier)
  826.            if (!carrier()) {
  827.                prints("^M^JConnection has been lost, call terminated.^M^J");
  828.                connection_lost = 1;
  829.                finished_caller = 1;
  830.            return 0;
  831.            }
  832.  
  833.        if ((c = inkey()) != 0) {
  834.            if (c == 27) {              // ESC key, sysop wants to exit
  835.                host_send("^M^J* Sysop Terminating DBBS *^M^J");
  836.                finished_caller = 1;
  837.                exit_requested = 1;
  838.                return 0;
  839.            }
  840.            else if (c == 0x4f00) {     // END key, temrinate user
  841.                host_send("^GSystem Lock Out! ^G GET LOST! ^M^J^M^J^M^J^G");
  842.                prints("^M^J* Jerk terminated! *");
  843.                ustamp("Bad User terminated!", 1, 1);
  844.                if (we_care_about_carrier)
  845.                hangup();
  846.  
  847.                finished_caller = 1;
  848.                kill_user = 1;
  849.                return 0;
  850.            }
  851.            else if (c == 0x4700) {
  852.                host_send("^M^J^M^J* Please Wait, Sysop is using DOS functions *");
  853.                ustamp("Sysop used DOS functions.",1,1);
  854.                dosfunction();
  855.                host_send("^M^J^M^J* Thanks for waiting *^M^J^M^J");
  856.                return 0;
  857.            }
  858.  
  859.            else if (c <= 255) {
  860.                if (c != 8 && c != 127) {
  861.                    if ( (echo_asterisk) && (c != 13) ) {
  862.                        host_send_c ('*');
  863.                    }
  864.                    else {
  865.                        host_send_c(c);
  866.                    }
  867.                }
  868.                return c;
  869.            }
  870.        }
  871.  
  872.        if (!local_mode)
  873.            if (cinp_cnt()) {
  874.                c = cgetc();
  875.                if (c != 8 && c != 127) {
  876.                    if ( (echo_asterisk) && (c != 13) ) {
  877.                    host_send_c ('*');
  878.                    }
  879.                else {
  880.                    host_send_c(c);
  881.                }
  882.            }
  883.            return c;
  884.        }
  885.    }
  886. }
  887.  
  888. //////////////////////////////////////////////////////////////////////////////
  889.  
  890.  
  891. // This routine maintains an ASCII file in the Telix files directory called
  892. //     PASSWORD.TLX.  The format for each line is:
  893.  
  894. //     name;password;access_level  (optional comment)
  895.  
  896. ask_for_pass(int maxtries) {
  897.    str password_file[64], line_from_file[80], password_from_file[16],
  898.            name_from_file[31], temporary[16], typed_password[16];
  899.  
  900.    int password_file_handle, field_length, field_start,
  901.            found_password = 0, access_from_file, counter = 0,
  902.            file_ends_in_control_z = 0, line_number = 0;
  903.  
  904.                                            // Build password file name
  905.    password_file = _telix_dir;
  906.    strcat (password_file, "PASSWORD.TLX");
  907.                                            // Try to open password file
  908.    if (password_file_handle = fopen (password_file, "r")) {
  909.                                            // Read next line from file.
  910.        while (fgets (line_from_file, 64, password_file_handle) != -1) {
  911.                                            // Check for ^Z termination
  912.            if (line_from_file == "^Z") {
  913.                file_ends_in_control_z = 1;
  914.                break;
  915.            }
  916.            line_number = line_number + 1;
  917.                                            // If line is long enough . . .
  918.            if (strlen (line_from_file) >= min_user_name+4) {
  919.                                            // Get length of name
  920.                if ( (field_length = strchr (line_from_file, 0, ';')) > 0) {
  921.                                            // Get name
  922.                    substr (line_from_file, 0, field_length, name_from_file);
  923.                                            // If name matches . . . .
  924.                    if (strcmpi (name_from_file, current_caller) == 0) {
  925.                                            // Get password
  926.                        field_start = field_length + 1;
  927.                        if ( (field_length = strchr (line_from_file, field_start, ';') - field_start) > 0) {
  928.                            substr (line_from_file, field_start, field_length, password_from_file);
  929.                                            // Get access level
  930.                            field_start = field_start + field_length + 1;
  931.                            substr (line_from_file, field_start, 1, temporary);
  932.                            access_from_file = stoi (temporary);
  933.                                            // Set flag that we got an old user
  934.                            found_password = 1;
  935.                            break;
  936.                        }
  937.                        else {
  938.                            password_file_error (line_number, line_from_file, "no second semicolon");
  939.                        }
  940.                    }
  941.                }
  942.                else {
  943.                    password_file_error (line_number, line_from_file, "no first semicolon");
  944.                }
  945.            }
  946.            else {
  947.                password_file_error (line_number, line_from_file, "line too short");
  948.            }
  949.        }
  950.        fclose (password_file_handle);
  951.    }
  952.  
  953.    if (found_password) {
  954.                                            // Password is on file; ask for it
  955.        host_send ("Password -> ");
  956.        for (counter = 1; counter <= maxtries; counter = counter + 1) {
  957.            host_input_strn (typed_password, 16, 1);
  958.                                            // If a match
  959.            if (strcmpi (typed_password, password_from_file) == 0) {
  960.                host_send ("^M^J");
  961.                return (access_from_file);
  962.            }
  963.            if (counter <maxtries) {
  964.                host_send ("^M^J^G WRONG PASSWORD! Try again.^M^J");
  965.                host_send ("Password -> ");
  966.            }
  967.            else {
  968.                host_send ("^L^M^J^G^GTOO MANY ATTEMPTS! ACCESS DENIED!^M^J^G^G");
  969.            }
  970.        }
  971.    }
  972.                                            // Password is not on file
  973.    else {
  974.                                            // Offer chance to register
  975.        host_send ("^L^M^J Hello ^"");
  976.        host_send (current_caller);
  977.        host_send ("^" , You are not found in the user file.^J^M^J^M");
  978.        host_send ("Would you like to register -> ");
  979.        host_input_strn (temporary, 1, 0);
  980.        host_send ("^M^J");
  981.                                            // If user doesn't want to register
  982.        if (not ((temporary == "Y") || (temporary == "y"))) {
  983.            return (0);
  984.        }
  985.                                            // If user wants to register
  986.        host_send("^LRegistration Questionaire^M^J");
  987.        host_send("=========================^M^J^M^J");
  988.        host_send ("Pick a password (16 characters maximum) -> ");
  989.        host_input_strn (password_from_file, 16, 1);
  990.  
  991.        host_send ("^M^JRe-Enter Your Password To Verify -> ");
  992.        for (counter = 1; counter <= maxtries; counter = counter + 1) {
  993.            host_input_strn (typed_password, 16, 1);
  994.                                            // If all is ok
  995.            if (strcmpi (typed_password, password_from_file) == 0) {
  996.                                            // Build new line for password file
  997.                line_from_file = current_caller;
  998.                strcat (line_from_file, ";");
  999.                strcat (line_from_file, password_from_file);
  1000.                strcat (line_from_file, ";1 ** NEW USER ** ");
  1001.                date (curtime(), temporary);
  1002.                strcat (line_from_file, temporary);
  1003.  
  1004.                password_file_handle = fopen (password_file, "a+");
  1005.                if (file_ends_in_control_z) {
  1006.                    fseek (password_file_handle, -1, 2);
  1007.                }
  1008.                fwrite (line_from_file, strlen (line_from_file), password_file_handle);
  1009.                fwrite ("^M^J", 2, password_file_handle);
  1010.                fclose (password_file_handle);
  1011.                host_send ("^M^J");
  1012.  
  1013.                return (1);
  1014.            }
  1015.            if (counter < maxtries){
  1016.                host_send ("^M^J^GWrong! Try again -> ");
  1017.            }
  1018.            else {
  1019.                host_send ("^M^J^GMaximum amount of tries exceeded!^G^M^J");
  1020.            }
  1021.        }
  1022.    }
  1023.    return (0);
  1024. }
  1025.  
  1026. //////////////////////////////////////////////////////////////////////////////
  1027.  
  1028. password_file_error (int line_number, str line, str error_specifier) {
  1029.  
  1030.    str line_number_string[4];
  1031.  
  1032.    itos (line_number, line_number_string);
  1033.  
  1034.    prints ("");
  1035.    printsc ("* Sysop: Bad line ");
  1036.    printsc (line_number_string);
  1037.    prints (" in password file:");
  1038.    printsc ("   ^"");
  1039.    printsc (line);
  1040.    prints ("^"");
  1041.    prints (error_specifier);
  1042.    prints (" *^M^J");
  1043.    return (1);
  1044. }
  1045.  
  1046. //////////////////////////////////////////////////////////////////////////////
  1047.  
  1048. // Rev 11/25/88 by **Jon Fleming** to not read the lines from the old host mode
  1049. //  configuration file that are no longer applcable.
  1050.  
  1051. read_host_config_file() {
  1052.  
  1053.    str config_file_name[80], buffer [32];
  1054.    int config_file_handle;
  1055.  
  1056.    config_file_name = _telix_dir;
  1057.    strcat(config_file_name, "HOST2.CNF");
  1058.  
  1059.  
  1060.    if (not (config_file_handle = fopen(config_file_name, "r"))) {
  1061.        printsc("Can't open ");
  1062.        prints(config_file_name);
  1063.        return -1;
  1064.    }
  1065.  
  1066.    if (fgets(host_downloads, 80, config_file_handle) == -1) {
  1067.        fclose(config_file_handle);
  1068.        return -1;
  1069.    }
  1070.  
  1071.    if (fgets(host_uploads, 80, config_file_handle) == -1) {
  1072.        fclose(config_file_handle);
  1073.        return -1;
  1074.    }
  1075.  
  1076.    if (fgets(buffer, 80, config_file_handle) == -1) {
  1077.        fclose(config_file_handle);
  1078.        return -1;
  1079.    }
  1080.    direct_connect = (toupper(subchr(buffer, 0)) == 'D');
  1081.  
  1082.    fclose(config_file_handle);
  1083.    return 1;
  1084.  
  1085. }
  1086.  
  1087. //////////////////////////////////////////////////////////////////////////////
  1088.  
  1089. check_directories() {
  1090.  
  1091.    str s[80];
  1092.    int i, a;
  1093.  
  1094.    // first remove trailing slashes
  1095.  
  1096.    s = host_uploads;
  1097.    i = strlen(s);
  1098.    if (i > 0)
  1099.        if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  1100.            setchr(s, i - 1, 0);
  1101.    if (s && !(strlen(s) == 2 && subchr(s, 1) == ':')) {
  1102.        a = fileattr(s);
  1103.        if (a == -1 || !(a & 16))
  1104.            return 0;                  // not a directory or doesn't exist
  1105.    }
  1106.  
  1107.    s = host_downloads;
  1108.    i = strlen(s);
  1109.    if (i > 0)
  1110.        if (subchr(s, i - 1) == '\' || subchr(s, i - 1) == '/')
  1111.            setchr(s, i - 1, 0);
  1112.    if (s && !(strlen(s) == 2 && subchr(s, 1) == ':')) {
  1113.        a = fileattr(s);
  1114.        if (a == -1 || !(a & 16))
  1115.            return 0;                  // not a directory or doesn't exist
  1116.    }
  1117.  
  1118.    return 1;
  1119.  
  1120. }
  1121.  
  1122. //////////////////////////////////////////////////////////////////////////////
  1123. // returns TRUE if passed filespec is just a filename. Also handles the
  1124. // forward slash as a path separator.
  1125.  
  1126. just_filename(str filespec) {
  1127.  
  1128.    int slash, space;
  1129.  
  1130.    if (strpos(filespec, ":", 0) != -1)
  1131.        return 0;
  1132.    if (strpos(filespec, "\", 0) != -1)
  1133.        return 0;
  1134.    if ((slash = strpos(filespec, "/")) == -1)
  1135.        return 1;
  1136.  
  1137.    space = strpos(filespec, " ");
  1138.    if (space == -1)
  1139.        return 0;
  1140.    if (space < slash)
  1141.        return 1;
  1142.  
  1143.    return 0;
  1144.  
  1145. }
  1146.  
  1147. // End of DBBS...
  1148.