SHARE
TWEET

DynDNS.org Auto-Login for Free Users

a guest Jun 16th, 2013 1,029 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '###########################################
  2. '## DynDNS.org Auto-Login for Free Users
  3. '##
  4. '## Author: atomicrabbit (atombomb2k@hotmail.com)
  5. '## Date: 2013.05.30
  6. '##
  7. '## Usage:
  8. '##  Run dyndns_autologin.vbs from the command line:
  9. '##    dyndns_autologin.vbs username password
  10. '##  OR from a scheduled task by adding an action
  11. '##  pointing to:
  12. '##    C:\Windows\System32\CScript.exe
  13. '##  and with the following arguments:
  14. '##    //Nologo //B C:\path\to\dyndns_autologin.vbs username password
  15. '###########################################
  16.  
  17. title = "DynDNS.org Auto-Login"
  18. returnVal = 1
  19.  
  20. 'Edit the following variables appropriately
  21. '------- START EDITING HERE -------
  22. 'URLs
  23. basePage                = "https://account.dyn.com/"
  24. loginPage               = basePage & "entrance/"
  25. loginSvcPage    = loginPage & "?return=/services/"
  26. logoutPage              = loginPage & "?__logout=1"
  27. svcPage                 = basePage & "services/"
  28.  
  29. 'Login form variables
  30. ' These refer to various objects in the login form.
  31. ' Leave these variables alone unless you know what you're doing
  32. loginFormRe                             = "^login(\d*)$"                        'Allows to find the randomly generated number on the login page
  33. 'The # will be replaced with the randomly generated number
  34. loginUserFieldId                = "login#_username"
  35. loginPassFieldId                = "login#_password"
  36. loginSubmitId                   = "login#_submit"
  37. loginErrorId                    = "error_login#_password"
  38. loggedInId                              = "myServicesButton"   
  39.  
  40. 'IE Window Visibility
  41. ' True - IE window will be visible while processing the code
  42. ' False - IE window will be hidden and run the code in the background
  43. windowVisible           = False
  44.  
  45. 'Browser Timeout
  46. ' Set max timeout for browser responsiveness (in seconds)
  47. ' Default: 7
  48. timeout                 = 7 'seconds
  49.  
  50. '------- STOP EDITING HERE ... DO NOT TOUCH ANYTHING BELOW -------
  51.  
  52. ' open log file
  53. Set objLogFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - 3) & "log",8,true)
  54.  
  55. Sub writeLog(user, msg, errorCode)
  56.         dim log
  57.         log     = Now & vbTab
  58.         if Trim(user) <> "" then log = log & "Username: " & user & ", "
  59.         if (errorCode = 0) then
  60.                 log = log & "Message: "
  61.         else
  62.                 log = log & "Error (" & errorCode & "): "
  63.         end if
  64.         log = log & msg
  65.         objLogFile.WriteLine(log)
  66. End Sub
  67.  
  68. sub missingArgs
  69.         writeLog username, "Username and/or password arguments missing", 10022
  70.         Wscript.quit(10022) 'An invalid argument was supplied.
  71. end sub
  72.  
  73. 'Login Info - should be passed in via the command line as arguments
  74. if WScript.Arguments.count < 2 then
  75.         missingArgs
  76. end if
  77. username                        = WScript.Arguments(0)  'Your username
  78. password                        = WScript.Arguments(1)  'Your passowrd
  79.  
  80. timeout                         = timeout * 20 'because the iterations are 50ms
  81. tCount                          = 0
  82. Set objLoginForm                = Nothing
  83.  
  84. ' Check supplied arguments
  85. if Trim(username) = "" OR Trim(password) = "" Then
  86.         missingArgs
  87. end if
  88.  
  89. 'Create IE object
  90. Set objIE = CreateObject("InternetExplorer.Application")
  91. set WshShell = WScript.CreateObject("WScript.Shell")
  92.  
  93. Sub timeoutReached
  94.         'Close IE
  95.         objIE.Quit
  96.        
  97.         returnVal = 1460 'This operation returned because the timeout period expired.
  98.         writeLog username, "Browser timeout", returnVal
  99.         Wscript.quit(returnVal)
  100. End Sub
  101.  
  102. 'Find randomly generated number in login form
  103. Function getRandomLoginNum
  104.         Set objLoginForm = objIE.Document.Forms(0) 'the login form is usually the first form
  105.         Set re = new RegExp
  106.         re.Pattern = loginFormRe
  107.         re.IgnoreCase = true
  108.         Set reMatches = re.Execute(objLoginForm.id)
  109.         if reMatches(0) is nothing then
  110.                 getRandomLoginNum = null
  111.         else
  112.                 getRandomLoginNum = reMatches(0).SubMatches(0)
  113.         end if
  114. End function
  115.  
  116. 'Go to Login page
  117. objIE.Navigate loginSvcPage
  118. objIE.Visible = windowVisible
  119.  
  120. 'Wait for page to load or timeout
  121. tCount = 0
  122. While objIE.Busy AND tCount < timeout
  123.     tCount = tCount + 1
  124.         WScript.Sleep 50
  125. Wend
  126.  
  127. if tCount >= timeout Then
  128.         timeoutReached
  129. end if
  130.  
  131. tCount = 0
  132. While objIE.ReadyState <> 4 AND tCount < timeout 'complete
  133.         tCount = tCount + 1
  134.         WScript.Sleep 50
  135. Wend
  136.  
  137. if tCount >= timeout Then
  138.         timeoutReached
  139. end if
  140.  
  141. loginFormNum = getRandomLoginNum
  142.  
  143. if loginFormNum = null then
  144.         'Close IE
  145.         objIE.Quit
  146. else
  147.         'Check if not logged in
  148.         if not objLoginForm is nothing then
  149.                 ' Login if you're not already
  150.                 objIE.Document.All.Item(Replace(loginUserFieldId,"#",loginFormNum)).Value = username
  151.                 objIE.Document.All.Item(Replace(loginPassFieldId,"#",loginFormNum)).Value = password
  152.                 objIE.Document.All.Item(Replace(loginSubmitId,"#",loginFormNum)).click
  153.                
  154.                 'Wait for page to load
  155.                 tCount = 0
  156.                 While objIE.Busy AND tCount < timeout
  157.                         tCount = tCount + 1
  158.                         WScript.Sleep 50
  159.                 Wend
  160.         end if
  161.        
  162.         'Set objLoginCheck =
  163.         if tCount >= timeout AND NOT isObject(objIE.document.getElementById(loggedInId)) Then
  164.                 timeoutReached
  165.         Elseif objIE.LocationURL = svcPage AND isObject(objIE.document.getElementById(loggedInId)) Then
  166.                 'Logout
  167.                 objIE.Navigate logoutPage
  168.  
  169.                 'Close IE
  170.                 objIE.Quit
  171.  
  172.                 returnVal = 0
  173.                 writeLog username, "Logged in successfully!", returnVal
  174.  
  175.         Else
  176.                 Dim errorText
  177.                 errorText = "Could be caused by an invalid username or password"
  178.                 returnVal = 13816 'Unknown error occurred.
  179.                 ' if the login failed, it would have reloaded the page and the random number would be different
  180.                 loginFormNum = getRandomLoginNum
  181.                
  182.                 if isObject(objIE.Document.getElementById(Replace(loginErrorId,"#",loginFormNum))) then
  183.                         errorText = objIE.Document.getElementById(Replace(loginErrorId,"#",loginFormNum)).innerText
  184.                         returnVal = 1326 'Logon failure: unknown user name or bad password.
  185.                 end if
  186.                
  187.                 'Close IE
  188.                 objIE.Quit
  189.                
  190.                 writeLog username, "Login failed. " & errorText, returnVal
  191.         End if
  192.  
  193. end if
  194.  
  195. objLogFile.Close
  196.  
  197. 'Clear variables
  198. Set objLogFile                  = Nothing
  199. Set objIE                               = Nothing
  200. Set title                               = Nothing
  201. Set basePage                    = Nothing
  202. Set loginPage                   = Nothing
  203. Set loginSvcPage                = Nothing
  204. Set logoutPage                  = Nothing
  205. Set svcPage                     = Nothing
  206. Set loginFormRe                 = Nothing
  207. Set loginUserFieldId    = Nothing
  208. Set loginPassFieldId    = Nothing
  209. Set loginSubmitId               = Nothing
  210. Set loginErrorId                = Nothing
  211. Set loggedInId                  = Nothing
  212. Set objLoginCheck               = Nothing
  213. Set username                    = Nothing
  214. Set password                    = Nothing
  215. Set windowVisible               = Nothing
  216. Set timeout                             = Nothing
  217. Set tCount                              = Nothing
  218. Set re                                  = Nothing
  219. Set reMatches                   = Nothing
  220. Set objLoginForm                = Nothing
  221. Set loginFormNum                = Nothing
  222.  
  223. Wscript.quit(returnVal)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top