Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping Problem involving ADSI

Status
Not open for further replies.

stevebanks

Programmer
Mar 30, 2004
93
0
0
Hi everyone,

I have a project that i am doing and it is a fair bit of code to create a virtual server, website, NT username, Mailserver username, disk quota, etc.. The code i am using is a bit of everyone elses, although I have modified it to my own needs. My problem is, that the script will create everything, the virtual server, website, NT username, mailserver info, disk quota, etc... but will then LOOPS back to the beginning and starts again which causes a File already exists error... There are NO loops (as far as I can see) in the code.??? I am most confused!!!

Here is the code:
Code:
<%
conn = "dsn=xxxxx;"

Dim domain 
domain = Request("M_domain")
Dim add
Dim add_numRows

Set add = Server.CreateObject("ADODB.Recordset")
add.ActiveConnection = conn
add.Source = "SELECT * FROM users"
add.CursorType = 0
add.CursorLocation = 2
add.LockType = 2
add.Open()

add_numRows = 0

add.addnew
add("yourdomain") = Request("M_domain")
add("password") = Request("M_password")
add("mailboxes") = Request("M_nopop3")
add("mysqldbs") = Request("M_mysql")
add("email") = "admin@" & Request("M_domain")
add("foldersize") = Request("M_amwebspace")
add("telephone") = Request("M_telephone")
add("name") = Request("M_name")
add("address") = Request("M_address")
add("otheremail") = Request("M_otheremail")
add("transfer") = Request("M_amtransfer")
add.update

'Create Directory for storing info in...
unamefolder = "d:inetpub\[URL unfurl="true"]wwwroot\"[/URL] & domain
web = "d:\inetpub\[URL unfurl="true"]wwwroot\"[/URL] & domain & "\web"
userdb = "d:\inetpub\[URL unfurl="true"]wwwroot\"[/URL] & domain & "\db"

set dirobj = CreateObject("Scripting.FileSystemObject")
dirobj.CreateFolder(unamefolder)
dirobj.CreateFolder(web)
dirobj.CreateFolder(userdb)

'Use ASP Execute as the helper for ACL
Set Executor = Server.CreateObject("ASPExec.Execute")
Executor.Application = "c:\windows\system32\cacls"
' Set the ACL for user directory
Executor.Parameters = userdir & " /t /e /p " & domain & ":f"
strResult = Executor.ExecuteDosApp
' Set the ACL for DB directory
Executor.Parameters = userdb & " /t /e /g IUSR_xxxxx-xxxxxx:c "
strResult = Executor.ExecuteDosApp
' Set the ACL for the CGI directory 
set Executor = nothing

'Create NT username
	Dim Container
	Dim NewUser
	Dim CurrentDate
	Dim ExpireDate
	Dim HomeDir
HomeDir = "d:\Inetpub\[URL unfurl="true"]wwwroot\"[/URL] & domain
CurrentDate = DateSerial(Year(Now),Month(Now),Day(Now))
ExpireDate = DateAdd("d",400000,CurrentDate)
Set Container = GetObject("WinNT://xxxxxx-xxxxxxx")
Set NewUser = Container.Create("user", domain)
	NewUser.FullName = Full_Name
	NewUser.Description = Request("M_email")
	NewUser.AccountExpirationDate = ExpireDate
	NewUser.HomeDirectory = HomeDir
	NewUser.SetInfo
	NewUser.SetPassword(Request("M_password"))

