Skip to content

Commit

Permalink
Release v1.0.14 (#33)
Browse files Browse the repository at this point in the history
* ci: run on PR
* ci(publish): constrain to when package.json changes
* style: remove useless variable
* style(es6): eslint prefer-template
  • Loading branch information
msimerson authored Dec 13, 2023
1 parent eb5e0e4 commit 8765f9f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI

on: [ push ]
on: [ push, pull_request ]

env:
CI: true
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ on:
push:
branches:
- master
paths:
- package.json

env:
CI: true

jobs:
publish:
uses: haraka/.github/.github/workflows/publish.yml@master
secrets: inherit
secrets: inherit
2 changes: 1 addition & 1 deletion .release
Submodule .release updated 4 files
+6 −2 CHANGELOG.md
+8 −0 README.md
+4 −1 finish.sh
+2 −2 submit.sh
8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
### Unreleased


### [1.0.14] - 2023-12-12

- style: remove useless variable
- ci(publish): constrain to when package.json changes
- ci: run on PR


### [1.0.13] - 2022-06-05

- doc(README): update CI badge URL
Expand Down Expand Up @@ -80,3 +87,4 @@

[1.0.12]: https://github.com/haraka/haraka-plugin-log-reader/releases/tag/1.0.12
[1.0.13]: https://github.com/haraka/haraka-plugin-log-reader/releases/tag/1.0.13
[1.0.14]: https://github.com/haraka/haraka-plugin-log-reader/releases/tag/1.0.14
63 changes: 30 additions & 33 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ let plugin;

exports.register = function () {
plugin = this;
plugin.get_logreader_ini();
plugin.load_karma_ini();
this.get_logreader_ini();
this.load_karma_ini();
}

exports.hook_init_http = function (next, server) {
Expand All @@ -19,7 +19,6 @@ exports.hook_init_http = function (next, server) {
}

exports.get_logreader_ini = function () {
plugin = this;
plugin.cfg = plugin.config.get('log.reader.ini', function () {
plugin.get_logreader_ini();
})
Expand Down Expand Up @@ -71,7 +70,7 @@ exports.get_logs = function (req, res) {
// spawning a grep process is quite a lot faster than fs.read
// (yes, I benchmarked it)
exports.grepWithShell(log, uuid, function (err, matched) {
if (err) return res.send('<p>' + err + '</p>');
if (err) return res.send(`<p>${err}</p>`);

exports.asHtml(uuid, matched, function (html) {
res.send(html);
Expand Down Expand Up @@ -128,7 +127,7 @@ exports.asHtml = function (uuid, matched, done) {
if (uuidMatch && uuidMatch[1]) {
transId = uuidMatch[1].match(/\.([0-9]{1,2})$/);
}
if (transId && transId[1]) replaceString = '[' + transId[1] + '] ';
if (transId && transId[1]) replaceString = `[${transId[1]}] `;

let trimmed = line
.replace(/\[[A-F0-9\-.]{12,40}\] /, replaceString) // UUID
Expand All @@ -142,7 +141,7 @@ exports.asHtml = function (uuid, matched, done) {
trimmed = trimmed.replace(/(?: [a-z.-]+)? haraka: /, ' ');
}

rawLogs += trimmed + '<br>';
rawLogs += `${trimmed}<br>`;
if (/\[karma/.test(line) && /awards/.test(line)) {
lastKarmaLine = line;
}
Expand All @@ -155,22 +154,22 @@ exports.asHtml = function (uuid, matched, done) {
}

done(
htmlHead() +
`${htmlHead() +
htmlBody(
`for connection ${uuid} on ${monthDay}`,
getAwards(awardNums).join(''),
getResolutions(awardNums).join('')
) +
rawLogs + '</pre></div></body></html>'
rawLogs}</pre></div></body></html>`
);
}

// exports.grepWithFs = function (file, regex, done) {
// var wantsRe = new RegExp(regex);
// var fsOpts = { flag: 'r', encoding: 'utf8' };
// const wantsRe = new RegExp(regex);
// const fsOpts = { flag: 'r', encoding: 'utf8' };
// require('fs').readFile(log, fsOpts, function (err, data) {
// if (err) throw (err);
// var res = '';
// let res = '';
// data.toString().split(/\n/).forEach(function (line) {
// if (wantsRe && !wantsRe.test(line)) return;
// res += line + '\n';
Expand All @@ -191,13 +190,12 @@ function getAwards (awardNums) {

const listItems = [];
awards.sort(sortByAward).forEach(function (a) {
const start = '<li> ' + a.award + ', ';
const start = `<li> ${a.award}, `;
if (a.reason) {
listItems.push(start + a.reason + ' (' + a.value + ')</li>');
listItems.push(`${start + a.reason} (${a.value})</li>`);
return;
}
listItems.push(start + a.pi_name + ' ' + a.property +
' ' + a.value + '</li>');
listItems.push(`${start + a.pi_name} ${a.property} ${a.value}</li>`);
});
return listItems;
}
Expand All @@ -217,7 +215,7 @@ function getResolutions (awardNums) {
if (!a.resolution) return;
if (resolutionSeen[a.resolution]) return;
resolutionSeen[a.resolution] = true;
listItems.push('<li>' + a.resolution + '</li>');
listItems.push(`<li>${a.resolution}</li>`);
});
return listItems;
}
Expand All @@ -229,16 +227,15 @@ function sortByAward (a, b) {
}

function htmlHead () {
const str = '<html> \
<head> \
<meta charset="utf-8"> \
<link rel="stylesheet" href="/haraka/css/bootstrap.min.css"> \
<link rel="stylesheet" href="/haraka/css/bootstrap-theme.min.css"> \
<style> \
div { padding: 1em; } \
</style> \
</head>';
return str;
return '<html> \
<head> \
<meta charset="utf-8"> \
<link rel="stylesheet" href="/haraka/css/bootstrap.min.css"> \
<link rel="stylesheet" href="/haraka/css/bootstrap-theme.min.css"> \
<style> \
div { padding: 1em; } \
</style> \
</head>';
}

function htmlBody (uuid, awards, resolve) {
Expand All @@ -250,19 +247,19 @@ function htmlBody (uuid, awards, resolve) {
your IT helpdesk or Systems Administrator and ask them for help.</p>';

if (awards) {
str += '<hr><h3>Policy Rules Matched</h3> \
<ul>' + awards + '</ul>';
str += `<hr><h3>Policy Rules Matched</h3> \
<ul>${awards}</ul>`;
}

if (resolve) {
str += '<hr><h3>Steps to Resolve</h3> \
<ul>' + resolve + '</ul>';
str += `<hr><h3>Steps to Resolve</h3> \
<ul>${resolve}</ul>`;
}

str += '<hr> \
str += `<hr> \
<h3>Raw Logs</h3> \
<p>' + uuid + '</p> \
<p>${uuid}</p> \
<pre> \
\n';
\n`;
return str;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "haraka-plugin-log-reader",
"version": "1.0.13",
"version": "1.0.14",
"description": "display log entries from haraka log files via HTTP",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 8765f9f

Please sign in to comment.