<%@ Language=VBScript %> <% Option Explicit %> <% '------------------------------------------------------------------------- ' id_prop.asp: Page for changing the Device Name and Domain Name ' ' Copyright (c) Microsoft Corporation. All rights reserved. ' ' Date Description ' 21-Jul-2000 Created date ' 05-Mar-2001 Modified date ' 24-Mar-2001 Modified date '------------------------------------------------------------------------- %> <% '------------------------------------------------------------------------- ' Form Variables '------------------------------------------------------------------------- Dim F_strDeviceName 'Device Name from the form Dim F_strAppleTalkName 'Name of Computer in Apple Talk Dim F_strNetWareName 'Name of Computer in NetWare Dim F_strWorkGroup 'Workgroup Name Dim F_strDomain 'Domain Name Dim F_strDefaultDNS 'Default DNS Dim F_strUserName 'User Name Dim F_strPassword 'Password Dim F_strRadio 'Radio button value(Workgroup/Domain) Dim F_strOriginalStatus 'variable for storing original status of 'the machine(Workgroup/Domain) Dim F_strRebootState 'Indicate if Reboot required or not '------------------------------------------------------------------------- ' Global Variables '------------------------------------------------------------------------- Dim page 'Variable that receives the output page object when 'creating a page Dim rc 'Return value for CreatePage Dim G_bAppleTalkInstalled 'Indicate if AppleTalk is installed or not Dim G_bNetWareInstalled 'Indicate if NetWare is installed or not '------------------------------------------------------------------------- ' Error constants '------------------------------------------------------------------------- Const N_DUPLICATECOMPUTERNAME_ERRNO1 = &H800708B0 Const N_DUPLICATECOMPUTERNAME_ERRNO2 = &H80070034 Const N_INVALIDDOMAIN_ERRNO = &H8007054B Const N_DOMAININVALIDDOMAINPERMISSIONDENIES_ERRNO = 70 Const N_INVALIDCREDENTIALS_ERRNO = &H8007052E Const N_DOMAININVALIDDOMAIN_ERRNO = &H80070520 Const N_UNEXPECTED_COMPUTERNAMEERROR = &H8007092F Const N_DNSNAMEINVALID_ERRNO = 5 Const N_DOMAINNAMESYSTAX_ERRNO = &H8007007B Const N_UNSPECIFIED_ERRNO = &H80004005 Const CONST_APPLETALK_SERVICENAME ="MacFile" Const CONST_NETWARE_SERVICENAME ="FPNW" Const CONST_HTTPS_OFF ="OFF" Const CONST_YES ="Yes" Const CONST_NO ="No" Const CONST_WORKGROUP ="Workgroup" Const CONST_DOMAIN ="Domain" Const CONST_APPLETALK_REGKEYPATH ="SYSTEM\CurrentControlSet\Services\MacFile\Parameters" Const CONST_NETWARE_REGKEYPATH ="SYSTEM\CurrentControlSet\Services\FPNW\Parameters" rc = SA_CreatePage(L_TASKTITLE_TEXT, "", PT_PROPERTY, page) if rc = SA_NO_ERROR then Call SA_ShowPage(page) End if '------------------------------------------------------------------------- 'Function: OnInitPage() 'Description: Called to signal first time processing for this page. ' Used to do first time initialization tasks 'Input Variables: PageIn,EventArg 'Output Variables: PageIn,EventArg 'Returns: True/False 'Global Variables: F_strRebootState '------------------------------------------------------------------------- Public Function OnInitPage(ByRef pageIn, ByRef EventArg) On Error Resume Next Err.Clear Call GetSystemSettings() Call AppleTalkNetWare() Call GetAppleTalkNetWareSettings() F_strRebootState = CONST_NO OnInitPage = TRUE End Function 'End of Set Variables From System Function '------------------------------------------------------------------------- 'Function: OnServePropertyPage() 'Description: Called when the page needs to be served.Use this ' method to serve content 'Input Variables: PageIn,EventArg 'Output Variables: None 'Returns: True/False 'Global Variables: None '------------------------------------------------------------------------- Function OnServePropertyPage(ByRef PageIn, ByRef EventArg) %> <% If G_bAppleTalkInstalled = True then %> <% End If %> <% IF G_bNetWareInstalled = True then %> <% End If %>
<%CheckForSecureSite()%>
<%=server.HTMLEncode(L_DEVICENAME_TEXT)%>
<%=server.HTMLEncode(L_DEFAULTDNS_TEXT)%>

