Solved

asp help

Posted on 2010-09-14
5
545 Views
Last Modified: 2012-06-21
I have an asp page  (achg.asp) which IIS uses to call upon our domain for a users change password request. I have the domain specified (wfinet) in the asp page; however, I now have another domain in my forest and I want to specifiy that domain in the asp page too, so when the account isn’t found in the wfinet domain, it will look in the (newdomainname) for the account. I don’t know how that would be written in this asp page, as I am not an asp guru. Here is the snippet:
<%end if%>
<%
      On Error resume next
      dim domain, posbs, posat, username, pUser, root
      dim upn_name

      upn_name = ""

      domain = Trim(Request.Form("domain"))
      ' if no domain is present we try to get the domain from the username,
      ' e.g. domainusername or praesi@ultraschallpiloten.com
     
      if domain = "" then
            posbs = Instr(1,Request.Form("acct"),"\" )
            posat = Instr(1,Request.Form("acct"),"@" )
            if posbs > 0 then
                  domain = Left(Request.Form("acct"),posbs-1)
                  username = Right(Request.Form("acct"),len(Request.Form("acct")) - posbs)
            elseif posat > 0 then
                  upn_name = Request.Form("acct")
                  domain = Right(upn_name, len(upn_name) - posat)
                  username = Left(upn_name, posat-1)
            else      
                  username = Request.Form("acct")
                  set nw = Server.CreateObject("WScript.Network")
                  domain = "WFINET"
                  ' domain = nw.Computername
            end if

Note the domain WFINET, that’s the domain it works for, I need it to look at an additional domain, if the user account doesnt exist in the wfinet domain. Can you provide the asp text that would specify both domains?
0
Comment
Question by:KratosDefense
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:KratosDefense
ID: 33676056
here is the full page if that helps:

<%@Language="VBScript"%>
<HTML>
<!--#include file = "text.asp"-->

<title><%=L_Title_Text%></title>

<STYLE>
</STYLE>
<head>
            <META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
</head>
      
<BODY BGCOLOR=#FFFFFF LINK=000000 VLINK=000000>
<%On Error goto 0%>
<%if Request.Form("cancel") <> "" then
      if Request.Form("denyifcancel") <> "" then
            Response.Status = "401 Unauthorized"
            Response.End
      else
            Response.Redirect(Request.QueryString)
      end if
      Response.End
end if
%>



<!-- Windows NT Server with IIS  -->
<%if Instr(1,Request.ServerVariables("SERVER_SOFTWARE"), "IIS") > 0 then%>
      <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
      <TR VALIGN=CENTER>
            <TD></TD>
            <TD WIDTH=20> </TD>
            <TD><FONT SIZE=+3 COLOR=#000000><B><%=L_ISM_Text%><BR> <FONT SIZE=-1><%=L_IIS6_Text%><FONT></B></FONT></TD>
      </TR>
      </Table>
<%end if%>  

<!-- Windows NT Workstation with PWS  -->
<%if Instr(1,Request.ServerVariables("SERVER_SOFTWARE"), "PWS") then%>
      <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>
      <TR VALIGN=CENTER>
            <TD></TD>
            <TD WIDTH=20> </TD>
            <TD><FONT SIZE=+3 COLOR=#000000><B><%=L_ISM_Text%><BR> <FONT SIZE=-1><%=L_PWS_Text%><FONT></B></FONT></TD>
      </TR>
      </Table>
<%end if%>
<p>

<%if Request.Form("new") <> Request.Form("new2") then %>
      <%=L_PWDM_Text%><p>
      <%Response.Write "<br><H3><a href=" & Server.HTMLEncode(Request.ServerVariables("HTTP_REFERER")) & ">" & L_Back_Text & " </a></H3>"
      Response.End%>
<%end if%>
<%
      On Error resume next
      dim domain, posbs, posat, username, pUser, root
      dim upn_name

      upn_name = ""

      domain = Trim(Request.Form("domain"))
      ' if no domain is present we try to get the domain from the username,
      ' e.g. domainusername or praesi@ultraschallpiloten.com
      
      if domain = "" then
            posbs = Instr(1,Request.Form("acct"),"\" )
            posat = Instr(1,Request.Form("acct"),"@" )
            if posbs > 0 then
                  domain = Left(Request.Form("acct"),posbs-1)
                  username = Right(Request.Form("acct"),len(Request.Form("acct")) - posbs)
            elseif posat > 0 then
                  upn_name = Request.Form("acct")
                  domain = Right(upn_name, len(upn_name) - posat)
                  username = Left(upn_name, posat-1)
            else      
                  username = Request.Form("acct")
                  set nw = Server.CreateObject("WScript.Network")
                  domain = "WFINET"
                  ' domain = nw.Computername
            end if
      else
            username = Trim(Request.Form("acct"))
      end if
      ' verify that the characters in the user name are valid
      if IsInvalidUsername(username) = true then
            Response.Write L_InvalidUsername_Text & "."
            Response.Write "<br><H3><a href=" & Server.HTMLEncode(Request.ServerVariables("HTTP_REFERER")) & ">" & L_Back_Text & " </a></H3>"
            Response.End
      end if
      
      ' verify that the characters in the domain name are valid
      if IsInvalidDomainname(domain) = true then
            Response.Write L_InvalidDomainname_Text & "."
            Response.Write "<br><H3><a href=" & Server.HTMLEncode(Request.ServerVariables("HTTP_REFERER")) & ">" & L_Back_Text & " </a></H3>"
            Response.End
      end if  
      
      if upn_name = "" then
            set pUser = GetObject("WinNT://" & domain & "/" & username & ",user")

            if Not IsObject(pUser) then
                  set root = GetObject("WinNT:")
                  set pUser = root.OpenDSObject("WinNT://" & domain & "/" & username & ",user", username, Request.Form("old"),1)
                  Response.Write "<!--OpenDSObject call-->"
            end if

            if Not IsObject(pUser) then
                  set pUser = Server.CreateObject("IIS.PwdChg")
                  pUser.Domain = domain
                  pUser.User = username
            end if
      else
            set pUser = Server.CreateObject("IIS.PwdChg")
            if Not IsObject(pUser) then
                  set pUser = GetObject("WinNT://" & domain & "/" & username & ",user")
                  if Not IsObject(pUser) then
                        set root = GetObject("WinNT:")
                        set pUser = root.OpenDSObject("WinNT://" & domain & "/" & username & ",user", username, Request.Form("old"),1)
                        Response.Write "<!--OpenDSObject call-->"
                  end if
            else
                  pUser.Domain = domain
                  pUser.User = username
                  pUser.UPN = upn_name
            end if
      end if

      if Not IsObject(pUser) then
            'Response.Write "domain <> null - OpenDSObject also failed"
            if err.number = -2147024843 then
                  Response.Write L_NotExist_Text & "."
            else
                  if err.description <> "" then
                        Response.Write L_Error_Text & ": " & err.description
                  else
                        Response.Write L_Errornumber_Text & ": " & err.number
                  end if
                  Response.Write "<br><H3><a href=" & Server.HTMLEncode(Request.ServerVariables("HTTP_REFERER")) & ">" & L_Back_Text & " </a></H3>"
            end if
            Response.End
      end if
      
      err.Clear
      pUser.ChangePassword Request.Form("old"), Request.Form("new")

      if err.number <> 0 then
            if err.number = -2147024810 then
                  Response.Write "<p>" & L_Error_Text & ": " & L_Invalid_Text
            elseif err.number = -2147022651 then
                   Response.Write L_PasswordToShort_Text
            else
                  Response.Write L_Errornumber_Text & ": " & err.number
            end if
            Response.Write "<br><H3><a href=" & Server.HTMLEncode(Request.ServerVariables("HTTP_REFERER")) & ">" & L_Back_Text & " </a></H3>"
            Response.End
      else
            Response.Write L_PasswordChanged_Text & ".<p>"

      end if
      
      %>
      <br>
      <a href="<%=Server.HTMLEncode(Request.QueryString)%>"> " <%=L_BackTo_Text%> "<%=Server.HTMLEncode(Request.QueryString)%></a>
</body></html>


<%
function IsInvalidUsername(username)
      dim re
      set re = new RegExp
      ' list of invalid characters in a user name.
      re.Pattern = "[/\\""\[\]:<>\+=;,@]"
      IsInvalidUsername =  re.Test(username)
end function

function IsInvalidDomainname(domainname)
      dim re
      set re = new RegExp
      ' list of invalid characters in a domain name.
      re.Pattern = "[/\\""\[\]:<>\+=;,@!#$%^&\(\)\{\}\|~]"
      IsInvalidDomainName =  re.Test(domainname)
end function
%>
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 33680550
You really need to learn to use the [Code] view below the editor to post your code.
It makes it a lot easier for us to be able to copy it out and run through it.

Carrzkiss
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 33680969
What you need to do is refactor the code into an array
  http://www.tizag.com/vbscriptTutorial/vbscriptarrays.php

So your code would look something like this:

...
      dim domainList(1)  'Domain list has a maximum of 2 entries
      dim posbs, posat, username, pUser, root
      dim upn_name

      domainList(0)=""   'Initialize list to empty strings
      domainList(1)=""
      upn_name = ""

      domainList(0) = Trim(Request.Form("domain"))
      ' if no domain is present we try to get the domain from the username,
      ' e.g. domainusername or praesi@ultraschallpiloten.com
      
      if domainList(0) = "" then
            posbs = Instr(1,Request.Form("acct"),"\" )
            posat = Instr(1,Request.Form("acct"),"@" )
            if posbs > 0 then
                  domainList(0) = Left(Request.Form("acct"),posbs-1)
                  username = Right(Request.Form("acct"),len(Request.Form("acct")) - posbs)
            elseif posat > 0 then
                  upn_name = Request.Form("acct")
                  domain = Right(upn_name, len(upn_name) - posat)
                  domainList(0) = Left(upn_name, posat-1)
            else      
                  username = Request.Form("acct")
                  set nw = Server.CreateObject("WScript.Network")
                  domainList(0) = "WFINET"
                  domainList(1) = nw.Computername
            end if
      else
            username = Trim(Request.Form("acct"))
      end if

...
'And then the code to process the domains would look like this:
For Each domain in domainList
  on error goto TryNextDomain

  ' verify that the characters in the domain name are valid
      if IsInvalidDomainname(domain) = true then
            Response.Write L_InvalidDomainname_Text & "."
            Response.Write "<br><H3><a href=" & Server.HTMLEncode(Request.ServerVariables("HTTP_REFERER")) & ">" & L_Back_Text & " </a></H3>"
            Response.End
      end if  
      
      if upn_name = "" then
            set pUser = GetObject("WinNT://" & domain & "/" & username & ",user")

            if Not IsObject(pUser) then
                  set root = GetObject("WinNT:")
                  set pUser = root.OpenDSObject("WinNT://" & domain & "/" & username & ",user", username, Request.Form("old"),1)
                  Response.Write "<!--OpenDSObject call-->"
            end if

            if Not IsObject(pUser) then
                  set pUser = Server.CreateObject("IIS.PwdChg")
                  pUser.Domain = domain
                  pUser.User = username
            end if
      else
            set pUser = Server.CreateObject("IIS.PwdChg")
            if Not IsObject(pUser) then
                  set pUser = GetObject("WinNT://" & domain & "/" & username & ",user")
                  if Not IsObject(pUser) then
                        set root = GetObject("WinNT:")
                        set pUser = root.OpenDSObject("WinNT://" & domain & "/" & username & ",user", username, Request.Form("old"),1)
                        Response.Write "<!--OpenDSObject call-->"
                  end if
            else
                  pUser.Domain = domain
                  pUser.User = username
                  pUser.UPN = upn_name
            end if
      end if

   TryNextDomain:
next

Open in new window

0
 
LVL 21

Expert Comment

by:MogalManic
ID: 33680985
EDITORIAL COMMENT:

You should consider upgrading this classic ASP page to ASP.Net.  It would make the code more maintainable and you would have much more resources available (people and web sites) that know ASP.Net .  It also has the advantage that it will separate the HTML from the code behind making the page easier to understand.
0
 

Author Closing Comment

by:KratosDefense
ID: 33686388
thxs
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question