home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rxdyndns.zip / rxdyndns.cmd < prev    next >
OS/2 REXX Batch file  |  1997-07-27  |  7KB  |  218 lines

  1. /*------------------------------------------------------------------
  2.  * rxdyndns.cmd
  3.  *------------------------------------------------------------------
  4.  * Dennis Peterson
  5.  * 7-27-97
  6.  *
  7.  * Archive includes b64rx.dll which encodes the userid:password string
  8.  * The b64rx.dll code was created by Teet K⌡nnussaar (teet@aetec.estnet.ee)
  9.  * 
  10.  * Requires rxsock.dll
  11.  * Requires registation with www.ml.org which is free for now
  12.  *
  13.  * This code is free to everyone.
  14.  *------------------------------------------------------------------*/
  15.  
  16. /*-------------------
  17. Basic Info from www.ml.org:
  18.  
  19. The host to connect to is: monolith2.ml.org.
  20. The protocol to use is HTTP or HTTPS.
  21. The port number is 80 (HTTP) or 443 (HTTPS).
  22. The path is /mis-bin/ms3/nic/dyndns
  23. Both PUT and GET methods can be used.
  24. The arguments are (these are examples, but they're reasonable defaults):
  25.  
  26. command=Update+Host
  27. do=mod
  28. domain=HOST
  29.  
  30. This is an example of a line that could be sent to the ML server to
  31. update a host artur.dyn.ml.org:
  32.  
  33. GET /mis-bin/ms3/nic/dyndns?command=Update+Host&domain=artur&act=act&wildcard=on&do=mod&agree=agree HTTP/1.0
  34.  
  35. That line should be followed by the authorization data on one line, and an
  36. empty line.
  37.  
  38. Authorization
  39. The authorization line mentioned above is:
  40. Authorization: Basic ENCODED_MID_AND_PASSWORD
  41. Eg if artur1 is the MID and password is the password, then it is
  42. formatted as "artur1:password" (w/o the qoutes) and encoded using
  43. base64 (Authorization: Basic YXJ0dXIxOnBhc3N3b3Jk).
  44.  
  45. When successful action is 'activate' returns:
  46. <!-- MS3V STATUS:OK HOSTNAME:dkp ACT:1 IP:206.63.32.92 MX: -->
  47.  
  48. When successful action is 'deactivate' returns:
  49. <!-- MS3V STATUS:OK HOSTNAME:dkp ACT:0 IP: MX: -->
  50. ---------------------*/
  51.  
  52. parse arg action domain userid password .
  53.  
  54. if (action = "?") then
  55.    Usage()
  56. if (action = "") then
  57.    Usage()
  58.  
  59. /*------------------------------------------------------------------
  60.  * initialize md5rx API package
  61.  *------------------------------------------------------------------*/
  62.  
  63. call rxfuncadd 'B64encode','md5rx','B64encode'
  64. call rxfuncadd 'B64decode','md5rx','B64decode'
  65.  
  66. /*------------------------------------------------------------------
  67.  * initialize socket package
  68.  *------------------------------------------------------------------*/
  69. if RxFuncQuery("SockLoadFuncs") then
  70.    do
  71.       rc = RxFuncAdd("SockLoadFuncs","RxSock","SockLoadFuncs")
  72.       rc = SockLoadFuncs()
  73. end
  74.  
  75. crlf = "0d0a"x
  76. activation = 'unsuccessful'
  77.  
  78. /*------------------------------------------------------------------
  79.  * Get IP from PPP log file in %etc%\ppp0.log
  80.  *------------------------------------------------------------------*/
  81. In_File = VALUE('etc',,OS2ENVIRONMENT) || '\ppp0.log'
  82. Do While lines(In_File) > 0
  83.    Line_In = Linein(In_File)
  84.    If Wordpos('local', Line_In) > 0 Then
  85.    IP = Word(Line_In, Words(Line_In))
  86. End
  87.  
  88. /*------------------------------------------------------------------
  89.  * Initialize http variables - Yes -- rexx can to HTML!
  90.  *------------------------------------------------------------------*/
  91. server = "monolith2.ml.org"
  92. security = "Authorization: Basic" B64Encode(userid || ":" || password) || crlf || crlf
  93.  
  94. URL = "GET /mis-bin/ms3/nic/dyndns?"
  95. URL = URL || "command=Update+Host"
  96. URL = URL || "&domain=" || domain
  97. URL = URL || "&act=" || action
  98. URL = URL || "&wildcard=on"
  99. URL = URL || "&do=mod"
  100. URL = URL || "&agree=agree HTTP/1.0" || crlf
  101.  
  102. /*------------------------------------------------------------------
  103.  * choose port number - http port is normally 80
  104.  *------------------------------------------------------------------*/
  105. port = 80
  106.  
  107. /*------------------------------------------------------------------
  108.  * get server name
  109.  *------------------------------------------------------------------*/
  110. rc = SockGetHostByName(server,"host.!")
  111. if (rc = 0) then
  112.    do
  113.       say "Error" h_errno "calling SockGetHostByName("server")"
  114.       exit
  115.    end
  116.  
  117. server = host.!addr;
  118.  
  119. /*---------------------------------------------------------------
  120.  * open socket
  121.  *---------------------------------------------------------------*/
  122. socket  = SockSocket("AF_INET","SOCK_STREAM",0)
  123. if (socket = -1) then
  124.    do
  125.       say "Error on SockSocket:" errno
  126.       exit
  127.    end
  128.  
  129. /*------------------------------------------------------------------
  130.  * catch breaks
  131.  *------------------------------------------------------------------*/
  132. signal on halt
  133.  
  134. /*---------------------------------------------------------------
  135.  * connect socket
  136.  *---------------------------------------------------------------*/
  137. server.!family = "AF_INET"
  138. server.!port   = port
  139. server.!addr   = server
  140.  
  141. rc = SockConnect(socket,"server.!")
  142. if (rc = -1) then
  143.    do
  144.       say "Error on SockConnect:" errno
  145.       exit
  146.    end
  147.  
  148. rc = SockSend(socket, URL)
  149. if (rc = -1) then
  150.    do
  151.       say "Error on SockSend URL:" errno
  152.       exit
  153.    end
  154.  
  155. rc = SockSend(socket, security)
  156. if (rc = -1) then
  157.    do
  158.       say "Error on SockSen security:" errno
  159.       exit
  160.    end
  161.    
  162. /*------------------------------------------------------------------
  163.  * receive the result from the server
  164.  *------------------------------------------------------------------*/
  165.  
  166. do until rc = 0
  167.    rc = SockRecv(socket,"newData",512)
  168.    returnData = returnData || newData
  169. end
  170.  
  171. /*------------------------------------------------------------------
  172.  * check results
  173.  *------------------------------------------------------------------*/
  174.  
  175. select
  176.    when translate(action) = 'ACT' then do
  177.       if wordpos("ACT:1",returnData) > 0 then
  178.          activation = 'successful'
  179.       say 'Activation was' activation
  180.    end
  181.  
  182.    when translate(action) = 'DEC' then do
  183.       if wordpos("ACT:0",returnData) > 0 then
  184.          activation = 'successful'
  185.       say 'Deactivation was' activation
  186.    end
  187.  
  188.    otherwise
  189.       nop
  190. end
  191.  
  192. /*------------------------------------------------------------------
  193.  * close socket (and catch signals)
  194.  *------------------------------------------------------------------*/
  195. halt:
  196.  
  197. rc = SockSoClose(socket)
  198. if (rc = -1) then
  199.    do
  200.    say "Error on SockSoClose:" errno
  201.    exit
  202.    end
  203.  
  204. exit
  205.  
  206. /*------------------------------------------------------------------
  207.  * some simple help
  208.  *------------------------------------------------------------------*/
  209. Usage: procedure
  210.    parse source . . me .
  211.  
  212.    say "usage:"
  213.    say "   " me "action domain userid password"
  214.    say "    is used to activate (act) or deactivate (dec) the dynamin DNS"
  215.    say "    domain becomes 'domain.dyn.ml.org'"
  216.    say
  217.    exit
  218.