Set objIIS = GetObject("IIS://xxxxx-xxxxxxx/W3SVC/xxxxxxxx/ROOT")
strVirtualDirectoryPath = "d:\Inetpub\[URL unfurl="true"]wwwroot\"[/URL] & domain
Set objVirtualDirectory = objIIS.Create("IISWebVirtualDir", domain)
objVirtualDirectory.AccessScript = blnScriptPermissions
objVirtualDirectory.Path = strVirtualDirectoryPath
objVirtualDirectory.AppCreate blnInProcessApplication
objVirtualDirectory.AccessWrite = blnWritePermissions 
objVirtualDirectory.AccessRead = blnReadPermissions
objVirtualDirectory.AccessExecute = blnExecutePermissions
objVirtualDirectory.AuthAnonymous =True
objVirtualDirectory.AnonymousUserName=strOwner
objVirtualDirectory.AnonymousPasswordSync=True
objVirtualDirectory.AppCreate (True)
objVirtualDirectory.SetInfo 


'CREATE DOMAIN.COM website in IIS
Dim oWeb,oSite,oRoot,nSiteID
Const POOLED = 2
Set oWeb = GetObject("IIS://LocalHost/W3SVC")
' Find next ID for new server and stop current servers
nSiteID = 0
For Each oSite In oWeb
 If oSite.Class="IIsWebServer" Then
  If IsNumeric(oSite.Name) Then
   If CLng(oSite.Name)>nSiteID Then _
    nSiteID = CLng(oSite.Name)
  End If
 End If
Next
nSiteID = nSiteID + 1

' Create new server
Set oSite = oWeb.Create("IIsWebServer",CStr(nSiteID))
oSite.ServerComment = domain
oSite.DefaultDoc = "default.htm,default.asp,index.asp,index.htm,index.php"
oSite.ServerBindings = "12.345.678.90:80:[URL unfurl="true"]www."&[/URL] domain
oSite.ServerAutoStart = 1
oSite.SetInfo

' Create root
Set oRoot = oSite.Create("IIsWebVirtualDir","ROOT")
oRoot.Path = "d:\inetpub\[URL unfurl="true"]wwwroot\"[/URL] & domain & "\web\"
oRoot.AccessRead = True
oRoot.SetInfo
oSite.Start 

'CREATE MAIL.DOMAIN.COM website in IIS
Dim nWeb,nSite,nRoot,mSiteID

Set nWeb = GetObject("IIS://LocalHost/W3SVC")
' Find next ID for new server and stop current servers
mSiteID = 0
For Each nSite In nWeb
 If nSite.Class="IIsWebServer" Then
  If IsNumeric(nSite.Name) Then
   If CLng(nSite.Name)>mSiteID Then _
    mSiteID = CLng(nSite.Name)
  End If
 End If
Next
mSiteID = mSiteID + 1

' Create new server
Set nSite = nWeb.Create("IIsWebServer",CStr(mSiteID))
nSite.ServerComment = "mail." & domain
nSite.DefaultDoc = "index.php"
nSite.ServerBindings = "12.345.678.90:80:mail."& domain
nSite.ServerAutoStart = 1
nSite.SetInfo

' Create root
Set nRoot = nSite.Create("IIsWebVirtualDir","ROOT")
nRoot.Path = "d:\inetpub\[URL unfurl="true"]wwwroot\mail.xxxxxx.co.uk\SquirrelMail[/URL] For hMailServer mod 0.1\"
nRoot.AccessRead = True
nRoot.SetInfo
nSite.Start 

'CREATE ADMIN.DOMAIN.COM website in IIS
Dim xWeb,xSite,xRoot,xSiteID

Set xWeb = GetObject("IIS://LocalHost/W3SVC")
' Find next ID for new server and stop current servers
xSiteID = 0
For Each xSite In xWeb
 If xSite.Class="IIsWebServer" Then
  If IsNumeric(xSite.Name) Then
   If CLng(xSite.Name)>xSiteID Then _
   xSiteID = CLng(xSite.Name)
  End If
 End If
Next
xSiteID = xSiteID + 1

' Create new server
Set xSite = xWeb.Create("IIsWebServer",CStr(xSiteID))
xSite.ServerComment = "admin." & domain
xSite.DefaultDoc = "index.asp"
xSite.ServerBindings = "12.345.678.90:80:admin."& domain
xSite.ServerAutoStart = 1
xSite.SetInfo

