Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '###########################################
- '## DynDNS.org Auto-Login for Free Users
- '##
- '## Author: atomicrabbit (atombomb2k@hotmail.com)
- '## Date: 2013.05.30
- '##
- '## Usage:
- '## Run dyndns_autologin.vbs from the command line:
- '## dyndns_autologin.vbs username password
- '## OR from a scheduled task by adding an action
- '## pointing to:
- '## C:\Windows\System32\CScript.exe
- '## and with the following arguments:
- '## //Nologo //B C:\path\to\dyndns_autologin.vbs username password
- '###########################################
- title = "DynDNS.org Auto-Login"
- returnVal = 1
- 'Edit the following variables appropriately
- '------- START EDITING HERE -------
- 'URLs
- basePage = "https://account.dyn.com/"
- loginPage = basePage & "entrance/"
- loginSvcPage = loginPage & "?return=/services/"
- logoutPage = loginPage & "?__logout=1"
- svcPage = basePage & "services/"
- 'Login form variables
- ' These refer to various objects in the login form.
- ' Leave these variables alone unless you know what you're doing
- loginFormRe = "^login(\d*)$" 'Allows to find the randomly generated number on the login page
- 'The # will be replaced with the randomly generated number
- loginUserFieldId = "login#_username"
- loginPassFieldId = "login#_password"
- loginSubmitId = "login#_submit"
- loginErrorId = "error_login#_password"
- loggedInId = "myServicesButton"
- 'IE Window Visibility
- ' True - IE window will be visible while processing the code
- ' False - IE window will be hidden and run the code in the background
- windowVisible = False
- 'Browser Timeout
- ' Set max timeout for browser responsiveness (in seconds)
- ' Default: 7
- timeout = 7 'seconds
- '------- STOP EDITING HERE ... DO NOT TOUCH ANYTHING BELOW -------
- ' open log file
- Set objLogFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(left(WScript.ScriptFullName, Len(WScript.ScriptFullName) - 3) & "log",8,true)
- Sub writeLog(user, msg, errorCode)
- dim log
- log = Now & vbTab
- if Trim(user) <> "" then log = log & "Username: " & user & ", "
- if (errorCode = 0) then
- log = log & "Message: "
- else
- log = log & "Error (" & errorCode & "): "
- end if
- log = log & msg
- objLogFile.WriteLine(log)
- End Sub
- sub missingArgs
- writeLog username, "Username and/or password arguments missing", 10022
- Wscript.quit(10022) 'An invalid argument was supplied.
- end sub
- 'Login Info - should be passed in via the command line as arguments
- if WScript.Arguments.count < 2 then
- missingArgs
- end if
- username = WScript.Arguments(0) 'Your username
- password = WScript.Arguments(1) 'Your passowrd
- timeout = timeout * 20 'because the iterations are 50ms
- tCount = 0
- Set objLoginForm = Nothing
- ' Check supplied arguments
- if Trim(username) = "" OR Trim(password) = "" Then
- missingArgs
- end if
- 'Create IE object
- Set objIE = CreateObject("InternetExplorer.Application")
- set WshShell = WScript.CreateObject("WScript.Shell")
- Sub timeoutReached
- 'Close IE
- objIE.Quit
- returnVal = 1460 'This operation returned because the timeout period expired.
- writeLog username, "Browser timeout", returnVal
- Wscript.quit(returnVal)
- End Sub
- 'Find randomly generated number in login form
- Function getRandomLoginNum
- Set objLoginForm = objIE.Document.Forms(0) 'the login form is usually the first form
- Set re = new RegExp
- re.Pattern = loginFormRe
- re.IgnoreCase = true
- Set reMatches = re.Execute(objLoginForm.id)
- if reMatches(0) is nothing then
- getRandomLoginNum = null
- else
- getRandomLoginNum = reMatches(0).SubMatches(0)
- end if
- End function
- 'Go to Login page
- objIE.Navigate loginSvcPage
- objIE.Visible = windowVisible
- 'Wait for page to load or timeout
- tCount = 0
- While objIE.Busy AND tCount < timeout
- tCount = tCount + 1
- WScript.Sleep 50
- Wend
- if tCount >= timeout Then
- timeoutReached
- end if
- tCount = 0
- While objIE.ReadyState <> 4 AND tCount < timeout 'complete
- tCount = tCount + 1
- WScript.Sleep 50
- Wend
- if tCount >= timeout Then
- timeoutReached
- end if
- loginFormNum = getRandomLoginNum
- if loginFormNum = null then
- 'Close IE
- objIE.Quit
- else
- 'Check if not logged in
- if not objLoginForm is nothing then
- ' Login if you're not already
- objIE.Document.All.Item(Replace(loginUserFieldId,"#",loginFormNum)).Value = username
- objIE.Document.All.Item(Replace(loginPassFieldId,"#",loginFormNum)).Value = password
- objIE.Document.All.Item(Replace(loginSubmitId,"#",loginFormNum)).click
- 'Wait for page to load
- tCount = 0
- While objIE.Busy AND tCount < timeout
- tCount = tCount + 1
- WScript.Sleep 50
- Wend
- end if
- 'Set objLoginCheck =
- if tCount >= timeout AND NOT isObject(objIE.document.getElementById(loggedInId)) Then
- timeoutReached
- Elseif objIE.LocationURL = svcPage AND isObject(objIE.document.getElementById(loggedInId)) Then
- 'Logout
- objIE.Navigate logoutPage
- 'Close IE
- objIE.Quit
- returnVal = 0
- writeLog username, "Logged in successfully!", returnVal
- Else
- Dim errorText
- errorText = "Could be caused by an invalid username or password"
- returnVal = 13816 'Unknown error occurred.
- ' if the login failed, it would have reloaded the page and the random number would be different
- loginFormNum = getRandomLoginNum
- if isObject(objIE.Document.getElementById(Replace(loginErrorId,"#",loginFormNum))) then
- errorText = objIE.Document.getElementById(Replace(loginErrorId,"#",loginFormNum)).innerText
- returnVal = 1326 'Logon failure: unknown user name or bad password.
- end if
- 'Close IE
- objIE.Quit
- writeLog username, "Login failed. " & errorText, returnVal
- End if
- end if
- objLogFile.Close
- 'Clear variables
- Set objLogFile = Nothing
- Set objIE = Nothing
- Set title = Nothing
- Set basePage = Nothing
- Set loginPage = Nothing
- Set loginSvcPage = Nothing
- Set logoutPage = Nothing
- Set svcPage = Nothing
- Set loginFormRe = Nothing
- Set loginUserFieldId = Nothing
- Set loginPassFieldId = Nothing
- Set loginSubmitId = Nothing
- Set loginErrorId = Nothing
- Set loggedInId = Nothing
- Set objLoginCheck = Nothing
- Set username = Nothing
- Set password = Nothing
- Set windowVisible = Nothing
- Set timeout = Nothing
- Set tCount = Nothing
- Set re = Nothing
- Set reMatches = Nothing
- Set objLoginForm = Nothing
- Set loginFormNum = Nothing
- Wscript.quit(returnVal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement