Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-10 of 10 total  RSS 

ASP Page listing and making changes to AD accounts

// Used for automated AD account migration
<HTML><HEAD><TITLE>Workstation User Account migration</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK 
href="files/v2006.css" type=text/css rel=stylesheet>
<BODY leftMargin=0 topMargin=30 marginwidth="0" marginheight="0">
<CENTER>
<%
' ------------------------------------------------------------------------
Const ADS_PROPERTY_CLEAR = 1

Const SOURCE_OU="ou=NT Users,ou=NT,dc=fr,dc=erm,dc=int"
Const TARGET_OU="ou=SUPPORT SERVICES,dc=fr,dc=erm,dc=int"

Const HOMES_PATH="\\frsrvfil0001\USERS\"
Const PROFILES_PATH="\\frsrvfil0001\PROFILES\"

Const ADMIN_HOMES_PATH_SOURCE="\\frsrvfil0001\U$\NT\"
Const ADMIN_PROFILES_PATH_SOURCE="\\frsrvfil0001\P$\NT\"
Const ADMIN_HOMES_PATH_DEST="\\frsrvfil0001\U$\"
Const ADMIN_PROFILES_PATH_DEST="\\frsrvfil0001\P$\"

Const SCRIPT_NAME="ntuser_to_xp.asp"

Dim State
State="Init"
Dim OU, Member
 
If Request.QueryString("login") <> "" Then
		' Affichage formulaire pour modif du compte
		State="Info"
End If
If Request.Form("login") <> "" Then
		' On a cliqué sur OK pour valider le formulaire
		State="Modify"
End If
' ------------------------------------------------------------------------
%>
<TABLE cellSpacing=0 cellPadding=1 width=500 align=center bgColor=#26333e 
border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=1 width=500 align=center border=0>
        <TBODY>
        <TR bgColor=#f0f3f5>
          <TD width=160 valign="top"><IMG height=116 src="files/man_portable.jpg" 
            width=160> </TD>
          <TD width=302 bgColor=#e5ebef>

<%
	If State="Init" Then
	'-----------------------------------------------------------------------------------
	' Listing of the NT Users
	'-----------------------------------------------------------------------------------