' Create root
Set xRoot = xSite.Create("IIsWebVirtualDir","ROOT")
xRoot.Path = "d:\inetpub\[URL unfurl="true"]wwwroot\admin.xxxxxx.co.uk\"[/URL]
xRoot.AccessRead = True
xRoot.SetInfo
xSite.Start 

'Restrict disk quota for user
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "D:\", True
set objUser = colDiskQuotas.AddUser(domain)
set objUser = colDiskQuotas.FindUser(domain)
objUser.QuotaLimit = 1000000 * (Request("M_amwebspace"))


'Add Mail domain
Set obBaseApp = Server.CreateObject("hCOM.BaseApp") 
Set obDomain = obBaseApp.Domains.Add
	obdomain.Name = domain
	obDomain.Active = True
	obdomain.Save
	
	
'Add Default Mail user account admin@domain.com
sName = obBaseApp.Domains.ItemByName(domain).DomainID
Set obAccounts = obBaseApp.Domains.ItemByDBID(sName).Accounts.Add
	obAccounts.Address = "admin@" & domain
	obAccounts.Password = Request("M_password")
	obAccounts.Active = True
	obAccounts.MaxSize = 0
	obAccounts.Save


'Send mail to administrator
body2me = "Register this domain : " & Request("M_domain") & VBCRLF & VBCRLF
body2me = body2me & "For : " & Request("M_name") & VBCRLF
body2me = body2me & "Address : " & Request("M_address") & VBCRLF
body2me = body2me & "Telephone : " & Request("M_telephone") & VBCRLF
body2me = body2me & "Email : " & Request("M_email")


Set mail2me = Server.CreateObject("JMail.Message")
mail2me.From = "admin@xxxx.co.uk"
mail2me.MailServerUserName = "xxx@xxx.com"
mail2me.MailServerPassword = "xxxxxx"	
mail2me.Logging = True	'email address from sender
mail2me.AddRecipient "xxx@xxx.com"             		'email address to student
mail2me.Subject = "!domain registration required!"       		'subject of email
mail2me.body = body2me            							'Body of email
mail2me.Send "mail.xxxxxxx.com"

' Send e-mail to new user
Body = "Dear " & Request("M_name") &"," & VBCRLF & VBCRLF 
Body = Body & "Thank you for your recent order from Pulse Interactive. You opted to pay " & Request("M_payment") & "." & VBCRLF
Body = Body & "Your login details are as follows:" & VBCRLF
Body = Body & "Your web address: " & Request("M_domain") & VBCRLF
Body = Body & "Your ftp address:  ftp." & Request("M_domain") & VBCRLF
Body = Body & "Your temporary FTP address: ftp://ftp.xxxx.co.uk/" & Request("M_domain") & "/" & VBCRLF
Body = Body & "Your temporary web address: [URL unfurl="true"]www.xxxx.co.uk/"[/URL] & Request("M_domain") & "/" & VBCRLF
Body = Body & "Your  FTP username is : " & Request("M_domain") & VBCRLF
Body = Body & "Your FTP password is : " & Request("M_password") & VBCRLF & VBCRLF
Body = Body & "To log-in to the administration area please visit [URL unfurl="true"]http://admin.xxxx.co.uk[/URL] and enter your login details" & VBCRLF
Body = Body & "From here you can add/remove email addresses, databases and more... Your login information for this area is below" & VBCRLF
Body = Body & "Your Administration login is : admin@" & Request("M_domain") & VBCRLF
Body = Body & "Your Administration password is : " & Request("M_password") & VBCRLF
Body = Body & "This email address is also your 'catch-all' email address(please visit [URL unfurl="true"]http://mailadmin."[/URL] & Request("M_domain") &" to add/remove email accounts." & VBCRLF & VBCRLF
Body = Body & "To download mail on the move, why not use the webmail service located at [URL unfurl="true"]http://mail."[/URL] & Request("M_domain") & ". You can send and receive, even add attachments!" & VBCRLF & VBCRLF
Body = Body & "Thank you for your order. Please wait between 24-48 hours for the domain information to be propagated with xxxxxxxxxx" &VBCRLF
Body = Body & "Until then please test your site using the temporary addresses given" & VBCRLF & VBCRLF
Body = Body & " Kind Regards" & VBCRLF & VBCRLF
Body = Body & " Sales Dept." & VBCRLF & VBCRLF
Body = Body & " xxxxxx"

