DoWork.asp
At the start of DoWork.asp multiple constants
are set and will need to be changed for your environment. Those are
StorageGroup, StoreName, ServerName, Admingroup, and ExchangeOrg.
These settings are used to mailbox enabled users. The code then
gets the current domain name the user is logged into, for the code
to work the user must be authenticated by IIS.
Set rootDSE = GetObject("LDAP://rootDSE")
DomainDN =
rootDSE.Get("defaultNamingContext")
DomainDN gets the distinguished name of the
domain the authenticated user is logged into. For example, in
my domain this would return 'DC=Altered,DC=Net'.
Next the SubmitType is retrieved from
CreateUser.asp, currently the pages only support creating users but
I do plan on expanding it to support resetting passwords and
updating properties at some point in the near future. Using a Case
statement the
CreateUser sub is called.
CreateUser first confirms some of the values are set
correctly. For example Password1 and Password2 and check to make
sure they match. Next the value of 'User Type' is checked in a Case
statement. The Case statement searches on the samAccountName, using
the FindObjectPath function, in the domain. If the user is not
found or the passwords don't match DoWork.asp exist. The Case
statement below will need to be customized for the name of your
template accounts and 'User Types' in the CreateUser.asp page:
CODE SAMPLE 1:
Select Case
UCase(Request.Form("UserType"))
Case "DDO"
UserTemplateName = "_DDOTemplate"
UserTemplatePath = FindObjectPath ("samAccountName",UserTemplateName,DomainDN)
If
UserTemplatePath = "" Then
Response.Write("Template account not found<BR>")
Exit Sub
End If
Case "TAC"
UserTemplateName = "_TACTemplate"
UserTemplatePath = FindObjectPath ("samAccountName",UserTemplateName,DomainDN)
If
UserTemplatePath = "" Then
Response.Write("Template account not found<BR>")
Exit Sub
End If
Case Else
Response.Write("Unsupported user type, aborting<BR>")
Exit Sub
End Select
In the code above two user types are supported,
'DDO' and 'TAC', and the
UserTemplateName for needs to be changed to match the
pre-Windows 2000 (samAccountName) of the
template accounts in your environment.
In CreateUser.asp three options are listed for
'User Type', only two are supported in DoWork.asp. The ASP code
below will need to be customized for your environment also:
CODE SAMPLE 2:
<select id="UserType"
name="UserType" class="drop" size="1">
<option
value="EMail">E-Mail Ony</option>
<option
value="DDO">D&D On-Line Guild Member</option>
<option
value="TAC" selected>Afternoon Club</option>
</select></td>
In the code above 'Email', 'DDO', and 'TAC'
must be changed to match the values in Case statement in DoWork.asp
above, see CODE SAMPLE 1. The 'selected'
text controls which option will be the default, or selected, option
in the drop-down; in this case it will be 'Afternoon Club'.
Each Case statement in CODE SAMPLE 1
searches the AD, using the
FindObjectPath function, for
the template account. See my previous article,
Searching the AD, for more details on how
FindObjectPath works. Once the template user is
found the OU it exists in is retrieved. In addition, the values
entered in the CreateUser.asp form are stored in local variables.
The code then checks to make sure the User Name (samAccountName)
entered doesn't already exist in the domain. The key values entered
are then displayed on a new page opened up by CreateUser.asp. Next
the options selected for the mail section are checked to make sure
they are valid, at least basically.
Assuming all of the options selected are valid
and the other checks pass the page will the start the user creation
process. The following attributes are then set based on values
entered in the CreateUser page:
cn = Display Name:
samAccountName = User Name:
userPrincipalName= User Name@<DNS
Domain name>
displayName = Display Name:
givenName = First Name:
sn = Last Name:
telephoneNumber = Phone #:
info = IM Addresses and notes:
Once the user object is created the
CopyGroups sub is called,
which copies the group membership of the template account. Then
CopyAttributes sub is called, which copies any
attributes in the Notes (info)
field of the template account to the new user account. The password
on the account is then set and the account is enabled. The default
password for new users will be 'Passw0rd!' but can be changed by
editing the following line in CreateUser.asp:
CODE SAMPLE 3:
<input
name="Password1" class="all" id="Password1" size="20"
type="password" value="Passw0rd!">
'
<input
name="Password2" class="all" id="Password2" size="20"
type="password" value="Passw0rd!">
Find the above lines of code in CreateUser.asp
and change 'Passw0rd!' to the preferred default password you want
for new users. When creating a new user account any password can be
entered.
If 'Mail Enable' is selected the page will then
mail enable the new user and add create an internal address based on
the value entered in 'E-mail address prefix' and the value in the
E-mail (mail) field of the template
account. This allows the new user to have an e-mail address in your
domain name but have mail sent to it forwarded to the external
address specified. If 'Create Mailbox' was selected then an
Exchange mailbox is created for the user and the primary e-mail
address is set to value entered in 'E-mail address prefix' and the
E-mail (mail)
field of the template account. |