From 0fe35c298f313a0b0cd218a40b4cad7a0d1cf162 Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Wed, 8 May 2024 09:22:56 -0700 Subject: [PATCH] esets: repackaged as NPM module --- Changes.md | 1 + Plugins.md | 2 +- docs/plugins/esets.md | 8 ----- package.json | 1 + plugins/esets.js | 71 ------------------------------------------- 5 files changed, 3 insertions(+), 80 deletions(-) delete mode 100644 docs/plugins/esets.md delete mode 100644 plugins/esets.js diff --git a/Changes.md b/Changes.md index 97d5fe450..6e0d2da69 100644 --- a/Changes.md +++ b/Changes.md @@ -19,6 +19,7 @@ - NOTE: remove a handful of 3.0 sunset property names #3315 - deps: bump all versions to latest #3303, #3344 - dkim: repackaged as NPM module #3311 +- esets: repackaged as NPM module - greylist: repackaged as NPM module - new NPM plugin dns-list, repackages dnsbl, dnswl, backscatterer #3313 - when using message-stream, don't send default options #3290 diff --git a/Plugins.md b/Plugins.md index c5010a1ca..343e03d93 100644 --- a/Plugins.md +++ b/Plugins.md @@ -157,7 +157,7 @@ A comprehensive list of known plugins. Create a PR to add yours to these lists. [url-opendkim]: https://www.npmjs.com/package/haraka-plugin-opendkim [url-dns-list]: https://github.com/haraka/haraka-plugin-dns-list [url-early]: https://github.com/haraka/Haraka/blob/master/docs/plugins/early_talker.md -[url-esets]: https://github.com/haraka/Haraka/blob/master/docs/plugins/esets.md +[url-esets]: https://github.com/haraka/haraka-plugin-esets [url-geoip]: https://github.com/haraka/haraka-plugin-geoip [url-graph]: https://github.com/haraka/haraka-plugin-graph [url-greylist]: https://github.com/haraka/haraka-plugin-greylist diff --git a/docs/plugins/esets.md b/docs/plugins/esets.md deleted file mode 100644 index e491aa842..000000000 --- a/docs/plugins/esets.md +++ /dev/null @@ -1,8 +0,0 @@ -esets ------ - -This plugin allows virus scanning with ESET Mail Security for Linux/BSD. - -Install the software as per the intructions from ESET and enable this plugin -and it will scan each message using the "esets_cli" command which defaults to -/opt/eset/esets/bin/esets_cli. diff --git a/package.json b/package.json index e081e292b..56c5e3d41 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "haraka-plugin-dkim": "^1.0.3", "haraka-plugin-dns-list": "^1.2.0", "haraka-plugin-elasticsearch": "^8.0.2", + "haraka-plugin-esets": "^1.0.0", "haraka-plugin-fcrdns": "^1.1.0", "haraka-plugin-geoip": "^1.1.0", "haraka-plugin-graph": "^1.0.5", diff --git a/plugins/esets.js b/plugins/esets.js deleted file mode 100644 index cc4d25547..000000000 --- a/plugins/esets.js +++ /dev/null @@ -1,71 +0,0 @@ -// esets -const fs = require('fs'); -const child_process = require('child_process'); -const virus_re = new RegExp('virus="([^"]+)"'); - -exports.hook_data_post = function (next, connection) { - const plugin = this; - const cfg = this.config.get('esets.ini'); - - // Write message to temporary file - const tmpdir = cfg.main.tmpdir || '/tmp'; - const tmpfile = `${tmpdir}/${connection?.transaction?.uuid}.esets`; - const ws = fs.createWriteStream(tmpfile); - - ws.once('error', err => { - connection.logerror(plugin, `Error writing temporary file: ${err.message}`); - next(); - }); - - let start_time; - - function wsOnClose (error, stdout, stderr) { - // Remove the temporary file - fs.unlink(tmpfile, () => {}); - - // Timing - const end_time = Date.now(); - const elapsed = end_time - start_time; - - // Debugging - [stdout, stderr].forEach(channel => { - if (channel) { - const lines = channel.split('\n'); - for (const line of lines) { - if (line) connection.logdebug(plugin, `recv: ${line}`); - } - } - }); - - // Get virus name - let virus = virus_re.exec(stdout) - if (virus) virus = virus[1]; - - // Log a summary - const exit_code = parseInt((error) ? error.code : 0) - connection.loginfo(plugin, `elapsed=${elapsed}ms code=${exit_code - }${exit_code === 0 || (exit_code > 1 && exit_code < 4) - ? ` virus="${virus}"` - : ` error="${(stdout || stderr || 'UNKNOWN').replace('\n',' ').trim()}"`}`); - - // esets_cli returns non-zero exit on virus/error - if (exit_code) { - if (exit_code > 1 && exit_code < 4) { - return next(DENY, `Message is infected with ${virus || 'UNKNOWN'}`); - } - else { - return next(DENYSOFT, 'Virus scanner error'); - } - } - next(); - } - - ws.once('close', () => { - start_time = Date.now(); - child_process.exec(`LANG=C /opt/eset/esets/bin/esets_cli ${tmpfile}`, - { encoding: 'utf8', timeout: 30 * 1000 }, - wsOnClose); - }); - - connection.transaction.message_stream.pipe(ws); -}