Module/Rule.WebAppPool/Convert/Methods.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
#region Method Functions
<#
    .SYNOPSIS
        Returns the key and value properties for the STIG rule.
 
    .PARAMETER CheckContent
        An array of the raw string data taken from the STIG setting.
#>

function Get-KeyValuePair
{
    [CmdletBinding()]
    [OutputType([object])]
    param
    (
        [Parameter(Mandatory = $true)]
        [psobject]
        $CheckContent
    )

    switch ( $checkContent )
    {
        { $PsItem -match 'Idle Time-out' }
        {
            $key = 'idleTimeout'
            $value = $null
        }
        { $PsItem -match 'Queue Length' }
        {
            $key = 'queueLength'
            $value = $null
        }
        { $PsItem -match 'Ping Enabled' }
        {
            $key = 'pingingEnabled'
            $value = '$true'
        }
        { $PsItem -match 'Rapid Fail Protection:Enabled' }
        {
            $key = 'rapidFailProtection'
            $value = '$true'
        }
        { $PsItem -match 'Failure Interval' }
        {
            $key = 'rapidFailProtectionInterval'
            $value = $null
        }
        { $PsItem -match 'Virtual Memory Limit' }
        {
            $key = 'restartMemoryLimit'
            $value = $null
        }
        { $PsItem -match 'Private Memory Limit' }
        {
            $key = 'restartPrivateMemoryLimit'
            $value = $null
        }
        { $PsItem -match 'Request Limit' }
        {
            $key = 'restartRequestsLimit'
            $value = $null
        }
        { $PsItem -match 'Generate Recycle Event Log Entry' }
        {
            $key = 'logEventOnRecycle'
            $value = "'Time,Schedule'"
        }
    }

    if ($null -ne $key)
    {
        Write-Verbose -Message $("[$($MyInvocation.MyCommand.Name)] Found Key: {0}, value: {1}" -f $key, $value)

        return @{
            key   = $key
            value = $value
        }
    }
    else
    {
        Write-Verbose -Message "[$($MyInvocation.MyCommand.Name)] No Key or Value found"
        return $null
    }
}

<#
    .SYNOPSIS
        Takes the key property from a WebAppPoolrule to determine the Organizational value
        test string to return.
 
    .PARAMETER Key
        Key property from the WebAppPoolrule.
#>

function Get-WebAppPoolOrganizationValueTestString
{
    [CmdletBinding()]
    [OutputType([string])]
    param
    (
        [Parameter(Mandatory = $true)]
        [string]
        $Key
    )

    # TO DO - This should not be a static list
    switch ( $Key )
    {
        { $PsItem -match 'idleTimeout' }
        {
            return "[TimeSpan]{0} -le [TimeSpan]'00:20:00' -and [TimeSpan]{0} -gt [TimeSpan]'00:00:00'"
        }
        { $PsItem -match 'queueLength' }
        {
            return "{0} -le 1000"
        }
        { $PsItem -match 'rapidFailProtectionInterval' }
        {
            return "[TimeSpan]{0} -le [TimeSpan]'00:05:00'"
        }
        { $PsItem -match 'restartMemoryLimit|restartPrivateMemoryLimit|restartRequestsLimit'}
        {
            return "{0} -ne 0"
        }
        default
        {
            return $null
        }
    }
}
#endregion