Dim usermailer

Set usermailer = Server.CreateObject("JMail.Message")
usermailer.From = "admin@xxxxx.co.uk"			
usermailer.MailServerUserName = "xxxx@xxxx.com"
usermailer.MailServerPassword = "xxxx"	
usermailer.Logging = True	'email address from sender
usermailer.AddRecipient Request("M_otheremail")                      		'email address to student
usermailer.Subject = "xxxxxxx hosting package order"       		'subject of email
usermailer.body = Body            							'Body of email
usermailer.Send "mail.xxxxx.com"%>

Any help would be most appreciated!!!

Thanks
 
Well there are at least 3 For/Next loops...

Or you you mean that the entire page is being called a second time?
 
Sorry, the WHOLE page is being called for a second time... I don't suppose it would have anything to do with my IIS settings would it? Thank you
 
stevebanks,

The asp page is being actioned upon by a page where the students register themselves for their own sites etc. In that matter, you cannot take it for granted that they, or even professors for that matter, do it right the first time all the data. Or they do not casually register themselves again.

Even they do it carefully the first time, you cannot take it for granted that they do not change their mind on the setting of some of their attributes, such as password etc. some time later.

Hence, you have to provision measure in the script to check :
[1] If the folder ...\domain\web or ...\domain\db exist, do not create them anymore.
[2] If the user with samaccountname domain already exists in the WinNT namespace, do not create it again. But rather get (bind) to the user object and modify the properties according to the user's will.
[3] Similarly for site and mail accounts etc etc.

The burden is really on the script writer rather than the users---that would be to much to ask on the part of users.

regards - tsuji
 
Hi Tsuji,

Thanks for the information, the script is not currently live, and I am testing it, and it still loops itself on its own... The folders domain\web and domain\db cannot exist before the script runs, the folder name is decided by the domain e.g. microsoft.com and, as is known, one cannot have two domains the same, therefore the folder could not be created twice, this is also the case with the username which is "xxx.com" thus allowing no repetition, as before the user gets to this page they have passed through a domain name availability check.. Do you have any other ideas as to why it would loop? Would IIS be the root of my problem, application pools etc...??

Thanks


Steve
 
stevebanks,

Actually I do not see that the script as you shown us will execute twice.

The only reason I can think of is that the source script submit action submit twice on the client side. It is not uncommon for misconceived form submit to act up like that.

- tsuji
 
I have been querying it using a querystring! so, unfortunately not a possibility!
 
stevebanks,

I meant you have to look again at the page where the form is exposed to the client. In particular, take a look at its submit mechanism.

- tsuji
 
Thats what i am saying, I haven't been using a form to submit from when testing just a ?xyz=qwe&sdf=123 etc... so the form submit mechanism has nothing to do with it!

Thanks

steve
 
I could be wrong, as I haven't done a lot of scripting for DC's, but it look slike your adding the user to the DC using the recordset then you attempt to add them a second time with your WinNT call...

Generally I just do everything from an LDAP:// call so I haven't used the recordset method or WinNT domain address...

Also, does it appear that the whole script is repeating twice or only certain portions? Could you maybe increment and display a numeric counter in a session variable to see if it is truly executing twice or you just have the same thing happening twice due to either an external application triggering off a series of additions or your WinNT vs recordset Domain access stuff?

-T

barcode_1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top