completed the UI and docker-compose.yaml basic app

This commit is contained in:
Volodymyr Smirnov 2020-10-27 19:26:16 +02:00
parent 61224d5cb5
commit 931db11b6e
30 changed files with 391 additions and 278 deletions

View File

@ -3,3 +3,6 @@
Dockerfile
bin
obj
dist
node_modules
.nuxt

View File

@ -7,14 +7,6 @@
<option name="command" value="" />
<option name="containerName" value="malware-multi-scan-worker-clamav" />
<option name="entrypoint" value="" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9901" />
<option name="hostPort" value="9901" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="" />
<option name="sourceFilePath" value="MalwareMultiScan.Backends/Dockerfiles/Clamav.Dockerfile" />
</settings>

View File

@ -7,14 +7,6 @@
<option name="command" value="" />
<option name="containerName" value="malware-multi-scan-worker-comodo" />
<option name="entrypoint" value="" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9901" />
<option name="hostPort" value="9901" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="" />
<option name="sourceFilePath" value="MalwareMultiScan.Backends/Dockerfiles/Comodo.Dockerfile" />
</settings>

View File

@ -7,14 +7,6 @@
<option name="command" value="" />
<option name="containerName" value="malware-multi-scan-worker-drweb" />
<option name="entrypoint" value="" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9901" />
<option name="hostPort" value="9901" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="" />
<option name="sourceFilePath" value="MalwareMultiScan.Backends/Dockerfiles/DrWeb.Dockerfile" />
</settings>

View File

@ -7,14 +7,6 @@
<option name="command" value="" />
<option name="containerName" value="malware-multi-scan-worker-kes" />
<option name="entrypoint" value="" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9901" />
<option name="hostPort" value="9901" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="" />
<option name="sourceFilePath" value="MalwareMultiScan.Backends/Dockerfiles/KES.Dockerfile" />
</settings>

View File

@ -7,14 +7,6 @@
<option name="command" value="" />
<option name="containerName" value="malware-multi-scan-worker-mcafee" />
<option name="entrypoint" value="" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9901" />
<option name="hostPort" value="9901" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="" />
<option name="sourceFilePath" value="MalwareMultiScan.Backends/Dockerfiles/McAfee.Dockerfile" />
</settings>

View File

@ -7,14 +7,6 @@
<option name="command" value="" />
<option name="containerName" value="malware-multi-scan-worker-sophos" />
<option name="entrypoint" value="" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9901" />
<option name="hostPort" value="9901" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="" />
<option name="sourceFilePath" value="MalwareMultiScan.Backends/Dockerfiles/Sophos.Dockerfile" />
</settings>

View File

@ -7,14 +7,6 @@
<option name="command" value="" />
<option name="containerName" value="malware-multi-scan-worker-windows-defender" />
<option name="entrypoint" value="" />
<option name="portBindings">
<list>
<DockerPortBindingImpl>
<option name="containerPort" value="9901" />
<option name="hostPort" value="9901" />
</DockerPortBindingImpl>
</list>
</option>
<option name="commandLineOptions" value="" />
<option name="sourceFilePath" value="MalwareMultiScan.Backends/Dockerfiles/WindowsDefender.Dockerfile" />
</settings>

16
Dockerfile Normal file
View File

@ -0,0 +1,16 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS builder
WORKDIR /src
COPY MalwareMultiScan.Scanner /src/MalwareMultiScan.Scanner
COPY MalwareMultiScan.Backends /src/MalwareMultiScan.Backends
RUN dotnet publish -c Release -r linux-x64 -o ./publish MalwareMultiScan.Scanner/MalwareMultiScan.Scanner.csproj
FROM mcr.microsoft.com/dotnet/core/runtime:3.1
WORKDIR /worker
COPY --from=builder /src/publish /worker
ENTRYPOINT ["/worker/MalwareMultiScan.Scanner"]

View File

