<%@ Language=VBScript %> <% Option Explicit %> <% '------------------------------------------------------------------------- ' Ftp_LogSettings.asp: set the logs for FTP sites ' ' Copyright (c) Microsoft Corporation. All rights reserved. ' ' Date Description ' 06-11-2000 Created date '------------------------------------------------------------------------- %> <% '------------------------------------------------------------------------- ' Form Variables '------------------------------------------------------------------------- Dim F_strWebRoorDir 'Root Dir for the form Dim F_chkEnableLogging Dim F_selectActiveFormat Dim F_optLogPeriod Dim F_FileSize Dim F_LocalTime Dim F_LogFileDir Dim F_IISSites Dim F_selectTasks Dim L_FILE 'Dim F_SiteCriteria Dim G_objSites Dim FTPInstalled '------------------------------------------------------------------------- ' Global Variables '------------------------------------------------------------------------- Dim G_objService '------------------------------------------------------------------------- ' Start of localization content '------------------------------------------------------------------------- Dim L_INVALID_DIR_FORMAT_ERRORMESSAGE Dim L_INVALID_DIR_ERRORMESSAGE Dim L_DIRPATHEMPTY_ERRORMESSAGE Dim L_INFORMATION_ERRORMESSAGE Dim L_FILEINFORMATION_ERRORMESSAGE Dim L_FAILED_CREATE_DIR_ERRORMESSAGE Dim L_NOT_NTFS_DRIVE_ERRORMESSAGE Dim L_INVALID_DRIVE_ERRORMESSAGE Dim L_DIRQUOTAERRORMESSAGE Dim L_FAIL_TO_SET_LOGS Dim L_APPLYTOALLFTPTEXT Dim L_APPLYTOINHERITEDFTPTEXT Dim L_LOGFILEDIR Dim L_LOCALTIME 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_FTPLOG_TEXT 'Dim L_FTPLOGSDIRHELP Dim L_FTPNOTINSTALLED_ERRORMESSAGE Dim L_ID_NOTEMPTY_ERROR_MESSAGE Dim L_SITE_IDENTIFIER_EMPTY_TEXT L_FTPLOG_TEXT = GetLocString("GeneralSettings.dll", "4042004E", "") 'L_FTPLOGSDIRHELP = GetLocString("GeneralSettings.dll", "40420050", "") 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_APPLYTOALLFTPTEXT = GetLocString("GeneralSettings.dll", "4042002B", "") L_APPLYTOINHERITEDFTPTEXT = GetLocString("GeneralSettings.dll", "4042002C", "") 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", "") L_FTPNOTINSTALLED_ERRORMESSAGE = GetLocString("GeneralSettings.dll", "C0420058", "") '------------------------------------------------------------------------- 'END of localization content '------------------------------------------------------------------------- 'Create property page Dim rc Dim page rc=SA_CreatePage(L_FTPLOG_TEXT,"",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() if FTPInstalled = false then ServeFailurePage L_FTPNOTINSTALLED_ERRORMESSAGE ,sReturnURL end if 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 %>
<% if F_chkEnableLogging = "true" then %> <%else%> <%end if%> <%= L_ENABLELOGGING %>
<%= L_ACTIVELOGFORMAT %>
<%= L_NEWLOGTIME %> <%if F_optLogPeriod = L_HOURLY then%> <%elseif F_selectActiveFormat = CONST_ODBCLOGFILE_FORMAT then %> <%else%> <%end if %> <%= L_HOURLY %> <%if F_optLogPeriod = L_MONTHLY and F_selectActiveFormat <> CONST_ODBCLOGFILE_FORMAT then%> <%elseif F_selectActiveFormat = CONST_ODBCLOGFILE_FORMAT then %> <%else%> <%end if %> <%= L_MONTHLY %>
<%if F_optLogPeriod = L_DAILY then%> <%elseif F_selectActiveFormat = CONST_ODBCLOGFILE_FORMAT then %> <% else %> <%end if%> <%= L_DAILY %> <%if F_optLogPeriod = L_UNLIMITEDFILESIZE and F_selectActiveFormat <> CONST_ODBCLOGFILE_FORMAT then%> <%elseif F_selectActiveFormat = CONST_ODBCLOGFILE_FORMAT then %> <%else%> <%end if %> <%= L_UNLIMITEDFILESIZE %>
<%if F_optLogPeriod = L_WEEKLY then%> <%elseif F_selectActiveFormat = CONST_ODBCLOGFILE_FORMAT then %> <%else%> <%end if%> <%= L_WEEKLY %>
<%if F_optLogPeriod = L_FILE then%> <%=L_WHENFILESIZE %>   <%elseif F_selectActiveFormat = CONST_ODBCLOGFILE_FORMAT then %> <%=L_WHENFILESIZE %>   <%else%> <%=L_WHENFILESIZE %>   <%end if %>
 