<%=server.HTMLEncode(L_MEMBEROF_TEXT)%> <%=server.HTMLEncode(L_WORKGROUP_TEXT)%>
  <%=server.HTMLEncode(L_DOMAIN_TEXT) %>
  <%=Server.HTMLEncode(L_USERWITHPERMISSION_TEXT)%>
    <%=Server.HTMLEncode(L_ADMINUSERNAME_TEXT)%>
    <%=Server.HTMLEncode(L_ADMINPASSWORD_TEXT)%>
 

<%=server.HTMLEncode(L_APPLETALKNAME_TEXT)%>
<%=server.HTMLEncode(L_NETWARENAME_TEXT)%>
<% OnServePropertyPage = True End Function '------------------------------------------------------------------------- 'Function: OnPostBackPage() 'Description: Called to signal that the page has been posted-back. 'Input Variables: PageIn, EventArg 'Output Variables: PageIn, EventArg, F_(*) 'Returns: True/False 'Global Variables: F_(*) '------------------------------------------------------------------------- Public Function OnPostBackPage(ByRef PageIn,ByRef EventArg) F_strDeviceName = Trim(Request.Form("txtdevicename")) F_strAppleTalkName = Trim(Request.Form("txtappletalkname")) F_strNetWareName = Trim(Request.Form("txtnetwarename")) F_strWorkGroup = Trim(Request.Form("txtworkgroup")) F_strDomain = Trim(Request.Form("txtdomain")) F_strDefaultDNS = Trim(Request.Form("txtdefaultdns")) F_strUserName = Trim(Request.Form("txtdomainusername")) F_strPassword = Trim(Request.Form("pwdomainuserpw")) F_strRadio = Trim(Request.Form("radiodomainorworkgroup")) F_strOriginalStatus = Trim(Request.Form("hdnOriginalStatus")) F_strRebootState = Trim(Request.Form("hdnRebootState")) OnPostBackPage = TRUE End Function '----------------------------------------------------------------------------- 'Function: OnSubmitPage() 'Description: Called when the page has been submitted for processing. ' Use this method to process the submit request. 'Input Variables: PageIn, EventArg 'Output Variables: PageIn, EventArg 'Returns: True/False 'Global Variables: None '----------------------------------------------------------------------------- Function OnSubmitPage(ByRef PageIn, ByRef EventArg) Dim objSystem 'System Object Set objSystem = CreateObject("comhelper.SystemSetting") If not SetSystemSettings(objSystem) then onSubmitPage = False Set objSystem = nothing Exit Function End If Call AppleTalkNetWare() If not IsRestartReq(objSystem) Then onSubmitPage = False Set objSystem = nothing Exit Function End If Set objSystem = nothing OnSubmitPage = True End Function '------------------------------------------------------------------------- 'Function: OnClosePage() 'Description: Called when the page is about to be closed.Use this ' method to perform clean-up processing 'Input Variables: PageIn,EventArg 'Output Variables: None 'Returns: True/False 'Global Variables: None '------------------------------------------------------------------------- Public Function OnClosePage(ByRef PageIn,ByRef EventArg) OnClosePage=TRUE End Function '------------------------------------------------------------------------- 'Sub routine: AppleTalkNetWare 'Description: To check whether required services are installed or not 'Input Variables: None 'Output Variables: None 'Returns: None 'Global Variables: Out:G_bAppleTalkInstalled ' Out:G_bNetWareInstalled ' In:CONST_APPLETALK_SERVICENAME ' In:CONST_NETWARE_SERVICENAME ' In:CONST_WMI_WIN32_NAMESPACE ' In:L_(*) '------------------------------------------------------------------------- Sub AppleTalkNetWare() On Error Resume Next Err.Clear Dim objWMIConnection Dim strProtocol Dim strPath Dim strServerName Set objWMIConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE) 'Incase connection fails If Err.number <> 0 Then Call SA_ServeFailurePageEx(L_FAILEDTOGETWMICONNECTION_ERRORMESSAGE, mstrReturnURL ) Exit Sub End If G_bAppleTalkInstalled = SA_IsServiceInstalled(CONST_APPLETALK_SERVICENAME) G_bNetWareInstalled = SA_IsServiceInstalled(CONST_NETWARE_SERVICENAME) Set objWMIConnection = nothing End Sub '------------------------------------------------------------------------- 'Function: GetSystemSettings 'Description: To get the System Settings using a Com Object 'Input Variables: None 'Output Variables: None 'Returns: None 'Global Variables: F_(*), L_ERROROCCUREDINCREATEOBJECT_ERRORMESSAGE ' L_ERRORINGETTINGCOMPUTERSYSTEMOBJECT_ERRORMESSAGE '------------------------------------------------------------------------- Function GetSystemSettings() On Error Resume Next Err.Clear Dim objSystem Dim objComputer Set objSystem = CreateObject("comhelper.SystemSetting") If Err.Number <> 0 Then Call SA_ServeFailurePageEx(L_ERROROCCUREDINCREATEOBJECT_ERRORMESSAGE, mstrReturnURL) Exit Function End If Set objComputer = objSystem.Computer If Err.Number <> 0 Then Call SA_ServeFailurePageEx(L_ERRORINGETTINGCOMPUTERSYSTEMOBJECT_ERRORMESSAGE, mstrReturnURL ) Exit Function End If F_strDeviceName = objComputer.ComputerName F_strDomain = objComputer.DomainName 'Incase Domain returns null then an error number -2147467259 If Err.number = N_UNSPECIFIED_ERRNO then Err.Clear End If F_strWorkGroup = objComputer.WorkgroupName 'Incase Workgroup returns null then an error number -2147467259 If Err.number = N_UNSPECIFIED_ERRNO then Err.Clear End If F_strDefaultDNS = objComputer.FullQualifiedComputerName LTrim(F_strDomain) LTrim(F_strWorkGroup) 'Assigning the original status(Domain/Workgroup) If LTrim(F_strDomain) <> "" Then F_strOriginalStatus = CONST_DOMAIN Else F_strOriginalStatus = CONST_WORKGROUP End If 'Assigning the DNS value If IsNull(F_strDefaultDNS) = False Then Dim DNSlen, Devicelen DNSlen = Len(F_strDefaultDNS) Devicelen = Len(F_strDeviceName) DNSlen = DNSlen - Devicelen - 1 If DNSlen < 0 Then DNSlen = 0 End If F_strDefaultDNS = Right(F_strDefaultDNS, DNSlen) End If Set objComputer = Nothing Set objSystem = Nothing End Function '------------------------------------------------------------------------- 'Function: SetSystemSettings 'Description: To set the System Settings using a Com Object 'Input Variables: objSystem 'Output Variables: None 'Returns: True/False 'Global Variables: F_(*), L_ERROROCCUREDINCREATEOBJECT_ERRORMESSAGE ' L_ERRORINGETTINGCOMPUTERSYSTEMOBJECT_ERRORMESSAGE ' L_LOGONINFOFAILED_ERRORMESSAGE '------------------------------------------------------------------------- Function SetSystemSettings(objSystem) On Error Resume Next Err.Clear Dim objComputer SetSystemSettings = False If Err.Number <> 0 Then SA_SetErrMsg L_ERROROCCUREDINCREATEOBJECT_ERRORMESSAGE &_ "( " & Hex(Err.number)& " )" objComputer = nothing Exit Function End If 'get the computer object Set objComputer=objSystem.Computer If Err.Number <> 0 Then SA_SetErrMsg L_ERRORINGETTINGCOMPUTERSYSTEMOBJECT_ERRORMESSAGE &_ "(" & Hex(Err.Number)& " )" objComputer = nothing Exit Function End If 'Assigning the Host name objComputer.ComputerName=F_strDeviceName 'If DNS Suffix is not empty/If DNS Suffix is empty If F_strDefaultDNS <> "" Then objComputer.FullQualifiedComputerName=F_strDeviceName & "."& F_strDefaultDNS Else objComputer.FullQualifiedComputerName=F_strDeviceName End If 'Machine belongs to Workgroup 'If F_strOriginalStatus = "workgroup" then If ( UCase(F_strOriginalStatus) = UCase(CONST_WORKGROUP)) then 'Adding to Workgroup If (UCase(F_strRadio) = UCase(CONST_WORKGROUP)) then objComputer.workgroupName = F_strWorkGroup 'Adding to Domain Elseif (UCase(F_strRadio) = UCase(CONST_DOMAIN) ) then objcomputer.domainName = F_strDomain End If 'Machine belongs to Domain Else 'Adding to Workgroup If (UCase(F_strRadio) = UCase(CONST_WORKGROUP)) then objComputer.workgroupName = F_strWorkGroup 'Adding to Domain Elseif (UCase(F_strRadio) = UCase(CONST_DOMAIN) ) then objcomputer.domainName = F_strDomain End If End If 'In XPE, to join a domain, the username has to be domain\username If CONST_OSNAME_XPE = GetServerOSName() Then if (UCase(F_strRadio) = UCase(CONST_DOMAIN) ) then if InStr(F_strUserName, "\") = 0 Then F_strUserName = F_strDomain & "\" & F_strUserName End If End If End If 'Logon information(Username & Password) objComputer.LogonInfo F_strUserName,F_strPassword 'Checking for logoninfo method failure If Err.number <> 0 Then SA_SetErrMsg L_LOGONINFOFAILED_ERRORMESSAGE &_ "("& Hex(Err.Number) &")" objComputer = nothing Exit Function End If Set objComputer = nothing SetSystemSettings = True End Function '--------------------------------------------------------------------- 'Function name: ApplySettings 'Description: Applies the settings for the System 'Input Variables: objSystem 'Output Variables: None 'Return Values: Returns (True/False) 'Global Variables: In:L_(*) ' In:N_(*) '--------------------------------------------------------------------- Function ApplySettings(objSystem) on error resume next Err.Clear Dim errorcode Dim strErrorMessage ApplySettings = FALSE SA_TraceOut "ID_PROP", "Beginning ApplySettings" If ( Err.Number <> 0 ) Then SA_TraceOut "ID_PROP", "Precondition assert failed. Err.Number != 0 " + CStr(Hex(Err.Number)) End If 'Apply System Settings using ComObject objSystem.Apply(1) errorCode = Err.Number If errorCode = 0 Then If ( G_bAppleTalkInstalled ) Then 'If AppleTalk service installed 'Function call to set the servername in the regisrty If not IsSetServerNameInRegistry(CONST_APPLETALK_REGKEYPATH,"ServerName",F_strAppleTalkName) Then ApplySettings = False Exit function End If End If ' end of If ( G_bAppleTalkInstalled ) Then If ( G_bNetWareInstalled ) Then 'If Netware service installed 'Function call to set the servername in the regisrty If not IsSetServerNameInRegistry(CONST_NETWARE_REGKEYPATH,"ComputerName",F_strNetWareName) Then ApplySettings = False Exit function End If End If ' end of If ( G_bNetWareInstalled ) Then ApplySettings = TRUE Else ApplySettings = FALSE SA_TraceOut "ID_PROP", "objSystem.Apply(1) failed: " + CStr(Hex(errorCode)) Select Case errorCode Case N_UNEXPECTED_COMPUTERNAMEERROR strErrorMessage = L_COMPUTERNAME_INVALID_ERRORMESSAGE Case N_DUPLICATECOMPUTERNAME_ERRNO1 strErrorMessage = L_COMPUTERNAME_INUSE_ERRORMESSAGE Case N_DUPLICATECOMPUTERNAME_ERRNO2 strErrorMessage = L_COMPUTERNAME_INUSE_ERRORMESSAGE Case N_INVALIDDOMAIN_ERRNO strErrorMessage = L_INVALIDDOMAINNAME_ERRORMESSAGE Case N_INVALIDCREDENTIALS_ERRNO strErrorMessage = L_DOMAINUSERINVALIDCREDENTIALS_ERRORMESSAGE Case N_DOMAININVALIDDOMAIN_ERRNO strErrorMessage = L_DOMAINUSERINVALIDCREDENTIALS_ERRORMESSAGE Case N_DOMAININVALIDDOMAINPERMISSIONDENIES_ERRNO strErrorMessage = L_DOMAINUSERINVALIDCREDENTIALS_ERRORMESSAGE Case N_DNSNAMEINVALID_ERRNO strErrorMessage = L_INVALIDDNSNAME_ERRORMESSAGE Case N_DOMAINNAMESYSTAX_ERRNO strErrorMessage = L_DOMAINNAMESYNTAX_ERRORMESSAGE Case Else strErrorMessage = L_CHANGESYSTEMSETTINGSFAILED_ERRORMESSAGE End Select strErrorMessage = strErrorMessage & " ("& Hex(errorCode) &")" SA_SetErrMsg strErrorMessage End If End Function '------------------------------------------------------------------------ 'Subroutine name: IsRestartReq 'Description: To check if restart required or not 'Input Variables: objSystem 'Ouput Variables: None 'Return Values: True/False 'Global Variables: L_ERRORINISREBOOT_ERRORMESSAGE, F_strRebootState ' : L_CHANGESYSTEMSETTINGSFAILED_ERRORMESSAGE '------------------------------------------------------------------------ Function IsRestartReq(objSystem) On Error Resume Next Err.Clear Dim nIsRestartReq Dim strReturnURL Dim strMessage strReturnURL = "RebootSys.asp" 'Is Restart Required nIsRestartReq = objSystem.IsRebootRequired(strMessage) If Err.Number <> 0 Then SA_SetErrMsg L_ERRORINISREBOOT_ERRORMESSAGE &_ "("& Hex(Err.Number) &")" objSystem = nothing IsRestartReq = False Exit Function End If ' ' If restart not required for this change If (NOT nIsRestartReq) Then ' Make sure the last attempt did not require a reboot If (UCase(F_strRebootState) = UCase(CONST_YES)) Then SA_TraceOut "ID_PROP", "Cached reboot state being set" nIsRestartReq = 1 End If End If If nIsRestartReq Then 'If restart required then assign all the SA_TraceOut "ID_PROP", "Reboot is required" F_strRebootState = CONST_YES SA_TraceOut "ID_PROP", "Calling ApplySettings" If ApplySettings(objSystem) = TRUE Then 'Calling the applysettings method SA_TraceOut "ID_PROP", "Redirecting to RebootSys.asp" 'Redirecting to reboot page Call SA_MungeURL(strReturnURL,"Tab1",getTab1()) Call SA_MungeURL(strReturnURL,"Tab2",getTab2()) Call SA_MungeURL(strReturnURL, SAI_FLD_PAGEKEY, SAI_GetPageKey()) Response.Redirect strReturnURL Else SA_TraceOut "ID_PROP", "ApplySettings failed " objSystem = nothing Exit Function End If Else SA_TraceOut "ID_PROP", "Reboot is NOT required" objSystem.Apply(1) 'Applying the settings to object If Err.Number <> 0 Then SA_SetErrMsg L_CHANGESYSTEMSETTINGSFAILED_ERRORMESSAGE &_ "("& Hex(Err.Number) &")" IsRestartReq = False objSystem = nothing Exit Function End If End If IsRestartReq = True End Function '----------------------------------------------------------------------- 'Subroutine name: GetAppleTalkNetWareSettings 'Description: To get AppleTalk and NetWare Settings from the ' Registry 'Input Variables: G_bAppleTalkInstalled, G_bNetWareInstalled ' F_strDeviceName 'Ouput Variables: F_strNetWareName, F_strAppleTalkName 'Return Values: None 'Global Variables: G_bAppleTalkInstalled, G_bNetWareInstalled, ' F_strAppleTalkName, F_strNetWareName, F_strDeviceName '------------------------------------------------------------------------ Function GetAppleTalkNetWareSettings On Error Resume Next Err.Clear Dim strPath Dim strServerName Dim objAppleNetwareRegistry GetAppleTalkNetWareSettings = False If G_bAppleTalkInstalled = True or G_bNetWareInstalled = True Then set objAppleNetwareRegistry = RegConnection() If Err.number <> 0 then SA_SetErrMsg L_REGISTRYCONNECTIONFAIL_ERRORMESSAGE & "(" & Err.Number & ")" Exit Function End If If G_bAppleTalkInstalled = True Then strPath = "SYSTEM\CurrentControlSet\Services\MacFile\Parameters" strServerName = getRegkeyvalue(objAppleNetwareRegistry,strPath,"ServerName",CONST_STRING) 'Checking for the AppleTalk servername If strServerName = "" Then F_strAppleTalkName = F_strDeviceName 'if null assign the machine name itself Else F_strAppleTalkName = strServerName 'Get it from the registry End IF End If If G_bNetWareInstalled = True Then strPath = "SYSTEM\CurrentControlSet\Services\FPNW\Parameters" strServerName = getRegkeyvalue(objAppleNetwareRegistry,strPath,"ComputerName",CONST_STRING) 'Checking for the Netware servername If strServerName = "" Then F_strNetWareName = F_strDeviceName & "_NW" 'if null assign the machine name itself Else F_strNetWareName = strServerName 'Get it from the registry End IF End If End If GetAppleTalkNetWareSettings = True End Function '----------------------------------------------------------------------- 'Function: IsSetServerNameInRegistry 'Description: To set Server names like AppleTalk and NetWare in Registry 'Input Variables: strRegkeyPath -Path ' strKeyName -KeyName ' strValue -Keyvalue 'Ouput Variables: 'Return Values: TRUE/FALSE 'Global Variables: In:L_(*) '------------------------------------------------------------------------ Function IsSetServerNameInRegistry(strRegkeyPath , strKeyName , strValue ) On Error Resume Next Err.Clear Dim objRegistry Dim nReturnValue IsSetServerNameInRegistry=TRUE Set objRegistry = RegConnection() If Err.number <> 0 then SA_SetErrMsg L_REGISTRYCONNECTIONFAIL_ERRORMESSAGE Exit Function End If nReturnValue= updateRegkeyvalue(objRegistry , strRegkeyPath , strKeyName , strValue , CONST_STRING ) If nReturnValue = FAlSE Then IsSetServerNameInRegistry=FALSE End If End function %>