cEPRSWebProperties.psm1
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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
enum Ensure { Present Absent } [DSCResource()] class cEPRSISAPIRestrictions { [DscProperty(Key)] [String] $ISAPIPath #[DscProperty(Key)] [Ensure] $Ensure [DscProperty(Key)] [String] $Description [cEPRSISAPIRestrictions] Get() { $config = @{FarmName = $this.FarmName; } return $config } [bool] Test() { if (!(Test-Path $this.ISAPIPath)) { Write-Warning "$($this.ISAPIPath) doesn't exists, please provide a valid path" return $true } else { return $false } } [void] Set() { Write-Verbose "set function execution starts......." Import-Module WebAdministration $checkifenabled=Get-WebConfiguration system.webServer/security/isapiCgiRestriction/* 'IIS:\' | where {$_.path -eq "$ISAPIPath"} if($checkifenabled) { if((Test-path $checkifenabled.path) -and ($checkifenabled.allowed -eq $true)) { write-verbose "$($this.ISAPIPath) already exists in ISAPI CGI Restrictions" } elseif((Test-path $checkifenabled.path) -and ($checkifenabled.allowed -eq $false)) { Write-Verbose "Enabling $($this.ISAPIPath) for ISAPI and CGI properties" set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$($this.ISAPIPath)']/@allowed" -value "True" -PSPath:IIS:\ } } else { Write-Verbose "Enabling $($this.ISAPIPath) for ISAPI and CGI properties" Add-WebConfiguration /system.webServer/security/isapiCgiRestriction "IIS:\" -Value @{path="$($this.ISAPIPath)"} set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$($this.ISAPIPath)']/@allowed" -value "True" -PSPath:IIS:\ set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$($this.ISAPIPath)']/@groupid" -value "$($this.Description)" -PSPath:IIS:\ set-webconfiguration "/system.webServer/security/isapiCgiRestriction/add[@path='$($this.ISAPIPath)']/@description" -value "$($this.Description)" -PSPath:IIS:\ } Write-Verbose "set function execution ends......." } } [DSCResource()] class cEPRSExtendedProtection { [DscProperty(Key)] [String] $Website #[DscProperty(Key)] [Ensure] $Ensure [DscProperty(Key)] [String] $Vdir [cEPRSExtendedProtection] Get() { $config = @{Website = $this.Website; } return $config } [bool] Test() { Import-Module WebAdministration $checkifenabled=Get-WebConfiguration system.webServer/security/authentication/windowsAuthentication if ($checkifenabled.extendedProtection.tokenChecking -ne "Allow") { return $false } else { return $true } } [void] Set() { Write-Verbose "set function execution starts......." write-Verbose "Configuring IIS for extended protection..." #Setting extended protection property to website & $env:WinDir\system32\inetsrv\appcmd.exe set config "$($this.WebSite)" -section:system.webServer/security/authentication/windowsAuthentication /extendedProtection.tokenChecking:"Allow" /extendedProtection.flags:"None" /commit:apphost #Setting extended protection property to virtual directory & $env:WinDir\system32\inetsrv\appcmd.exe set config "$($this.WebSite)/$($this.Vdir)" -section:system.webServer/security/authentication/windowsAuthentication /extendedProtection.tokenChecking:"Allow" /extendedProtection.flags:"None" /commit:apphost write-Verbose "Configuring IIS for extended protection completed..." Write-Verbose "set function execution ends......." } } [DSCResource()] class cEPRSAutoStart { [DscProperty(Key)] [String] $AutoStartEnabled #[DscProperty(Key)] [Ensure] $Ensure [DscProperty(Key)] [String] $Website [cEPRSAutoStart] Get() { $config = @{AutoStartEnabled = $this.AutoStartEnabled; } return $config } [bool] Test() { Import-Module WebAdministration $Websitestate = Get-WebsiteState -Name "$this.Website" if($Websitestate -eq "Started") { return $true } else { return $false } } [void] Set() { Write-Verbose "set function execution starts......." write-Verbose "Setting property AutoStartEnabled..." -Verbose & $env:WinDir\system32\inetsrv\appcmd.exe set site "$($this.WebSite)" /serverAutoStart:$($this.AutoStartEnabled) Write-Verbose "set function execution ends......." -Verbose } } |