home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / easyon1a.zip / EASYON.CMD < prev    next >
OS/2 REXX Batch file  |  1993-12-24  |  16KB  |  524 lines

  1. /* EasyOn.cmd */
  2. /* copyright 1993 by Mark Bernard */
  3. /* ver 1.01 */
  4.  
  5. /*********************/
  6. /*** Configuration ***/
  7. /*********************/
  8.  
  9. /*** paths & filenames ***/
  10. UserFile = "c:\max\user.bbs"   /* you maximus user.bbs */
  11. LogFile = "c:\bink\bink.log"  /* your Binkley log */
  12. OutputFile = "c:\max\misc\phone.bbs" /* usually ...\max\misc\phone.bbs 
  13. */ CmdFile = "c:\max\EasyBBS.cmd" /* ..\max\EasyBBS.cmd */
  14. EasyOnLog = "C:\max\EasyOn.log"
  15. BadList = "c:\max\EasyOn.bad"
  16.  
  17. /*** Your maximus command-line with switches ***/
  18. MaxString = "maxp -b%2 -p%3 -t%4 -s%1 -n2 -lLine2.log -z\pipe\snoop2"
  19.            /* your "usual" string from your spawnbbs.cmd */
  20.  
  21.  
  22. /*** Options: 0 = No, 1 = Yes ***/
  23. MoreThanOne = 1  /* If sysop allows more than one user per number */
  24. AutoName = 1
  25. AutoPwd = 1 /* Must also have AutoName = 1, in order to work */
  26.             /* User must also have "!" as first character of password */
  27. TurfBlock = 1 /* Logs on using Blockname and BlockPwd,
  28.                so that Maximus can display <custom>.bbs */
  29. TurfBad = 1  /* Logs on using BadName and BadPass,
  30.                so that Maximus can display <custom>.bbs */
  31. CallidLog = 1 /* Log Numbers in file listed in EasyOnLog (above) */
  32. LogOnly = 0 /* Only LogNumber - then exit,  */
  33.             /* must also have CallidLog = 1 */
  34.  
  35. /*** Other ***/
  36. ConnectString = "Connect " /* note the trailing space! */
  37. MdmString = "Mesg ="  /* Most frequent */
  38. MdmString2 = "Nmbr =" /* less frequent */
  39. BlockIDString = "P"  /* Private */
  40. BlockName = "Call Block" 
  41. BlockPwd = "!AnyBlockhead" /* First letter must be "!" */
  42. BadName = "Badlist Name"
  43. BadPwd = "!InBadList"  /*First letter must be "!"  */
  44. AreaCode = "604"  /* local areacode */
  45.  
  46.  
  47. /**** End of configuration *****/
  48. /*******************************/
  49.  
  50. LineCon = 0 /* leave as is... needed in case of empty (new) binkley.log */
  51. LineNum = 1 /*    as above     */
  52. LineNum2 = 1 /*   as above     */
  53. PhoneNum = "Unavailable."  /* default */
  54.  
  55. /* Flags - Do Not Alter */
  56. UseString = 0
  57. NotUse = 1
  58. Found = 0
  59. Blocked =0
  60. Found = 0
  61. IsBad = 0
  62.  
  63. /* Put parameters into MaxString */
  64.  
  65. arg p.1 p.2 p.3 p.4 p.5 p.6 p.7 p.8 p.9
  66.  
  67. do i = 1 to 9
  68.    Pari = insert("%",i)
  69.    do while pos(Pari, MaxString) > 0
  70.      ParPos = pos(Pari, MaxString)
  71.      MaxString = delstr(MaxString, ParPos, 2)
  72.      MaxString = insert(p.i, MaxString, ParPos-1)
  73.    end /* do */
  74. end /* do */
  75.  
  76. if RxFuncquery(SysLoadFuncs) > 0 then
  77.   do
  78.     call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  79.     call SysLoadFuncs
  80.   end /* do */
  81.                          
  82. rc1 = SysFileDelete(OutPutFile)
  83. rc2 = SysFileDelete(CmdFile)
  84.  
  85. /* Find Number returned by Modem */
  86.  
  87.    /*find last occurence of MdmString in LogFile */
  88.  
  89. call SysFileSearch MdmString, LogFile,'hit.',N 
  90.  
  91. do i=1 to hit.0; end /* do */
  92. i=(i-1)
  93. LineNum = word(hit.i,1)
  94. LineNum = strip(LineNum,'B')
  95.    /*line number of last "MdmString" hit */
  96.   
  97. call SysFileSearch ConnectString, Logfile, 'con.',N
  98.  
  99. do j = 1 to con.0; end /* do */
  100. j = (j-1)
  101.  
  102. LineCon = word(con.j,1)
  103. LineCon = strip(LineCon,'B')
  104.  
  105.    /* Line number of last "Connect" message */
  106.  
  107. if ((LineCon > LineNum) & ((LineCon-LineNum) < 3)) then
  108.   do
  109.     UseString = 1
  110.     PhoneNum = strip(hit.i, 'B')
  111.   end /* do */
  112.  
  113.   /**** check for alternate MdmString2 */
  114.   else
  115.     do
  116.       call SysFileSearch MdmString2, LogFile, 'hit2.', 'N'
  117.       do k = 1 to hit2.0; end /* do */
  118.       k = (k-1)
  119.       LineNum2 = word(hit2.k, 1)
  120.       if ((LineCon > LineNum2)&(LineCon-LineNum2 < 3))
  121.         then
  122.           do
  123.             UseString = 2
  124.             PhoneNum = strip(hit2.k,'B')
  125.           end /* do */
  126.           
  127.     end /* do - else */
  128.   /**** can delete this block if there is only one string */
  129.  
  130. If UseString = 0 then PhoneNum = "Unavailable."
  131.  
  132.   else  /* UseString > 0 */
  133.     do
  134.       if UseString = 2 then MdmString = MdmString2
  135.       
  136.       PhonePos = pos(MdmString, PhoneNum)
  137.          /* position of the result code in newstring.*/
  138.  
  139.       PhonePos = PhonePos + length(MdmString)
  140.          /* position of string returned by telephone company */
  141.    
  142.       PhoneSize = length(PhoneNum) - PhonePos
  143.         /* size of string after return code. Includes blank if any */
  144.  
  145.       PhoneNum = substr(PhoneNum, PhonePos)
  146.       PhoneNum = strip(PhoneNum,Both)     
  147.       /* remove leading and trailing blanks */
  148.  
  149.       PhoneNum = DeGrunge(PhoneNum) /* removes extra stuff from information */
  150.                                     /* received from incompatable caller-id */
  151.       PhoneNum = StripArea(PhoneNum)
  152.  
  153.       if datatype(PhoneNum, 'N') = 1 then nop /* PhoneNum not a number */
  154.         else do
  155.            UseString = 0
  156.            If compare(translate(PhoneNum),translate(BlockIDString)) = 0 then do
  157.               Blocked = 1  /* Caller is blocking caller-id */
  158.               end /* do */
  159.            end /* end else do */
  160.  
  161.  
  162.       /* Log the Call and exit if LogOnly = 1 */
  163.       if LogOnly = 1 then do
  164.          call LogEntry("Call From: ", PhoneNum)
  165.          call lineout CmdFile, MaxString /*Use maxstring with no stuffing*/
  166.          call lineout CmdFile  /* close file */
  167.          exit   /* DO NOT PROCEED - LOG ONLY */
  168.          end  /* Do */
  169.  
  170.  
  171.       if UseString > 0 then do /* Was a useable number */
  172.         
  173.          TotalSize = stream(UserFile,'C', 'query size')
  174.          UserTotal = format((TotalSize/240),6,0) /* Rounded, no decimals */
  175.          
  176.          /* Flags */
  177.          LookNext = 1
  178.          UserNum = 0
  179.  
  180.          If TurfBad = 1 then IsBad = CheckBad(PhoneNum)
  181.          If IsBad = 1 then LookNext = 0
  182.          If AutoName = 0 then LookNext = 0
  183.            
  184.          do while LookNext = 1
  185.             UserNum = UserNum + 1
  186.             if UserNum > UserTotal then do
  187.                LookNext = 0
  188.                MoreThanOne = 0 /* Looked at all the users phone numbers */
  189.                end /* do */
  190.  
  191.             RecordStart = (240*UserNum)-239
  192.             UserPhone = charin(Userfile, (RecordStart+93), 15)
  193.             UserPhone = CleanPhone(UserPhone)
  194.             UserPhone = StripArea(UserPhone)
  195.  
  196.             if UserPhone = PhoneNum then do
  197.                Found = 1
  198.                UserNumL = UserNum
  199.                if UserNum > UserTotal then nop
  200.                   else do
  201.                      do while MoreThanOne = 1
  202.                         UserNum = UserNum + 1
  203.                         if UserNum > UserTotal then MoreThanOne = 0
  204.                         RecordStart = (240*UserNum)-239
  205.                         UserPhone = charin(UserFile, (RecordStart+93), 15)
  206.                         UserPhone = CleanPhone(UserPhone)
  207.                         UserPhone = StripArea(UserPhone)
  208.                         if UserPhone = PhoneNum then
  209.                         UserNumL = LatestUser(UserNumL, UserNum)
  210.                         end /* do while */
  211.                      UserNum = UserNumL
  212.                
  213.                      end /* else do */
  214.  
  215.               LookNext = 0
  216.               RecordStart = (240*UserNum)-239
  217.  
  218.               UserName = charin(Userfile,RecordStart,32)
  219.               UserName = UnPadName(UserName)
  220.  
  221.               UserPwd = charin(UserFile,(RecordStart+112),16)
  222.               UserPwd = UnPadName(UserPwd)
  223.  
  224.               end /* do UserPhone = PhoneNum*/
  225.                         
  226.             end /* do while LookNext = 1 */
  227.  
  228.             PhoneNum = FormatPhone(PhoneNum)
  229.  
  230.       end /* was a useable number */
  231.  
  232.   else PhoneNum = "Unavailable."
  233.   end /* UseString > 0 */
  234.  
  235. /* output PhoneNum, and BBSStuff */
  236.  
  237.  
  238. if Blocked =1 then do
  239.    PhoneNum = "Blocked."
  240.    if Turfblock = 1 then do
  241.       UserName = BlockName
  242.       UserPwd = BlockPwd
  243.       Found = 1
  244.       AutoName = 1
  245.       AutoPwd = 1
  246.       end /* do */
  247.    end /* do */
  248.  
  249. if IsBad = 1 then do
  250.    UserName = BadName
  251.    UserPwd = BadPwd
  252.    Found = 1
  253.    AutoName = 1
  254.    AutoPwd = 1
  255.    call LogEntry "!!Non-Allowed Number: ", PhoneNum
  256.    end  /* Do */
  257.  
  258.    else call LogEntry "Call From: ", PhoneNum /* Not in BadList */
  259.  
  260.  
  261. if Found = 1 then do /* Found number in UserList      */
  262.                      /* OR Turfing Blocker            */
  263.                      /* OR Turfing caller in BadList  */
  264.  
  265.    BBSStuff = ""
  266.    if AutoName =1 then do
  267.       BBSStuff = '"-j'    /* Note quotes!! */
  268.       BBSStuff = insert(UserName, BBSStuff, length(BBSStuff))
  269.       if AutoPwd = 1 then do
  270.          if substr(UserPwd,1,1) = "!" then do
  271.             BBSStuff = insert(";Y;", BBSStuff, length(BBSStuff))
  272.             BBSStuff = insert(UserPwd, BBSStuff, length(BBSStuff))
  273.             end /* do (first character is a "!") */
  274.          end /* do AutoPwd = 1 */
  275.       BBSStuff = insert('" ', BBSStuff, length(BBSStuff))
  276.       end /* do AutoName = 1 */
  277.    BBSStuff = insert(BBSStuff, MaxString, wordindex(MaxString,2)-1)
  278.    end /* do */
  279.    else BBSStuff = MaxString  /* found = 0 */
  280.       
  281.  
  282. call lineout OutputFile, PhoneNum
  283. call lineout OutputFile  /* close file */
  284.  
  285. call lineout CmdFile, BBSStuff
  286. call lineout CmdFile    /* close file */
  287.  
  288. /* Testing stuff - must use NON-ACTIVE binkley.log */
  289.  
  290. /*
  291. say Logfile   
  292. say BBSStuff
  293. say PhoneNum 
  294. */
  295.  
  296. exit
  297.  
  298. LatestUser:
  299.  
  300.   /* compares two users, and returns the one who */
  301.   /* signed on most recently     */
  302.  
  303.   UNum1 = arg(1)
  304.   UNum2 = arg(2)
  305.  
  306.   RecordStart1=(240*UNum1)-239
  307.   RecordStart2=(240*UNum2)-239
  308.  
  309.   UDate1 = charin(UserFile, (RecordStart1 + 142), 18)
  310.   UDate2 = charin(UserFile, (RecordStart2 + 142), 18)
  311.   UYear1 = substr(UDate1, 8, 2)
  312.   UYear2 = substr(UDate2, 8, 2)
  313.  /* Stupid way of dealing with callers after year 2000 */
  314.  If UYear1 < 81 then Uyear1 = Uyear1 + 2000
  315.     else Uyear1 = Uyear1 + 1900
  316.   If UYear2 < 81 then Uyear2 = Uyear2 + 2000
  317.     else Uyear2 = Uyear2 + 1900
  318.   select
  319.    when UYear2 > UYear1 then UNum1 = UNum2
  320.    when UYear2 < UYear1 then nop
  321.    otherwise /* the years are equal */
  322.      UMonth.1 = substr(UDate1, 4, 3)
  323.      UMonth.2 = substr(Udate2, 4, 3)
  324.      do i = 1 to 2
  325.        select
  326.         when UMonth.i = "Jan" then UMonth.i = 1
  327.         when UMonth.i = "Feb" then UMonth.i = 2
  328.         when UMonth.i = "Mar" then UMonth.i = 3
  329.         when UMonth.i = "Apr" then UMonth.i = 4
  330.         when UMonth.i = "May" then UMonth.i = 5
  331.         when UMonth.i = "Jun" then UMonth.i = 6
  332.         when UMonth.i = "Jul" then UMonth.i = 7
  333.         when UMonth.i = "Aug" then UMonth.i = 8
  334.         when UMonth.i = "Sep" then UMonth.i = 9
  335.         when UMonth.i = "Oct" then UMonth.i = 10
  336.         when UMonth.i = "Nov" then UMonth.i = 11
  337.         when UMonth.i = "Dec" then UMonth.i = 12
  338.         otherwise nop
  339.        end  /* select */
  340.  
  341.        select
  342.         when UMonth2 > UMonth1 then UNum1 = UNum2
  343.         when UMonth2 < UMonth1 then nop
  344.         otherwise
  345.           UDay1 = substr(UDate1, 1, 2)
  346.           UDay2 = substr(UDate2, 1, 2)
  347.           select
  348.            when UDay2 > UDay1 then UNum1 = UNum2
  349.            when UDay2 < UDay1 then nop
  350.            otherwise  /* Days are the same */
  351.              UHour1 = substr(UDate1, 11, 2)
  352.              UHour2 = substr(UDate2, 11, 2)
  353.              select
  354.                 when UHour2 > UHour1 then UNum1 = UNum2
  355.                 when UHour2 < UHour1 then nop
  356.                 otherwise
  357.                   UMin1 = substr(UDate1, 14, 2)
  358.                   UMin2 = substr(UDate2, 14, 2)
  359.                   select
  360.                      when UMin2 > UMin1 then UNum1 = UNum2
  361.                      when UMin2 < UMin1 then nop
  362.                      otherwise
  363.                        USec1 = substr(UDate1, 17, 2)
  364.                        USec1 = substr(UDate2, 17, 2)
  365.                        Select
  366.                         when USec2 > Usec1 then UNum1 = UNum2
  367.                         when USec2 < USec1 then nop
  368.                         otherwise nop
  369.                        end  /* select USec */
  370.                   end  /* select UMIn */
  371.              end  /* select UHour */
  372.           end /* select UDay */
  373.        end  /* select - Month */
  374.   end /* select - Year */
  375.  
  376. return UNum1
  377.  
  378. LogEntry:
  379.  
  380.    EntryPrefix = arg(1)
  381.    Entry = arg(2)
  382.  
  383.    if datatype(Entry, 'N') then Entry = FormatPhone(Entry)
  384.    LogDate = date('N')
  385.    Entry = insert(EntryPrefix, Entry)
  386.    Entry = insert(" EasyOn: ", Entry)
  387.    Entry = insert(time('N'), Entry)
  388.  
  389.    dd = word(LogDate, 1)
  390.    if length(dd) = 1 then dd = insert("0", dd)
  391.    mon = word(LogDate, 2)
  392.    yy = word(Logdate, 3)
  393.    yy = substr(yy, 3)
  394.  
  395.    Entry = insert(dd, Entry, 0, 3, " ") /* mon */
  396.    Entry = insert(mon, Entry, 0, 4, " ") /* dd */
  397.    Entry = insert(yy, Entry, 0, 3, " ") /* yy mon dd time*/
  398.    Entry = insert("# ", Entry)
  399.  
  400.    if CallidLog = 1 then call lineout EasyOnLog, Entry
  401.  
  402.    return
  403.  
  404. StripArea:
  405.   /* Remove AreaCode if present */
  406.  
  407.   PhNumS = arg(1)
  408.   
  409.   if compare(AreaCode,PhNumS) > length(AreaCode) then
  410.     do
  411.       PhNumS = delstr(PhNumS,1,length(AreaCode))
  412.     end /* do */
  413.  
  414.   return PhNumS
  415.  
  416. DeGrunge:
  417.  
  418.  /* kludge removing part */
  419.  
  420.  PhNumG = arg(1)
  421.  
  422.  if substr(PhNumG,1,1) = "0" then
  423.    do
  424.      NumSize = substr(PhNumG, 3, 2)
  425.      NumSize = x2d(NumSize)     /* hex to decimal */
  426.      PhNumG = delstr(PhNumG, 1, 4)
  427.  
  428.      if (datatype(PhNumG,'N') = 1) then  /* PhNumG is a number */
  429.        do i = 1 to (NumSize*2)
  430.          PhNumG = delstr(PhNumG, i, 1)
  431.            /* removes every second character, */
  432.            /* starting with the first.        */
  433.            /* PhNumG is now filtered.       */
  434.  
  435.         end /* do i = 1 NumSize */
  436.               /***** End of Kludge Removing Part */
  437.  
  438.     end /* do if substsr(PhNumG,1,1) = "0") */
  439.  
  440. return PhNumG
  441.  
  442. FormatPhone:
  443.  
  444.   PhNumf = arg(1)
  445.   /****** Long Disatance Number handling - May require tweaking */
  446.   if substr(PhNumf,1,1) = "1" then
  447.     /* number in form "1xxxxxxx" */
  448.     do
  449.       PhNumf = insert("-",PhNumf,1,1)
  450.  
  451.       if substr(PhNumf,4,1) = "1" | substr(PhNumf,4,1) = "0" then
  452.         /* Number has "1" or "0" as 4th digit -ie "1-x0xxxxxxxx" */
  453.       do
  454.         PhNumf = insert("-",PhNumf,5,1) /* After area code */
  455.       end /* do */
  456.     end /* do if first number is a "1" */
  457.  
  458.   if substr(PhNumf,2,1) = "1" | substr(PhNumf,2,1) = "0" then
  459.     /* Number has "1" or "0" as 4th digit -ie "x0xxxxxxxx" */
  460.     do
  461.       PhNumf = insert("-",PhNumf,3,1) /* After area code */
  462.     end /* do if 2nd digit is a "1" or "0" */
  463.  
  464.   PhNumf = insert("-",PhNumf,length(PhNumf)-4,1)
  465.    /* end of long distance numbers handling */
  466.  
  467. return PhNumf
  468.  
  469.  
  470. UnPadName:
  471.   /* removes trailing blanks from username */
  472.  
  473.   Unpadded = arg(1)
  474.   CharSet="ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890~`!@#$%^&*()_-:;',.<>/?=+\|"
  475.  
  476.   LastPos = verify(Translate(Unpadded),CharSet)
  477.   if LastPos > 0 then Unpadded = delstr(Unpadded,LastPos)
  478.  
  479. return Unpadded
  480.  
  481.  
  482. CleanPhone:
  483.   /* Clean UserPhone */
  484.  
  485.   PhNmC = Arg(1)
  486.   PhNmC = strip(PhNmC, Both)
  487.   BadPos = Verify(PhNmC,'1234567890','Nomatch')
  488.   Do While BadPos > 0 /* strip all non-digits */
  489.     PhNmC = delstr(PhNmC, BadPos, 1)
  490.     BadPos =Verify(PhNmC,'1234567890','Nomatch')
  491.   end /* do */
  492.  
  493. return PhNmC
  494.  
  495.  
  496. CheckBad:
  497.    /* Check to see if in BadList  */
  498.  
  499.    PhNmb = Arg(1)
  500.    FoundBad = 0
  501.  
  502.    RC = SysFileSearch("-",BadList,hitN) 
  503.    Select
  504.      when RC = 2 then LogEntry("Error Checking BadList ","Not enough memory")
  505.      when RC = 3 then LogEntry("Error Checking BadList ","error opening file")
  506.      otherwise
  507.        do t = 1 to hitN.0
  508.           BadNum = hitN.t
  509.           EndNum = pos(";", BadNum) /* where comment starts */
  510.           If EndNum > 0 then BadNum = delstr(BadNum,EndNum)
  511.             /* Read in line from BadList */
  512.           BadNum = strip(BadNum, Both)
  513.           BadNum = CleanPhone(BadNum)  /* strip all non-digits */
  514.           BadNum = StripArea(BadNum)
  515.           if BadNum = PhNmb then do
  516.              FoundBad = 1
  517.              t = hitN.0
  518.              end  /* Do */
  519.           end /* do t = 1 to hitN.0  */
  520.        end /* select */
  521.  
  522.    
  523.    return FoundBad
  524.