This commit is contained in:
Philipp Kunz 2025-01-10 03:09:32 +01:00
commit 8f805e0ebf
16 changed files with 10309 additions and 0 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

19
.gitignore vendored Normal file
View File

@ -0,0 +1,19 @@
.nogit/
# artifacts
coverage/
public/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
#------# custom

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

18
npmextra.json Normal file
View File

@ -0,0 +1,18 @@
{
"gitzone": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartantivirus",
"description": "a package for doing antivirus testing",
"npmPackagename": "@push.rocks/smartantivirus",
"license": "MIT",
"projectDomain": "push.rocks"
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
}
}

50
package.json Normal file
View File

@ -0,0 +1,50 @@
{
"name": "@push.rocks/smartantivirus",
"version": "1.0.1",
"private": false,
"description": "a package for doing antivirus testing",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Task Venture Capital GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "(tsdoc)"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.25",
"@git.zone/tsbundle": "^2.0.5",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.44",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.7"
},
"dependencies": {
"@push.rocks/smartfile": "^11.1.5",
"@push.rocks/smartpath": "^5.0.18",
"axios": "^1.7.9",
"tar": "^7.4.3"
},
"repository": {
"type": "git",
"url": "git+https://code.foss.global/push.rocks/smartantivirus.git"
},
"bugs": {
"url": "https://code.foss.global/push.rocks/smartantivirus/issues"
},
"homepage": "https://code.foss.global/push.rocks/smartantivirus#readme",
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
]
}

9802
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

3
readme.hints.md Normal file
View File

@ -0,0 +1,3 @@
# Project Readme Hints
This is the initial readme hints file.

7
readme.md Normal file
View File

@ -0,0 +1,7 @@
# @push.rocks/smartantivirus
a package for doing antivirus testing
## How to create the docs
To create docs run gitzone aidoc.

35
test/test.ts Normal file
View File

@ -0,0 +1,35 @@
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import * as smartantivirus from '../ts/index.js';
let clamService: smartantivirus.ClamAvService;
tap.test('should create a ClamAvService instance', async () => {
clamService = new smartantivirus.ClamAvService();
expect(clamService).toBeDefined();
});
tap.test('should scan a string', async () => {
const scanResult = await clamService.scanString('X5O!P%@AP[4\PZX54(P^)7CC)7}' + '$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*');
console.log('Scan Result:', scanResult);
// expect(scanResult).toEqual({ isInfected: true, reason: 'FOUND' });
});
tap.start();
/* (async () => {
try {
await clamService.updateVirusDefinitions(); // Step 2: Update definitions
await clamService.startClamDaemon(); // Step 3: Start daemon
const scanResult = await clamService.scanString('EICAR test string...');
console.log('Scan Result:', scanResult);
} catch (error) {
console.error('Error:', error);
}
})(); */

View File

@ -0,0 +1,103 @@
import * as plugins from './plugins.js';
import * as paths from './paths.js';
import { exec } from 'child_process';
import net from 'net';
import { promisify } from 'util';
const execAsync = promisify(exec);
export class ClamAvService {
private host: string;
private port: number;
constructor(host: string = '127.0.0.1', port: number = 3310) {
this.host = host;
this.port = port;
}
/**
* Scans an in-memory Buffer using ClamAV daemon's INSTREAM command.
*/
public async scanBuffer(buffer: Buffer): Promise<{ isInfected: boolean; reason?: string }> {
return new Promise((resolve, reject) => {
const client = new net.Socket();
client.connect(this.port, this.host, () => {
console.log('Connected to ClamAV daemon');
client.write('zINSTREAM\0'); // Start the INSTREAM command
const chunkSize = 1024;
let offset = 0;
// Send data in chunks
while (offset < buffer.length) {
const chunk = buffer.slice(offset, offset + chunkSize);
console.log('Sending chunk:', chunk.toString('utf8'));
const sizeBuf = Buffer.alloc(4);
sizeBuf.writeUInt32BE(chunk.length, 0);
client.write(sizeBuf);
client.write(chunk);
offset += chunkSize;
}
// Send end-of-stream signal
const endOfStream = Buffer.alloc(4);
endOfStream.writeUInt32BE(0, 0);
console.log('Sending end-of-stream signal');
client.write(endOfStream);
});
client.on('data', (data) => {
const response = data.toString();
console.log('Raw Response from ClamAV:', response);
const isInfected = response.includes('FOUND');
const reason = isInfected ? response.split('FOUND')[0].trim() : undefined;
resolve({ isInfected, reason });
client.end();
});
client.on('error', (err) => {
console.error('Error communicating with ClamAV:', err);
reject(err);
});
client.on('close', () => {
console.log('Connection to ClamAV daemon closed');
});
});
}
/**
* Scans a string by converting it to a Buffer and using scanBuffer.
*/
public async scanString(input: string): Promise<{ isInfected: boolean; reason?: string }> {
console.log('Scanning string:', input); // Debug the input string
const buffer = Buffer.from(input, 'utf8');
console.log('Converted buffer:', buffer.toString('utf8')); // Debug the converted buffer
return this.scanBuffer(buffer);
}
/**
* Verifies the ClamAV daemon is reachable.
*/
public async verifyConnection(): Promise<boolean> {
return new Promise((resolve, reject) => {
const client = new net.Socket();
client.connect(this.port, this.host, () => {
console.log('Successfully connected to ClamAV daemon');
client.end();
resolve(true);
});
client.on('error', (err) => {
console.error('Failed to connect to ClamAV daemon:', err);
reject(err);
});
});
}
}

1
ts/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './classes.smartantivirus.js';

4
ts/paths.ts Normal file
View File

@ -0,0 +1,4 @@
import * as plugins from './plugins.js';
export const packageDir = plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '..');
export const nogitDir = plugins.path.join(packageDir, '.nogit/');

24
ts/plugins.ts Normal file
View File

@ -0,0 +1,24 @@
// node native scope
import * as fs from 'fs';
import * as path from 'path';
export {
fs,
path,
}
// @push.rocks scope
import * as smartpath from '@push.rocks/smartpath';
import * as smartfile from '@push.rocks/smartfile';
export {
smartpath,
smartfile,
}
// third party scope
import axios from 'axios';
export {
axios,
}

16
tsconfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"baseUrl": ".",
"paths": {}
},
"exclude": [
"dist_*/**/*.d.ts"
]
}