home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pcnt4v11.zip / PPPCNT.CMD < prev    next >
OS/2 REXX Batch file  |  1999-03-13  |  9KB  |  252 lines

  1. /*
  2.  
  3.    Started on April 3rd 1998, Walt Shekrota  Use pinstall.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.             Call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
  55.             Call sysloadfuncs
  56.  
  57. /* get parms that were stored in TCPOS2.INI by Other Provider Dialer */
  58.  
  59.             inif=tcpchk(appl)
  60.             if(inif="") Then Exit 28
  61.  
  62.             running=SysIni(inif, appl, 'CAUTION')  /* caution state icon    */
  63.  
  64. /* maintain current/last connection names for newsreader */
  65.  
  66.             ls=SysIni(inif, 'CONNECTION', 'CURRENT_CONNECTION') /* get last connect id */
  67.  
  68.             If("ERROR:"=SysIni(inif,"CONNECTION","LAST_CONNECTION",ls)) Then
  69.                Say "Error INI write LAST_CONNECTION"
  70.             If("ERROR:"=SysIni(inif,"CONNECTION","CURRENT_CONNECTION",appl)) Then
  71.                Say "Error INI write CURRENT_CONNECTION"
  72.  
  73.             ip=SysIni(inif, appl, 'DNS') /* get nameserver i/p addr */
  74.             dn=SysIni(inif, appl, 'DOMAIN_NAME') /* get domain */
  75. /*
  76.  * resolv files are really a manual configuration issue but dialer
  77.  * will modify it on a connection basis. (ISP) Why not, slippm does it.
  78.  * Yes rename will fail in most cases if existing
  79.  * as intended so as to save ONLY the original!
  80.  */
  81.  
  82.            '@rename resolv resolv.org'  /* save bu if org doesn't exist */
  83.            '@erase resolv'              /* make room for temp create */
  84.  
  85.             xx=Lineout("resolv","domain" dn,1)
  86.             xx=Lineout("resolv","nameserver" ip)
  87.             xx=Lineout("resolv")
  88.  
  89. /* Turn on the yellow light that says we be a going */
  90.  
  91.             Call SysCreateObject "WPProgram", appl,"<WP_DESKTOP>","OBJECTID=<"Substr(appl,1,8,'_')">;EXENAME="cmdpath"\pppcnt.cmd;PARAMETERS=" appl ";ICONFILE="cmdpath"\"running,"U"
  92.  
  93.             stopped=SysIni(inif, appl, 'STOP')     /* stop state icon       */
  94.  
  95.             amready=SysIni(inif, appl, 'GO')       /* running state icon    */
  96.  
  97.             id=SysIni(inif, appl, 'LOGIN_ID')      /* Query the login       */
  98.             id=Delstr(id, Length(id))
  99.  
  100.             pw=SysIni(inif, appl, 'PWD')           /* Query the password    */
  101.             pw=Delstr(pw, Length(pw))
  102.  
  103.             phone=SysIni(inif, appl, 'PHONE_NUMBER') /* Query the phonenumber */
  104.             phone=Delstr(phone, Length(phone))
  105.  
  106.             port=SysIni(inif, appl, 'COMPORT')     /* COM port used?        */
  107.             port=Delstr(port, Length(port))
  108.  
  109.             speed=SysIni(inif, appl, 'BAUD')       /* Linespeed?            */
  110.             speed=Delstr(speed, Length(speed))
  111.  
  112.             prefix=SysIni(inif, appl, 'PREFIX')    /* prefix dial tone/pulse*/
  113.             prefix=Delstr(prefix, Length(prefix))
  114.  
  115.             init1=SysIni(inif, appl, 'INIT')       /* init string 1         */
  116.             init1=Delstr(init1, Length(init1))
  117.  
  118.             init2=SysIni(inif, appl, 'INIT2')      /* init string 2         */
  119.             init2=Delstr(init2, Length(init2))
  120.  
  121.             mru=SysIni(inif, appl, 'MTU_SIZE')     /* MRU                   */
  122.             mru=Delstr(mru, Length(mru))
  123.  
  124.             scr=SysIni(inif, appl, 'SCRIPT')       /* Connection script     */
  125.             scr=Delstr(scr, Length(scr))
  126.  
  127.             dis=SysIni(inif, appl, 'DISABLE')      /* disable cw if 'TRUE'  */
  128.             dis=Delstr(dis, Length(dis))
  129.  
  130.             seq=SysIni(inif, appl, 'DISABLE_SEQ')  /* usually *70           */
  131.             seq=Delstr(seq, Length(seq))
  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 mru' mru port speed
  163.  
  164. /* Start PPP in another process and wait for connection ready */
  165.  
  166. say        '@start "PPP Connection" /i /c /b /min' cmdpath'\rxppp' stopped appl cmdpath namenpw 'connect' cstr
  167.            '@start "PPP Connection" /i /c /b /min' cmdpath'\rxppp' stopped appl cmdpath namenpw 'connect' cstr
  168.  
  169.             Say "Serial Link Commands."
  170.  
  171. /* Validate that shared memory is ready */
  172.  
  173.             Do While(\PPPrunning())      /* process id yet? */
  174.             End
  175.  
  176.             NotStarted=1
  177.  
  178.             Do While NotStarted & PPPrunning()
  179.  
  180.               '@pstat /m|rxqueue'
  181.                Do Queued()
  182.                     Pull a "PPP0PID" b
  183.                     If b<>"" Then NotStarted=0
  184.                End
  185.  
  186.                etime=Time("R")
  187.                etime=Time("R")
  188.  
  189.                Do While(etime<1)
  190.                    etime=Time("E")
  191.                End
  192.  
  193.             End
  194.  
  195.             If(\PPPrunning()) Then StopIt()
  196.  
  197.                Else Say "PPP started."
  198.  
  199. /* Turn on the green light and GO if still running */
  200.  
  201.             If(PPPrunning()) Then
  202.                Call SysCreateObject "WPProgram", appl,"<WP_DESKTOP>","OBJECTID=<"Substr(appl,1,8,'_')">;EXENAME="cmdpath"\pppcnt.cmd;PARAMETERS=" appl ";ICONFILE="cmdpath"\"amready,"U"
  203.  
  204.             Else StopIt()
  205.  
  206. /* was application passed to start? */
  207.           StartAPP:
  208.  
  209.             If runthis<>"" Then Address CMD 'start' runthis
  210.  
  211.            'Exit'           /*  Normal Exit command shell */
  212.  
  213.  
  214. /* ================= INTERNAL SUBROUTINES ====================== */
  215.  
  216. /* See if PPP running by sifting through PSTAT */
  217.  
  218.           PPPrunning:
  219.  
  220.               '@pstat /c|rxqueue'
  221.                found=0
  222.                Do Queued()
  223.                  Pull a "PPP.EXE" b
  224.                  If b<>"" Then found=1
  225.                End
  226.  
  227.                Return found
  228.  
  229. /* In a string, find a string and replace it, easiest is find, delete, insert */
  230.  
  231.           Replaceif:
  232.  
  233.             Parse Arg tstring,from,to
  234.  
  235.                idx=Pos(from,tstring)
  236.                If(idx<>0) Then
  237.                  Do
  238.                    tstring=Delstr(tstring,idx,Length(from))
  239.                    idx=idx-1
  240.                    tstring=Insert(to,tstring,idx)
  241.                  End
  242.                Return tstring
  243.  
  244. /* Abnormal condition, restore traffic light Red! */
  245.  
  246.           StopIt:
  247.  
  248.             Say "Error PPP not running for some reason."
  249.             Call SysCreateObject "WPProgram", appl,"<WP_DESKTOP>","OBJECTID=<"Substr(appl,1,8,'_')">;EXENAME="cmdpath"\pppcnt.cmd;PARAMETERS=" appl ";ICONFILE="cmdpath"\"stopstate,"U"
  250.             Exit 28
  251.  
  252.