63 строки
2.3 KiB
PowerShell
63 строки
2.3 KiB
PowerShell
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\navcontainerhelper-dev\NavContainerHelper.psm1") {
|
|
Import-module "C:\demo\navcontainerhelper-dev\NavContainerHelper.psm1" -DisableNameChecking
|
|
} else {
|
|
Import-Module -name navcontainerhelper -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"
|
|
}
|