%>          

            <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
            border=0>
              <TBODY>
              <TR>
                <TD class=medium colSpan=3 height=22>
                    <%
                    'Response.Write(SOURCE_OU & "<BR>") 
                    %>
					Please select the NT 4.0 Workstation user account to migrate
                </TD></TR>
                
              <TR>
                <TD class=td11 height=22>
                                  <%
                  Set OU = GetObject("LDAP://" & SOURCE_OU)
                  OU.Filter = Array("user")
    	          For Each Member In OU
    	          		' Bug with the SMS Account ??
    	          		If Member.Name <> "CN=SMSService" Then 
    	          		If Member.AccountDisabled = 0 Then
	    	                Response.Write("<A HREF=""" & SCRIPT_NAME & "?login=" & Server.URLEncode(Member.Name) & """>" & Member.FullName & "</A><BR>")
	    	            End If
	    	            End If 
            	  Next      
                  
                  %>

                </TD>
                </TR>
                
                </TBODY></TABLE>

<%
End If
%>                
                
<%
	If State="Info" Then
	'-----------------------------------------------------------------------------------
	' Information page about the NT Users
	'-----------------------------------------------------------------------------------
%>          
			<FORM method=post>

            <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
            border=0>
              <TBODY>
              <TR>
                <TD class=medium colSpan=2 height=22>
                 	<%
                 	Response.Write("Windows NT 4.0 User Account Migration")
                    %>
					
                </TD></TR>
               
                  <%
                  Sub TabRow(v1,v2)
                  		Response.Write("<TR class=td11 height=16><TD><B>" & v1 & "</B>")
                  		Response.Write("<TD>" & v2 & "</TD>")
                  		Response.Write("</TD></TR>")
                  End Sub
                  Set Member = GetObject("LDAP://" & Request.QueryString("login") & "," & SOURCE_OU)

                  TabRow "User Name",Member.FullName
                  TabRow "NT Login",Member.sAMAccountName
				  TabRow "Login Script", Member.LoginScript & " (to delete)"
				  TabRow "Profile Path", Member.Profile
				  TabRow "New Path",PROFILES_PATH & Member.sAMAccountName
				  TabRow "Home Folder", Member.HomeDirectory
				  TabRow "New Path",HOMES_PATH & Member.sAMAccountName
				  
				  ' Liste des OU dans SUPPORT SERVICES
 				  Dim OUSuppServices, Entity, BoxList
 				  Set OUSuppServices=GetObject("LDAP://" & TARGET_OU)
				  OUSuppServices.Filter = Array("organizationalUnit")
				  BoxList="<SELECT NAME=""entity"">"
				  For Each Entity in OUSuppServices
				  	BoxList= BoxList & "<OPTION VALUE=""" & Entity.Name & """>" & Mid(Entity.Name,4) & "</OPTION>"
				  Next
				  BoxList=BoxList & "</SELECT>"
				  TabRow "Organizational Unit",BoxList
                                    
                  %>

                
                </TBODY></TABLE>
                <BR>
                <INPUT name=login type=hidden value=<% Response.Write(Member.sAMAccountName) %> >
                <INPUT type=image height=18 alt="GO !" width=15 src="files/submit.gif" value=login border=0 name=ok>
                &nbspCliquer ici pour migrer ce compte.<BR><BR>
                ATTENTION, l'utilisateur ne doit pas être connecté ! 
                <% Response.Write("<BR><BR><A HREF=""" & SCRIPT_NAME & """>" & "Cliquer ICI pour annuler" & "</A><BR>") %>
                </FORM>

<%
End If
%>                

<%

	If State="Modify" Then
	'-----------------------------------------------------------------------------------
	' Migration of the NT Users
	'-----------------------------------------------------------------------------------
Sub dirMoveTree(source, dest)
	Response.Write "Deplacement de <B>" & source & " vers " & dest & "</B><BR>"
	Dim Folder,File,SubFolder
	set Folder=fso.GetFolder(source)
	For Each File In Folder.Files
	      Response.Write File.Name & " File -> " & dest & "<BR>"
	      file.move dest & "\"
	Next
	For Each SubFolder In Folder.SubFolders
	      Response.Write SubFolder.Name & " Folder -> " & dest & "<BR>"
	      SubFolder.move dest & "\"
	Next
End Sub

%>          
<CENTER>
Windows NT 4.0 User Account Migration<BR><BR>
<%

' Modification des proprietes l'utilisateur dans AD
Set Member = GetObject("LDAP://" & Request.QueryString("login") & "," & SOURCE_OU)

' ADS_PROPERTY_CLEAR
Member.PutEx 1, "scriptPath", 0
Member.SetInfo

Member.Put "profilePath", PROFILES_PATH & Member.sAMAccountName
Member.Put "homeDirectory", HOMES_PATH & Member.sAMAccountName
' 
Member.SetInfo
' 
Response.Write("Utilisateur <B>" & Member.sAMAccountName & "</B> Modifié dans AD<BR><BR>")

' Deplacement dans le bon conteneur
Set OU = GetObject("LDAP://" & "OU=Users," & Request.Form("entity") & "," & TARGET_OU)
OU.MoveHere "LDAP://" & Request.QueryString("login") & "," & SOURCE_OU, Request.QueryString("login")
Response.Write("Utilisateur <B>" & "LDAP://" & Request.QueryString("login") & "," & SOURCE_OU & "</B> Deplacé dans " & "LDAP://" & "OU=Users," & Request.Form("entity") & "," & TARGET_OU & "<BR><BR>")

DIM fso, File, Folder, SubFolder
Set fso = CreateObject("Scripting.FileSystemObject")

' Creation des repertoires cible

fso.CreateFolder(ADMIN_HOMES_PATH_DEST & Request.Form("login"))
fso.CreateFolder(ADMIN_PROFILES_PATH_DEST & Request.Form("login"))

' Deplacement des données

dirMoveTree ADMIN_HOMES_PATH_SOURCE & Request.Form("login"),ADMIN_HOMES_PATH_DEST & Request.Form("login")
dirMoveTree ADMIN_PROFILES_PATH_SOURCE & Request.Form("login"),ADMIN_PROFILES_PATH_DEST & Request.Form("login")

' Applications des ACLs, en arriere plan car ca peut etre long !
Response.Write("<BR>Creation du script d'application des ACLs C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd<BR><BR>")
Set server_shell = Server.CreateObject("wscript.shell")

server_shell.Run "cmd /c echo echo Excecution Cacls >C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1
server_shell.Run "cmd /c echo xcacls.exe """ & ADMIN_HOMES_PATH_DEST & Request.Form("login") & """ /T /C /G SYSTEM:F ADMINISTRATORS:F FR-ERM\" & Request.Form("login") & ":C /Y >>C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1
server_shell.Run "cmd /c echo xcacls.exe """ & ADMIN_PROFILES_PATH_DEST & Request.Form("login") & """ /T /C /G SYSTEM:F ADMINISTRATORS:F FR-ERM\" & Request.Form("login") & ":F /Y >>C:\Inetpub\wwwroot\techcity\xcacls_" & Request.Form("login") & ".cmd 2>&1",,1

' server_shell.Run "C:\Inetpub\wwwroot\techcity\xcacls.cmd >C:\Inetpub\wwwroot\techcity\xcacls.log 2>&1",,1
Response.Write("<BR>Les ACLs seront appliquee dans 5 min (scheduled)...<BR><BR>")
Response.Write("Attendre egalement la fin de replication de AD ...<BR><BR>")

Response.Write("<BR>Terminé !<BR>")

%>
<% Response.Write("<BR><BR><A HREF=""" & SCRIPT_NAME & """>" & "Cliquer ICI pour quitter" & "</A><BR>") %>
</CENTER>
<%
End If
%>                


              </TD></TR>            
                
                </TBODY></TABLE></TD></TR>
                        
                
</TBODY></TABLE></CENTER></BODY></HTML>

Simple ASP page to reset passwords

// This page allows to reset an AD account password.
<HTML><HEAD><TITLE>Reinitialisation de mot de passe</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"><LINK 
href="files/v2006.css" type=text/css rel=stylesheet>
<BODY leftMargin=0 topMargin=30 marginwidth="0" marginheight="0">
<FORM method=post>
<CENTER>
<TABLE cellSpacing=0 cellPadding=1 width=500 align=center bgColor=#26333e 
border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=1 width=500 align=center border=0>
        <TBODY>
        <TR bgColor=#f0f3f5>
          <TD width=160><IMG height=116 src="files/man_portable.jpg" 
            width=160> </TD>
          <TD width=302 bgColor=#e5ebef>
            <TABLE cellSpacing=4 cellPadding=4 width="100%" align=center 
            border=0>
              <TBODY>
              <TR>
                <TD class=medium colSpan=3 height=22>
                <%
                If Request.Form("login") = "" Then
                	Response.Write("<B>Saisir le compte à reinitialiser</B>")
                Else
                    Dim Group, Member, Domain, UserFound
                    ' 
                    Domain ="FR-ERM"
                    '
                    UserFound=0
                    
	                Set Group = GetObject("WinNT://" & Domain & "/Domain Users")
    	            For Each Member In Group.Members
    	            	' Response.Write(Member.Name & "<BR>")
        	        	If UCase(Member.Name) = UCase(Request.Form("login")) Then
        	        		UserFound=1
        	        		If Member.AccountDisabled Then 
        	        			Response.Write(" " & Request.Form("login") &" est un compte desactive</B>")
        	        			Exit For
        	        		Else
        	        			' Essai de reinit de mot de passe
        	        			Dim res
        	        			res=Member.SetPassword(Request.Form("pass"))
        	        			'Member.Put "pwdLastSet", CLng(0)
        	        			Member.Put "PasswordExpired", 1
								Member.SetInfo
        	        			Response.Write("<B>L'utilisateur "& Request.Form("login") & " a changé de mot de passe !<BR><BR></B>Il devra changer de mot de passe au prochain login.")
        	        			Exit For
        	        		End If
        	        	End If 
            	    Next      
       	        	If UserFound = 0 Then
       	        		Response.Write(Request.Form("login") &" non trouvé dans le domaine "& Domain)
       	        	End If           	            	
                	
                End If
                %>
              
                </TD></TR>
              <TR>
                <TD class=td11 width="1%" height=22>Identifiant
               
                </TD>
                <TD class=td11 colSpan=2>Nouveau mot de passe</TD></TR>
              <TR>
                <TD width="25%"><INPUT maxLength=20 name=login>
 
                </TD>
                <TD width="20%"><INPUT type=password maxLength=10 size=10 
                  name=pass> </TD>
                <TD><INPUT type=image height=18 alt="Reset !" width=15 
                  src="files/submit.gif" value=login border=0 name=ok> 
                </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER></FORM></BODY></HTML>

Vbscript Array sort in alphabetical order

// sort vbscript array

<%
dim arrSortOut(8)
arrSortOut(0)="xCount"
arrSortOut(1)="zExec"
arrSortOut(2)="yFinance"
arrSortOut(3)="HR"
arrSortOut(4)="IT "
arrSortOut(5)="!aaaLegal"
arrSortOut(6)="Liberman"
arrSortOut(7)="Martha"
arrSortOut(8)="Regis"

for x=0 to 8
response.write arrSortOut(x)&"<br>"
next

response.write "<br>"

for i = UBound(arrSortOut) - 1 To 0 Step -1
    for j= 0 to i
        if arrSortOut(j)>arrSortOut(j+1) then
            temp=arrSortOut(j+1)
            arrSortOut(j+1)=arrSortOut(j)
            arrSortOut(j)=temp
        end if
    next
next 


for x=0 to 8
response.write arrSortOut(x)&"<br>"
next

%>

Write all ASP page variables

// description of your code here

<%
  Response.Write "Server Variables" & "<br><br>"
For Each strName in Request.ServerVariables
  Response.Write strName & " - " & Request.ServerVariables(strName) & "<BR>"
Next

  Response.Write "Session Variables" & "<br><br>"
For Each strName in Session.Contents
  Response.Write strName & " - " & Session.Contents(strName) & "<BR>"
Next

  Response.Write "Form Variables" & "<br><br>"
For Each strName in request.form
  Response.Write strName & " - " & request.form(strName) & "<BR>"
Next

  Response.Write "String Variables" & "<br><br>"
For Each strName in request.querystring
  Response.Write strName & " - " & request.querystring(strName) & "<BR>"
Next
%>

Simple FSO directory file listing

// simple browsing tool

<%

dim aryURL, URLvar
aryURL = Split(Request.ServerVariables("SCRIPT_NAME"), "/", -1, 1)
URLvar = aryURL(ubound(aryURL))

if request.querystring("sPP")<>"" then 
	
	sPP=request.querystring("sPP") & "\"
	ParentVar="<a href=""#"" onClick=""history.go(-1)"">Parent Directory</a><br><br>" & vbCrLF
else
	sPP = "\\serverlocation\"
end if

	
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set f = fso.GetFolder(sPP)  
	Set fc = f.Files 
	Set ff = f.SubFolders 
	For Each f1 in ff	
	  HeaderVar=HeaderVar& "<a href=""" & URLvar & "?sPP=" & sPP & f1.name & """>" & f1.name & "</a> &nbsp;|&nbsp;" & vbCrLF
	Next  
	For Each f1 in fc
	  SubHeaderVar=SubHeaderVar& "<a href=""" & sPP & f1.name & """>" & f1.name & "</a> <br>" & vbCrLF
	Next  
	Set ff = nothing
	Set fso = nothing
	Set f = nothing
	Set fc = nothing


response.write ParentVar
if HeaderVar<>"" then response.write "<b>Folders" & vbCrLF & "<br><br>&nbsp;|&nbsp;" & vbCrLF & HeaderVar & "</b><br><br>" & vbCrLF
if SubHeaderVar<>"" then response.write "<b>Files</b>" & vbCrLF & "<br><br>" & vbCrLF & SubHeaderVar & vbCrLF

%>




SQL server ASP database test

// basic sql server database asp code test

<%
str_ConnectionString = "Provider=SQLOLEDB;Data Source=servername;Initial Catalog=database;User Id=user;Password=pwd;"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open str_ConnectionString

set rs = Server.CreateObject("ADODB.recordset")
strSQL="select * from tablename"

rs.Open strSQL, oConn

do until rs.EOF
	for each x in rs.Fields
		response.write x.value & "|"
	next
	rs.MoveNext
	response.write "<br>"
loop	

rs.Close

oConn.Close
set oConn = Nothing
%>

Auto-store all request variables

// Puts all request variables into local variables. Never type request.querystring again. Easily modified to work with option explicit.

<%
	For each item in Request.querystring
		If not len(item) <= 0 Then
			Execute("[" & item & "] = Request(""" & item & """)")
		End If
	Next

	For each item in Request.form
		If not len(item) <= 0 Then
			Execute("[" & item & "] = Request(""" & item & """)")
		End If
	Next
%>

Find the count of a given character in a text string

ASP / VBScript offers no built-in functionality for this.

CharacterCount = Len(MyString) - Len(Replace(MyString, TargetCharacter, ""))

Using Scheme in ASP

;The following example is in VBScript. Any scripting language that uses com objects will be similar
;1 Install PLT Scheme - it will register the dlls
;2 Control Panel > Administrative Tools > Component Services
; My Computer > DCOM Config > MzCOM
; Properties > Security > Launch and Activation Permissions > Customize
; Add Everyone or IUSR_<Computername> Allow Local Launch, Local Activation

;Output
;(define test (lambda () (+ 1 2 3 4 5)))
;15
strScheme = "(define test (lambda () (+ 1 2 3 4 5)))" 'Test Function
    
Set objScheme = Server.CreateObject("MzCOM.MzObj")   
result = objScheme.Eval(strScheme) 
result = objScheme.Eval("(test)")  'It remembers the function
Set objScheme = Nothing

Response.Write(strScheme & "<br>" & result & "<br>") 'Display Results

simple templating engine

this will replace variables within a string that are denoted as [[variable]] and will replace it with the value of data[variable]


function parseTemplate(content, data) {
	content=String(content);
	re = /\[\[(\w*)\]\]/gi;

	return (
		content.replace(
			re, 
			function ($1,$2,$3) {
				return data[$2];
			}
		)
	);
}
« Newer Snippets
Older Snippets »
Showing 1-10 of 10 total  RSS