Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-97: DevelopFriendly - PowerShell scripts to help in troubleshooting instances #98

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions Source/Builders/DevelopFriendly/Enable-IISDetailedErrors.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
param(

)


$cmdletsPaths="$PSScriptRoot\..\..\Cmdlets"

. "$cmdletsPaths\Helpers\Write-Separator.ps1"
. "$cmdletsPaths\Helpers\Get-ProgressHash.ps1"

Write-Separator -Invocation $MyInvocation -Header
$scriptProgress=Get-ProgressHash -Invocation $MyInvocation


$CustomErrorsMode = "Off"
$HttpErrorserrorMode = "Detailed"
$AspScriptErrorSentToBrowser = "true"


[xml]$CustomErrorsXml = @"
<customErrors mode="$CustomErrorsMode"><!-- ISHTROUBLESHOOTING --></customErrors>
"@

[xml]$HttpErrorsXml = @"
<httpErrors errorMode="$HttpErrorserrorMode"><!-- ISHTROUBLESHOOTING --></httpErrors>
"@

[xml]$AspScriptErrorSentToBrowserXml = @"
<asp scriptErrorSentToBrowser="true"><!-- ISHTROUBLESHOOTING --></asp>
"@

$blockName="[DEVELOPFRIENDLY][Windows Server]:Enabling IIS Detailed Errors"
Write-Host $blockName
Write-Warning "$blockName - ONLY USE THIS FOR TROUBLESHOOTING A LOCAL DEVELOPMENT INSTANCE!"


$blockName="Getting deployment information"
Write-Progress @scriptProgress -Status $blockName
Write-Host $blockName

$deploymentParameters = Get-ISHDeploymentParameters # -ISHDeployment $ishDeploymentName

$paramWebPath = $deploymentParameters |Where-Object -Property Name -EQ "webpath"|Select-Object -ExpandProperty Value
$paramProjectSuffix = $deploymentParameters |Where-Object -Property Name -EQ "projectsuffix"|Select-Object -ExpandProperty Value


$webPath = "$paramWebPath\Web$paramProjectSuffix\Author\ASP"
$webConfig = "web.config"
$fullISHCMPath = "$webPath\$webConfig"
Write-Verbose "ISHCM web.config: $fullISHCMPath"

$webPath = "$paramWebPath\Web$paramProjectSuffix\InfoShareCE"
$webConfig = "web.config"
$fullISHCEPath = "$webPath\$webConfig"
Write-Verbose "ISHCE web.config: $fullISHCEPath"

$webPath = "$paramWebPath\Web$paramProjectSuffix\InfoShareSTS"
$webConfig = "web.config"
$fullISHSTSPath = "$webPath\$webConfig"
Write-Verbose "ISHSTS web.config: $fullISHSTSPath"

$fullPaths = @($fullISHCMPath,$fullISHCEPath,$fullISHSTSPath)


$blockName="Processing all web.config files"
Write-Progress @scriptProgress -Status $blockName
Write-Host $blockName

foreach($fullPath in $fullPaths)
{
$blockName="Updating $fullPath"
Write-Progress @scriptProgress -Status $blockName
Write-Host $blockName
#customErrors - mode attribute
[xml]$webConfigXML = Get-Content $fullPath
if ($webConfigXML.configuration."system.web".customErrors -and $webConfigXML.configuration."system.web".customErrors.mode)
{
Write-Verbose "customErrors - change: 'mode' attribute from: $webConfigXML.configuration.'system.web'.customErrors.mode to: $CustomErrorsMode"
$webConfigXML.configuration."system.web".customErrors.mode = $CustomErrorsMode
}
elseif ($webConfigXML.configuration."system.web".customErrors -and -not($wnebConfigXML.configuration."system.web".customErrors.mode))
{
Write-Verbose "customErrors - add: 'mode' attribute with value: $CustomErrorsMode"
$webConfigXML.configuration."system.web".customErrors.SetAttribute("mode", $CustomErrorsMode)
}
elseif (-not $webConfigXML.configuration."system.web".customErrors)
{
Write-Verbose "customErrors - add: 'customErrors' element and 'mode' attribute with value: $CustomErrorsMode"
$webConfigXML.configuration."system.web".AppendChild($webConfigXML.ImportNode($CustomErrorsXml.customErrors, $true))
}

#httpErrors - errorMode attribute
if ($webConfigXML.configuration."system.webserver".httpErrors -and $webConfigXML.configuration."system.webserver".httpErrors.errorMode)
{
Write-Verbose "httpErrors - change: 'errorMode' attribute from: $webConfigXML.configuration.'system.webserver'.httpErrors.errorMode to: $HttpErrorserrorMode"
$webConfigXML.configuration."system.webserver".httpErrors.errorMode = $HttpErrorserrorMode
}
elseif ($webConfigXML.configuration."system.webserver".httpErrors -and -not($webConfigXML.configuration."system.webserver".httpErrors.errorMode))
{
Write-Verbose "httpErrors - add: 'errorMode' attribute with value: $HttpErrorserrorMode"
$webConfigXML.configuration."system.webserver".httpErrors.SetAttribute("errorMode", $HttpErrorserrorMode)
}
elseif (-not $webConfigXML.configuration."system.webserver".httpErrors)
{
Write-Verbose "customErrors - add: 'httpErrors' element and 'errorMode' attribute with value: $HttpErrorserrorMode"
$webConfigXML.configuration."system.webserver".AppendChild($webConfigXML.ImportNode($HttpErrorsXml.httpErrors, $true))
}

#asp - scriptErrorSentToBrowser attribute
if ($webConfigXML.configuration."system.webserver".asp -and $webConfigXML.configuration."system.webserver".asp.scriptErrorSentToBrowser)
{
Write-Verbose "asp - change: 'scriptErrorSentToBrowser' $webConfigXML.configuration.'system.webserver'.asp.scriptErrorSentToBrowser to: $AspScriptErrorSentToBrowser"
$webConfigXML.configuration."system.webserver".asp.scriptErrorSentToBrowser = "$ScriptErrorSentToBrowser"
}
elseif ($webConfigXML.configuration."system.webserver".asp -and -not($webConfigXML.configuration."system.webserver".asp.scriptErrorSentToBrowser))
{
Write-Verbose "asp - add: 'scriptErrorSentToBrowser attribute with value: $AspScriptErrorSentToBrowser"
$webConfigXML.configuration."system.webserver".asp.SetAttribute("scriptErrorSentToBrowser", $AspScriptErrorSentToBrowser)
}
elseif (-not $webConfigXML.configuration."system.webserver".asp)
{
Write-Verbose "asp - add: 'asp' element and 'scriptErrorSentToBrowser' attribute with value: $AspScriptErrorSentToBrowser"
$webConfigXML.configuration."system.webserver".AppendChild($webConfigXML.ImportNode($AspScriptErrorSentToBrowserXml.asp, $true))
}

$webConfigXML.Save($fullPath)
}

