<!--#include virtual="/NR/Shared/ASPUtils.inc"-->
<!--#include virtual="/NR/System/Access/Constants/UIStringConstants.inc" -->
<!--#include virtual="/NR/System/Access/Constants/LayoutConstants.inc" -->
<!--#include virtual="/NR/System/Access/Constants/ProgrammingConstants.inc" -->
<!--#include virtual="/NR/System/WBC/Internals/ServerControls/StateControl/CNCStateControl.inc"-->
<!--#include file="CNCStateRenderer_SecurityAlert.inc" -->

<%
' ********************************************************************
' Copyright (C) 2001 Microsoft Corporation. All rights reserved.
'
'	IMPORTANT.  Please read the legal.txt file, located in the
'	"<CMS Install Directory>\Server\httpexec\WBC\Internals"
'	directory, governing the use of this internal file."
' ********************************************************************

' ********************************************************************
' File:		/NR/System/Access/CNCASPPageManager_ManualLogin.inc
' Version: 	Microsoft Corporation
' Author:	Microsoft Corporation
' Purpose:	Encapsulate the ASP logic associated with ManualLogin.asp
'
' Implements the INCASPPageManager interface:
'	- Sub InitManager()
'	- Sub SetupCheckBoxStateControl()
'	- Sub SetupSSLRunningFlag()

'	- Property CheckBoxStateControl
'	- Property ReasonText
'	- Property SiteServerMessageURL
'	- Property DomainsList
'	- Property IsUsingSiteServerAuthentication
'	- Property IsSSLRunning
'	- Property ReturnUrl
'	- Property ShowSSLWarning
'	- Property IsLocalHost
'
' *********************************************************************