@ -0,0 +1,19 @@
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS builder
WORKDIR /src
COPY MalwareMultiScan.Api /src/MalwareMultiScan.Api
COPY MalwareMultiScan.Backends /src/MalwareMultiScan.Backends
RUN dotnet publish -c Release -r linux-x64 -o ./publish MalwareMultiScan.Api/MalwareMultiScan.Api.csproj
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /worker
COPY --from=builder /src/publish /worker
ENV ASPNETCORE_URLS=http://+:5000
ENV ASPNETCORE_ENVIRONMENT=Production
ENTRYPOINT ["/worker/MalwareMultiScan.Api"]

View File

@ -39,13 +39,15 @@ namespace MalwareMultiScan.Api.Services
{
_bus.Receive<ScanResultMessage>(_configuration.GetValue<string>("ResultsSubscriptionId"), async message =>
{
message.Threats ??= new string[] { };
_logger.LogInformation(
$"Received a result from {message.Backend} for {message.Id} " +
$"with threats {string.Join(",", message.Threats)}");
await _scanResultService.UpdateScanResultForBackend(
message.Id, message.Backend, true,
message.Succeeded, message.Threats ?? new string[] { });
message.Succeeded, message.Threats);
});
_logger.LogInformation(

View File

@ -6,6 +6,7 @@
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {

View File

@ -1,2 +1,23 @@
- id: dummy
enabled: true
- id: clamav
enabled: true
- id: windows-defender
enabled: true
- id: comodo
enabled: false
- id: drweb
enabled: false
- id: kes
enabled: false
- id: mcafee
enabled: false
- id: sophos
enabled: false

View File

@ -27,6 +27,8 @@ namespace MalwareMultiScan.Backends.Backends.Implementations
private static async Task<string[]> Scan()
{
throw new Exception("Something");
await Task.Delay(
TimeSpan.FromSeconds(5));

View File

@ -10,7 +10,7 @@ namespace MalwareMultiScan.Backends.Backends.Implementations
{
}
public override string Id { get; } = "mcafeee";
public override string Id { get; } = "mcafee";
protected override string BackendPath { get; } = "/usr/local/uvscan/uvscan";

View File

@ -0,0 +1,3 @@
FROM mindcollapse/malware-multi-scan-scanner:latest
ENV BackendType=Dummy

View File

@ -2,12 +2,12 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS builder
WORKDIR /src
COPY MalwareMultiScan.Worker /src/MalwareMultiScan.Scanner
COPY MalwareMultiScan.Scanner /src/MalwareMultiScan.Scanner
COPY MalwareMultiScan.Backends /src/MalwareMultiScan.Backends
RUN dotnet publish -c Release -r linux-x64 -o ./publish MalwareMultiScan.Scanner/MalwareMultiScan.Scanner.csproj
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
FROM mcr.microsoft.com/dotnet/core/runtime:3.1
WORKDIR /worker

View File

@ -80,11 +80,13 @@ namespace MalwareMultiScan.Scanner.Services
_logger.LogError(
exception, "Scanning failed with exception");
}
finally
{
_logger.LogInformation(
$"Sending scan results with status {result.Succeeded}");
await _bus.SendAsync(
_configuration.GetValue<string>("ResultsSubscriptionId"), result);
}
}
}
}

View File

@ -0,0 +1,90 @@
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
/logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# parcel-bundler cache (https://parceljs.org/)
.cache
# next.js build output
.next
# nuxt.js build output
.nuxt
# Nuxt generate
dist
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless
# IDE / Editor
.idea
# Service worker
sw.*
# macOS
.DS_Store
# Vim swap files
*.swp

View File

@ -1,13 +0,0 @@
# editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View File

@ -0,0 +1,11 @@
FROM node:lts
WORKDIR /app
COPY package.json /app/package.json
RUN npm install
COPY . /app
RUN npm run build
ENTRYPOINT ["npm", "run", "start"]

View File

