%@ Language=VBScript %>
<% Option Explicit %>
<%
'-------------------------------------------------------------------------
' Web_LogSettings.asp: set the log settings to the web service\sites
'
' Copyright (c) Microsoft Corporation. All rights reserved.
'
' Date Description
' 8-11-2000 Created date
' 15-01-2001 Modified for new Framework
'-------------------------------------------------------------------------
%>
<%
'-------------------------------------------------------------------------
' Form Variables
'-------------------------------------------------------------------------
Dim F_chkEnableLogging
Dim F_selectActiveFormat
Dim F_optLogPeriod
Dim F_FileSize
Dim F_LocalTime
Dim F_LogFileDir
Dim F_SiteCriteria
'-------------------------------------------------------------------------
' Global Variables
'-------------------------------------------------------------------------
Dim G_objService
'-------------------------------------------------------------------------
' Start of localization content
'-------------------------------------------------------------------------
Dim L_IISLOGSTASKTITLETEXT
'Dim L_IISLOGSWEBROOTDIRHELP
Dim L_ENABLELOGGING
Dim L_ACTIVELOGFORMAT
Dim L_IISLOGFORMAT
Dim L_COMMONLOGFORMAT
Dim L_ODBCLOG
Dim L_EXTENDEDLOGFILE
Dim L_NEWLOGTIME
Dim L_HOURLY
Dim L_MONTHLY
Dim L_DAILY
Dim L_UNLIMITEDFILESIZE
Dim L_WEEKLY
Dim L_WHENFILESIZE
Dim L_MB
Dim L_LOCALTIME
Dim L_LOGFILEDIR
Dim L_APPLYTOALLIISTEXT
Dim L_APPLYTOINHERITEDIISTEXT
Dim L_FAIL_TO_SET_LOGS
Dim L_INVALID_DRIVE_ERRORMESSAGE
Dim L_NOT_NTFS_DRIVE_ERRORMESSAGE
Dim L_FAILED_CREATE_DIR_ERRORMESSAGE
Dim L_FILEINFORMATION_ERRORMESSAGE
Dim L_INFORMATION_ERRORMESSAGE
Dim L_INVALID_DIR_FORMAT_ERRORMESSAGE
Dim L_INVALID_DIR_ERRORMESSAGE
Dim L_DIRPATHEMPTY_ERRORMESSAGE
Dim L_DIRQUOTAERRORMESSAGE
Dim L_FILE
Dim L_ID_NOTEMPTY_ERROR_MESSAGE
Dim L_SITE_IDENTIFIER_EMPTY_TEXT
L_IISLOGSTASKTITLETEXT = GetLocString("GeneralSettings.dll", "40420037", "")
'L_IISLOGSWEBROOTDIRHELP = GetLocString("GeneralSettings.dll", "40420038", "")
L_ENABLELOGGING = GetLocString("GeneralSettings.dll", "40420039", "")
L_ACTIVELOGFORMAT = GetLocString("GeneralSettings.dll", "4042003A", "")
L_IISLOGFORMAT = GetLocString("GeneralSettings.dll", "4042003B", "")
L_COMMONLOGFORMAT = GetLocString("GeneralSettings.dll", "4042003C", "")
L_ODBCLOG = GetLocString("GeneralSettings.dll", "4042003D", "")
L_EXTENDEDLOGFILE = GetLocString("GeneralSettings.dll", "4042003E", "")
L_NEWLOGTIME = GetLocString("GeneralSettings.dll", "4042003F", "")
L_HOURLY = GetLocString("GeneralSettings.dll", "40420040", "")
L_MONTHLY = GetLocString("GeneralSettings.dll", "40420041", "")
L_DAILY = GetLocString("GeneralSettings.dll", "40420042", "")
L_UNLIMITEDFILESIZE = GetLocString("GeneralSettings.dll", "40420043", "")
L_WEEKLY = GetLocString("GeneralSettings.dll", "40420044", "")
L_WHENFILESIZE = GetLocString("GeneralSettings.dll", "40420045", "")
L_MB = GetLocString("GeneralSettings.dll", "40420046", "")
L_LOCALTIME = GetLocString("GeneralSettings.dll", "40420047", "")
L_LOGFILEDIR = GetLocString("GeneralSettings.dll", "40420048", "")
L_APPLYTOALLIISTEXT = GetLocString("GeneralSettings.dll", "40420035", "")
L_APPLYTOINHERITEDIISTEXT = GetLocString("GeneralSettings.dll", "40420034", "")
L_FAIL_TO_SET_LOGS = GetLocString("GeneralSettings.dll", "C0420049", "")
L_INVALID_DRIVE_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C0420022", "")
L_NOT_NTFS_DRIVE_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C042000D", "")
L_FAILED_CREATE_DIR_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C042000E", "")
L_FILEINFORMATION_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C042000C", "")
L_INFORMATION_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C042000F", "")
L_INVALID_DIR_FORMAT_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "40420004", "")
L_INVALID_DIR_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C042004B", "")
L_DIRPATHEMPTY_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C042004C", "")
L_FILE = GetLocString("GeneralSettings.dll", "4042004A", "")
'-------------------------------------------------------------------------
'END of localization content
'-------------------------------------------------------------------------
'Create property page
Dim rc
Dim page
rc=SA_CreatePage(L_IISLOGSTASKTITLETEXT,"",PT_PROPERTY,page)
'Serve the page
If(rc=0) then
SA_ShowPage(Page)
End if
'-------------------------------------------------------------------------
'Function: OnInitPage()
'Description: Called to signal first time processing for this page.
' Use this method to do first time initialization tasks
'Input Variables: PageIn,EventArg
'Output Variables: None
'Returns: True/False
'Global Variables: None
'-------------------------------------------------------------------------
Public Function OnInitPage(ByRef PageIn,ByRef EventArg)
InitObjects()
SetVariablesFromSystem()
OnInitPage = True
End Function
'-------------------------------------------------------------------------
'Function: OnServePropertyPage()
'Description: Called when the page needs to be served.Use this
' method to serve content
'Input Variables: PageIn,EventArg
'Output Variables: None
'Returns: True/False
'Global Variables: None
'-------------------------------------------------------------------------
Public Function OnServePropertyPage(ByRef PageIn,Byref EventArg)
Call ServeCommonJavaScript()
Call ServePage()
OnServePropertyPage = True
End Function
'-------------------------------------------------------------------------
'Function: OnPostBackPage()
'Description: Called to signal that the page has been posted-back.
'Input Variables: PageIn,EventArg
'Output Variables: None
'Returns: True/False
'Global Variables: None
'-------------------------------------------------------------------------
Public Function OnPostBackPage(ByRef PageIn ,ByRef EventArg)
OnPostBackPage = True
End Function
'-------------------------------------------------------------------------
'Function: OnSubmitPage()
'Description: Called when the page has been submitted for processing.
' Use this method to process the submit request.
'Input Variables: PageIn,EventArg
'Output Variables: None
'Returns: True/False
'Global Variables: None
'-------------------------------------------------------------------------
Public Function OnSubmitPage(ByRef PageIn ,ByRef EventArg)
OnSubmitPage = ServeVariablesFromForm()
End Function
'-------------------------------------------------------------------------
'Function: OnClosePage()
'Description: Called when the page is about closed.Use this method
' to perform clean-up processing
'Input Variables: PageIn,EventArg
'Output Variables: None
'Returns: True/False
'Global Variables: None
'-------------------------------------------------------------------------
Public Function OnClosePage(ByRef PageIn ,ByRef EventArg)
OnClosePage = TRUE
End Function
'-------------------------------------------------------------------------
'Function: ServeCommonJavaScript
'Description: Serves in initialiging the values,setting the form
' data and validating the form values
'Input Variables: None
'Output Variables: None
'Returns: True/False
'Global Variables: None
'-------------------------------------------------------------------------
Function ServeCommonJavaScript()
%>
<% End Function
'-------------------------------------------------------------------------
'Function: ServePage()
'Description: For displaying outputs HTML to the user
'Input Variables: None
'Output Variables: None
'Returns: None
'Global Variables: L_DELETE_CONFIRM_TEXT
'-------------------------------------------------------------------------
Function ServePage
%>
<% select case F_chkEnableLogging
case "true" %>
<%case else%>
<%end select%>
<%= L_ENABLELOGGING %>
<%= L_ACTIVELOGFORMAT %>
<%= L_NEWLOGTIME %>
<%select case F_optLogPeriod
case L_HOURLY %>
<%case else%>
<%end select %>
<%= L_HOURLY %>
<%select case F_optLogPeriod
case L_MONTHLY %>
<%case else%>
<%end select %>
<%= L_MONTHLY %>
<%select case F_optLogPeriod
case L_DAILY %>
<%case else %>
<%end select%>
<%= L_DAILY %>
<%select case F_optLogPeriod
case L_UNLIMITEDFILESIZE %>
<%case else%>
<%end select %>
<%= L_UNLIMITEDFILESIZE %>
<%select case F_optLogPeriod
case L_WEEKLY %>
<%case else%>
<%end select%>
<%= L_WEEKLY %>
<%select case F_optLogPeriod
case L_FILE %>
<%=L_WHENFILESIZE %>
<%case else%>
<%=L_WHENFILESIZE %>
<%end select %>
<%if F_optLogPeriod = L_FILE or F_optLogPeriod = L_UNLIMITEDFILESIZE then%>
<%else%>
<%if F_selectActiveFormat = CONST_W3CEXLOGFILE_FORMAT and F_LocalTime=true then %>
<%elseif F_selectActiveFormat = CONST_W3CEXLOGFILE_FORMAT and F_LocalTime=false then %>
<%else%>
<%end if%>
<%end if%>
<%= L_LOCALTIME %>
<%= L_LOGFILEDIR %>
<%= L_APPLYTOINHERITEDIISTEXT %>
<%= L_APPLYTOALLIISTEXT %>
<%
End Function
'-------------------------------------------------------------------------
'Function name: ServeVariablesFromForm()
'Description: Serves in getting the data from Client
'Input Variables: None
'Output Variables: None
'Returns: True/False
'Global Variables: None
'-------------------------------------------------------------------------
Function ServeVariablesFromForm
'setting the form variables
F_chkEnableLogging = Request.Form("hdnEnableLog")
F_selectActiveFormat = Request.Form("selectActiveFormat")
F_optLogPeriod = Request.Form("optLogPeriod")
F_FileSize = Request.Form("txtFileSize")
F_LocalTime = Request.Form("fileRollOver")
F_LogFileDir = Request.Form("txtLogFileDir")
F_SiteCriteria = Request.Form("optAllSites")
'set the master settings
If SetLogSettings()then
ServeVariablesFromForm = true
else
ServeVariablesFromForm = false
end if
End Function
'-------------------------------------------------------------------------
'Function name: SetVariablesFromSystem
'Description: Serves in Getting the data from Client
'Input Variables: None
'Output Variables: None
'Returns: None
'Global Variables: G_objService
'-------------------------------------------------------------------------
Function SetVariablesFromSystem
Err.Clear
on error resume next
'Getting values from system
Dim objSites
Dim strQuery
Dim objLogFormat
Dim instLog
strQuery = GetIISWMIProviderClassName("IIs_WebServiceSetting") & ".Name='W3SVC'"
set objSites = G_objService.Get(strQuery)
if Err.number <> 0 then
SetErrMsg L_INFORMATION_ERRORMESSAGE
exit function
end if
select case objSites.Logtype
case 1
F_chkEnableLogging = "true"
case else
F_chkEnableLogging = "false"
end select
if F_chkEnableLogging = "true" then
F_selectActiveFormat = IISLogFileGUIDToENName(objSites.LogPluginClsId)
end if
select case objSites.LogFilePeriod
case 1
F_optLogPeriod = L_DAILY
case 2
F_optLogPeriod = L_WEEKLY
case 3
F_optLogPeriod = L_MONTHLY
case 4
F_optLogPeriod = L_HOURLY
case 0
if objSites.LogFileTruncateSize <>-1 then
F_optLogPeriod = L_FILE
F_FileSize = objSites.LogFileTruncateSize / (1024*1024)
else
F_optLogPeriod = L_UNLIMITEDFILESIZE
F_FileSize = ""
end if
end select
F_LocalTime = cbool(objSites.LogFileLocaltimeRollover)
F_LogFileDir = objSites.LogFileDirectory
'release the object
set objSites = nothing
set objLogFormat = nothing
End Function
'-------------------------------------------------------------------------
'Function name: InitObjects
'Description: Initialization of global variables is done
'Input Variables: None
'Returns: true/false
'Global Variable: G_objService
'--------------------------------------------------------------------------
Function InitObjects()
Err.Clear
on error resume next
' Get the connection that is visible throughout
Set G_objService = getWMIConnection(CONST_WMI_IIS_NAMESPACE)
if Err.number <> 0 then
SetErrMsg L_INFORMATION_ERRORMESSAGE
end if
end function
'----------------------------------------------------------------------
'Function name: SetLogSettings
'Description: Serves in setting the logs to the web server
'Input Variables: None
'Output Variables: boolean
'Returns: None
'Global Variables: G_objService
'----------------------------------------------------------------------
Function SetLogSettings()
Err.Clear
on error resume next
SetLogSettings = false
Dim strObjPath
InitObjects()
if F_chkEnableLogging = "true" then
if ValidateInputs = True then
select case F_SiteCriteria
'apply to all sites
case "All"
if NOT SetLogsForAllSites(G_objService) then
ServeFailurePage L_FAIL_TO_SET_LOGS, sReturnURL
Call SA_TraceOut("Web_LogSettings", "SetLogSettings 1")
end if
'apply to inherited sites
case "inherited"
if NOT SetLogsForNewSites(G_objService) then
ServeFailurePage L_FAIL_TO_SET_LOGS,sReturnURL
Call SA_TraceOut("Web_LogSettings", "SetLogSettings 2")
end if
end select
SetLogSettings = true
exit function
End if
else
Dim inst
Dim objSite
Dim arrProp(4)
arrProp(0) = "LogType"
arrProp(1) = "LogPluginClsId"
arrProp(2) = "LogFilePeriod"
arrProp(3) = "LogFileTruncateSize"
arrProp(4) = "LogFileLocaltimeRollover"
select case F_SiteCriteria
'apply to all sites
case "All"
set objSite = G_objService.InstancesOf(GetIISWMIProviderClassName("IIS_WebServiceSetting"))
if Err.number <> 0 or objSite.count = 0 then
SetErrMsg L_INFORMATION_ERRORMESSAGE
Call SA_TraceOut("Web_LogSettings", "SetLogSettings 3")
exit function
end if
for each inst in objSite
inst.Logtype = 0
inst.put_(WBEMFLAG)
if Err.number <> 0 then
SA_TraceOut "Web_LogSettings", L_FAIL_TO_SET_LOGS
SetLogSettings = false
exit function
end if
next
'Release the object
set objSite = nothing
Set objSite = GetNonInheritedIISSites(G_objService, GetIISWMIProviderClassName("IIS_WebServerSetting"), GetIISWMIProviderClassName("IIS_WebServiceSetting"), arrProp)
if objSite.count = 0 then
SetLogSettings = true
exit function
end if
for each inst in objSite
inst.Logtype = 0
inst.put_(WBEMFLAG)
if Err.number <> 0 then
SA_TraceOut "Web_LogSettings", L_FAIL_TO_SET_LOGS
SetLogSettings = false
exit function
end if
next
'apply to inherited sites
case "inherited"
strObjPath = GetIISWMIProviderClassName("IIs_WebServiceSetting") & ".Name='W3SVC'"
set objSite = G_objService.Get(strObjPath)
if Err.number <> 0 then
SetErrMsg L_INFORMATION_ERRORMESSAGE
Call SA_TraceOut("Web_LogSettings", "SetLogsForNewSites 1")
exit function
end if
objSite.Logtype = 0
objSite.put_(WBEMFLAG)
if Err.number <> 0 then
SA_TraceOut "Web_LogSettings", L_FAIL_TO_SET_LOGS
SetLogSettings = false
exit function
end if
end select
SetLogSettings = true
end if
'Release the object
set G_objService = nothing
set objSite = nothing
end function
'-----------------------------------------------------------------------------------------------------------
'Function name: SetLogsForAllSites
'Description: Serves in setting the logs to all Web sites
'Input Variables: G_objService
'Output Variables: boolean
'Returns: None
'Global Variables: G_objService
'Other functions called:GetNonInheritedIISSites
'-----------------------------------------------------------------------------------------------------------
Function SetLogsForAllSites(G_objService)
Err.Clear
On error resume next
Dim objSite
Dim inst
Dim arrProp(4)
'Set logs for new sites
SetLogsForNewSites G_objService
SetLogsForAllSites = false
arrProp(0) = "LogType"
arrProp(1) = "LogPluginClsId"
arrProp(2) = "LogFilePeriod"
arrProp(3) = "LogFileTruncateSize"
arrProp(4) = "LogFileLocaltimeRollover"
Set objSite = GetNonInheritedIISSites(G_objService, GetIISWMIProviderClassName("IIs_WebServerSetting"), GetIISWMIProviderClassName("IIS_WebServiceSetting"), arrProp)
if objSite.count = 0 then
SetLogsForAllSites = true
exit function
end if
for each inst in objSite
if not SetLogs(inst) then
SA_TraceOut "Web_LogSettings", L_FAIL_TO_SET_LOGS
end if
next
'release the object
set objSite = nothing
SetLogsForAllSites = true
End Function
'-----------------------------------------------------------------------------------------------------------
'Function name: SetLogsForNewSites
'Description: Serves in setting the logs to the new Web sites
'Input Variables: G_objService
'Output Variables: boolean
'Global Variables: G_objService
'Returns: boolean
'-----------------------------------------------------------------------------------------------------------
Function SetLogsForNewSites(G_objService)
Err.Clear
On error resume next
Dim objSite
Dim strObjPath
SetLogsForNewSites = false
strObjPath = GetIISWMIProviderClassName("IIs_WebServiceSetting") & ".Name='W3SVC'"
set objSite = G_objService.Get(strObjPath)
if Err.number <> 0 then
SetErrMsg L_INFORMATION_ERRORMESSAGE
Call SA_TraceOut("Web_LogSettings", "SetLogsForNewSites 1")
exit function
end if
if not SetLogs(objSite) then
SA_TraceOut "Web_LogSettings", L_FAIL_TO_SET_LOGS
SetLogsForNewSites = false
exit function
end if
'release the object
set objSite = nothing
SetLogsForNewSites = true
End Function
'----------------------------------------------------------------------------------------------------
'Function name: ValidateInputs
'Description: Check whether directory exists
' If directory does not exist, create the web site if the drive letter is valid
' else give error message
'Input Variables: None
'Global Variables: None
'Returns: true/false
'-----------------------------------------------------------------------------------------------------
Function ValidateInputs()
Err.Clear
on error resume next
Dim strIndx
Dim objFso
Dim nRetVal
Dim strDir
ValidateInputs = false
if F_selectActiveFormat <> CONST_ODBCLOGFILE_FORMAT then
strDir = F_LogFileDir
Set objFso = server.CreateObject("Scripting.FileSystemObject")
if Err.number <> 0 then
SetErrMsg L_FILEINFORMATION_ERRORMESSAGE
Call SA_TraceOut("Web_LogSettings", "ValidateInputs 1")
exit function
end if
if mid(ucase(F_LogFileDir),1,8) = ucase("%WinDir%") then
strDir = objFso.GetSpecialFolder(0) & mid(F_LogFileDir,9)
elseif mid(ucase(F_LogFileDir),1,13) = ucase("%SystemDrive%") then
strDir = objFso.GetSpecialFolder(0).Drive & mid(F_LogFileDir,14)
else
strDir = F_LogFileDir
end if
nRetVal = CreateSitePath( objFso, strDir )
if nRetVal <> CONST_SUCCESS then
if nRetVal = CONST_INVALID_DRIVE then
SetErrMsg L_INVALID_DRIVE_ERRORMESSAGE
Call SA_TraceOut("Web_LogSettings", "ValidateInputs 2")
elseif nRetVal = CONST_NOTNTFS_DRIVE then
SetErrMsg L_NOT_NTFS_DRIVE_ERRORMESSAGE
Call SA_TraceOut("Web_LogSettings", "ValidateInputs 3")
else
SetErrMsg L_FAILED_CREATE_DIR_ERRORMESSAGE
Call SA_TraceOut("Web_LogSettings", "ValidateInputs 4")
end if
exit Function
end if
Dim strDriveName,objDriveType, intDriveSize
strDriveName = left(strDir,2)
if objFso.DriveExists(ucase(strDriveName)) then
set objDriveType = objFso.GetDrive(strDriveName)
intDriveSize = clng(objDriveType.TotalSize / (1024*1024))
end if
'Release the object
set objDriveType = nothing
if clng(F_FileSize) > intDriveSize then
L_DIRQUOTAERRORMESSAGE = GetLocString("GeneralSettings.dll", "C0420057", Array(CStr(intDriveSize)))
SetErrMsg(L_DIRQUOTAERRORMESSAGE)
exit Function
end if
end if
ValidateInputs = true
'Release the object
set objFso = nothing
End Function
'------------------------------------------------------------------
'Function name: SetLogs
'Description: Serves in setting the logs
'Input Variables: inst
'Returns: boolean 'true if no error occurs else false
'Global Variables: G_objService
'------------------------------------------------------------------
Function SetLogs(inst)
Err.Clear
on error resume next
SetLogs = false
Dim strQuery
Dim objLogFormat
Dim instLog
inst.LogType = 1 'to enable logging
inst.LogPluginClsId = IISLogFileENNameToGUID(F_selectActiveFormat)
if F_selectActiveFormat <> CONST_ODBCLOGFILE_FORMAT then
select case F_optLogPeriod
case L_DAILY
inst.LogFilePeriod = 1
inst.LogFileTruncateSize = 512 * 1024 * 1024
case L_WEEKLY
inst.LogFilePeriod = 2
inst.LogFileTruncateSize = 512 * 1024 * 1024
case L_MONTHLY
inst.LogFilePeriod = 3
inst.LogFileTruncateSize = 512 * 1024 * 1024
case L_HOURLY
inst.LogFilePeriod = 4
inst.LogFileTruncateSize = 512 * 1024 * 1024
case L_FILE
inst.LogFilePeriod = 0
if trim(F_FileSize) <> "" then
inst.LogFileTruncateSize = clng(F_FileSize) * 1024 * 1024
else
inst.LogFileTruncateSize = 1024 * 1024
end if
case L_UNLIMITEDFILESIZE
inst.LogFilePeriod = 0
inst.LogFileTruncateSize = -1
end select
inst.LogFileLocaltimeRollover = cbool(F_LocalTime)
inst.LogFileDirectory = trim(F_LogFileDir)
end if
inst.put_(WBEMFLAG)
if Err.number <> 0 then
SA_TraceOut "Web_LogSettings", L_FAIL_TO_SET_LOGS
SetLogs = false
exit function
end if
'release the object
set objLogFormat = nothing
SetLogs = true
End function
%>