Skip to content

Commit

Permalink
Add check if log/report/backup paths exist
Browse files Browse the repository at this point in the history
  • Loading branch information
0x6d69636b committed Dec 18, 2023
1 parent 0263f33 commit f6079cf
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions HardeningKitty.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@
#
# Start Main
#
$HardeningKittyVersion = "0.9.3-1701693447"
$HardeningKittyVersion = "0.9.3-1702922807"

#
# Log, report and backup file
Expand All @@ -621,14 +621,39 @@
$ListName = [System.IO.Path]::GetFileNameWithoutExtension($FileFindingList)
}

If ($Log -and $LogFile.Length -eq 0) {
$LogFile = "hardeningkitty_log_" + $Hostname + "_" + $ListName + "-$FileDate.log"
If ($Log) {
If ($LogFile.Length -eq 0) {
$LogFile = "hardeningkitty_log_" + $Hostname + "_" + $ListName + "-$FileDate.log"
} ElseIf ($(Split-Path -Path $LogFile).Length -ne 0) {
If ( -Not(Test-Path -Path $(Split-Path $LogFile))) {
$Message = "The path to your log file does not exist."
$Log = $false
Write-ProtocolEntry -Text $Message -LogLevel "Error"
Break
}
}
}
If ($Report -and $ReportFile.Length -eq 0) {
$ReportFile = "hardeningkitty_report_" + $Hostname + "_" + $ListName + "-$FileDate.csv"
If ($Report) {
If ($ReportFile.Length -eq 0) {
$ReportFile = "hardeningkitty_report_" + $Hostname + "_" + $ListName + "-$FileDate.csv"
} ElseIf ($(Split-Path -Path $ReportFile).Length -ne 0) {
If ( -Not(Test-Path -Path $(Split-Path $ReportFile))) {
$Message = "The path to your report file does not exist."
Write-ProtocolEntry -Text $Message -LogLevel "Error"
Break
}
}
}
If ($Backup -and $BackupFile.Length -eq 0) {
$BackupFile = "hardeningkitty_backup_" + $Hostname + "_" + $ListName + "-$FileDate.csv"
If ($Backup) {
If ($BackupFile.Length -eq 0) {
$BackupFile = "hardeningkitty_backup_" + $Hostname + "_" + $ListName + "-$FileDate.csv"
} ElseIf ($(Split-Path -Path $BackupFile).Length -ne 0) {
If ( -Not(Test-Path -Path $(Split-Path $BackupFile))) {
$Message = "The path to your backup file does not exist."
Write-ProtocolEntry -Text $Message -LogLevel "Error"
Break
}
}
}
$ReportAllResults = @()
$BackupAllResults = @()
Expand Down

0 comments on commit f6079cf

Please sign in to comment.