Write-Separator -Invocation $MyInvocation -Footer
66 changes: 66 additions & 0 deletions Source/Builders/DevelopFriendly/Set-CertificateValidationMode.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

param(
[Parameter(Mandatory=$false)]
[string]$certificateValidationMode = "None"

)


$cmdletsPaths="$PSScriptRoot\..\..\Cmdlets"

. "$cmdletsPaths\Helpers\Write-Separator.ps1"
. "$cmdletsPaths\Helpers\Get-ProgressHash.ps1"

Write-Separator -Invocation $MyInvocation -Header
$scriptProgress=Get-ProgressHash -Invocation $MyInvocation


$blockName="[DEVELOPFRIENDLY][Windows Server]:Changing certificateValidationMode"
Write-Host $blockName
Write-Warning "$blockName - ONLY USE THIS FOR A LOCAL DEVELOPMENT INSTANCE!"


$blockName="Getting deployment information"
Write-Progress @scriptProgress -Status $blockName
Write-Host $blockName

$deploymentParameters = Get-ISHDeploymentParameters # -ISHDeployment $ishDeploymentName

$paramWebPath = $deploymentParameters |Where-Object -Property Name -EQ "webpath"|Select-Object -ExpandProperty Value
$paramProjectSuffix = $deploymentParameters |Where-Object -Property Name -EQ "projectsuffix"|Select-Object -ExpandProperty Value


$webPath = "$paramWebPath\Web$paramProjectSuffix\Author\ASP"
$webConfig = "web.config"
$fullISHCMPath = "$webPath\$webConfig"
Write-Verbose "ISHCM web.config: $fullISHCMPath"

$webPath = "$paramWebPath\Web$paramProjectSuffix\InfoShareCE"
$webConfig = "web.config"
$fullISHCEPath = "$webPath\$webConfig"
Write-Verbose "ISHCE web.config: $fullISHCEPath"

$webPath = "$paramWebPath\Web$paramProjectSuffix\InfoShareWS"
$webConfig = "web.config"
$fullISHWSPath = "$webPath\$webConfig"
Write-Verbose "ISHSTS web.config: $fullISHWSPath"

$fullPaths = @($fullISHCMPath,$fullISHCEPath,$fullISHWSPath)


$blockName="Processing all web.config files"
Write-Progress @scriptProgress -Status $blockName
Write-Host $blockName

foreach($fullPath in $fullPaths)
{
$blockName="Updating $fullPath - setting certificateValidationMode to: $certificateValidationMode"
Write-Progress @scriptProgress -Status $blockName
Write-Host $blockName
[xml]$webConfigXML = Get-Content $fullPath
Write-Verbose "certificateValidationMode - change from: $webConfigXML.configuration.'system.identityModel'.identityConfiguration.certificateValidation.certificateValidationMode to: $certificateValidationMode"
$webConfigXML.configuration."system.identityModel".identityConfiguration.certificateValidation.certificateValidationMode = $certificateValidationMode
$webConfigXML.Save($fullPath)
}

Write-Separator -Invocation $MyInvocation -Footer