@ -1,79 +0,0 @@
<template>
<div class="p-2 w-25">
<div :class="cardClass" class="card">
<h6 class="card-header">{{ id }}</h6>
<div class="card-body">
<b-skeleton-wrapper :loading="!result.completed">
<template #loading>
<b-skeleton/>
</template>
<div v-if="result.succeeded && !result.threats">No threats have been detected...</div>
<div v-if="result.succeeded === false">Scanning failed to complete...</div>
<ul v-if="result.threats" class="list-inline m-0">
<li v-for="threat in result.threats" v-bind:key="threat">{{ threat }}</li>
</ul>
</b-skeleton-wrapper>
</div>
</div>
</div>
</template>
<script lang="ts">
import Vue, {PropOptions} from 'vue'
import ScanResultEntry from '~/models/scan-result-entry';
export default Vue.extend({
name: 'scan-result-component',
props: {
id: {
type: String,
required: true
} as PropOptions<string>,
result: {
type: Object,
required: true
} as PropOptions<ScanResultEntry>
},
computed: {
cardClass() {
const result = this.result as ScanResultEntry;
return {
'succeeded': result.succeeded && !result.threats,
'detected': result.succeeded && result.threats,
'failed': result.succeeded === false,
};
}
}
});
</script>
<style lang="scss" scoped>
@import 'node_modules/bootstrap/scss/bootstrap.scss';
.card-header {
text-transform: uppercase;
}
.succeeded {
@extend .bg-success;
@extend .text-white;
}
.detected {
@extend .bg-danger;
@extend .text-white;
}
.failed {
@extend .bg-warning;
@extend .text-white;
}
</style>

View File

@ -1,15 +1,26 @@
<template>
<div class="container">
<div class="d-flex align-items-center p-3 my-3 text-white-50 bg-dark ">
<b-icon-bug class="mr-3" width="48" height="48" />
<div>
<h6 class="mb-0 text-white">MalwareMultiScan UI</h6>
<small>
A demo of a <a target="_blank" href="https://github.com/mindcollapse/MalwareMultiScan">microservice</a>
to scan your files against multiple AV solutions
</small>
</div>
</div>
<div class="application">
<b-navbar toggleable="md" type="dark" variant="primary">
<b-navbar-brand to="/">
<b-icon-bug-fill /> MalwareMultiScan
</b-navbar-brand>
<b-navbar-toggle target="nav-collapse" />
<b-collapse id="nav-collapse" is-nav>
<b-navbar-nav class="ml-auto">
<b-nav-form>
<b-button href="https://github.com/mindcollapse/MalwareMultiScan" variant="dark" size="sm" target="_blank">
<b-icon-code /> GitHub
</b-button>
</b-nav-form>
</b-navbar-nav>
</b-collapse>
</b-navbar>
<b-container :fluid="true" class="mt-3">
<nuxt />
</b-container>
</div>
</template>

View File

@ -0,0 +1,15 @@
import ScanResultEntry from '~/models/scan-result-entry';
export default class ScanResultEntryFlattened implements ScanResultEntry {
readonly id: string;
readonly completed: boolean;
readonly succeeded: boolean | null;
readonly threats: string[];
constructor(id: string, completed: boolean, succeeded: boolean | null, threats: string[]) {
this.id = id;
this.completed = completed;
this.succeeded = succeeded;
this.threats = threats;
}
}

View File

@ -4,14 +4,9 @@ export default {
meta: [
{charset: 'utf-8'},
{name: 'viewport', content: 'width=device-width, initial-scale=1, shrink-to-fit=no'},
],
bodyAttrs: {
class: "bg-light"
}
]
},
components: true,
buildModules: [
'@nuxt/typescript-build',
],

View File

