Kestrel in ASP.NET 5 Core MVC application in Debian writes escape codes to /var/log/syslog text file like
Apr 5 22:02:21 ew kestrel-store[31907]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: Microsoft.Hosting.Lifetime[0]
Apr 5 22:02:21 ew kestrel-store[31907]: Now listening on: http://localhost:5000
Apr 5 22:02:21 ew kestrel-store[31907]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: Microsoft.Hosting.Lifetime[0]
Apr 5 22:02:21 ew kestrel-store[31907]: Application started. Press Ctrl+C to shut down.
Apr 5 22:02:21 ew kestrel-store[31907]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: Microsoft.Hosting.Lifetime[0]
Apr 5 22:02:21 ew kestrel-store[31907]: Hosting environment: Production
Apr 5 22:02:21 ew kestrel-store[31907]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: Microsoft.Hosting.Lifetime[0]
Apr 5 22:02:21 ew kestrel-store[31907]: Content root path: /var/www/store5
This file is read by MVC controller and sent to user in view.
How to convert this file to html (for example, using colored or italic lines) or remove escape codes from file so that file is easier to read ?
Or how to force kestrel output plain text without escape codes ?
Controller code:
public IActionResult Syslog()
{
return new ContentResult()
{
Content = FileToStr("/var/log/syslog")
};
}
static string FileToStr(string cFileName)
{
StreamReader oReader = File.OpenText(cFileName);
string lcString = oReader.ReadToEnd();
oReader.Close();
return lcString;
}
Escape sequence is defined as:
One \x1b
One [
Zero or more parameter bytes 0x30-0x3f
Zero or more intermediate bytes 0x20-0x2f
One final byte 0x40-0x7f
Update
Code in answer adds span to start of every line and does not remove escape sequences:
<span style="color: blue">Apr 8 00:00:05 ew rsyslogd: [origin software="rsyslogd" swVersion="8.1901.0" x-pid="573" x-info="https://www.rsyslog.com"] rsyslogd was HUPed</span>
<span style="color: blue">Apr 8 00:00:05 ew systemd[1]: logrotate.service: Succeeded.</span>
<span style="color: blue">Apr 8 00:00:05 ew systemd[1]: Started Rotate log files.</span>
<span style="color: blue">Apr 8 00:00:10 ew colord[1172]: failed to get session [pid 23699]: No data available</span>
<span style="color: blue">Apr 8 00:00:12 ew colord[1172]: failed to get session [pid 23699]: No data available</span>
<span style="color: blue">Apr 8 00:00:14 ew colord[1172]: failed to get session [pid 23699]: No data available</span>
<span style="color: blue">Apr 8 00:05:01 ew CRON[23838]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)</span>
<span style="color: blue">Apr 8 00:15:01 ew CRON[24082]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)</span>
<span style="color: blue">Apr 8 00:17:01 ew CRON[24128]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)</span>
<span style="color: blue">Apr 8 00:21:49 ew kestrel-store[22413]: #033[40m#033[32minfo#033[39m#033[22m#033[49m: WebOptimizer.AssetMiddleware[1000]</span>
<span style="color: blue">Apr 8 00:21:49 ew kestrel-store[22413]: Request started for '/c/version.js'</span>
<span style="color: blue">Apr 8 00:21:49 ew kestrel-store[22413]: #033[41m#033[30mfail#033[39m#033[22m#033[49m: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]</span>
<span style="color: blue">Apr 8 00:21:49 ew kestrel-store[22413]: An unhandled exception has occurred while executing the request.</span>
Expected output is:
Hope this is helpful. I used rextester.com write a formatted code. But tests with files doesn't work there.
Please correct this post if necessary. Also its not the shortest version, but I think its most clear.
//Rextester.Program.Main is the entry point for your code. Don't change it.
//Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354)
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
public class Program
{
public static void Main(string[] args)
{
using (var reader = new StreamReader(#"c:\your_input_file.txt"))
using (var writer = new StreamWriter(#"c:\your_output_file.html"))
{
WriteHtmlHeader(writer);
string line;
while((line = reader.ReadLine()) != null)
{
line = AddSpan(line);
}
WriteHtmlFooter(writer);
}
}
private static void WriteHtmlHeader(StreamWriter outfile)
{
// writing all the header and the start of body...
// you can take it from another file
}
private static void WriteHtmlFooter(StreamWriter outfile)
{
// writing the footer of your html file
}
private static string AddSpan(string line)
{
if (Regex.IsMatch(line, "\x1b"))
{
return AddStyledSpan(line, "color: green");
}
else if (Regex.IsMatch(line, "\["))
{
return AddStyledSpan(line, "color: blue");
}
// ...
else
{
// Mark this span as error or standard
return AddStyledSpan(line, "color: red");
}
}
private static string AddStyledSpan(string line, string style)
{
return "<span style=\"" + style + "\">" + line + "</span>";
}
}
}
Hope this helps. Also look at
regex101 - online regex tester
and
debuggex - regex visualization.
(But use it carefully, regular expressions works somtimes different).
Related
I want to extract this text
Spectrum Mortis - Bit Meseri - The Incantation (2022)
Hate Legions - Exitus Letalis (Tota Vita Nihil Aliud Quam Ad Mortem Iter Est) (2014)
from this html block
<span id='tid-span-369523'><a id="tid-link-369523" href="http://metalarea.org/forum/index.php?showtopic=369523" title="This topic was started: Sep 16 2022, 04:18:47">Spectrum Mortis - Bit Meseri - The Incantation (2022)</a></span>
<span id='tid-span-221568'><a id="tid-link-221568" href="http://metalarea.org/forum/index.php?showtopic=221568" title="This topic was started: Apr 11 2014, 14:31:18">Hate Legions - Exitus Letalis (Tota Vita Nihil Aliud Quam Ad Mortem Iter Est) (2014)</a></span>
I'm trying to set this code but nothing is written on output2.txt
$html = Get-Content -Path 'C:\temp\html\metalarea2.html' -Raw
$pattern = '<span id="tid-span-\\d+"><a id="tid-link-\\d+" href=".+?" title=".+?">(.+?)</a></span>'
$matches = Select-String -InputObject $html -Pattern $pattern -AllMatches
$result = $matches | % { $_.Matches } | % { $_.Groups[1].Value }
$result | Out-File -FilePath "C:\temp\html\output2.txt"
I don't understand where the problem lies
EDIT: SOLUTIONS
$pattern = '<span id=\x27tid-span-\d+\x27><a id="tid-link-\d+" href=".+?" title=".+?">(.+?)</a></span>'
OR
$pattern = '<a id="tid-link-\d+".+?>(.+?)</a>'
It is generally a bad idea to peek and/or poke in structured text using regular expressions. Instead, it is better to use a proper (html) parser to manipulate your data.
To give you an example using the IHTMLDocument2 interface:
$Html = #'
<html>
<head>
<title>Title</title>
</head>
<body>
<span id="tid-span-369523"><a id="tid-link-369523" href="http://metalarea.org/forum/index.php?showtopic=369523" title="This topic was started: Sep 16 2022, 04:18:47">Spectrum Mortis - Bit Meseri - The Incantation (2022)</a></span>
<span id='tid-span-221568'><a id="tid-link-221568" href="http://metalarea.org/forum/index.php?showtopic=221568" title="This topic was started: Apr 11 2014, 14:31:18">Hate Legions - Exitus Letalis (Tota Vita Nihil Aliud Quam Ad Mortem Iter Est) (2014)</a></span>
<div id="something">Text within div</div>
</body>
</html>
'#
function ParseHtml($String) {
$Unicode = [System.Text.Encoding]::Unicode.GetBytes($String)
$Html = New-Object -Com 'HTMLFile'
if ($Html.PSObject.Methods.Name -Contains 'IHTMLDocument2_Write') {
$Html.IHTMLDocument2_Write($Unicode)
}
else {
$Html.write($Unicode)
}
$Html.Close()
$Html
}
$Document = ParseHtml $Html
$Document.getElementsByTagName('a') |
Where-Object { $_.id -Like 'tid-link-*' } |
Foreach-Object { $_.innerText }
Spectrum Mortis - Bit Meseri - The Incantation (2022)
Hate Legions - Exitus Letalis (Tota Vita Nihil Aliud Quam Ad Mortem Iter Est) (2014)
You can use below regular expression to capture plain text between HTML tags:
(<[^>]*>)+(?<plaintext>[^<]+)<\/[^>]*>
You can refer to this example from regex101.com: Live sample
Here is a full script example:
$html = #"
<span id="tid-span-369523"><a id="tid-link-369523" href="http://metalarea.org/forum/index.php?showtopic=369523" title="This topic was started: Sep 16 2022, 04:18:47">Spectrum Mortis - Bit Meseri - The Incantation (2022)</a></span>
<span id='tid-span-221568'><a id="tid-link-221568" href="http://metalarea.org/forum/index.php?showtopic=221568" title="This topic was started: Apr 11 2014, 14:31:18">Hate Legions - Exitus Letalis (Tota Vita Nihil Aliud Quam Ad Mortem Iter Est) (2014)</a></span>
<div id="something">Text within div</div>
"#
$pattern = '(<[^>]*>)+(?<plaintext>[^<]+)<\/[^>]*>'
$options = [System.Text.RegularExpressions.RegexOptions]::Multiline
$matches = [regex]::Matches($html, $pattern, $options)
$results = $matches | %{ $_.Groups["plaintext"].Value }
$results
Now I'm working on collecting logs from many OenWRT routers and using for this task fluentd.
Unfortunately, I don't know why my parser isn't working.
For example, logs looks like this:
Aug 15 06:55:05 HOST123 daemon:warning Expiring: (mcpd_process_query_timer)
Aug 15 06:55:05 HOST123 daemon:warning Sending IGMPv2 query of len: 8
Aug 15 06:55:05 HOST123 daemon:warning MLD QUERY: MRT is 00:0a ifindex=15
Aug 15 06:55:05 HOST123 daemon:warning Sending Query size: 28
Aug 15 06:55:07 HOST123 daemon:notice iptv (8359): udhcpc: sending renew to 192.168.131.1
Aug 15 06:55:21 HOST123 daemon:notice data (8351): udhcpc: sending renew to 192.168.130.1
Aug 15 07:06:17 HOST123 daemon:notice voice (6262): udhcpc: sending renew to 192.168.117.1
Aug 15 07:06:17 HOST123 daemon:notice voice (6262): udhcpc: lease of 192.168.117.8 obtained, lease time 600
Aug 15 07:06:22 HOST123 daemon:notice mgmt (6263): udhcpc: sending renew to 192.168.121.1
Aug 15 07:06:22 HOST123 daemon:notice mgmt (6263): udhcpc: lease of 192.168.121.8 obtained, lease time 600
Aug 15 07:06:24 HOST123 daemon:notice iptv (6261): udhcpc: sending renew to 192.168.131.1
Aug 15 07:06:25 HOST123 daemon:notice iptv (6261): udhcpc: lease of 192.168.131.8 obtained, lease time 600
My config:
<source>
#type syslog
port 1514
tag scom
<parse>
#type syslog
expression /^(?<logtime>[^ ]) (?<host>HOST\d{4}) (?<facility>[^ ]*) (?<message>[\d\w\s\S\W]*)$/
time_key logtime
time_format "%b %d %T"
</parse>
</source>
or
<source>
#type syslog
port 1514
tag scom
expression /^\(?<time>[^ ]*) (?<host>[^ ]*) (?<facility>[^ ]*) (?<message>[\d\w\s\S\W]*)$/
time_format "%b %d %H:%M:%S"
</source>
And no one solution is working.
What's wrong?
I have a problem in app rails.
My app works fine on the development server, but on my host it does not work when uploading, and throws me this error on any path of my application.
I checked all the drivers to see if there are any closures, but I did not find anything unusual.
Here I show my log production.
I, [2017-07-06T02:47:57.031902 #30638] INFO -- : Started GET "/" for 187.204.162.35 at 2017-07-06 02:47:57 +0200
I, [2017-07-06T02:47:57.046063 #30638] INFO -- : Processing by WelcomeController#index as HTML
I, [2017-07-06T02:47:57.608254 #30638] INFO -- : Rendered welcome/index.html.erb within layouts/application (535.1ms)
I, [2017-07-06T02:47:57.608542 #30638] INFO -- : Completed 500 Internal Server Error in 562ms (ActiveRecord: 0.0ms)
F, [2017-07-06T02:47:57.610259 #30638] FATAL -- :
ActionView::Template::Error (SyntaxError: Unexpected token: keyword (else)):
130: <div class="row">
131:
132: <div class="col-md-4">
133: <%= image_tag("mision.png", :style => "width: 50px; margin: auto; display: block;", class: "img-responsive") %>
134: <h3 class="text-center" style="color: #004467;"><strong>MISIÓN</strong></h3>
135: <p style=" text-align: justify;">Hacer realidad los sueños de nuestros clientes Lo logramos con: propuestas y soluciones claras, asesoría persona$
136: </div>
app/views/welcome/index.html.erb:133:in `_app_views_welcome_index_html_erb___3018899638396619987_70193610437540'
I'm using logback for logging from an app deployed in Tomcat, with a fairly simple setup (see code fragments). We use a RollingFileAppender, with TimeBasedRollingPolicy, set for daily rollover. When running locally, everything appears to be fine. When running in AWS in an EC2 instance, I'm seeing that some log files are missing.
I wrote a really simple app that does nothing but log once per second with a counter, and then a logback config that rolls every minute. For this particular test, we're seeing every third log file is missing.
So, for example, we'll get:
-rw-r--r-- 1 tomcat tomcat 891 May 13 18:46 logtest_tomcat.2014-05-13_1845.0.log.gz
-rw-r--r-- 1 tomcat tomcat 499 May 13 18:47 logtest_tomcat.2014-05-13_1846.0.log.gz
-rw-r--r-- 1 tomcat tomcat 541 May 13 18:49 logtest_tomcat.2014-05-13_1848.0.log.gz
-rw-r--r-- 1 tomcat tomcat 519 May 13 18:50 logtest_tomcat.2014-05-13_1849.0.log.gz
-rw-r--r-- 1 tomcat tomcat 532 May 13 18:52 logtest_tomcat.2014-05-13_1851.0.log.gz
-rw-r--r-- 1 tomcat tomcat 510 May 13 18:53 logtest_tomcat.2014-05-13_1852.0.log.gz
-rw-r--r-- 1 tomcat tomcat 536 May 13 18:55 logtest_tomcat.2014-05-13_1854.0.log.gz
-rw-r--r-- 1 tomcat tomcat 1226 May 13 18:56 logtest_tomcat.2014-05-13_1855.0.log.gz
-rw-r--r-- 1 tomcat tomcat 531 May 13 18:58 logtest_tomcat.2014-05-13_1857.0.log.gz
-rw-r--r-- 1 tomcat tomcat 496 May 13 18:59 logtest_tomcat.2014-05-13_1858.0.log.gz
-rw-r--r-- 1 tomcat tomcat 1244 May 13 19:01 logtest_tomcat.2014-05-13_1900.0.log.gz
-rw-r--r-- 1 tomcat tomcat 496 May 13 19:02 logtest_tomcat.2014-05-13_1901.0.log.gz
-rw-r--r-- 1 tomcat tomcat 514 May 13 19:04 logtest_tomcat.2014-05-13_1903.0.log.gz
-rw-r--r-- 1 tomcat tomcat 500 May 13 19:05 logtest_tomcat.2014-05-13_1904.0.log.gz
-rw-r--r-- 1 tomcat tomcat 522 May 13 19:07 logtest_tomcat.2014-05-13_1906.0.log.gz
The file format is yyyy-mm-dd_HHmm - so you can see that 1847, 1850, 1853, 1856, 1859, 1902, 1905 are all missing.
I've checked the contents - the sequential numbering on the log statements jumps by 60 for the missing logs - so it's not that multiple minutes are being collapsed into a single rolled over log.
We also thought it might be due to our Splunk forwarder - we ran the test both with and without the Splunk forwarder running, and got the same results - every third log file is missing.
Here's the logback appender for this test:
<appender name="daily" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${bc.logs.home}/logtest_tomcat.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Rollover every minute for this test -->
<fileNamePattern>${bc.logs.home}/logtest_tomcat.%d{yyyy-MM-dd_HHmm}.%i.log.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 250MB -->
<maxFileSize>250MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>60</maxHistory>
</rollingPolicy>
<append>true</append>
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm:ss,SSS z", UTC} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
And here's my little driver class (the 'BCLog' is a simple wrapper around slf4j logging, instantiated by
Logger log = LoggerFactory.getLogger(clazz);
)
package com.sirsidynix.logtest.biz.svc.impl;
import com.sirsidynix.bccommon.util.BCLog;
import com.sirsidynix.bccommon.util.BCLogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
public class JustLogIt implements InitializingBean, DisposableBean
{
private static final BCLog LOG = BCLogFactory.getLog(JustLogIt.class);
private Thread thread;
#Override
public void afterPropertiesSet() throws Exception
{
LOG.info("Firing up JustLogIt thread");
thread = new Thread(){
#Override
public void run()
{
long iteration = 0;
while (true)
{
try
{
Thread.sleep(1000);
iteration++;
LOG.info("Logging Iteration " + iteration);
}
catch (InterruptedException e)
{
LOG.info("LogIt thread sleep interrupted!!!");
}
}
}
};
thread.start();
}
#Override
public void destroy() throws Exception
{
LOG.info("Shutting down JustLogIt thread");
thread.interrupt();
}
}
Any ideas?
Thanks!
When I add a pass in a device, I see on the console like this:
Mar 26 14:32:36 CamMobs-iPod4 passd[7128] <Warning>: Card has more than 10 locations. Capping.
Mar 26 14:32:38 CamMobs-iPod4 MobileSafari[7115] <Warning>: Warning: Attempt to dismiss from view controller <BrowserRootViewController: 0x1ed546a0> while a presentation or dismiss is in progress!
Mar 26 14:32:39 CamMobs-iPod4 backboardd[52] <Warning>: CoreAnimation: updates deferred for too long
Mar 26 14:32:39 CamMobs-iPod4 locationd[41] <Notice>: Location icon should now be in state 'Active'
Mar 26 14:32:50 CamMobs-iPod4 locationd[41] <Notice>: Location icon should now be in state 'Inactive'
Mar 26 14:32:52 CamMobs-iPod4 profiled[7122] <Notice>: (Note ) profiled: Idled.
Mar 26 14:32:52 CamMobs-iPod4 profiled[7122] <Notice>: (Note ) profiled: Service stopping.
Mar 26 14:33:31 CamMobs-iPod4 locationd[41] <Warning>: Launch Services: Registering unknown app identifier com.apple.PassKit failed
Mar 26 14:33:31 CamMobs-iPod4 locationd[41] <Warning>: Launch Services: Unable to find app identifier com.apple.PassKit
Mar 26 14:33:33 CamMobs-iPod4 configd[50] <Notice>: network changed: v4(en0:192.168.1.109) DNS Proxy
Mar 26 14:33:53 CamMobs-iPod4 backboardd[52] <Notice>: Posting 'com.apple.iokit.hid.displayStatus' notifyState=0
.....
Why it tries to register to com.apple.PassKit ?
In my server, I use some codes in index.php like the following:
<?php
// Transfer Request URL into array
$request = explode("/", substr(#$_SERVER['REQUEST_URI'], 1));
//$request = explode("/", substr(#$_SERVER['REQUEST_URI'], 1));
print_r($_SERVER['REQUEST_URI']);
if (strtoupper($_SERVER['REQUEST_METHOD']) === "POST"
&& isset($_SERVER['HTTP_AUTHORIZATION'])
&& strpos($_SERVER['HTTP_AUTHORIZATION'], 'ApplePass') === 0
&& $request[2] === "devices"
&& $request[4] === "registrations") {
$auth_key = str_replace('ApplePass ', '', $_SERVER['HTTP_AUTHORIZATION']);
$device_id = $request[3];
$pass_id = $request[5];
$serial = $request[6];
echo $request[3];
//$device_id = $_POST[''];
echo $device_id;
echo $pass_id;
echo $serial ;
// Catch the JSON post and decode it
$dt = #file_get_contents('php://input');
// $dt = #file_get_contents('php://input');
//$device_token = json_decode($dt);
//$device_token = $device_token->pushToken;
$pushtoken=json_decode($dt)->pushToken;
if (!$device_token) die('No Token Found'); // Token wasn't found
$dbhost = 'localhost:8889';
$dbuser = 'root';
$dbpass = 'root';
$dbname = 'passesdb';
$conn = mysql_connect($dbhost, $dbuser, $dbpass)
or die ('Error connecting to mysql'.mysql_error());
mysql_select_db($dbname);
mysql_query("SET NAMES UTF8");
mysql_query($sql,$conn);
$table = 'Devices';
$sql = mysql_query("insert into Devices values('$device_id','$pushtoken')");
mysql_query($sql);
exit;
}
?>
This is what a successful registration looks like in the console:
1. Mar 26 17:00:03 iPhone5 passd[6262] <Warning>: Generating POST request with URL <https:/afr.passk.it/v1/devices/7864dc8fdcfe739273cf7362a0db2b35/registrations/pass.it.passk.developer3/1wqdDAqHydkRURA9YCjbq>
2. Mar 26 17:00:03 iPhone5 passd[6262] <Warning>: Request contains header field <Authorization: ApplePass 5cdddad65324384efa39575a4cf22424>
3. Mar 26 17:00:03 iPhone5 passd[6262] <Warning>: Request contains body dictionary {
pushToken = 0bbe54794500332b789a3ddb69827386d5c9aad1cb035c9f2725761d419950b2;
}
4. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Register task (for device 7864dc8fdcfe739273cf7362a0db2b35, pass type pass.it.passk.developer3, serial number 1wqdDAqHydkRURA9YCjbq; with web service url https://afr.passk.it/) got response with code 201
5. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Generating GET request with URL <https:/afr.passk.it/v1/devices/7864dc8fdcfe739273cf7362a0db2b35/registrations/pass.it.passk.developer3?passesUpdatedSince=1364287618>
6. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Generating GET request with URL <https:/afr.passk.it/v1/passes/pass.it.passk.developer3/1wqdDAqHydkRURA9YCjbq>
7. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Request contains header field <If-Modified-Since: Tue, 26 Mar 2013 07:35:33 GMT>
8. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Request contains header field <Authorization: ApplePass 5cdddad65324384efa39575a4cf22424>
9. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Get serial #s task (for device 7864dc8fdcfe739273cf7362a0db2b35, pass type pass.it.passk.developer3, last updated 1364287618; with web service url https://afr.passk.it/) got response with code 204
10. Mar 26 17:00:04 iPhone5 passd[6262] <Warning>: Get serial numbers task completed with update tag (null), serial numbers (null)
11. Mar 26 17:00:05 iPhone5 passd[6262] <Warning>: Get pass task (pass type pass.it.passk.developer3, serial number 1wqdDAqHydkRURA9YCjbq, if-modified-since Tue, 26 Mar 2013 07:35:33 GMT; with web service url https://afr.passk.it/) got response with code 304
What you have posted above is only the last line of this process, (where passd has picked up that you have more than 10 locations in your pass.json).
If you examine the above you can see the flow of events that your web service needs to respond to:
Row 1: Device sends a POST request to:
https://webserviceURL/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}/{serialNumber}`
Row 2: POST request is sent with the header field:
Authorization: ApplePass {authenticationToken}
Row 3: POST body contains the JSON Dictionary:
{
pushToken = {pushToken};
}
Provided your rewrite rule is correct, your PHP code should analyse the URL and capture the deviceLibraryIdentifier and pushToken and store it in the database, linked to the pass record containing the serialNumber, authenticationToken and passTypeIdentifier.
Then Row 4: Your web service responds to the device with a 201 code to indicate that the registration was successful.
On Row 5: The device then generates a GET request to your web service to check if there is a newer versions pof passes for the same certificate:
https:/webserviceURL/v1/devices/{deviceLibraryIdentifier}/registrations/{passTypeIdentifier}?passesUpdatedSince={lastUpdateTag}
On Row 6, 7 and 8: The device generates a GET request to your web service to check if there is a newer version of this specific pass. It provides an If-Modified-Since header containing the date provided in the header of the last downloaded .pkpass bundle (Row 7), and provides another Authorization header containing Applepass {authenticationToken} (Row 8) so that your web service can validate the request against by checking the database record for the serialNumber.
https:/webserviceURL/v1/passes/{passTypeIdentifier}/{serialNumber}
Header: If-Modified-Since: {last modified date}
Header: Authorization: ApplePass {authenticationToken}
On Row 9: the web service responds with a 204 response, indicating that there are no serialNumbers for the passTypeIdentifier that require updating. Row 10 confirms this.
Finally, on Row 11, the device receives a 304 response from your web service, confirming that the pass it has just installed is the latest version of the pass.
The above outlines precisely what your web service will receive and the responses it needs to provide to successfully register a device.