Skip to content

Commit 819b6f7

Browse files
committed
change
1 parent e179d06 commit 819b6f7

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

02-LogModules/Auth.Log/03-Features/08-FTP.ps1

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ $ActivateTableFlag = "False"
4545

4646
# if statment to check if there is at least 1 event
4747
if ($AuthenticationFailure_Count -ge 1) {
48-
48+
4949
$ActivateTableFlag = "True"
50-
50+
5151
# title
5252
Write-Output ""
5353
Write-Output "FTP Authentication Failure - Raw Events"
@@ -64,7 +64,7 @@ if ($AuthenticationFailure_Count -ge 1) {
6464
$singleEventPlusSpace = $singleEvent.PadRight($maxLength)
6565
Write-Output "+$longBorderHyphen+"
6666
Write-Output "|$singleEventPlusSpace|"
67-
67+
6868
}
6969
# end of the table line
7070
Write-Output "+$longBorderHyphen+"
@@ -75,51 +75,44 @@ $UsernameCounts2 = @{}
7575

7676
if ($ActivateTableFlag -eq "True") {
7777

78-
$FTP_HT["AuthenticationFailure"] | ForEach-Object {
78+
$FTP_HT["AuthenticationFailure"] | ForEach-Object {
7979
if ($_ -match $AuthenticationFailureFormats[0]) {
80-
$UserName = ($_ -replace '.*ruser=','') -replace ' rhost=.*',''
81-
$UsernameCounts1[$UserName]++
80+
$UserName = ($_ -replace '.*ruser=','') -replace ' rhost=.*',''
81+
$UsernameCounts1[$UserName]++
8282
}
8383
elseif ($_ -match $AuthenticationFailureFormats[2]) {
84-
$UserName = ($_ -replace '.* Refused user ','') -replace ' for service.*',''
85-
$UsernameCounts2[$UserName]++
84+
$UserName = ($_ -replace '.* Refused user ','') -replace ' for service.*',''
85+
$UsernameCounts2[$UserName]++
8686
}
87-
}
88-
89-
# Find the maximum character count in $UsernameCounts1 and $UsernameCounts2
90-
$maxCharCount1 = ($UsernameCounts1.Keys | Measure-Object Length -Maximum).Maximum
91-
$maxCharCount2 = ($UsernameCounts2.Keys | Measure-Object Length -Maximum).Maximum
92-
$maxCharCount = [Math]::Max($maxCharCount1, $maxCharCount2)
87+
}
9388

94-
$Measure_HT = $UsernameCounts1.GetEnumerator() | ForEach-Object {
95-
$UserName, $FailCount = $_.Key, $_.Value
96-
"| Event: Authentication Failure | User Name: $($UserName.PadRight($maxCharCount)) | Fail Count: $FailCount |"
97-
}
89+
# Find the maximum character count in $UsernameCounts1 and $UsernameCounts2
90+
$maxCharCount1 = ($UsernameCounts1.Keys | Measure-Object Length -Maximum).Maximum
91+
$maxCharCount2 = ($UsernameCounts2.Keys | Measure-Object Length -Maximum).Maximum
92+
$maxCharCount = [math]::Max($maxCharCount1,$maxCharCount2)
9893

99-
$Measure2_HT = $UsernameCounts2.GetEnumerator() | ForEach-Object {
100-
$UserName, $FailCount = $_.Key, $_.Value
101-
"| Event: User Refused | User Name: $($UserName.PadRight($maxCharCount)) | Fail Count: $FailCount |"
102-
}
94+
$Measure_HT = $UsernameCounts1.GetEnumerator() | ForEach-Object {
95+
$UserName,$FailCount = $_.Key,$_.Value
96+
"| Event: Authentication Failure | User Name: $($UserName.PadRight($maxCharCount)) | Fail Count: $($FailCount.ToString().PadLeft(2)) |"
97+
}
10398

104-
if ($Measure2_HT.Length -eq 0) {
105-
# calc the character count of one of the measure hash table
106-
$CharacterCount = $Measure_HT.Length - 2
107-
}
99+
$Measure2_HT = $UsernameCounts2.GetEnumerator() | ForEach-Object {
100+
$UserName,$FailCount = $_.Key,$_.Value
101+
"| Event: User Refused | User Name: $($UserName.PadRight($maxCharCount)) | Fail Count: $($FailCount.ToString().PadLeft(2)) |"
102+
}
108103

109-
else {
110-
$CharacterCount = $Measure2_HT.Length - 2
111-
}
104+
$maxLineLength = ($Measure_HT + $Measure2_HT | Measure-Object -Property Length -Maximum).Maximum
105+
$Hyphens = '-' * ($maxLineLength - 2)
112106

113-
$Hyphens = '-' * $CharacterCount
114107

115-
# the end output
116-
Write-Output " |"
117-
Write-Output " V FTP Authentication Failure - Statistics Table"
118-
Write-Output " +$Hyphens+"
119-
foreach ($OneEvent in ($Measure_HT + $Measure2_HT)) {
120-
Write-Output " $OneEvent"
121-
}
122-
Write-Output " +$Hyphens+"
108+
# the end output
109+
Write-Output " |"
110+
Write-Output " V FTP Authentication Failure - Statistics Table"
111+
Write-Output " +$Hyphens+"
112+
foreach ($OneEvent in ($Measure_HT + $Measure2_HT)) {
113+
Write-Output " $OneEvent"
114+
}
115+
Write-Output " +$Hyphens+"
123116

124117
}
125118

0 commit comments

Comments
 (0)