home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1996 October / PCO_10.ISO / filesbbs / cfos2.arj / TONLINE.CMD < prev    next >
Encoding:
Text File  |  1996-09-05  |  12.8 KB  |  465 lines

  1. /***********************************************************
  2. ** Telekom Online Internet Access via Datex-J & ISDN
  3. ** Dial In Script
  4. ************************************************************
  5. ** The routines send, waitfor und flush_receive are derived from
  6. ** OS/2 2.0 REXX Driver for IBM TCP/IP version 2.0, ANNEX.CMD
  7. ***********************************************************/
  8.  
  9. parse arg interface , dialcmd username password
  10.  
  11. call RxFuncAdd SysLoadFuncs, RexxUtil, SysLoadFuncs
  12. call SysLoadFuncs
  13.  
  14. /***********************************************************
  15. ** Set up some variables with convenient values
  16. ***********************************************************/
  17. cr='0d'x
  18. crlf='0d0a'x
  19. ctrlc='03'x
  20.  
  21. newline='0a'x
  22.  
  23. regpage=ctrlc'190144200#'
  24.  
  25. gatewaypage=ctrlc'190144100#'
  26.  
  27. identstring='OS2 4'
  28.  
  29. tcpos2=value('ETC',,'OS2ENVIRONMENT') || '\TCPOS2.INI'
  30. price=value('ETC',,'OS2ENVIRONMENT') || '\..\TELEKOM\PRICE.MIN'
  31.  
  32. say 'tcpos2: ' || tcpos2
  33.  
  34. gate=sysini(tcpos2,CONNECTION,CURRENT_CONNECTION)
  35. gate=left(gate,7)
  36.  
  37. say 'gate: ' || gate
  38.  
  39. /***********************************************************
  40. ** Read the Datex-J parameters stored in DXJDIAL.INI
  41. ***********************************************************/
  42. call ReadDxJDial
  43.  
  44. /***********************************************************
  45. ** Dial into Datex-J and enter the Internet Gateway
  46. ***********************************************************/
  47. if gate = 'DxJ2400' then do
  48.    initstring = modem_init_0
  49.    dialstring = dial_prefix || default_node
  50. end
  51.  
  52. if gate = 'DxJfast' then do
  53.    initstring = modem_init_1
  54.    dialstring = dial_prefix || fast_node
  55. end
  56.  
  57. kennung   = left(account,12)
  58. teilnehmer = left(user_no, 12)
  59. mitbenutzer = left(co_user_no, 4)
  60. passwort = left(password, 8)
  61.  
  62. say ''
  63. say 'Telekom Online Internet Access via Datex-J'
  64. /* call flush_receive 'echo' */
  65.  
  66. dial_in_loop:
  67. say 'Dialing ...'
  68. call send initstring || cr     
  69. call waitfor 'OK'
  70. call flush_receive 'echo'
  71. call send dialstring || cr
  72. call waitfor 'CONNECT' , 40 
  73.  
  74. if RC = 1
  75.    then
  76.    do
  77.       say 'Wahlwiederholung in 40 Sekunden'
  78.       call flush_receive
  79.       call send 'ath' || cr
  80.       call waitfor 'OK' ; call flush_receive 'echo'
  81.       SIGNAL dial_in_loop
  82.    end
  83.  
  84. /* Datex-J login procedure: enter identification data */
  85. call waitfor 'kennung:' , 30 
  86. if RC = 1 then
  87. do
  88.   SIGNAL Failure 
  89. end
  90. call flush_receive 'echo'
  91.  
  92. call send kennung 
  93. call waitfor 'L120', 5
  94. /* in case Anschluß is teilnehmerfreizügig, we must enter Teilnehmer */
  95. if RC = 1 then
  96. do
  97.    call send teilnehmer
  98. end
  99.  
  100. call waitfor 'Mitbenutzer' , 5
  101. if RC = 1 then
  102. do
  103.   SIGNAL Failure 
  104. end
  105. call flush_receive 'echo'
  106.  
  107. call send mitbenutzer
  108. call waitfor '1' , 5 
  109. if RC = 1 then
  110. do
  111.   SIGNAL Failure 
  112. end
  113. call flush_receive 'echo'
  114.  
  115. call send passwort
  116. call waitfor 'L200' , 10 
  117. if RC = 1 then
  118. do
  119. /* Keine Telekom-Seite; Container-Seite? */
  120.         if lastpos("34561",waitfor_buffer)=0 then
  121. /* Nein */
  122.                 SIGNAL Failure
  123. end
  124. call flush_receive 'echo'
  125.  
  126. /* Check if registration is necessary */
  127. if stream( regfile, 'command', 'query exists') = '' then
  128. do
  129.    call send regpage
  130.    call waitfor 'Absenden'
  131.  
  132.    zeit = Time('S')
  133.    do until Time('S') > zeit+1
  134.    end
  135.  
  136.    call flush_receive 'echo'
  137.    call send '19'
  138.    call waitfor 'beendet' , 10
  139.    if RC=1 then
  140.         SIGNAL FailureER
  141.  
  142.    call flush_receive 'echo'
  143. end
  144. /* Datex-J login procedure: enter X.29 gateway */
  145. call send gatewaypage
  146. call waitfor 'ER-Verb.'
  147.  
  148. call waitfor 'SH'
  149. parse var waitfor_buffer minuteprice 'J' .
  150. minuteprice = LEFT(minuteprice,13)
  151. say 'Kosten:'||minuteprice
  152.  
  153. minutepriceold = LINEIN(price,1,1)
  154. LINEOUT(price)
  155. minutepriceold = LEFT(minutepriceold,13)
  156.  
  157. if minutepriceold \= minuteprice then do
  158.  
  159.   title = 'Telekom Online Gebühreninformation'
  160.   message = cr,
  161.     'Für das Internet beträgt der Zeittakt' || minuteprice || crlf,
  162.     'Hinzu kommt der Datex-J Zeittakt von 0,02/DM Min.' || cr,
  163.     'An Werktagen von 8-18 Uhr erhöht sich der Datex-J' || cr,
  164.     'Zeittakt um DM 0,04/DM Min. (nicht an bundesein-' || cr,
  165.     'heitlichen Feiertagen!).',
  166.     newline || newline,
  167.     'Soll dieser Hinweis beim nächsten Login wieder angezeigt' || cr,
  168.     'werden? Falls Sie die Frage mit NEIN beantworten, so' || cr,
  169.     'bekommen Sie diese Information erst wieder bei einer' || cr,
  170.     'Tarifänderung angezeigt.' || crlf
  171.  
  172.    buttons = 'YesNoCancel'
  173.    infosym = 'Information'
  174.    action  = RxMessageBox( message, title, buttons, infosym )
  175.  
  176.    if action = 2 /* Cancel */ then exit 1
  177.  
  178.    if action = 6 /* Yes */ then do
  179.      LINEOUT(price,'0',1)
  180.      LINEOUT(price)
  181.    end
  182.  
  183.    if action = 7 /* Nein */ then do
  184.      LINEOUT(price,minuteprice,1)
  185.      LINEOUT(price)
  186.    end
  187. end
  188.  
  189. call send '19'
  190. call waitfor 'STATUS ' , 10
  191. if RC=1 then
  192.         SIGNAL FailureER
  193.  
  194.  
  195. call waitfor crlf
  196. parse var waitfor_buffer a ' ' challenge '0d0a'x
  197. if a \= 'OK' then do
  198.   say 'Fehler: ' a
  199.   exit 1
  200. end
  201.  
  202. /* Send Identification String */
  203. crypt 'Encode'  challenge '| RXQUEUE'
  204. parse pull response
  205.  
  206. call send IdentString || ' ' || response || cr
  207.  
  208. call waitfor crlf
  209. parse var waitfor_buffer a '0d0a'x
  210. if a \= 'OK' then do
  211.   say 'Fehler: ' a
  212.   exit 1
  213. end
  214.  
  215.  
  216. do forever
  217.   call waitfor crlf
  218.   parse var waitfor_buffer a ' ' b '0d0a'x
  219.  
  220.   if a = '.' || '0d0a'x then leave
  221.   call SysIni tcpos2, gate, a, b || '0'x
  222. end
  223.  
  224. do forever
  225.   call waitfor crlf
  226.   parse var waitfor_buffer a ' ' b '0d0a'x
  227.  
  228.   if a = '.' || '0d0a'x then leave
  229.  
  230.   select
  231.     when a = 'MSG'     then 
  232.        do 
  233.        title = 'Telekom Online Hinweis'
  234.        message =,
  235.        b
  236.        call InfoMessage
  237.        end
  238.     when a = 'DOREG'   then 'del' regfile
  239.     when a = 'DONTREG' then call lineout regfile
  240.     otherwise  /* Ignore */
  241.   end
  242. end
  243.  
  244. call send 'OK' || cr
  245.  
  246. parse value SysIni(tcpos2,gate,'YOURIP') with yourip '0'x
  247. parse value SysIni(tcpos2,gate,'DESTIP') with destip '0'x
  248. parse value SysIni(tcpos2,gate,'NETMASK') with netmask '0'x
  249.  
  250. 'ifconfig sl0' yourip destip 'netmask' netmask
  251. 'route add default' destip '1'
  252.  
  253. say 'Connected to Telekom Online Internet Access'
  254. say 'Eigene Adresse =' yourip ', Gateway-Rechner =' destip
  255.  
  256. /* Success */
  257. exit 0
  258.  
  259. /* Failure */
  260. Failure:
  261. title = 'Telekom Online Hinweis'
  262. message =,
  263. 'Bei der Eingabe der Zugangsdaten ist ein Fehler aufgetreten',
  264. 'Bitte überprüfen Sie Ihre Zugangsdaten im Telekom Online Dialer Setup'
  265. call InfoMessage
  266. exit 1
  267.  
  268. /* FailureER */
  269. FailureER:
  270. title='Telekom Online Hinweis'
  271. message =,
  272. 'Der Verbindungsaufbau zum externen Rechner ist derzeit nicht',
  273. 'möglich. Bitte versuchen Sie es später noch einmal.'
  274. call InfoMessage
  275. exit 1
  276.  
  277. /**********************************************************
  278. **                          end of main program                           
  279. ***********************************************************/
  280.  
  281.  
  282. /**********************************************************
  283. ** subroutines for modem access: send, waitfor, flush_receive
  284. ***********************************************************/
  285. /*                            send ( sendstring)                         */
  286. /* Routine to send a character string off to the modem.                  */
  287.  
  288. send:
  289.  
  290.    parse arg sendstring
  291.    call slip_com_output interface , sendstring
  292.  
  293.    return
  294.  
  295.  
  296. /*                    waitfor ( waitstring , [timeout] )                    */
  297. /* Waits for the supplied string to show up in the COM input.  All input    */
  298. /* from the time this function is called until the string shows up in the   */
  299. /* input is accumulated in the "waitfor_buffer" variable.                   */
  300. /*                                                                          */
  301. /* If timeout is specified, it says how long to wait if data stops showing  */
  302. /* up on the COM port (in seconds).             */
  303.  
  304. waitfor:
  305.  
  306.    parse arg waitstring , timeout
  307.  
  308.    if timeout = '' then
  309.      timeout = 5000    /* L O N G   delay if not specified */
  310.    waitfor_buffer = '' ; done = -1; curpos = 1
  311.    ORI_TIME=TIME('E')
  312.  
  313.    if (remain_buffer = 'REMAIN_BUFFER') then do
  314.       remain_buffer = ''
  315.    end
  316.  
  317.    do while (done = -1)
  318.       if (remain_buffer \= '') then do
  319.          line = remain_buffer
  320.          remain_buffer = ''
  321.        end
  322.        else do
  323.          line = slip_com_input(interface,,10)
  324.       end
  325.       waitfor_buffer = waitfor_buffer || line
  326.       index = pos(waitstring,waitfor_buffer)
  327.       if (index > 0) then do
  328.          remain_buffer = substr(waitfor_buffer,index+length(waitstring))
  329.          waitfor_buffer = delstr(waitfor_buffer,index+length(waitstring))
  330.          done = 0
  331.       end
  332.       call charout , substr(waitfor_buffer,curpos)
  333.       curpos = length(waitfor_buffer)+1
  334.       if ((done \= 0) & (TIME('E')>timeout)) then do
  335. /*        call lineout , ' WAITFOR: timed out ' */
  336.         done = 1
  337.        end
  338.    end
  339.    timeout=0
  340.    RC=done
  341.  return RC
  342.  
  343.  
  344. /*                             flush_receive ()                             */
  345. /* Routine to flush any pending characters to be read from the COM port.    */
  346. /* Reads everything it can until nothing new shows up for 100ms, at which   */
  347. /* point it returns.                                                        */
  348. /*                                                                          */
  349. /* The optional echo argument, if 1, says to echo flushed information.      */
  350.  
  351. flush_receive:
  352.  
  353.    parse arg echo
  354.  
  355.    /* If echoing the flush - take care of waitfor remaining buffer */
  356.    if (echo \= '') & (length(remain_buffer) > 0) then do
  357.       call charout , remain_buffer
  358.       remain_buffer = ''
  359.    end
  360.  
  361.    /* Eat anything left in the modem or COM buffers */
  362.    /* Stop when nothing new appears for 100ms.      */
  363.  
  364.    do until line = ''
  365.      line = slip_com_input(interface,,100)
  366.      if echo \= '' then
  367.         call charout , line
  368.    end
  369.  
  370.    return
  371.  
  372.  
  373. /*********************************************************************
  374. /
  375. /  The procedure 'ReadDxJDial' reads the file DXJDIAL.INI and
  376. /  transforms the settings made in that file into values of
  377. /  globally accessible variables.
  378. /
  379. /  DXJDIAL.INI is assumed to reside in the Telekom directory
  380. /  which is a subdirectory of the base directory where the IBM
  381. /  Internet Connection is installed.
  382. /
  383. *********************************************************************/
  384.  
  385. ReadDxJDial:
  386.  
  387.    procedure expose,
  388.       account password user_no co_user_no,
  389.       comport_no modem_init_0 modem_init_1,
  390.       dial_prefix default_node fast_node,
  391.       crypt regfile
  392.  
  393.    /* Get drive, path and name of the INI file
  394.    */
  395.    parse upper source . . this_cmd
  396.    c_drive = filespec( 'drive', this_cmd )
  397.    c_path  = filespec( 'path',  this_cmd )
  398.    dxjdial = c_drive || c_path || 'DXJDIAL.INI'
  399.    crypt   = c_drive || c_path || 'CRYPT.EXE'
  400.    regfile = c_drive || c_path || 'REGISTER.OK'
  401.  
  402.    /* Preserve compatibility with version 1.0 DXJDIAL.INI format
  403.    */
  404.    exchange_0 = ''
  405.    exchange_1 = ''
  406.  
  407.    /* Read the contents of the INI file
  408.    */
  409.    do while lines( dxjdial ) > 0
  410.       parse value linein( dxjdial ) with keyword '=' value
  411.       value = strip( value )  /* Strip leading/trailing blanks */
  412.       select
  413.          when keyword = 'Account'     then account      = value
  414.          when keyword = 'UserNo'      then user_no      = value
  415.          when keyword = 'CoUserNo'    then co_user_no   = value
  416.          when keyword = 'Password'    then password     = value
  417.          when keyword = 'ComPortNo'   then comport_no   = value
  418.          when keyword = 'ModemInit_0' then modem_init_0 = value
  419.          when keyword = 'ModemInit_1' then modem_init_1 = value
  420.          when keyword = 'DialPrefix'  then dial_prefix  = value
  421.          when keyword = 'DefaultNode' then default_node = value
  422.          when keyword = 'FastNode'    then fast_node    = value
  423.          when keyword = 'Exchange_0'  then exchange_0   = value
  424.          when keyword = 'Exchange_1'  then exchange_1   = value
  425.          otherwise  /* Ignore */
  426.       end
  427.    end
  428.    call lineout dxjdial  /* Close the INI file */
  429.  
  430.    /* Decode the encoded password
  431.    */
  432.    if password <> '' then do
  433.       crypt 'Decode' password '| RXQUEUE'
  434.       parse pull password
  435.       password = x2c( password )
  436.    end
  437.  
  438.    /* Prefix telephone numbers with exchange codes
  439.    */
  440.    default_node = exchange_0 || default_node
  441.    fast_node    = exchange_1 || fast_node
  442.  
  443. return
  444.  
  445.  
  446. /*********************************************************************
  447. /
  448. /  The procedure 'InfoMessage' displays a message box and offers
  449. /  the buttons 'Ok' and 'Abbruch'. While 'Ok' continues REXX
  450. /  command file execution, 'Abbruch' terminates it.
  451. /
  452. *********************************************************************/
  453.  
  454. InfoMessage:
  455.  
  456.    buttons = 'OkCancel'
  457.    infosym = 'Information'
  458.    action  = RxMessageBox( message, title, buttons, infosym )
  459.    if action = 2 /* Cancel */ then exit 1
  460.    
  461. return
  462.  
  463.  
  464. /* Ende des Programms */
  465.