home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mlup152.zip / mlup.cmd < prev    next >
OS/2 REXX Batch file  |  1998-08-13  |  9KB  |  261 lines

  1. /* mlup 1.52                                                      */
  2. /*                                                                */
  3. /* Script to upload your dynamic IP to the Monolith server,       */
  4. /* with the new MS3 updating scheme.                              */
  5. /*                                                                */
  6. /* Work by Cristiano Guadagnino                                   */
  7. /* (cristiano.guadagnino@usa.net)                                 */
  8. /*                                                                */
  9. /* (NOTE:                                             )           */
  10. /* (Code for base64 encoding taken from mlddc package,)           */
  11. /* (some other ideas taken from other PD ml scripts.  )           */
  12. /*                                                                */
  13. /* Remember to customize the script with your stuff. See below.   */
  14. /*                                                                */
  15.  
  16. /* Fill in the following stuff  */
  17.  
  18. USERNAME='name'         /* Your Monolith Username.                              */
  19. PW='password'           /* Your Monolith Password.                              */
  20. DOMAIN='host_here'      /* Your Host-Name.                                      */
  21. ALIAS='off'             /* Want multiple aliases? (on/off)                      */
  22. MAIL=''                 /* Mail Exchanger (optional)                            */
  23.  
  24. INJOYPATH=''
  25.                         /* If you have InJoy 1.1+, and you want mlup to signal  */
  26.                         /* injoy on termination, fill in the above line with    */
  27.                         /* the path to the injoy executable.                    */
  28.  
  29. NETSTR='interface 10'   /* Some national versions of OS/2 translate the message */
  30.                         /* reported by netstat. This makes it impossible for    */
  31.                         /* the program to correctly detect the interface for    */
  32.                         /* PPP/SLIP. If you have such a national version of     */
  33.                         /* OS/2, replace this string with the one reported by   */
  34.                         /* your netstat. EG: italian netstat reports            */
  35.                         /* 'interfaccia 10' instead of 'interface 10'. So the   */
  36.                         /* italian users should replace the above string with:  */
  37.                         /* NETSTR='interfaccia 10'                              */
  38.  
  39. DEBUGMODE=0             /* This is only useful if you're having problems with   */
  40.                         /* the update process. It will activate various reports */
  41.                         /* and will store the output of the session in the      */
  42.                         /* 'dynreturn' file even on succesfull connections.     */
  43.                         /* Note that reports are NOT auto-explaining. You must  */
  44.                         /* look at this proggie to understand what they mean.   */
  45.                         /* If you're not a rexx programmer, you'll probably do  */
  46.                         /* not need this.                                       */
  47.                         /* 0 = debugging turned off                             */
  48.                         /* 1 = debugging turned on                              */
  49.  
  50. /* Fill in the above stuff      */
  51.  
  52. /* -- DO NOT EDIT UNDER THIS LINE!! --------------------------------------- */
  53.  
  54. /* Constants used by the program */
  55. OKSTRING = ' STATUS:OK '    /* Positive response: database updated  */
  56. ACTIVATE = 'act'            /* Activate your host name in the DNS   */
  57. DEACTIVATE = 'dec'          /* Deactivate your host name in the DNS */
  58. VERSION = '1.52'            /* Program release */
  59.  
  60. say ''
  61. say '<mlup> script by Cristiano Guadagnino'
  62. say 'Email:  cristiano.guadagnino@usa.net'
  63. say ''
  64. say 'version: 'VERSION
  65. say ''
  66.  
  67. Parse UPPER ARG ActDec TheRest
  68.  
  69. if (TheRest \= '' | ActDec = '') then do
  70.     say
  71.     say " Correct syntax is:"
  72.     say "   mlup on|off"
  73.     say
  74.     say " 'mlup on' will refresh your IP and activate your host name in the DNS."
  75.     say " 'mlup off' will deactivate your host name in the DNS."
  76.     say
  77.     say " 'mlup off' is used before dropping connection with your ISP, if"
  78.     say " you don't want your domain name to point anywhere while you're"
  79.     say " not connected to the net."
  80.     say
  81.     exit
  82. end
  83.  
  84. if ActDec = 'ON' then
  85.     ACTION = ACTIVATE
  86. else
  87.     ACTION = DEACTIVATE
  88.  
  89. rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  90. if rc=0 then do
  91.     rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  92.     if rc=0 then do
  93.         say 'Error with rxSock.dll'
  94.         say 'check path and make sure file exists'
  95.         call finish2
  96.         exit
  97.     end
  98. end
  99.  
  100. rc = SockLoadFuncs(bypass_copyright)
  101.  
  102. /* writes the output of netstat -a  to the file netstat  */
  103. '@netstat.exe -a>netstat'
  104.  
  105. /* This section sorts through netstat and finds interface 10, which is the    */
  106. /* standard address for SLIP/PPP.  If your software uses a different address, */
  107. /* please modify as needed.  Thanks to NewOrder@flash.net for the idea        */
  108.  
  109. ok = 0
  110.  
  111. do until ok = 1
  112.     if LINES(netstat) = 0 then
  113.         call nonetwork
  114.     else
  115.         parse value LINEIN(netstat) with ipaddr
  116.     if subword(ipaddr,3,2) = NETSTR then ok = 1
  117. end
  118.  
  119. ok = 0
  120.  
  121. /* Grabs IP address from the line containing "interface 10" */
  122. parse value DELWORD(ipaddr,1,1) with ipaddr
  123. parse value DELWORD(ipaddr,2) with ipaddr
  124. if ipaddr='Not' then call nonetwork
  125. if ipaddr=''  then call nonetwork
  126.  
  127. iplength = length(ipaddr)
  128. ipaddr = left(ipaddr,(iplength - 1))
  129. rc = stream('netstat','c','close')
  130. '@del netstat >NUL'
  131.  
  132. /* Gets dotted IP address  of members.ml.org  */
  133. server.!family = 'AF_INET'
  134. server.!port = '80'
  135. server.!addr = 'members.ml.org'
  136. server = 'members.ml.org'
  137. rc=sockgethostbyname(server,serv.!)
  138. dotted = serv.!addr
  139.  
  140. /* Gets encoded username and password */
  141. ToEncode = USERNAME' 'PW
  142. ToExec = "'"'@base64 'ToEncode' >pwdfile'"'"
  143. interpret ToExec
  144.  
  145. rc = LINEIN('pwdfile', 1, 0)
  146. if LINES('pwdfile') = 0 then do
  147.     say 'Error trying to encode username and password. Shutting down.'
  148.     call finish
  149.     exit
  150. end /* do */
  151. Encoded = LINEIN('pwdfile')
  152. rc = LINEOUT('pwdfile')
  153. '@del pwdfile >NUL'
  154. if debugmode then do
  155.     say
  156.     say Encoded
  157.     say
  158.     say RIGHT(Encoded, 3)
  159.     say "Lunghezza: "LENGTH(Encoded)
  160. end
  161.  
  162. sock = SockSocket('AF_INET','SOCK_STREAM','IPPROTO_TCP')
  163.  
  164. crlf = D2C(13)''D2C(10)
  165. Parse Upper Var ALIAS ALIAS
  166. if ALIAS = 'ON' then
  167.     message = 'GET /mis-bin/ms3/nic/dyndns?command=Update+Host&domain='DOMAIN'&do=mod&act='ACTION'&wildcard=on&ipaddr='ipaddr'&mail='MAIL'&agree=agree HTTP/1.0'
  168. else
  169.     message = 'GET /mis-bin/ms3/nic/dyndns?command=Update+Host&domain='DOMAIN'&do=mod&act='ACTION'&ipaddr='ipaddr'&mail='MAIL'&agree=agree HTTP/1.0'
  170. message = message''crlf
  171. message = message'Pragma: no-cache'crlf
  172. message = message'User-Agent: mlup/'VERSION''crlf
  173. message = message'Authorization: Basic 'Encoded''crlf''crlf
  174. if debugmode then do
  175.     say
  176.     say message
  177.     say
  178. end
  179.  
  180. addr.!family='AF_INET'
  181. addr.!port = '80'
  182. addr.!addr = dotted
  183.  
  184. /* Connects to server  */
  185.  
  186. rc = SockConnect(sock,addr.!)
  187.  if rc = -1 then
  188.     do
  189.        say 'Error connecting!'
  190.        call nonetwork
  191.        exit
  192.   end
  193.  
  194. /* Sends the IP info to the server, thereby updating the database  */
  195. ret.0 = 15
  196. return = ''
  197. rc = SockSend(sock, message)
  198. /* The following two loops are split to enhance the speed of the first. */
  199. do i=1 to ret.0
  200.     rc = SockRecv(sock, ret.i, 10240)
  201. end
  202. do i=1 to ret.0
  203.     return = return''ret.i
  204. end
  205. rc = SockClose(sock)
  206. rc = SockShutDown(sock, 2)
  207.  
  208. rc = WORDPOS(OKSTRING, return)
  209. if rc = 0 then do
  210.     say 'Error: ML.ORG did not return the update confirmation.'
  211.     say 'The database was probably NOT updated.'
  212.     say 'See the file <dynreturn> to look at the response given.'
  213.     rc = lineout( 'dynreturn', return )
  214.     rc = lineout( 'dynreturn', '-------End of return from ML.ORG-------' )
  215.     rc = lineout( 'dynreturn', ' ' )
  216.     rc = lineout( 'dynreturn' )
  217. end /* if_do */
  218. else do
  219.     say 'Database correctly updated. Your IP was correctly refreshed.'
  220.     say 'Now you have your hostname configured.'
  221.     if debugmode then do
  222.         rc = lineout( 'dynreturn', return )
  223.         rc = lineout( 'dynreturn', '-------End of (succesfull) return from ML.ORG-------' )
  224.         rc = lineout( 'dynreturn', ' ' )
  225.         rc = lineout( 'dynreturn' )
  226.     end /* if_do */
  227. end /* else_do */
  228.  
  229. call finish
  230. exit
  231.  
  232. nonetwork:
  233. say 'No IP address found or problem with server'
  234. call BEEP 392,500
  235. say 'Check your network!'
  236. say 'Make sure you are connected to the internet!'
  237. call finish
  238. exit
  239.  
  240. finish:
  241. rc = SockDropFuncs()
  242.  
  243. finish2:
  244. if (INJOYPATH \= '' & ACTION = DEACTIVATE) then do
  245.     curdir = directory()
  246.     injoydir = directory(INJOYPATH)
  247.     PARSE UPPER VAR injoydir injoydir
  248.     PARSE UPPER VAR INJOYPATH INJOYPATH
  249.     if injoydir = INJOYPATH then do
  250.         '@setjoy /C > NUL'
  251.         rc = directory(curdir)
  252.     end
  253.     else do
  254.         say
  255.         say 'Cannot find InJoy directory. Be sure you have typed it correctly.'
  256.         say 'Shutting down without signaling InJoy.'
  257.     end
  258. end
  259. exit
  260.  
  261.