This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
/
clamav.clj
42 lines (39 loc) · 1.89 KB
/
clamav.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
;; Copyright (c) 2013 The Finnish National Board of Education - Opetushallitus
;;
;; This program is free software: Licensed under the EUPL, Version 1.1 or - as
;; soon as they will be approved by the European Commission - subsequent versions
;; of the EUPL (the "Licence");
;;
;; You may not use this work except in compliance with the Licence.
;; You may obtain a copy of the Licence at: http://www.osor.eu/eupl/
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; European Union Public Licence for more details.
(ns aitu.integraatio.clamav
(:require [clojure.tools.logging :as log]
[org.httpkit.client :as http]
[aitu.asetukset :refer [asetukset]]
[clojure.tools.logging :as log]
clojure.java.io))
(def ok-reply "Everything ok : true\n")
(def found-reply "Everything ok : false\n")
(defn tarkista-tiedosto [tiedostonimi tiedosto]
(let [{:keys [host port]} (:clamav @asetukset)
url (str "http://" host ":" port "/scan")
{:keys [body status error]} @(http/post url {:method :post
:multipart [{:name "file"
:content tiedosto
:filename tiedostonimi}]
:headers {"Content-Type" "multipart/form-data"}
:query-params {:name tiedostonimi}})]
(cond
error (do
(log/error "Virhe ClamAV-yhteydessä. Url: " url ", virhe: " error)
:error)
(and (= status 200)
(= body ok-reply)) :passed
:else (do
(log/error "Virus havaittu tiedostossa " tiedostonimi)
:failed))))