npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

antivirus-microservice

v2.1.1

Published

Antivirus Microsevice

Downloads

10

Readme

antivirus-microservice

Antivirus Microservice

This is a free antivirus microservice for file scanning using ClamAV. The service is written in TypeScript and uses Bun as the runtime environment.

DEMO

Demo with default maximum file upload size 512Kb is here

Features

  • Free solution for antivirus file scanning
  • There are clients available for Node.js, PHP, and Python.
  • Uses the reliable and widely adopted ClamAV antivirus engine
  • Easy deployment with Docker
  • Simple RESTful API for file upload and scanning
  • Automatic waiting for ClamAV to start up

Table of Contents

Antivirus Microservice Server

Requirements

  • Docker
  • Docker Compose

Installation and Running

  1. Clone the repository:

    git clone https://github.com/ivanoff/antivirus-microservice.git
    cd antivirus-microservice
  2. Build the Docker image:

    sudo docker compose build
  3. Start the service:

    sudo docker compose up

After successful startup, you will see the message:

[2024-08-10T11:27:05.038Z] Service started on 3000 port

Usage

The service provides a single endpoint for uploading and scanning files.

Scanning a File

Send a POST request to http://localhost:3000 with the file in a multipart/form-data form.

Example of checking a file without a virus:

curl -X POST http://localhost:3000 -F "file=@Dockerfile"

Response:

{"ok":true}

Checking a File with a Virus

To demonstrate working with an infected file, first create a test virus:

base64 -d virus.txt.base64 > virus.txt

Then send the file for scanning:

curl -X POST http://localhost:3000 -F "[email protected]"

Response:

{"ok":false,"viruses":["Eicar-Signature"]}

Notes

  • The service automatically deletes scanned files after scanning.
  • In case of an error during file upload or scanning, the service will return an appropriate error message.

Antivirus Microservice Client

This client provides a simple interface to interact with the Antivirus Microservice. It allows you to easily scan files for viruses using the ClamAV engine.

See Antivirus Microservice Server section to set up the server.

Installation

To install the Antivirus Microservice client, use npm:

npm i -S antivirus-microservice

Usage

Here's a basic example of how to use the Antivirus Microservice client:

import Antivirus from 'antivirus-microservice';

// Initialize the client with the server URL
const antivirus = new Antivirus('http://localhost:3000');

// For example: Create a test file (this is the EICAR test virus file)
const file = new File(['X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*'], 'test.txt', { type: 'text/plain' });

// Check the file
const { ok, viruses } = await antivirus.checkFile(file);

// Log the result
console.log(ok? 'File is clean' : `File is infected: ${viruses}`);
// Result> File is infected: Win.Test.EICAR_HDB-1

In this example, we're creating a file with the EICAR test virus signature. This is a standard test file used to verify that antivirus software is working correctly. When scanned, it should be detected as a virus.

API

The Antivirus class provides the following method:

  • checkFile(file: File | Blob): Promise<{ ok: boolean, viruses?: string[], error?: string }>

    Scans the provided file for viruses. Returns a promise that resolves to an object with:

    • ok: boolean indicating whether the file is clean (true) or infected (false)
    • viruses: an array of detected virus names (only present if ok is false)
    • error: a string with error (only present if ok is false)

Notes

  • Make sure the Antivirus Microservice server is running and accessible at the URL you provide when initializing the Antivirus client.
  • The client works with both File and Blob objects, making it flexible for various use cases.
  • Error handling is built into the client. If there's an error communicating with the server, the checkFile method will return { ok: false, viruses: ['Error checking file'] }.

For more information on setting up and using the server, refer to the Antivirus Microservice Server documentation above.

Nginx configuration

Here is the Nginx configuration with a 200MB file size limit set as an example:

server {
    listen       80;
    server_name  antivirus.your-domain.com;

    root /path/to/antivirus-microservice/www;
    index index.html;

    error_log /var/log/nginx/antivirus.your-domain.com.error.log;
    access_log /var/log/nginx/antivirus.your-domain.com.access.log;

    location / {
    }

    location /check {
        rewrite ^/check /$1 break;
        resolver 127.0.0.1;
        proxy_pass http://antivirus-server:3000;
        proxy_set_header X-Real-IP       $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host            $host;
        proxy_connect_timeout 120;
        proxy_send_timeout    120;
        proxy_read_timeout    180;
        client_max_body_size  100M;
    }
}

License

This project is distributed under the MIT license. See the LICENSE file for more information.

Please note that ClamAV is licensed under the Apache 2.0 license. More details can be found here

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Support

If you encounter any problems or have questions, please open an issue in the project repository.

Created by

Dimitry Ivanov [email protected] # curl -A cv ivanoff.org.ua