From 6f41ddd1666dde11999ef58a8c4d5d15ad3c30d7 Mon Sep 17 00:00:00 2001 From: Steve Dinn Date: Thu, 6 Apr 2023 16:03:16 -0300 Subject: [PATCH] Fix referrer parsing. --- build-container.sh | 2 ++ source/CaddyLog-To-AccessLog.ps1 | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 build-container.sh diff --git a/build-container.sh b/build-container.sh new file mode 100644 index 0000000..a63a788 --- /dev/null +++ b/build-container.sh @@ -0,0 +1,2 @@ +#!/bin/sh +docker build ./source/ -t stevedinn/caddy-log-converter:latest diff --git a/source/CaddyLog-To-AccessLog.ps1 b/source/CaddyLog-To-AccessLog.ps1 index b60fdee..a720967 100644 --- a/source/CaddyLog-To-AccessLog.ps1 +++ b/source/CaddyLog-To-AccessLog.ps1 @@ -21,7 +21,9 @@ $outputWriter = New-Object -TypeName System.IO.StreamWriter -ArgumentList @($out Get-Content -Tail $lines -Wait -Path $inFile | ForEach-Object { $l = ConvertFrom-Json -InputObject $_ $r = $l.request; - $ua = $r.headers.'User-Agent' + + $userAgent = $r.headers.'User-Agent' | Select-Object -First 1 + $referer = $r.headers.Referer | Select-Object -First 1 $null = $builder.Clear() $null = $builder.Append($r.remote_ip) @@ -40,9 +42,9 @@ Get-Content -Tail $lines -Wait -Path $inFile | ForEach-Object { $null = $builder.Append(" ") $null = $builder.Append($l.size) $null = $builder.Append(" """) - $null = $builder.Append($r.headers.Referer) + $null = $builder.Append($referer) $null = $builder.Append(""" """) - $null = $builder.Append("$ua") + $null = $builder.Append($userAgent) $null = $builder.Append("""") $commonLog = $builder.ToString()