home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 January / PCO0197.ISO / filesbbs / os2 / isdnpm27.arj / TONLINE.FNC < prev   
Encoding:
Text File  |  1996-11-17  |  8.9 KB  |  310 lines

  1. /*--------------------------------------------------------------------------
  2.  
  3.                                   TONLINE.fnc         
  4.    Version 30.7.96                                    
  5.      - mit Korrektur nach Senden der Gateway-Seite
  6.        call WAITFOR "ER-Verb" und WAITFOR "SH"         
  7.        nun vor WAITFOR prompt_string beim Warten auf Gebuehren-Info 
  8.        (ein Tip von Jupp Chudzinski)
  9.  
  10.   --------------------------------------------------------------------------*/
  11.  
  12. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  13. call SysLoadFuncs
  14.  
  15. ARG Channel LocalIp HostIp Netmask DefaultIp
  16.  
  17. cr   = '0d'x
  18. crlf = '0d0a'x
  19. remain_buffer  = ''
  20. waitfor_buffer = ''
  21. prompt_vt100='[?25h'
  22. prompt_cept='1A'x
  23. prompt_string=prompt_cept
  24. prompt_string=prompt_vt100
  25.  
  26. say 'Line       ' Channel
  27. say 'LocalIp    ' LocalIp
  28. say 'HostIp     ' HostIp
  29. say 'Netmask    ' Netmask
  30. say 'DefaultIp  ' HostIp
  31.  
  32. /*--------------------------------------------------------------------------*/
  33. /*  tragen Sie hier Ihre ID und Ihr Password ein                            */
  34. /*  falls Ihr Password erfragt werden soll : password = ""                  */
  35. /*--------------------------------------------------------------------------*/
  36.  
  37. username="000111112222"
  38. password="33334444"
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /*                   Initialization and Main Script Code                    */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44.  
  45. say ''
  46. say 'TONLINE - SLIP TONLINE login script (channel' channel')'
  47.  
  48. say ""
  49. say "Warten auf 1.Zeichen..."
  50. call waitfor '80'x ,20
  51. if RC = 1 then signal failure
  52. call send "."||cr
  53. say ""
  54. say "Umgeschaltet in VT100. Anmeldung..."
  55. /* Handle login. */
  56. call waitfor prompt_string,20
  57. if RC = 1 then signal failure
  58. call flush_receive 'echo'
  59. say ''
  60. say '********* Anschlusskennung(=Username)...'
  61. say ''
  62. call send username
  63. call waitfor prompt_string,20
  64. if RC = 1 then signal failure
  65. call flush_receive 'echo'
  66. say ''
  67. say '********* Mitbenutzernr....'
  68. say ''
  69. call send '0001'
  70. call waitfor prompt_string,20
  71. if RC = 1 then signal failure
  72. call flush_receive 'echo'
  73. say ''
  74. say 'Kennwort...'
  75. say ''
  76. if password="" then
  77.   password=READPASSWORD(channel)
  78. call send password
  79. call send cr
  80. call waitfor prompt_string,20
  81. if RC = 1 then signal failure
  82. if Pos('Falsches Kennwort',remain_buffer)>0 then do
  83.   say ''
  84.   say 'Fehlerhafte Anmeldung: Falsches Kennwort!'
  85.   signal failure
  86. end
  87. call flush_receive 'echo'
  88.  
  89. if prompt_string=prompt_cept then do
  90.   say ''
  91.   say '********* Switching to VT100 Mode'
  92.   call send "*707#"
  93.   call waitfor prompt_string,20
  94.   if RC = 1 then signal failure
  95.   call flush_receive 'echo'
  96.   call send "j"
  97.   call waitfor prompt_string,20
  98.   if RC = 1 then signal failure
  99.   call flush_receive 'echo'
  100.   call send "."||cr
  101.   prompt_string=prompt_vt100
  102.   call waitfor prompt_string,20
  103.   if RC = 1 then signal failure
  104.   call flush_receive 'echo'
  105.   call send "n"
  106.   call waitfor prompt_string,20
  107.   if RC = 1 then signal failure
  108.   call flush_receive 'echo'
  109. end
  110.  
  111.  
  112. say ''
  113. say 'Gateway-Seite...'
  114. say ''
  115.  
  116. call send "*190144100#"
  117.  
  118. say ''
  119. say 'Warte auf Gebuehren-Info...'
  120. say ''
  121. call waitfor "ER-Verb.",20
  122. if rc=1 then signal failure
  123. call waitfor "SH",20
  124. if rc=1 then signal failure
  125. call waitfor prompt_string,20
  126. if rc=1 then signal failure
  127. say ""
  128. say "Gebuehren-Bestätigung..."
  129. say ""
  130. call send "19"
  131. call waitfor "STATUS OK",100
  132. if rc=1 then signal failure
  133. call waitfor crlf
  134. say "LIN..."
  135. call send "LIN"||cr
  136. do forever
  137.   call waitfor crlf
  138.   parse var waitfor_buffer a " " b "0d0a"x
  139.   if a="." ||"0d0a"x then leave
  140.   select
  141.     when a="YOURIP" then yourip=b
  142.     when a="DESTIP" then destip=b
  143.     when a="NETMASK" then netmask=b
  144.     when a="DNS" then dns=b
  145.     when a="DOMAIN_NAME" then domain_name=b
  146.     otherwise /* ignorieren */
  147.   end
  148. end
  149.  
  150. do forever
  151.   call waitfor crlf
  152.   parse var waitfor_buffer a " " b "0d0a"x
  153.   if a="." ||"0d0a"x then leave
  154. end
  155. call send "OK"||cr
  156.  
  157. /* Aus DNS und DOMAIN_NAME die RESOLV-Datei erstellen */
  158. resolv=Value('ETC',,'OS2ENVIRONMENT')'\resolv'
  159. resolv_sik=resolv'.~'
  160. if stream(resolv,'c','query exists')<>'' then do
  161.   if stream(resolv_sik,'c','query exists')<>'' then do
  162.     'cmd /c del' resolv_sik
  163.   end
  164.   'cmd /c ren' resolv FileSpec("name",resolv_sik)
  165.   if rc=0 then do
  166.     call lineout resolv,'domain' domain_name
  167.     call lineout resolv,'nameserver' dns
  168.     call stream resolv,'c','close'
  169.   end
  170.   else do
  171.     say 'Kann keine Sicherungskopie von %etc%\resolv-Datei erzeugen'
  172.   end
  173. end
  174. else do
  175.   call lineout resolv,'domain' domain_name
  176.   call lineout resolv,'nameserver' dns
  177.   call stream resolv,'c','close'
  178. end
  179.  
  180. "ifconfig" "sl0" yourip destip "netmask" netmask "mtu 296"
  181. "route add" "default" destip "1"
  182.  
  183. /* must not be changed ! */
  184.  
  185. say 'REXX DATAMODE'
  186. rc = ISDNDATAMODE(Channel)
  187. say 'REXX DATAMODE END'
  188.  
  189.  
  190. /* alte RESOLV-Datei restaurieren */
  191. if stream(resolv_sik,'c','query exists')<>'' then do
  192.   if stream(resolv,'c','query exists')<>'' then do
  193.     'cmd /c del' resolv
  194.   end
  195.   'cmd /c ren' resolv_sik FileSpec("name",resolv)
  196.   if rc<>0 then do
  197.     say 'Kann Sicherungskopie von %etc%\resolv-Datei nicht restaurieren'
  198.   end
  199. end
  200.  
  201. "route delete" destip yourip
  202. "route delete" "default" destip
  203.  
  204.  
  205.  
  206. exit 0
  207.  
  208. failure:
  209. say "Mist! Schiefgegangen!"
  210.   call ISDNDISCONNECT Channel
  211.   exit 1
  212.  
  213.  
  214. /*--------------------------------------------------------------------------*/
  215. /*                            send ( sendstring)                            */
  216. /*..........................................................................*/
  217. /*                                                                          */
  218. /* Routine to send a character string off to the modem.                     */
  219. /*                                                                          */
  220. /*--------------------------------------------------------------------------*/
  221.  
  222. send:
  223.  
  224.    parse arg sendstring
  225.    call ISDNWRITE channel , sendstring
  226.  
  227.    return
  228.  
  229.  
  230. /*----------------------------------------------------------------------*/
  231. /*  waitfor( waitforstring , [timeout] )                                */
  232. /*......................................................................*/
  233. /*                                                                      */
  234. /*                                                                      */
  235. /*                                                                      */
  236. /*----------------------------------------------------------------------*/
  237.  
  238. waitfor:
  239.  
  240.     parse arg waitstring , timeout
  241.     if timeout = '' then
  242.         timeout = 20        /* wait 20 sec */
  243.  
  244.     timeout = timeout * 10 ;    /* ISDNREAD returns after 1/10 Sek */
  245.  
  246.     waitfor_buffer = '' ; done = -1 ; curpos = 1
  247.     do while (( done = -1) & (timeout > 0))
  248.         if (remain_buffer \= '') then do
  249.             line = remain_buffer
  250.             remain_buffer = ''
  251.         end
  252.         else do
  253.             line = ISDNREAD(Channel)
  254.             if Substr(line,1,1)<>'00'x then do
  255.               say 'ISDNREAD-Fehler'
  256.               signal failure
  257.             end
  258.             line=Substr(line,2)
  259.         end
  260.         waitfor_buffer = waitfor_buffer || line
  261.         if waitstring>='80'x then
  262.           index=1
  263.         else
  264.           index = pos(waitstring,waitfor_buffer)
  265.         if (index > 0 ) then do
  266.             remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  267.             waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  268.             done = 0
  269.         end
  270.         call charout,substr(waitfor_buffer,curpos)
  271.         curpos = length(waitfor_buffer)+1
  272.         timeout = timeout - 1
  273.         call SysSleep 0
  274.     end
  275.     if (timeout = 0 ) then do
  276.         say 'WAITFOR : timed out '
  277.         done = 1
  278.     end
  279.     RC = done
  280. return RC
  281. /*----------------------------------------------------------------------*/
  282. /*  flush_receive()                                                     */
  283. /*......................................................................*/
  284. /*                                                                      */
  285. /*                                                                      */
  286. /*                                                                      */
  287. /*----------------------------------------------------------------------*/
  288. flush_receive:
  289.  
  290.     parse arg echo
  291.     /* if echoing the flush - take care of waitfor remainig buffer */
  292.     if( echo \= '' ) && (length(remain_buffer) > 0 ) then do
  293.         call charout, remain_buffer
  294.     end
  295.     cx = 20
  296.     line = ''
  297.     do while (line \= '') & (cx > 0 )
  298.         line = ISDNREAD(Channel)
  299.         if Substr(line,1,1)<>'00'x then do
  300.           say 'ISDNREAD-Fehler'
  301.           signal failure
  302.         end
  303.         line=Substr(line,2)
  304.         if echo \= '' then
  305.             call charout,line
  306.         cx = cx - 1
  307.     end
  308.     return
  309.  
  310.