@ -1,20 +1,33 @@
<template>
<div class="d-flex results align-content-stretch flex-wrap">
<scan-result-component v-for="(result, id) in data.results"
v-bind:key="id" v-bind:id="id" v-bind:result="result" />
<b-table :fields="fields" :items="flattenedData" class="m-0" striped>
<template #cell(completed)="data">
<div class="h5 m-0">
<b-icon-check-circle-fill v-if="data.item.succeeded === true" variant="success"/>
<b-icon-exclamation-circle-fill v-if="data.item.succeeded === false" variant="danger"/>
<b-icon-bug-fill v-if="!data.item.completed" animation="spin-pulse"
class="rounded-circle bg-primary text-white" scale="0.7"/>
</div>
</template>
<style>
.results {
margin: -0.5rem;
}
</style>
<template #cell(threats)="data">
<div class="text-success" v-if="data.item.succeeded && !data.item.threats.length">No threats have been detected</div>
<div class="text-danger" v-if="data.item.succeeded === false">Scanning failed to complete due to the error or timeout</div>
<div v-if="!data.item.completed">Scanning is in progress</div>
<ul v-if="data.item.completed && data.item.threats.length" class="list-inline m-0">
<li class="text-danger" v-for="threat in data.item.threats" v-bind:key="threat">{{ threat }}</li>
</ul>
</template>
</b-table>
</template>
<script lang="ts">
import Vue from 'vue';
import ScanResult from '~/models/scan-result';
import ScanResultEntryFlattened from '~/models/scan-result-entry-flattened';
export default Vue.extend({
async asyncData({params, $axios}) {
@ -35,10 +48,25 @@ export default Vue.extend({
}
},
computed: {
flattenedData(): ScanResultEntryFlattened[] {
return Object
.entries((this.data as ScanResult).results)
.map(([k, v]) => new ScanResultEntryFlattened(k, v.completed, v.succeeded, v.threats))
}
},
data() {
return {
data: null as ScanResult | null,
timer: 0 as any
data: {} as ScanResult,
fields: [
{key: 'id', label: 'Backend'},
{key: 'completed', label: 'Completed'},
{key: 'threats', label: 'Threats'},
],
timer: 0 as any // otherwise it conflicts with SSR / Type Checking
}
}
});

View File

@ -1,22 +1,22 @@
<template>
<b-card no-body>
<b-tabs card pills>
<b-tab title="File Scan" active>
<b-tabs card no-fade pills>
<b-tab active title="File Scan">
<b-input-group>
<b-form-file placeholder="Select or drop files here" v-model="file"/>
<b-form-file v-model="file" placeholder="Select or drop files here"/>
<b-input-group-append>
<b-button variant="primary" :disabled="!file || uploading" @click="scanFile">Scan</b-button>
<b-button :disabled="!file || uploading" variant="primary" @click="scanFile">Scan</b-button>
</b-input-group-append>
</b-input-group>
<b-progress class="mt-3" v-if="uploading" :value="progress" animated />
<b-progress v-if="uploading" :value="progress" animated class="mt-3"/>
</b-tab>
<b-tab title="URL Scan">
<b-input-group>
<b-input type="url" placeholder="https://secure.eicar.org/eicar.com.txt" v-model="url"/>
<b-input v-model="url" placeholder="https://secure.eicar.org/eicar.com.txt" type="url"/>
<b-input-group-append>
<b-button variant="primary" :disabled="!isUrl(url)" @click="scanUrl">Scan</b-button>
<b-button :disabled="!isUrl(url)" variant="primary" @click="scanUrl">Scan</b-button>
</b-input-group-append>
</b-input-group>
</b-tab>
@ -53,8 +53,7 @@ export default Vue.extend({
data.append('file', this.file, this.file.name);
try
{
try {
this.uploading = true;
const result = await this.$axios.$post<ScanResult>('queue/file', data, {
@ -67,8 +66,7 @@ export default Vue.extend({
});
await this.$router.push({name: 'id', params: {id: result.id}});
}
finally {
} finally {
this.progress = 0;
this.uploading = false;
}

View File

@ -1,10 +0,0 @@
# STORE
**This directory is not required, you can delete it if you don't want to use it.**
This directory contains your Vuex Store files.
Vuex Store option is implemented in the Nuxt.js framework.
Creating a file in this directory automatically activates the option in the framework.
More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store).

View File

@ -6,6 +6,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MalwareMultiScan.Api", "Mal
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MalwareMultiScan.Scanner", "MalwareMultiScan.Scanner\MalwareMultiScan.Scanner.csproj", "{8A16A3C4-2AE3-4F63-8280-635FF7878080}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{A248B5B7-7CBB-4242-98BD-51A9E915E485}"
ProjectSection(SolutionItems) = preProject
.dockerignore = .dockerignore
.gitignore = .gitignore
docker-compose.yaml = docker-compose.yaml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

View File

@ -1,47 +1,94 @@
version: "3"
version: "3.8"
services:
clamav-backend:
image: ${DOCKER_IMAGE_PREFIX-mindcollapse}/malware-multi-scan-worker-clamav
rabbitmq:
image: rabbitmq:3
restart: on-failure
expose:
- "5672"
volumes:
- rabbitmq_etc/:/etc/rabbitmq/
- rabbitmq_data:/var/lib/rabbitmq/
- rabbitmq_logs/:/var/log/rabbitmq/
mongodb:
image: mongo:4
restart: on-failure
expose:
- "27019"
volumes:
- mongodb:/data
ui:
image: mindcollapse/malware-multi-scan-ui
restart: on-failure
ports:
- "8888:8888"
expose:
- "8888"
depends_on:
- api
environment:
- "API_URL=http://api:5000"
- "NUXT_HOST=0.0.0.0"
- "NUXT_PORT=8888"
build:
context: MalwareMultiScan.Ui
dockerfile: Dockerfile
api:
image: mindcollapse/malware-multi-scan-api
restart: on-failure
expose:
- "5000"
depends_on:
- rabbitmq
- mongodb
environment:
- "ConnectionStrings__RabbitMQ=host=rabbitmq"
- "ConnectionStrings__Mongo=mongodb://mongodb:27017"
- "BackendsConfiguration=/etc/backends.yaml"
volumes:
- "./MalwareMultiScan.Api/backends.yaml:/etc/backends.yaml:ro"
build:
context: .
dockerfile: MalwareMultiScan.Api/Dockerfile
dummy-scanner:
image: mindcollapse/malware-multi-scan-scanner-dummy
restart: on-failure
depends_on:
- rabbitmq
environment:
- "ConnectionStrings__RabbitMQ=host=rabbitmq;prefetchcount=1"
build:
context: MalwareMultiScan.Backends/Dockerfiles
dockerfile: Dummy.Dockerfile
clamav-scanner:
image: mindcollapse/malware-multi-scan-scanner-clamav
restart: on-failure
depends_on:
- rabbitmq
environment:
- "ConnectionStrings__RabbitMQ=host=rabbitmq;prefetchcount=1"
build:
context: MalwareMultiScan.Backends/Dockerfiles
dockerfile: Clamav.Dockerfile
windows-defender-backend:
image: ${DOCKER_IMAGE_PREFIX-mindcollapse}/malware-multi-scan-worker-windows-defender
windows-defender-scanner:
image: mindcollapse/malware-multi-scan-scanner-windows-defender
restart: on-failure
depends_on:
- rabbitmq
environment:
- "ConnectionStrings__RabbitMQ=host=rabbitmq;prefetchcount=1"
build:
context: MalwareMultiScan.Backends/Dockerfiles
dockerfile: WindowsDefender.Dockerfile
# SCAN BACKENDS BELOW DISABLE DUE TO THE VENDOR LICENSING POLICY
# RE-ENABLE ONLY AFTER CHECKING EULA POLICY & BUYING THE LICENSE
#
# comodo-backend:
# image: ${DOCKER_IMAGE_PREFIX-mindcollapse}/malware-multi-scan-worker-comodo
# build:
# context: MalwareMultiScan.Backends/Dockerfiles
# dockerfile: Comodo.Dockerfile
#
# drweb-backend:
# image: ${DOCKER_IMAGE_PREFIX-mindcollapse}/malware-multi-scan-worker-drweb
# build:
# context: MalwareMultiScan.Backends/Dockerfiles
# dockerfile: DrWeb.Dockerfile
#
# kes-backend:
# image: ${DOCKER_IMAGE_PREFIX-mindcollapse}/malware-multi-scan-worker-kes
# build:
# context: MalwareMultiScan.Backends/Dockerfiles
# dockerfile: KES.Dockerfile
#
# mcafee-backend:
# image: ${DOCKER_IMAGE_PREFIX-mindcollapse}/malware-multi-scan-worker-mcafee
# build:
# context: MalwareMultiScan.Backends/Dockerfiles
# dockerfile: McAfee.Dockerfile
#
# sophos-backend:
# image: ${DOCKER_IMAGE_PREFIX-mindcollapse}/malware-multi-scan-worker-sophos
# build:
# context: MalwareMultiScan.Backends/Dockerfiles
# dockerfile: Sophos.Dockerfile
volumes:
mongodb:
rabbitmq_etc:
rabbitmq_data:
rabbitmq_logs: