techsneeze / dmarcts-report-viewer

DMARC Report Tool for use with rddmarc or dmarcts-report-parser (formerly imap-dmarcts)
http://www.techsneeze.com/dmarc-report/
GNU General Public License v3.0
195 stars 56 forks source link

Add xml formatting for XML viewer #46

Closed trogper closed 4 years ago

trogper commented 4 years ago

this PR adds js function for XML formatting and applies it when showing the xource XML for dmarc reports

jnew-gh commented 4 years ago

Why do we need this? The raw xml is already wrapped in a <pre lang="xml"></pre> tag and is formatted to xml by the browser. See http://www.techsneeze.com/wp-content/uploads/2020/07/dmarcts-report-viewer.ReportDetailWithXML.png

The tag has support from all the major browsers. See https://www.w3schools.com/tags/tag_pre.asp

It works for me in the latest versions of Chrome, Firefox and Waterfox on Linux. Is there a specific browser or case where <pre lang="xml"> doesn't work?

trogper commented 4 years ago

I didn't even know browsers supported this, when I opened the XML viewer first time, it was just two lines. It seems that webkit (safari and every browser on iOS) does not support it. I have checked just now on iPadOS 14.0.1 with Chrome 85.0.4183.109 and it is the same, two lines only. Edit: so it is caused by reports from mail.ru. Reports from gmail.com and others are just fine. Will have to investigate further

jnew-gh commented 4 years ago

Hmm, interesting.

Can you post a mail.ru report (suitably scrubbed of personally identifiable data, of course)?

trogper commented 4 years ago

The <pre lang="xml"> doesn't work for even simple xml such as <xml><a>asdjo</a><v>qwer</v></xml>. XML reports from gmail come already formatted, that's why it looks ok, but mail.ru sends non-formatted. mail.ru report.zip

trogper commented 4 years ago

and my "enhancement" doesn't even work too, because I'm calling the function from the wrong place and formatting innerHTML 🤦‍♂️

trogper commented 4 years ago

So I moved the formatting from js to php, it works now. Thanks for assistance and sorry if I bothered you

jnew-gh commented 4 years ago

Absolutely no bother. We need to know if code doesn't work.

Your code works well for me on both formatted and unformatted xml. Nice, elegant solution. Thanks!

I'm not the repository owner so I can't merge the request but I'm sure @techsneeze will review it soon.