Class CNCASPPageManager_ManualLogin

	Public CheckBoxStateControl

	Private m_arrayDomains
	Private m_strURLSiteServerMessage
	Private m_bSSLRunning
	Private m_bIsUsingSiteServerAuthentication
	Private m_strReasonText
	Private m_strReturnUrl
	Private m_strShowSSLWarning
	Private m_strUserIIS
	Private m_bIsLocalHost

	Public Property Get ReasonText
		ReasonText = m_strReasonText
	End Property

	Public Property Get SiteServerMessageURL
		SiteServerMessageURL = m_strURLSiteServerMessage
	End Property

	Public Property Get DomainsList
		DomainsList = m_arrayDomains
	End Property

	Public Property Get IsUsingSiteServerAuthentication
		IsUsingSiteServerAuthentication = m_bIsUsingSiteServerAuthentication
	End	Property

	Public Property Get IsSSLRunning
		IsSSLRunning = m_bSSLRunning
	End Property

	Public Property Get ReturnUrl
		ReturnUrl = m_strReturnURL
	End Property

	Public Property Get UserIIS
		UserIIS = m_strUserIIS
	End Property
	
	Public Property Get IsLocalHost
		IsLocalHost = m_bIsLocalHost
	End Property
	

	' ---- [Private] Class standard initialization routine
	Private Sub Class_Initialize()

		Set m_arrayDomains = Nothing
		m_strURLSiteServerMessage = "#"
		m_bSSLRunning = False
		m_bIsUsingSiteServerAuthentication = False
		m_strReasonText = ""
		m_strReturnUrl = "#"
		m_strShowSSLWarning = ""
		m_strUserIIS = ""
		m_bIsLocalHost = False

	End Sub


	' ---- [Public] Do all the processing before hitting the ASP UI Page
	Public Sub InitManager()

		Dim pAutoSession

		Response.Buffer = True
		Response.Expires = 0


		' Set up data based on query string parameter
		m_strReasonText = Request.QueryString(IDS_ACCESS_QSTR_REASONTXT)
		m_strReturnUrl = Request.QueryString(IDS_ACCESS_QSTR_RETURNURL)
		m_strUserIIS = Request.ServerVariables(IDS_ACCESS_LOGON_USER)

		' Create AutoSession to get the list of domains
		Set pAutoSession = Server.CreateObject("ResolutionObjectModel.AutoSession3")

		' Get the domain Array
		m_arrayDomains = pAutoSession.GetConfiguredDirectories

		' Check for Site Server running or not
		m_bIsUsingSiteServerAuthentication = pAutoSession.IsUsingSiteServerAuthentication

		' Setup SiteServer URL since we need to redirect to this URL if SiteServer is running
		m_strURLSiteServerMessage = "/NR/Shared/NRSiteServerMessage.asp?" & IDS_ACCESS_QSTR_MESSAGETEXT & "=" & Server.URLEncode(IDS_UI_NR_SITESERVER_MESSAGE)

		' Certain kinds of authenicate method should
		' redirect to a different page
		Call ReDirectBasedOnAuthMethod()

		' Set up the state control to keep track of
		' whether has clicked on the check box
		Call SetupCheckBoxStateControl()
	
		' Check if SSL is running
		Call SetupSSLRunningFlag()
		
		' Check if LocalHostConnection
		Call ChkIsLocalHostConnection()
		
	End Sub

	' ---- [Private]  Setup the State Control for the check box
	Private Sub SetupCheckBoxStateControl()

		Set CheckBoxStateControl = New CNCStateControl

		Dim pStateControShowWarning
		Set pStateControlShowWarning = New CNCStateRenderer_SecurityAlert

		Call CheckBoxStateControl.InitStateControl( IDS_STATE_ID_SHOW_SSL_WARNING, pStateControlShowWarning, IDS_STATE_SHOW_SSL_WARNING, True )
		Call CheckBoxStateControl.AddState( IDS_STATE_SHOW_SSL_WARNING )
		Call CheckBoxStateControl.AddState( IDS_STATE_SKIP_SSL_WARNING )

	End Sub

	' ---- [Private] Setup the SSL running flag based on the Server variable
	Private Sub SetupSSLRunningFlag()

		Dim strSSLStatus

		strSSLStatus = CStr(Request.ServerVariables(IDS_ACCESS_HTTPS))

		If strSSLStatus = "on" Then
			m_bSSLRunning = true
		End If

	End Sub

	' ---- [Private] Chk if we are using LocalHost
	Private Sub ChkIsLocalHostConnection()
	
		Dim strRemoteHost
		Dim strLocalHost
	
		strRemoteHost = CStr(Request.ServerVariables(IDS_ACCESS_REMOTE_ADDR))
		strLocalHost = CStr(Request.ServerVariables(IDS_ACCESS_LOCAL_ADDR))
	
		If (strLocalHost = IDS_LOCAL_HOST_ID) OR (strRemoteHost = IDS_LOCAL_HOST_ID) OR _
		   (strLocalHost = strRemoteHost) Then
			m_bIsLocalHost = True
		End If


	End Sub

	' ---- [Private] Redirect to diff places based on different Authenicate Method
	Private Sub ReDirectBasedOnAuthMethod()

		' Handle IIS Authentication if configured
		If IsUsingIISAuthentication Then

			If g_pASPPageManager.UserIIS = "" Then

				' IIS authentication required and there is no logged in user, so
				' request IIS Authentication.

				RequestIISAuthentication("Access Denied")
			Else
				' IIS authentication required and there is an IIS user, so just
				' redirect to the next url. Note, logout to guest, and login as
				' a different user are not supported for IIS authentication.

				If ( Request.Cookies( CSTR_COOKIE_USING_IIS ) = "") Then
					Response.Cookies( CSTR_COOKIE_USING_IIS ) = "True"
					Response.Cookies( CSTR_COOKIE_USING_IIS ).Path = "/"
				End If

				ServerSideRedirect( g_pASPPageManager.ReturnUrl )
			End If

		End If

		If g_pASPPageManager.IsUsingSiteServerAuthentication Then
			ServerSideRedirect(g_pASPPageManager.SiteServerMessageURL)
		End If

	End Sub

End Class

%>