home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pcnt3v11.zip / pppcnt.cmd < prev    next >
OS/2 REXX Batch file  |  1999-03-12  |  9KB  |  283 lines

  1. /*
  2.  
  3.    Started on April 3rd 1998, Walt Shekrota  Use makeppp.cmd for setup.
  4.  
  5.    Establish point to point through desired service without intervention
  6.    of IBM's GUI front end. (slippm.exe) dialer.exe is the slick interface
  7.    that you only see if using IBM's Global Service. If you use another
  8.    ISP you are stuck using the clunky slippm cludge. It requires you to
  9.    hit enter on starting and asks questions shutting down. Not to mention
  10.    the fact that they did not implement saved window features. (shift key)
  11.  
  12.    Use the GUI (slippm) to enter the user data ie. userid, password etc and
  13.    let it modify the HOSTS file with correct domain info. Use it to try the
  14.    connection, then convert to using this procedure.
  15.  
  16.   'start' also generates desired effect that PPP doesn't autostart should
  17.    you have 'autostart programs' set in your config.sys and shutdown without
  18.    killing PPP.
  19.  
  20.    To END connection: Control-C on 'PPP Connection' screen selected from
  21.    task list.
  22.  
  23.  */
  24.  
  25.      Parse Arg appl runthis
  26.  
  27. /* Clear queue */
  28.  
  29.             Do Queued();Pull .;End
  30.  
  31. /* Check for PPP running? If not then continue */
  32.  
  33.             Call PPPrunning
  34.  
  35.             If (result=1) Then
  36.  
  37.              If (runthis="") Then
  38.  
  39.                 Do
  40.                  Say "PPP is already running!"
  41.                  Exit 20
  42.                 End
  43.  
  44.              Else Signal StartAPP
  45.  
  46.  
  47. /* get the path info from where this cmd file is run */
  48.  
  49.             Parse Source . . this .
  50.             this=Reverse(this)
  51.             Parse Var this . '\' cmdpath .
  52.             cmdpath=Reverse(cmdpath)
  53.  
  54.             If RxFuncQuery("sysloadfuncs") Then
  55.             Do
  56.               Call rxfuncadd "sysloadfuncs", "rexxutil", "sysloadfuncs"
  57.               Call sysloadfuncs
  58.             End
  59.  
  60. /* get parms that were stored in TCPOS2.INI by Other Provider Dialer */
  61.  
  62.             inif=tcpchk(appl)
  63.             if(inif="") Then Exit 28
  64.  
  65.             running=SysIni(inif, appl, 'CAUTION')  /* caution state icon    */
  66.  
  67. /* maintain current/last connection names for newsreader */
  68.  
  69.             ls=SysIni(inif, 'CONNECTION', 'CURRENT_CONNECTION') /* get last connect id */
  70.  
  71.             If("ERROR:"=SysIni(inif,"CONNECTION","LAST_CONNECTION",ls)) Then
  72.                Say "Error INI write LAST_CONNECTION"
  73.             If("ERROR:"=SysIni(inif,"CONNECTION","CURRENT_CONNECTION",appl)) Then
  74.                Say "Error INI write CURRENT_CONNECTION"
  75.  
  76.             ip=SysIni(inif, appl, 'DNS') /* get nameserver i/p addr */
  77.             dn=SysIni(inif, appl, 'DOMAIN_NAME') /* get domain */
  78. /*
  79.  * Save original resolv file, in case user has lan config etc
  80.  * and needs to reset it. For most cases resolv will be set on
  81.  * a connection basis. Yes rename will fail in most cases if existing
  82.  * as intended by me so as to save ONLY the original!
  83.  */
  84.            '@rename resolv resolv.ori'
  85.            '@erase resolv'
  86.             xx=Lineout("resolv","domain" dn,1)
  87.             xx=Lineout("resolv","nameserver" ip)
  88.  
  89. /* Turn on the yellow light that says we be a going */
  90.  
  91.                Call SysCreateObject "WPProgram", appl,"<WP_DESKTOP>","OBJECTID=<PPPCNT_"Substr(appl,1,8)">;ICONFILE="cmdpath"\"running,"U"
  92.  
  93.             speed=SysIni(inif, appl, 'BAUD')       /* Linespeed?            */
  94.             speed=Delstr(speed, Length(speed))
  95.  
  96.             port=SysIni(inif, appl, 'COMPORT')     /* COM port used?        */
  97.             port=Delstr(port, Length(port))
  98.  
  99.             dis=SysIni(inif, appl, 'DISABLE')      /* disable cw if 'TRUE'  */
  100.             dis=Delstr(dis, Length(dis))
  101.  
  102.             seq=SysIni(inif, appl, 'DISABLE_SEQ')  /* usually *70           */
  103.             seq=Delstr(seq, Length(seq))
  104.  
  105.             amready=SysIni(inif, appl, 'GO')       /* running state icon    */
  106.  
  107.             init1=SysIni(inif, appl, 'INIT')       /* init string 1         */
  108.             init1=Delstr(init1, Length(init1))
  109.  
  110.             init2=SysIni(inif, appl, 'INIT2')      /* init string 2         */
  111.             init2=Delstr(init2, Length(init2))
  112.  
  113.             id=SysIni(inif, appl, 'LOGIN_ID')      /* Query the login       */
  114.             id=Delstr(id, Length(id))
  115.  
  116.             mru=SysIni(inif, appl, 'MTU_SIZE')     /* MRU                   */
  117.             mru=Delstr(mru, Length(mru))
  118.  
  119.             prefix=SysIni(inif, appl, 'PREFIX')    /* prefix dial tone/pulse*/
  120.             prefix=Delstr(prefix, Length(prefix))
  121.  
  122.             phone=SysIni(inif, appl, 'PHONE_NUMBER') /* Query the phonenumber */
  123.             phone=Delstr(phone, Length(phone))
  124.  
  125.             pw=SysIni(inif, appl, 'PWD')           /* Query the password    */
  126.             pw=Delstr(pw, Length(pw))
  127.  
  128.             scr=SysIni(inif, appl, 'SCRIPT')       /* Connection script     */
  129.             scr=Delstr(scr, Length(scr))
  130.  
  131.             stopped=SysIni(inif, appl, 'STOP')     /* stop state icon       */
  132.  
  133. /* init strings and expected responses */
  134.  
  135.             If(dis='TRUE') Then phone=seq||phone    /* Call waiting */
  136.  
  137.             If(init1="") Then str1=""
  138.              Else str1=init1 "OK"
  139.             If(init2="") Then str2=""
  140.              Else str2=init2 "OK"
  141.  
  142.             str3=prefix||phone "NECT"
  143.  
  144. /* implement connection scripts here, insert id and password */
  145.  
  146.             If scr<>'NONE' Then
  147.               Do
  148.                chars="0d0a"x
  149.                scr=Translate(scr,"  ",chars)
  150.                scr=ReplaceIf(scr,"[LOGINID]",id)
  151.                scr=ReplaceIf(scr,"[PASSWORD]",pw)
  152.  
  153.                str3=str3 scr
  154.                namenpw=""
  155.               End
  156.  
  157.              Else
  158.               namenpw="secret" pw "name" id
  159.  
  160. /* PPP to run serial link attach, to talk commands to modem */
  161.  
  162.             cstr='"slattach' str1 str2 str3 '" defaultroute idle 999999 mru' mru port speed
  163.  
  164. /* Start PPP in another process and wait for connection ready */
  165.  
  166.            '@start "PPP Connection" /i /c /b /min' cmdpath'\rxppp' stopped appl runthis '(' cmdpath namenpw 'connect' cstr
  167.  
  168.             Say "Serial Link Commands."
  169.  
  170. /* Validate that shared memory is ready */
  171.  
  172.             Do While(\PPPrunning())      /* process id yet? */
  173.             End
  174.  
  175.             NotStarted=1
  176.  
  177.             Do While NotStarted & PPPrunning()
  178.  
  179.                b = ""
  180.               '@pstat /m|rxqueue'
  181.                Do Queued()
  182.                     Pull a
  183.                     b = b a
  184.                End
  185.                If(0<>Lastpos("DDE4@@@@",b))
  186.                   Then NotStarted=0
  187.  
  188.                etime=Time("R")
  189.                etime=Time("R")
  190.  
  191.                Do While(etime<1)
  192.                    etime=Time("E")
  193.                End
  194.  
  195.             End
  196.  
  197.             If(\PPPrunning()) Then StopIt()
  198.  
  199.                Else Say "PPP started."
  200.  
  201. /* Clear queue */
  202.  
  203.             Do Queued();Pull .;End
  204.  
  205. /* When shared memory freed, connection is complete */
  206.  
  207.             found=1
  208.  
  209.             Do While(found)
  210.  
  211.                b = ""
  212.               '@pstat /m|rxqueue'
  213.                Do Queued()
  214.                     Pull a
  215.                     b = b a
  216.                End
  217.                If(0=Lastpos("DDE4@@@@",b)) Then found=0
  218.  
  219.                etime=Time("R")
  220.                etime=Time("R")
  221.  
  222.                Do While(etime<1)
  223.                     etime=Time("E")
  224.                End
  225.  
  226.             End
  227.  
  228.             Say "Share Complete!"
  229.  
  230. /* Turn on the green light and GO if still running */
  231.  
  232.             If(PPPrunning()) Then
  233.                Call SysCreateObject "WPProgram", appl,"<WP_DESKTOP>","OBJECTID=<PPPCNT_"Substr(appl,1,8)">;ICONFILE="cmdpath"\"amready,"U"
  234.  
  235.             Else Call StopIt
  236.  
  237. /* was application passed to start? */
  238.           StartAPP:
  239.  
  240.             If runthis<>"" Then Address CMD start runthis
  241.  
  242.            'Exit'           /*  Normal Exit command shell */
  243.  
  244.  
  245. /* ================= INTERNAL SUBROUTINES ====================== */
  246.  
  247. /* See if PPP running by sifting through PSTAT */
  248.  
  249.           PPPrunning:
  250.  
  251.               '@pstat /c|rxqueue'
  252.                found=0
  253.                Do Queued()
  254.                  Pull a "PPP.EXE" b
  255.                  If b<>"" Then found=1
  256.                End
  257.  
  258.                Return found
  259.  
  260. /* In a string, find a string and replace it, easiest is find, delete, insert */
  261.  
  262.           Replaceif:
  263.  
  264.             Parse Arg tstring,from,to
  265.  
  266.                idx=Pos(from,tstring)
  267.                If(idx<>0) Then
  268.                  Do
  269.                    tstring=Delstr(tstring,idx,Length(from))
  270.                    idx=idx-1
  271.                    tstring=Insert(to,tstring,idx)
  272.                  End
  273.                Return tstring
  274.  
  275. /* Abnormal condition, restore traffic light Red! */
  276.  
  277.           StopIt:
  278.  
  279.             Say "Error PPP not running for some reason."
  280.             Call SysCreateObject "WPProgram", appl,"<WP_DESKTOP>","OBJECTID=<PPPCNT_"Substr(appl,1,8)">;ICONFILE="cmdpath"\"stopstate,"U"
  281.             Exit 28
  282.  
  283.