home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / lw30.zip / host.cmd < prev    next >
OS/2 REXX Batch file  |  1995-09-18  |  17KB  |  612 lines

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