old vb script to restore dns on windows server - Do not use on new windows servers.
restoredns.vbs
'-------------------------------------------------------------
' Global DNS Rebuild Script
' ~~~~~~~~~~~~~~~~~~~~~~~~~
' Rebuilds your entire DNS structure for all domains in Helm.
' Usefull for when moving servers, changing IPs, or for fixing
' messed up DNS records.
'
' It would be best to delete your DNS zones on your DNS server
' before running, to ensure new DNS zones are brand new!
'
' This script works with multi-server setups, run it on the
' control server!
'
' If you are using the script to change servers, or update IPs
' update all your system settings in the Helm Control Panel,
' then run this script.'
' This also rebuilds global records that ADMIN and RESELLERS
' have added. It gets the entrys the domain's reseller has
' added, then gets the entrys the ADMIN has added.
'
' UPDATED 10/11/2004: Now works with TXT records and dynamic
' [DomainName] variables.
' ------------------------------------------------------------
' © Copyright 2004 Warren Ashcroft (HelmPlus)
' All Rights Reserved
' This script must not be distributed without permission
' ------------------------------------------------------------
' Usage: Save this script as a VBS file and run like this:
' cscript.exe "c:\path\to\file.vbs"
' ------------------------------------------------------------
' For support email support@helmPlus
' Results of this are not my responsibility
'-------------------------------------------------------------
'-------------------------------------------------------------
' Configuration variables
'-------------------------------------------------------------
' Your ADMIN password for Helm
Dim AdminPass
AdminPass = "RR35RUJR"
'-------------------------------------------------------------
' DO NOT edit below here
'-------------------------------------------------------------
Dim oDomain, oDNS, oFTP, oEmail, oWebsite, oDomainAlias, oGlobalDNSRecord, oService, oServiceSet
Dim rsDomain, rsDomainAlias, rsGlobalDNS, rsGlobalDNSAdmin, rsDNS, rsService, rsServiceSet
Dim iCount, DomainID, DomainName, ResellerAccountNumber, ActionResult
Dim DNSRecordID, DomainAliasID, AliasName
Const DNS_A = 3 ' DNS_A
Const DNS_MX = 4 ' DNS_MX
Const DNS_CNAME = 5 ' DNS_CNAME
Const DNS_TXT = 6 ' DNS_TXT
Set oDomain = CreateObject("HELM.CDomain")
Set oDNS = CreateObject("HELM.CDNS")
Set oFTP = CreateObject("HELM.CFTP")
Set oEmail = CreateObject("HELM.CEmail")
Set oWebsite = CreateObject("HELM.CWebsite")
Set oService = CreateObject("HELM.CService")
Set oServiceSet = CreateObject("HELM.CServiceSet")
Set oDomainAlias = CreateObject("HELM.CDomainAlias")
Set oGlobalDNSRecord = CreateObject("HELM.CGlobalDNSRecord")
On Error Resume Next
WScript.Echo "Global DNS Rebuild Script"
WScript.Echo "© Copyright 2004 Warren Ashcroft (HelmPlus)"
WScript.Echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
WScript.Echo ""
Set rsDomain = oDomain.SearchEx()
If Not rsDomain.EOF Then rsDomain.MoveFirst
Do While Not rsDomain.EOF
' Set some standard data variables
iCount = iCount + 1
DomainID = rsDomain("DomainID")
DomainName = rsDomain("DomainName")
ResellerAccountNumber = rsDomain("ResellerAccountNumber")
' Setup the various recordsets
Set rsGlobalDNS = oGlobalDNSRecord.SearchEx(, ResellerAccountNumber)
Set rsGlobalDNSAdmin = oGlobalDNSRecord.SearchEx(, "ADMIN")
Set rsDomainAlias = oDomainAlias.SearchEx(, DomainID)
Set rsDNS = oDNS.SearchEx(, DomainID)
Set rsServiceSet = oServiceSet.SearchEx(, , DomainID, , "2")
Set rsService = oService.SearchEx(, rsServiceSet("ServiceSetId"))
WScript.Echo "[!] Processing Domain: " & UCase(DomainName)
WScript.Echo " [-] Removing... Removing all DNS A records!"
ActionResult = oDNS.RemoveARecordEx(DomainID)
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [-] Removing... Removing all DNS MX records!"
ActionResult = oDNS.RemoveMXRecordEx(DomainID)
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [-] Removing... Removing all DNS CNAME records!"
ActionResult = oDNS.RemoveCNAMERecordEx(DomainID)
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [-] Removing... Removing all DNS ID records from Helm!"
If Not rsDNS.EOF Then rsDNS.MoveFirst
Do While Not rsDNS.EOF
DNSRecordID = rsDNS("DNSRecordID")
If DNSRecordID <> "" Then
WScript.Echo " [-] Removing... DNS ID: " & DNSRecordID & "!"
ActionResult = oDNS.RemoveRecord("ADMIN", AdminPass, DNSRecordID)
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
End If
rsDNS.MoveNext
Loop
WScript.Echo " [-] Removing... Removing the domain ZONE completely!"
ActionResult = oDNS.RemoveDomainEx(DomainID)
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [+] Adding... Readding the domain zone!"
ActionResult = oDNS.CreateDomainEx(DomainID)
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [>] Adding... Readding standard DNS records!"
WScript.Echo " [+] Adding... DNS A Record: @!"
ActionResult = oDNS.CreateARecordEx(DomainID, "@", oWebsite.GetWebSiteIPEx(DomainID))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [+] Adding... DNS A Record: *!"
ActionResult = oDNS.CreateARecordEx(DomainID, "*", oWebsite.GetWebSiteIPEx(DomainID))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [+] Adding... DNS A Record: WWW!"
ActionResult = oDNS.CreateARecordEx(DomainID, "www", oWebsite.GetWebSiteIPEx(DomainID))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [+] Adding... DNS A Record: FTP!"
ActionResult = oDNS.CreateARecordEx(DomainID, "ftp", oFTP.GetFTPIPEx(DomainID))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [+] Adding... DNS A Record: MAIL!"
ActionResult = oDNS.CreateARecordEx(DomainID, "mail", oEmail.GetMailIPEx(DomainID))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [+] Adding... DNS MX Record: MAIL! [" & rsService("ServicePriority") & "]"
ActionResult = oDNS.CreateMXRecordEx(DomainID, "mail." & LCase(DomainName), rsService("ServicePriority"))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [>] Fixing... Removing and adding existing domain alias's!"
If Not rsDomainAlias.EOF Then rsDomainAlias.MoveFirst
Do While Not rsDomainAlias.EOF
DomainAliasID = rsDomainAlias("DomainAliasID")
AliasName = rsDomainAlias("AliasName")
If AliasName <> "" Then
WScript.Echo " [-] Removing... Alias: " & UCase(AliasName) & "!"
ActionResult = oDomainAlias.DeleteEx(DomainAliasID)
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
WScript.Echo " [+] Adding... Alias: " & UCase(AliasName) & "! New ID: " & oDomainAlias.AddEx(DomainID, AliasName)
End If
rsDomainAlias.MoveNext
Loop
WScript.Echo " [>] Adding... Global DNS Records from reseller: " & ResellerAccountNumber & "!"
If Not rsGlobalDNS.EOF Then rsGlobalDNS.MoveFirst
Do While Not rsGlobalDNS.EOF
Select Case rsGlobalDNS("RecordType")
Case DNS_A
WScript.Echo " [+] Adding... DNS A Record: " & UCase(rsGlobalDNS("RecordName")) & "!"
ActionResult = oDNS.CreateARecordEx(DomainID, rsGlobalDNS("RecordName"), Replace(rsGlobalDNS("RecordData"), "[DomainName]", DomainName))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
Case DNS_MX
WScript.Echo " [+] Adding... DNS MX Record: " & UCase(rsGlobalDNS("RecordData")) & "!"
ActionResult = oDNS.CreateMXRecordEx(DomainID, Replace(rsGlobalDNS("RecordData"), "[DomainName]", DomainName), rsGlobalDNS("RecordPreference"))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
Case DNS_CNAME
WScript.Echo " [+] Adding... DNS CNAME Record: " & UCase(rsGlobalDNS("RecordName")) & "!"
ActionResult = oDNS.CreateCNAMERecordEx(DomainID, rsGlobalDNS("RecordName"), Replace(rsGlobalDNS("RecordData"), "[DomainName]", DomainName))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
Case DNS_TXT
WScript.Echo " [+] Adding... DNS TXT Record: " & UCase(rsGlobalDNS("RecordName")) & "!"
ActionResult = oDNS.CreateTXTRecordEx(DomainID, rsGlobalDNS("RecordName"), Replace(rsGlobalDNS("RecordData"), "[DomainName]", DomainName))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
End Select
rsGlobalDNS.MoveNext
Loop
WScript.Echo " [>] Adding... Global DNS Records from the ADMIN account!"
If Not rsGlobalDNSAdmin.EOF Then rsGlobalDNSAdmin.MoveFirst
Do While Not rsGlobalDNSAdmin.EOF
Select Case rsGlobalDNSAdmin("RecordType")
Case DNS_A
WScript.Echo " [+] Adding... DNS A Record: " & UCase(rsGlobalDNSAdmin("RecordName")) & "!"
ActionResult = oDNS.CreateARecordEx(DomainID, rsGlobalDNSAdmin("RecordName"), Replace(rsGlobalDNSAdmin("RecordData"), "[DomainName]", DomainName))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
Case DNS_MX
WScript.Echo " [+] Adding... DNS MX Record: " & UCase(rsGlobalDNSAdmin("RecordData")) & "!"
ActionResult = oDNS.CreateMXRecordEx(DomainID, Replace(rsGlobalDNSAdmin("RecordData"), "[DomainName]", DomainName), rsGlobalDNSAdmin("RecordPreference"))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
Case DNS_CNAME
WScript.Echo " [+] Adding... DNS CNAME Record: " & UCase(rsGlobalDNSAdmin("RecordName")) & "!"
ActionResult = oDNS.CreateCNAMERecordEx(DomainID, rsGlobalDNSAdmin("RecordName"), Replace(rsGlobalDNSAdmin("RecordData"), "[DomainName]", DomainName))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
Case DNS_TXT
WScript.Echo " [+] Adding... DNS TXT Record: " & UCase(rsGlobalDNSAdmin("RecordName")) & "!"
ActionResult = oDNS.CreateTXTRecordEx(DomainID, rsGlobalDNSAdmin("RecordName"), Replace(rsGlobalDNSAdmin("RecordData"), "[DomainName]", DomainName))
If ActionResult <> "" Then
WScript.Echo " [E] " & ActionResult
WScript.Echo ""
ActionResult = ""
End If
End Select
rsGlobalDNSAdmin.MoveNext
Loop
WScript.Echo ""
rsDomain.MoveNext
Loop
WScript.Echo "Total Domains Processed: " & iCount
Set rsDomain = Nothing
Set rsGlobalDNS = Nothing
Set rsGlobalDNSAdmin = Nothing
Set rsDomainAlias = Nothing
Set rsDNS = Nothing
Set rsServiceSet = Nothing
Set rsService = Nothing
Set oDomain = Nothing
Set oDNS = Nothing
Set oFTP = Nothing
Set oEmail = Nothing
Set oWebsite = Nothing
Set oService = Nothing
Set oServiceSet = Nothing
Set oDomainAlias = Nothing
Set oGlobalDNSRecord = Nothing
Comments
Post a Comment