home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / lw22.zip / host.cmd < prev    next >
OS/2 REXX Batch file  |  1994-04-20  |  16KB  |  611 lines

  1. /**
  2.  **
  3.  ** LiveWire 2.1 Host Mode
  4.  ** REXX procedures language version
  5.  **
  6.  ** You may modify this script file to meed your needs
  7.  **
  8.  **/
  9.  
  10. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  11. call SysLoadFuncs
  12.  
  13. /* Return to this point if carrier lost */
  14. LostCarrier:
  15. SetLW(TimeOut,60);
  16. /*Trace I; */        /* Uncomment for debug tracing */
  17.  
  18. /** Current User Information **/
  19. Name=""
  20. Password=""
  21. Address1=""
  22. Address2=""
  23. PhoneNumber=""
  24.  
  25. /** Host Mode Configuration Information **/
  26. MessageDir=".\HSTMSGS"
  27. FileDir=".\HSTFILES"
  28. SysopPassword="PASSWORD"
  29. MaxTime=60
  30. LockPort=GetLW(LockedPort);
  31. OldSpeed=GetLW(Speed);
  32.  
  33.  
  34. /** Global Variables **/
  35. LogonName=""
  36. LogonPassword=""
  37.  
  38.    /* Check for LOCAL flag */
  39.    if (Translate(Arg(1))=='LOCAL') then
  40.       SetLW(LocalOnly, On);
  41.    else
  42.       SetLW(LocalOnly,Off);
  43.  
  44.    /* Main Host Loop */
  45.    do forever
  46.        LogLW("Host Mode Initiated");
  47.        SetLW(FGColor,15);
  48.        SetLW(BGColor,1);
  49.        ClrScrLW();
  50.        SetLW(Speed,OldSpeed);
  51.        HangUpLW();
  52.        SendLW("AT^M");
  53.  
  54.        DispLW("LiveWire Host / CTRL-BREAK to halt");
  55.  
  56.        if (stream("HOST.CFG",C,"query exists")="") then
  57.            MakeConfig();
  58.    
  59.        if (stream("HOST.USR",C,"query exists")="") then
  60.            MakeUserList();
  61.  
  62.        ReadConfigFile();
  63.        SysMkDir(MessageDir);
  64.        SysMkDir(FileDir);
  65.  
  66.        if (GetLW(LocalOnly)) then
  67.          Logon();
  68.        else do
  69.           LogLW("Awaiting a caller");
  70.           WaitForRing();
  71.           if (DoConnect()) then
  72.                Logon();
  73.        end
  74.     end
  75. exit
  76.  
  77. WaitForRing:
  78.      OldTimeOut=GetLW(TimeOut);
  79.      SetLW(TimeOut,0);
  80.      x=FindLW("RING");
  81.      SetLW(TimeOut,OldTimeOut);
  82.      return "";
  83.  
  84. DoConnect:
  85.    /* Send ATA to answer modem */
  86.    SendLW("ATA^M");
  87.  
  88.    /* First, see if we have a locked port */
  89.    if LockPort then
  90.    do
  91.       /* LOCKED PORT, DO NOT CHANGE BPS RATE ON CONNECT */
  92.  
  93.       q=FindLW("CONNECT", "NO CARRIER");
  94.       if (q=="CONNECT") then
  95.          return 1;
  96.       else
  97.          return 0;
  98.    end
  99.    else
  100.    do
  101.       /* Non-Locked port, attempt to parse bps rate */
  102.       q=FindLW("CONNECT^M", "CONNECT 1200", "CONNECT 2400",
  103.                   ,"CONNECT 4800", "CONNECT 9600", "CONNECT 19200",
  104.                   ,"CONNECT 38400", "CONNECT 14400", "NO CARRIER");
  105.  
  106.       if (q="CONNECT"||D2C(13)) then
  107.          SetLW(Speed, 300);
  108.       else
  109.       if (q="CONNECT 1200") then
  110.          SetLW(Speed, 1200);
  111.       else
  112.       if (q="CONNECT 2400") then
  113.          SetLW(Speed, 2400);
  114.       else
  115.       if (q="CONNECT 4800") then
  116.          SetLW(Speed, 4800);
  117.       else
  118.       if (q="CONNECT 9600") then
  119.          SetLW(Speed, 19200);
  120.       else
  121.       if (q="CONNECT 38400") then
  122.          SetLW(Speed, 38400);
  123.       else
  124.       if (q="CONNECT 14400") then
  125.          SetLW(Speed, 14400);
  126.       else
  127.          return 0;
  128.  
  129.       return 1;
  130.    end
  131.  
  132. Logon:
  133.    /* First, make sure modem is clear before logon */
  134.    DelayLW(500);
  135.    FlushBufferLW();
  136.  
  137.    SetLW(EchoBack,On);
  138.    DiseFile("WELCOME");
  139.  
  140.    LogonName="";
  141.  
  142.    /* Get users' name */
  143.    Done=0;
  144.    do until (Done)
  145.       DiseLW("^M^JEnter your full name > ");
  146.       LogonName=Translate(HostReadString("",40));
  147.       if (LogonName = "") then Done=0;
  148.           else Done=1;
  149.    end /* do */
  150.  
  151.    /* Get user record from host user file */
  152.    q=stream("HOST.USR",C,"open");
  153.    Done=0;
  154.    Name="";
  155.    do until (Name=LogonName | Lines("HOST.USR")=0)
  156.       Name=LineIn("HOST.USR");
  157.       Password=LineIn("HOST.USR");
  158.       Address1=LineIn("HOST.USR");
  159.       Address2=LineIn("HOST.USR");
  160.       PhoneNumber=LineIn("HOST.USR");
  161.    end /* do */
  162.  
  163.    if (Name=LogonName) then do
  164.  
  165.       LogLW("User Called " Name);
  166.       LogonPassword="";
  167.  
  168.       /* Verify caller's password */
  169.       do until (LogonPassword=Password)
  170.          DiseLW("^M^JEnter your password >");
  171.          SetLW(EchoBack, 0);
  172.          LogonPassword=Translate(HostReadString("", 40));
  173.          SetLW(EchoBack, 1);
  174.       end /* do */
  175.    end  /* Do */
  176.     else
  177.    do
  178.         /* If we could not find username, this must be a new user! */
  179.  
  180.         LogLW("New User Validated");
  181.         Name=LogonName;
  182.         DiseFile("NEWUSER");
  183.         PhoneNumber="";
  184.         Address1="";
  185.         Address2="";
  186.         DiseLW("^M^JPlease fill out the following information for our records^M^J");
  187.         DiseLW("Phone Number      : ");
  188.         PhoneNumber=HostReadString("",40);
  189.         DiseLW("^M^JStreet Address    : ");
  190.         Address1=HostReadString("",70);
  191.         DiseLW("^M^JCity, State & ZIP : ");
  192.         Address2=HostReadString("",70);
  193.         DiseLW("^M^J^M^JYou must now enter a password for your account on this system.^M^J");
  194.         DiseLW("If you do not wish to have a password, just press ENTER.^M^J");
  195.  
  196.         Retry="1";
  197.         Password="2";
  198.         do until (Retry=Password)
  199.             DiseLW("^M^JPassword        : ");
  200.             Password=Translate(HostReadString("",30));
  201.             DiseLW("^M^JRe-enter your password for verification : ");
  202.             Retry=Translate(HostReadString("",30));
  203.         end /* do */
  204.  
  205.         DiseLW("^M^J^M^JThank you...");
  206.  
  207.         /* Write new user information to disk */
  208.         q=LineOut("HOST.USR",Name);
  209.         q=LineOut("HOST.USR",Password);
  210.         q=LineOut("HOST.USR",Address1);
  211.         q=LineOut("HOST.USR",Address2);
  212.         q=LineOut("HOST.USR",PhoneNumber);
  213.    end /* Do */
  214.  
  215.    /* Close user file */
  216.    q=stream("HOST.USR","c","close");
  217.  
  218.    MainMenu:
  219.    DoHangup=0;
  220.    do until (DoHangup)
  221.       Option=""
  222.       DiseFile("MAINMENU");
  223.       DiseLW("Select a function: ");
  224.       Option=Translate(HostReadChar());
  225.       DiseLW("^M^J");
  226.       if Option="H" then DoHangup=1;
  227.       if Option="F" then ShowFiles();
  228.       if Option="U" then UploadFile();
  229.       if Option="D" then DownloadFile();
  230.       if Option="P" then PageSysop();
  231.       if Option="R" then ReadMessages();
  232.       if Option="S" then SendMessage();
  233.       if Option="O" then OperatorFuncs();
  234.    end;
  235.  
  236.    EndLogon:
  237.    LogLW("User Hung Up Normally");
  238.    DiseLW("^M^J^M^JThank you for calling... (click)^M^J^M^J");
  239.    SetLW(EchoBack,Off);
  240.    DelayLW(250);
  241.    HangUpLW();
  242.    SleepLW(1);
  243.    FlushBufferLW();
  244.    return "";
  245.  
  246. OperatorFuncs:
  247.    OpPswd=""
  248.    OpOption=""
  249.  
  250.    DiseLW("^M^J^M^JEnter system operator password: ");
  251.    SetLW(EchoBack,Off);
  252.    OpPswd=Translate(HostReadString("",40));
  253.    SetLW(EchoBack,On);
  254.    if OpPswd=SysopPassword then do
  255.       LogLW("User Entered Sysop Operations");
  256.       QuitSysop=0;
  257.       do until (QuitSysop)
  258.            DiseLW(" ^M^J^M^JSystem Operator Functions^M^J^M^J");
  259.            DiseLW("^M^J1. Change Message Directory : " MessageDir);
  260.            DiseLW("^M^J2. Change File Directory    : " FileDir);
  261.            DiseLW("^M^J3. Locked Baud Rate (0=No)  : " LockPort);
  262.            DiseLW("^M^J4. Change Sysop Password    : " SysopPassword);
  263.            DiseLW("^M^JS  Save these options");
  264.            DiseLW("^M^JQ  Quit without saving^M^J^M^J");
  265.            DiseLW("Select option: ");
  266.            OpOption=Translate(HostReadChar());
  267.            DiseLW("^M^J");
  268.            if OpOption="1" then OpGetMsgDir();
  269.            if OpOption="2" then OpGetFileDir();
  270.            if OpOption="3" then OpGetLockPort();
  271.            if OpOption="4" then OpGetPassword();
  272.            if OpOption="S" then OpSaveConfig();
  273.            if OpOption="Q" then OPQuitConfig();
  274.       end
  275.    end
  276.    return "";
  277.  
  278.    OpGetMsgDir:
  279.    DiseLW("Edit message directory (DO NOT END WITH A BACKSLASH)^M^J");
  280.    DiseLW("> ");
  281.    MessageDir=HostReadString(MessageDir,70);
  282.    return "";
  283.  
  284.    OpGetFileDir:
  285.    DiseLW("Edit files directory (DO NOT END WITH A BACKSLASH)^M^J");
  286.    DiseLW("> ");
  287.    FileDir=HostReadString(FileDir,70);
  288.    return "";
  289.  
  290.    OpGetLockPort:
  291.    DiseLW("Edit locked baud rate (1=on 0=off)^M^J");
  292.    DiseLW("> ");
  293.    LockPort=GetLW(LockedPort);
  294.    LockPort=HostReadString(LockPort,3);
  295.    SetLW(LockedPort, LockPort);
  296.    return "";
  297.  
  298.    OpGetPassword:
  299.    DiseLW("Edit sysop password^M^J");
  300.    DiseLW("> ");
  301.    SysopPassword=Translate(HostReadString(SysopPassword,70));
  302.    return "";
  303.  
  304.    OpSaveConfig:
  305.    DiseLW("Saving...");
  306.    MakeConfig();
  307.    DiseLW("^M^J^M^J");
  308.    QuitSysop=1;
  309.    return "";
  310.  
  311.    OpQuitConfig:
  312.    ReadConfigFile();
  313.    DiseLW("^M^J^M^J");
  314.    QuitSysop=1;
  315.    return "";
  316.  
  317. SendMessage:
  318.    MaxMessage=0
  319.    ThisMessage=0
  320.    MsgFileName=""
  321.    MsgLine=""
  322.    MsgOption=""
  323.  
  324.    LogLW("User began a message");
  325.  
  326.    if (stream(MessageDir||"\HOST.MSG",C,"query exists")\="") then do
  327.       q=stream(MessageDir||"\HOST.MSG",C,"open");
  328.       MaxMessage=LineIn(MessageDir||"\HOST.MSG");
  329.       q=stream(MessageDir||"\HOST.MSG",C,"close");
  330.    end  /* Do */
  331.  
  332.    MaxMessage=MaxMessage + 1;
  333.    ThisMessage=MaxMessage;
  334.  
  335.    MsgFileName=MessageDir||"\MESSAGE."||ThisMessage;
  336.    q=stream(MsgFileName, C, "open");
  337.    DiseLW("^M^J^M^JEnter your message");
  338.    DiseLW("^M^JEnd your message by placing a period (.) alone on the last line^M^J");
  339.    DiseLW("----------------------------------------------------------------------------^M^J");
  340.    q=LineOut(MsgFileName, " ------------------------------");
  341.    q=LineOut(MsgFileName, " Message #"||ThisMessage);
  342.    q=LineOut(MsgFileName, " From    :"||Name);
  343.    q=LineOut(MsgFileName, "------------------------------");
  344.    q=LineOut(MsgFileName, "^M^J");
  345.  
  346.    FinishedMessage=0;
  347.    LineNo=1;
  348.    do until(FinishedMessage)
  349.       DiseLW(LineNo||"> ");
  350.       MsgLine=HostReadString("",75);
  351.       DiseLW("^M^J");
  352.       if (MsgLine=".") then FinishedMessage=1;
  353.       q=LineOut(MsgFileName, MsgLine);
  354.       LineNo=LineNo+1;
  355.    end
  356.  
  357.    FinishedMessage=0;
  358.    do until (FinishedMessage)
  359.         DiseLW("^M^JMessage Ended^M^J");
  360.         DiseLW("[S]ave Message  [A]bort Message : ");
  361.         MsgOption=Translate(HostReadChar());
  362.         DiseLW("^M^J");
  363.         if MsgOption="S" then SaveMessage();
  364.         if MsgOption="A" then AbortMessage();
  365.    end /* do */
  366.  
  367.    return "";
  368.  
  369.    SaveMessage:
  370.         FinishedMessage=1;
  371.         q=LineOut(MsgFileName,"------------------------------");
  372.         q=stream(MsgFileName,C,"close");
  373.         "erase "||MessageDir||"\HOST.MSG"
  374.         q=stream(MessageDir||"\HOST.MSG",C,"open write");
  375.         q=LineOut(MessageDir||"\HOST.MSG", ThisMessage);
  376.         q=stream(MessageDir||"\HOST.MSG",C,"close");
  377.         return "";
  378.         Goto RetSendMessage
  379.  
  380.     AbortMessage:
  381.         FinishedMessage=1;
  382.         "erase "||MsgFileName
  383.         return "";
  384.  
  385. ReadMessages:
  386.    MaxMessage=1
  387.    ThisMessage=1
  388.    MsgFileName=""
  389.    MsgOption=""
  390.  
  391.    LogLW("User Read Messages");
  392.    if (stream(MessageDir||"\HOST.MSG",C,"query exists")="") then do
  393.       DiseLW("^M^JSorry, there are no messages.^M^J");
  394.       SleepLW(2);
  395.       return "";
  396.    end  /* Do */
  397.  
  398.    q=stream(MessageDir||"\HOST.MSG",C,"open read");
  399.    MaxMessage=LineIn(MessageDir||"\HOST.MSG");
  400.    q=stream(MessageDIR||"\HOST.MSG",C,"close");
  401.  
  402.    DiseLW("^M^JMessages range from 1 to "||MaxMessage||"^M^J");
  403.    DiseLW("Enter message to start reading at : ");
  404.    ThisMessage=HostReadString(ThisMessage,3);
  405.    DiseLW("^M^J");
  406.  
  407.    DoneReading=0;
  408.    do until (DoneReading)
  409.         MsgFileName=MessageDir||"\MESSAGE."||ThisMessage
  410.         if (stream(MsgFileName,C,"query exists")\="") then do
  411.            DiseFile(MsgFileName);
  412.            DiseLW("^M^J[ENTER] for next message or [Q] to quit : ");
  413.            MsgOption=HostReadChar();
  414.            DiseLW("^M^J");
  415.            if MsgOption="Q" then DoneReading=1;
  416.         end  /* Do */
  417.  
  418.         ThisMessage=ThisMessage+1;
  419.         if (ThisMessage>MaxMessage) then DoneReading=1;
  420.     end;
  421.  
  422.     DiseLW("^M^JEnd of messages.^M^J");
  423.     SleepLW(2);
  424.     return "";
  425.  
  426. PageSysop:
  427.     LogLW("User Attempted To Page Sysop");
  428.     DiseLW("^M^JPaging operator, press Q to abort...^M^J");
  429.     DispLW("SYSOP: Press 'C' to chat^M^J");
  430.  
  431.     StopPage=0;
  432.     OldTimeOut=GetLW(TimeOut);
  433.     SetLW(TimeOut,5);
  434.     do until (StopPage)
  435.         DispLW("");
  436.         
  437.         Key=Translate(HostReadChar());
  438.         if Key="Q" then do
  439.             SetLW(TimeOut,OldTimeOut);
  440.             return "";
  441.         end  /* Do */
  442.         if Key="C" then StopPage=1;
  443.     end
  444.  
  445.     SetLW(TimeOut,0);
  446.  
  447.     DiseLW("^M^J^M^J You are now in chat mode^M^J");
  448.     DispLW(" SYSOP: Type ~ (tilde character) on a blank line to end chat mode");
  449.     DispLW("^M^J^M^J");
  450.     LogLW("Sysop Answered Chat Request");
  451.  
  452.     Key=""
  453.     do until Key="~"
  454.         Key=""
  455.         DiseLW(" ");
  456.         Key=HostReadString("",77);
  457.         DiseLW("^M^J");
  458.     end
  459.  
  460.  
  461.     SetLW(TimeOut,OldTimeOut);
  462.     return "";
  463.  
  464. UploadFile:
  465.     ULProtocol=""
  466.     ULFile=""
  467.     ULFile2=""
  468.  
  469.     DiseFile("PROT");
  470.  
  471.     DiseLW("Select protocol: ");
  472.     ULProtocol=Translate(HostReadChar());
  473.  
  474.     /* Check if this is a batch upload... */
  475.     BatchUpload=0;
  476.     if ULProtocol="Y" then BatchUpload=1;
  477.     if ULProtocol="Z" then BatchUpload=1;
  478.  
  479.    /* Set download directory if this a a batch upload */
  480.     if (BatchUpload) then do
  481.        OldDLDir=GetLW(DLDir);
  482.        SetLW(DLDir, FileDir);
  483.     end
  484.       else
  485.     do
  486.         DiseLW("^M^J^M^JName of file you are uploading: ");
  487.         ULFile=HostReadString(ULFile,77);
  488.         if ULFile="" then return "";
  489.         ULFile2=FileDir||"\"||ULFile;
  490.     end
  491.  
  492.     DiseLW("^M^JStart your upload now...^M^J");
  493.  
  494.     if (BatchUpload) then
  495.         ReceiveFilesLW(ULProtocol, "");
  496.     else
  497.         ReceiveFilesLW(ULProtocol,ULFile2);
  498.  
  499.    /* Restore old download directory */
  500.     if (BatchUpload) then
  501.          SetLW(DLDir, OldDLDir);
  502.  
  503.     SleepLW(1);
  504.     FlushBufferLW();
  505.  
  506.     return "";
  507.  
  508. DownloadFile:
  509.    DLProtocol=""
  510.    DLFile=""
  511.    DLFile2=""
  512.  
  513.    DiseFile("PROT");
  514.    DiseLW("Select protocol: ");
  515.    DLProtocol=HostReadChar();
  516.    DiseLW("^M^JName of file you are downloading: ");
  517.    DLFile=HostReadString("",77);
  518.    if DLFile\="" then do
  519.       DiseLW("^M^J");
  520.       DLFile2=FileDir||"\"||DLFile;
  521.       if (stream(DLFile2,C,"query exists")="") then do
  522.          DiseLW("^M^J^M^JThat file does not exist!^M^J");
  523.          SleepLW(2);
  524.       end  /* Do */
  525.        else
  526.       do
  527.          DiseLW("Start download now...^M^J");
  528.          SendFilesLW(DLProtocol,DLFile2);
  529.          SleepLW(1);
  530.          FlushBufferLW();
  531.          LogLW("User downloaded file "||DLFile2);
  532.       end
  533.    end
  534.    return "";
  535.  
  536. ShowFiles:
  537.   "DIR "||FileDir||" >host.out"
  538.   DiseLW("^M^J^M^J");
  539.   DiseFile("HOST.OUT");
  540.   DiseLW("^M^JPress [ENTER]");
  541.   q=HostReadChar();
  542.   return "";
  543.  
  544. DiseFile:
  545. arg DispFile
  546.  
  547.     q=stream(DispFile,C,"open read");
  548.  
  549.     do until lines(DispFile) = 0
  550.          DiseLW(linein(DispFile));
  551.          DiseLW("^M^J");
  552.     end /* do */
  553.  
  554.     q=stream(DispFile,C,"close");
  555.     return "";
  556.  
  557. ReadConfigFile:
  558.     LogLW("Read Configuration File");
  559.     DispLW(" Reading configuration file...");
  560.     q=stream("HOST.CFG",C,"open read");
  561.     MessageDir=LineIn("HOST.CFG");
  562.     FileDir=LineIn("HOST.CFG");
  563.     SysopPassword=LineIn("HOST.CFG");
  564.     MaxTime=LineIn("HOST.CFG");
  565.     LockPort=LineIn("HOST.CFG");
  566.     q=stream("HOST.CFG",C,"close");
  567.     DispLW("OK^M^J");
  568.     return "";
  569.  
  570. MakeConfig:
  571.     LogLW("Created Configuration File");
  572.     DispLW(" Creating configuration file...");
  573.     "erase HOST.CFG"
  574.     q=stream("HOST.CFG",C,"open write");
  575.     q=LineOut("HOST.CFG", MessageDir);
  576.     q=LineOut("HOST.CFG", FileDir);
  577.     q=LineOut("HOST.CFG", SysopPassword);
  578.     q=LineOut("HOST.CFG", MaxTime);
  579.     q=LineOut("HOST.CFG", LockPort);
  580.     q=stream("HOST.CFG",C,"close");
  581.     DispLW("OK^M^J");
  582.     Return "";
  583.  
  584. MakeUserList:
  585.     LogLW("Created User File");
  586.     DispLW(" Creating user list file...");
  587.     q=stream("HOST.USR",C,"open write");
  588.     q=stream("HOST.USR",C,"close");
  589.     DispLW("OK^M^J");
  590.     Return "";
  591.  
  592.  
  593. HostReadChar:
  594.    ReturnString=GetKeyLW();
  595.  
  596.    if (ReturnString="TIMEOUT") | ((GetLW(Online)==0) & (\GetLW(LocalOnly))) then
  597.       Signal LostCarrier;
  598.  
  599.    return ReturnString;
  600.  
  601.  
  602. HostReadString:
  603. arg StartString, MaxStrLen
  604.  
  605.    ReturnString=GetStrLW(StartString, MaxStrLen);
  606.    if (ReturnString="TIMEOUT") | ((GetLW(Online)=0) & (\GetLW(LocalOnly))) then
  607.       Signal LostCarrier;
  608.  
  609.    return ReturnString;
  610.  
  611.