<%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 %>    <%if F_selectActiveFormat = CONST_ODBCLOGFILE_FORMAT then %> <%else%> <%end if%>
<% 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_IISSites = Request.Form("selectSites") '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 ' G_objSites '------------------------------------------------------------------------- Function SetVariablesFromSystem() Dim inst Dim strQuery Dim objLogFormat Dim instLog for each inst in G_objSites select case inst.Logtype case 1 F_chkEnableLogging = "true" case else F_chkEnableLogging = "false" end select if F_chkEnableLogging = "true" then F_selectActiveFormat = IISLogFileGUIDToENName(inst.LogPluginClsId) end if select case inst.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 inst.LogFileTruncateSize <>-1 then F_optLogPeriod = L_FILE else F_optLogPeriod =L_UNLIMITEDFILESIZE end if end select if F_optLogPeriod = L_FILE then F_FileSize = inst.LogFileTruncateSize / (1024*1024) else F_FileSize = "" end if F_LocalTime = inst.LogFileLocaltimeRollover if inst.LogFileDirectory = "" then Dim objSysDrive,strSysDrive Set objSysDrive = server.CreateObject("Scripting.FileSystemObject") strSysDrive = objSysDrive.GetSpecialFolder(1).Drive ' 1 for systemfolder,0 for windows folder F_LogFileDir = strSysDrive & "\" & CONST_DEF_WEBROOT else F_LogFileDir = inst.LogFileDirectory end if exit for next 'Getting values from system End Function '------------------------------------------------------------------------- 'Function name: InitObjects 'Description: Initialization of global variables is done 'Input Variables: None 'Returns: true/false 'Global Variables: G_objService ' G_objSites '-------------------------------------------------------------------------- Function InitObjects() Err.Clear on error resume next ' Get instances of IIS_FTPServiceSetting that are visible throughout Set G_objService = getWMIConnection(CONST_WMI_IIS_NAMESPACE) set G_objSites = G_objService.InstancesOf(GetIISWMIProviderClassName("IIS_FTPServiceSetting")) if Err.number <> 0 or G_objSites.count = 0 then FTPInstalled = false Err.Clear else FTPInstalled = true end if end function '---------------------------------------------------------------------- 'Function name: SetLogSettings 'Description: Serves in setting the logs to the FTP server 'Input Variables: None 'Output Variables: boolean 'Returns: None 'Global Variables: G_objService '---------------------------------------------------------------------- Function SetLogSettings() on error resume next Dim strObjPath InitObjects() if FTPInstalled = true then SetLogSettings = false if F_chkEnableLogging = "true" then if ValidateInputs = True then 'select case F_SiteCriteria 'apply to all sites if NOT SetLogsForAllSites(G_objService) then ServeFailurePage L_FAIL_TO_SET_LOGS, sReturnURL end if 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" strObjPath = GetIISWMIProviderClassName("IIs_FtpServiceSetting") & ".Name='MSFTPSVC'" set objSite = G_objService.Get(strObjPath) if Err.number <> 0 then SetErrMsg L_INFORMATION_ERRORMESSAGE exit function end if objSite.Logtype = 0 objSite.put_(WBEMFLAG) if Err.number <> 0 then SA_TraceOut "Ftp_LogSettings", L_FAIL_TO_SET_LOGS SetLogSettings = false exit function end if Err.Clear Set objSite = GetNonInheritedFTPSites(G_objService, "IIS_FTPServerSetting","IIS_FTPServiceSetting", arrProp) If ( Err.Number <> 0 ) Then Call SA_TraceOut(SA_GetScriptFileName(), "GetNonInheritedFTPSites failed, error: " & Hex(Err.Number) & " " & Err.Description) SetLogSettings = true exit function End If if (IsNull(objSite) OR 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 "Ftp_LogSettings", L_FAIL_TO_SET_LOGS SetLogSettings = false exit function end if next SetLogSettings = true end if end if 'release the object set G_objService = nothing set G_objSites = nothing set objSite = nothing end function '----------------------------------------------------------------------------------------------------------- 'Function name: SetLogsForAllSites 'Description: Serves in setting the logs to the new FTP sites 'Input Variables: G_objService 'Output Variables: boolean 'Returns: None 'Global variables: G_objService 'Other functions called:GetNonInheritedFTPSites '----------------------------------------------------------------------------------------------------------- Function SetLogsForAllSites(G_objService) Err.Clear On error resume next Dim objSite Dim inst Dim arrProp(4) 'Set Master settings SetLogsForNewSites G_objService SetLogsForAllSites = false arrProp(0) = "LogType" arrProp(1) = "LogPluginClsId" arrProp(2) = "LogFilePeriod" arrProp(3) = "LogFileTruncateSize" arrProp(4) = "LogFileLocaltimeRollover" Set objSite = GetNonInheritedFTPSites(G_objService, GetIISWMIProviderClassName("IIS_FTPServerSetting"),GetIISWMIProviderClassName("IIS_FTPServiceSetting"), arrProp) if (Err.number <> 0) then SetLogsForAllSites = false exit function end if 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 SetLogsForAllSites = false exit function 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 FTP sites 'Input Variables: G_objService 'Output Variables: boolean 'Returns: None 'Global Variables: G_objService '----------------------------------------------------------------------------------------------------------- Function SetLogsForNewSites(G_objService) Err.Clear On error resume next Dim objSite Dim strObjPath SetLogsForNewSites = false strObjPath = GetIISWMIProviderClassName("IIs_FtpServiceSetting") & ".Name='MSFTPSVC'" set objSite = G_objService.Get(strObjPath) if Err.number <> 0 then SetErrMsg L_INFORMATION_ERRORMESSAGE exit function end if if not SetLogs(objSite) then SA_TraceOut "FTP_LogSettings", L_FAIL_TO_SET_LOGS end if SetLogsForNewSites = true '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 'Returns: true/false 'Global Variables: None '----------------------------------------------------------------------------------------------------- Function ValidateInputs Dim strIndx Dim objFso Dim nRetVal Dim strDir ValidateInputs = false if F_selectActiveFormat <> CONST_ODBCLOGFILE_FORMAT then Set objFso = server.CreateObject("Scripting.FileSystemObject") if Err.number <> 0 then SetErrMsg L_FILEINFORMATION_ERRORMESSAGE 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 elseif nRetVal = CONST_NOTNTFS_DRIVE then SetErrMsg L_NOT_NTFS_DRIVE_ERRORMESSAGE else SetErrMsg L_FAILED_CREATE_DIR_ERRORMESSAGE 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) On Error Resume Next Err.Clear Dim strQuery Dim objLogFormat Dim instLog SetLogs = false 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 "Ftp_LogSettings", L_FAIL_TO_SET_LOGS SetLogs = false exit function end if 'release the object set objLogFormat = nothing SetLogs = true End function %>