forked from microsoft/nav-arm-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequest.ps1
63 lines (56 loc) · 2.31 KB
/
Request.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
Param (
[int] $eventID
)
if (!(Test-Path function:AddToStatus)) {
function AddToStatus([string]$line, [string]$color = "Gray") {
("<font color=""$color"">" + [DateTime]::Now.ToString([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortTimePattern.replace(":mm",":mm:ss")) + " $line</font>") | Add-Content -Path "c:\demo\status.txt" -Force -ErrorAction SilentlyContinue
Write-Host -ForegroundColor $color $line
}
}
if (Test-Path -Path "C:\demo\*\BcContainerHelper.psm1") {
$module = Get-Item -Path "C:\demo\*\BcContainerHelper.psm1"
Import-module $module.FullName -DisableNameChecking
} else {
Import-Module -name bccontainerhelper -DisableNameChecking
}
. (Join-Path $PSScriptRoot "settings.ps1")
Add-Type -AssemblyName System.Web
$event = Get-EventLog -LogName Application -Source Application -Newest 1 | Where-Object { $_.EventID -eq $eventID }
if ($event) {
$event.ReplacementStrings | ForEach-Object {
$request = $_
$idx = $request.IndexOf("?")
if ($idx -gt 0) {
$id = $request.Substring(0,$idx)
Start-Transcript -Path "c:\demo\request\$id.txt"
$request = $request.Substring($idx)
}
$queryParameters = [System.Web.HttpUtility]::ParseQueryString($request)
$token = $QueryParameters.Get("requesttoken")
$cmd = $QueryParameters.Get("cmd")
if ("$token".Equals("$requestToken")) {
$StatusStr = "$cmd"
$Parameters = @{}
$queryParameters.Keys | ForEach-Object {
if ($_ -ne "cmd" -and "$_" -ne "requesttoken") {
$StatusStr += " -$_ '$($queryParameters[$_])'"
$Parameters += @{ "$_" = $queryParameters[$_] }
}
}
$script = Get-Item -Path "c:\demo\request\$cmd.ps1" -ErrorAction Ignore
if (($script) -and ($script.FullName.ToLowerInvariant().StartsWith("c:\demo\request\"))) {
AddToStatus "Request: $StatusStr"
. $script @Parameters
} else {
AddToStatus "Illegal request: $StatusStr"
}
} else {
AddToStatus "Illegal RequestToken"
}
if ($idx -gt 0) {
Stop-Transcript
}
}
} else {
AddToStatus "No Event found with event ID $eventId"
}