home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April B / Pcwk4b98.iso / ie401gb / IEAK4.CAB / autocfg2.asp < prev    next >
Text File  |  1997-10-08  |  9KB  |  282 lines

  1. <%
  2.  
  3. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. '% FILE:    AUTOCFG.ASP                  
  5. '% DATE:    08/23/97
  6. '% AUTHOR:     Aaron Barth (MS)
  7. '% DESCRIPTION: Customizable ASP script to perform the
  8. '%             IEAK AutoConfig
  9. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10.  
  11.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  12.     '% Set the DEBUGFLAG Paramter to 
  13.     '% TRUE to DEBUG this File. By Default this Parameter
  14.     '% is FALSE
  15.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16.     DEBUGFLAG = FALSE
  17.     
  18.     if DEBUGFLAG =TRUE then
  19.         Response.Write "<FONT COLOR=RED> <B>DEBUG OUTPUT:</B></FONT><BR>"
  20.     
  21.     end if
  22.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  23.     '% Set AuthUserandDomain to the Authenticated user's
  24.     '% DOMAIN\username
  25.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  26.     
  27.     if Request.Cookies("IEAKUser") = "" then
  28.         AuthUserandDomain="DOMAIN\guest"
  29.     else
  30.         AuthUserandDomain = Request.Cookies("IEAKUser")
  31.     end if
  32.  
  33.     if DEBUGFLAG =TRUE then
  34.         Response.Write AuthUserandDomain & "<BR>"
  35.         Response.write "Authentication Method: " & Request.ServerVariables("AUTH_TYPE") & "<BR>"
  36.     end if
  37.  
  38.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  39.     '% Flip the "\" to a "/" so that the ADSI Command
  40.     '% GetObject:// can use it
  41.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  42.     AuthUserandDomain = Replace(AuthUserandDomain, "\", "/")
  43.     if DEBUGFLAG = TRUE then
  44.         Response.Write AuthUserandDomain + "<BR>"
  45.     end if 
  46.  
  47.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  48.     '% Because GetUser() is a destructive function, copy
  49.     '% the value of the the DOMAIN/username into UserandDomain
  50.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  51.     UserandDomain = AuthUserandDomain
  52.  
  53.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  54.     '% User the GetUser function to strip off the Domain
  55.     '% Name from UserandDomain and put it in AuthUser for
  56.     '% later
  57.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  58.     AuthUser = GetUser(UserandDomain)
  59.     if DEBUGFLAG = TRUE then
  60.         Response.Write AuthUser + "<BR>"
  61.     end if
  62.  
  63.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  64.     '% Use the GetObject (ADSI) to obtain the user object
  65.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  66.     Set User=GetObject("WinNT://" & AuthUserandDomain)
  67.     
  68.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  69.     '% Loop through all User.Groups looking for the "IE_"
  70.     '& prefix to a group name
  71.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  72.     For Each Group in User.Groups
  73.         if Left(Group.Name, 3) = "IE_" then
  74.             IsGroupMember = TRUE
  75.             IEGroupName = Group.Name
  76.         end if
  77.     Next
  78.  
  79.  
  80.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  81.     '% If user is a Member of IE_ [groupname] then
  82.     '% Build a custom INSFile
  83.     '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  84.     if IsGroupMember = TRUE then
  85.         if DEBUGFLAG = TRUE then
  86.             Response.write IEGroupName & "<BR>"
  87.         end if
  88.  
  89.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90.         '% Create the Conn Object and open it
  91.         '% with the supplied parameters
  92.         '% from the global.asa
  93.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  94.  
  95.         Set Conn = Server.CreateObject("ADODB.Connection")
  96.         Set rs = Server.CreateObject("ADODB.RecordSet")
  97.         Conn.Open Session("DataConn_ConnectionString"), Session("DataConn_RuntimeUserName"), Session("DataConn_RuntimePassword")
  98.  
  99.  
  100.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  101.         '% Create the SQL Statement to Select
  102.         '% GroupName and INSFile from IEgroup
  103.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  104.  
  105.         sql="SELECT * FROM IEGroup"
  106.         sql = sql & " WHERE GroupName"
  107.         sql = sql & " LIKE '" & IEGroupName & "'"
  108.  
  109.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  110.         '% When DEBUGFLAGE = TRUE.. Echo the SQL Statement
  111.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  112.         if DEBUGFLAG = TRUE then
  113.             Response.Write "<B><FONT SIZE=2 COLOR=BLUE>SQL STATEMENT: </B>" & sql & "<HR>" 
  114.         end if
  115.  
  116.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  117.         '% Open the RecordSet (RS) and pass it 
  118.         '% the connection (conn) and the SQL Statement (sql)
  119.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  120.         RS.Open sql, Conn, 1
  121.         RS.MoveFirst
  122.  
  123.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  124.         '% If the SQL statement does not return
  125.         '% any matches, write out a nice error statment
  126.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  127.         if RS.EOF then
  128.             Response.Write "No Configuration defined for " & IEGroupName & "<BR>"
  129.         else
  130.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  131.             '% Retrieve the whole INS file from
  132.             '% the DB and put it in TheINSFile
  133.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  134.             TheINSFile = RS("INSFile")
  135.             TheINSFileName = IEGroupName & ".INS"        
  136.  
  137.             if DEBUGFLAG = TRUE then
  138.                 Response.Write "<HR>" & TheINSFile & "<HR>"
  139.                 Response.Write "<HR>" & TheINSFileName & "<HR>"
  140.             end if 
  141.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  142.             '% Write information out to a text file
  143.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  144.             Set fs = CreateObject("Scripting.FileSystemObject")
  145.             filepath = server.mappath(TheINSFileName)
  146.             Set a = fs.CreateTextFile(filepath, True)
  147.             a.WriteLine(TheINSFile)
  148.             a.close
  149.             
  150.         end if
  151.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152.         '% Close the RecordSet (RS) 
  153.         '% and the Connection (Conn)
  154.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  155.         RS.Close
  156.         Conn.Close
  157.         
  158.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  159.         '% If DEBUGFLAG <> TRUE, send the 
  160.         '% file to the browser
  161.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  162.         if DEBUGFLAG = TRUE then
  163.             Response.Write "If you weren't debugging this File you would be redirected to " & TheINSFileName
  164.         else
  165.             Response.redirect TheINSFileName
  166.         end if 
  167.  
  168. else 
  169. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  170. '% Retrieve the Default INS File
  171. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  172.         if DEBUGFLAG = TRUE then
  173.             Response.write "Default User <BR>"
  174.         end if
  175.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  176.         '% Create the Conn Object and open it
  177.         '% with the supplied parameters
  178.         '% from the global.asa
  179.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  180.  
  181.         Set Conn = Server.CreateObject("ADODB.Connection")
  182.         Set rs = Server.CreateObject("ADODB.RecordSet")
  183.         Conn.Open Session("DataConn_ConnectionString"), Session("DataConn_RuntimeUserName"), Session("DataConn_RuntimePassword")
  184.  
  185.  
  186.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  187.         '% Create the SQL Statement to Select
  188.         '% GroupName and INSFile from IEgroup
  189.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  190.  
  191.         sql="SELECT * FROM IEGroup"
  192.         sql = sql & " WHERE GroupName"
  193.         sql = sql & " LIKE 'Default'"
  194.  
  195.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  196.         '% When DEBUGFLAGE = TRUE.. Echo the SQL Statement
  197.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  198.         if DEBUGFLAG = TRUE then
  199.             Response.Write "<B><FONT SIZE=2 COLOR=BLUE>SQL STATEMENT: </B>" & sql & "<HR>" 
  200.         end if
  201.  
  202.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  203.         '% Open the RecordSet (RS) and pass it 
  204.         '% the connection (conn) and the SQL Statement (sql)
  205.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  206.         RS.Open sql, Conn, 1
  207.         RS.MoveFirst
  208.         
  209.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  210.         '% If the SQL statement does not return
  211.         '% any matches, write out a nice error statment
  212.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  213.         if RS.EOF then
  214.             Response.Write "No Configuration defined for " & IEGroupName & "<BR>"
  215.         else
  216.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  217.             '% Retrieve the whole INS file from
  218.             '% the DB and put it in TheINSFile
  219.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  220.             TheINSFile = RS("INSFile")
  221.             TheINSFileName = "Default.INS"
  222.         
  223.         
  224.             if DEBUGFLAG = TRUE then
  225.                 Response.Write "<HR>" & TheINSFile & "<HR>"
  226.                 Response.Write "<HR>" & TheINSFileName & "<HR>"
  227.             end if 
  228.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  229.             '% Write information out to a text file
  230.             '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  231.             Set fs = CreateObject("Scripting.FileSystemObject")
  232.             filepath = server.mappath(TheINSFileName)
  233.             Set a = fs.CreateTextFile(filepath, True)
  234.             a.WriteLine(TheINSFile)
  235.             a.close
  236.         end if
  237.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  238.         '% Close the RecordSet (RS) 
  239.         '% and the Connection (Conn)
  240.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  241.         RS.Close
  242.         Conn.Close
  243.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  244.         '% If DEBUGFLAG <> TRUE, send the 
  245.         '% file to the browser
  246.         '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%        
  247.         if DEBUGFLAG = TRUE then
  248.             Response.Write "If you weren't debugging this File you would be redirected to " & TheINSFileName
  249.         else
  250.             Response.redirect TheINSFileName
  251.         end if 
  252.     end if
  253.  
  254. Function GetUser(username)
  255.  
  256. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  257. 'Syntax:  username = DOMAIN/username
  258. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  259.  
  260.  ' this is a destructive function, modifying the
  261.  ' passed in string
  262.  
  263.  ' trim leading slashes
  264.  While Mid(username, 1, 1) = "/"
  265.    username = Mid(username, 2)
  266.  Wend
  267.  
  268.  ' find next slash
  269.  pos = InStr(1, username, "/")
  270.  If pos = 0 Then
  271.   ' return the remaining string and null it out
  272.   GetUser = username
  273.   username = ""
  274.  Else
  275.   ' extract next user and chop username
  276.   GetUserFromString = Mid(username, 1, pos - 1)
  277.   username = Mid(username, pos + 1)
  278. GetUser = username
  279.  End If
  280. End Function
  281. '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  282. %>