kaspersky-linux_fs 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +14 -6
- data/kaspersky-linux_fs.gemspec +3 -1
- data/lib/kaspersky/linux_fs.rb +39 -42
- data/lib/kaspersky/linux_fs/version.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7362c182b5d69d09c5dd84d5165525d2bb6b85e
|
4
|
+
data.tar.gz: f9d6c94c8e6c42bb81178cf4e96a4895d2db4de5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1dfb5ba88939035c2c1359021c8b9758745f55270af0a7e8b92cb0ed8d97a228e84c9f4a5a5bba5a8e6de90a54d898bb3bf54eab6b84c84f4b0685a6fd4f1ff
|
7
|
+
data.tar.gz: 55dbaffbd12a4d752fecc31e33d834879aed94d3a9f8bbf5fcac803a1c09c3e7f196f54ff25fe16a1dd58297345f2a6ad7315896fd1ffb403c7d61ae06f8a6b3
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Small wrapper for Kaspersky linux file system
|
4
4
|
|
5
|
+
[](http://badge.fury.io/rb/kaspersky-linux_fs)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -21,6 +23,8 @@ Or install it yourself as:
|
|
21
23
|
## Usage
|
22
24
|
|
23
25
|
```ruby
|
26
|
+
require 'kaspersky/linux_fs'
|
27
|
+
|
24
28
|
# prepare arguments
|
25
29
|
use_sudo = true
|
26
30
|
bin_path_to_kaspersky = '/opt/kaspersky/kav4fs/bin/kav4fs-control'
|
@@ -29,12 +33,16 @@ bin_path_to_kaspersky = '/opt/kaspersky/kav4fs/bin/kav4fs-control'
|
|
29
33
|
linux_fs = Kaspersky::LinuxFs.new(bin_path_to_kaspersky, use_sudo)
|
30
34
|
|
31
35
|
# check file for virus
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
response.
|
36
|
+
begin
|
37
|
+
file_path = '/home/user/uploads/infected_file.exe'
|
38
|
+
response = linux_fs.fast_scan(file_path)
|
39
|
+
|
40
|
+
# check response
|
41
|
+
response.threat? # => true
|
42
|
+
response.safe? # => false
|
43
|
+
rescue => e
|
44
|
+
# process exception
|
45
|
+
end
|
38
46
|
````
|
39
47
|
|
40
48
|
## Contributing
|
data/kaspersky-linux_fs.gemspec
CHANGED
@@ -14,10 +14,12 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
#spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
#spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = '~> 2.0'
|
22
|
+
spec.required_rubygems_version = '~> 1.8'
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
25
|
end
|
data/lib/kaspersky/linux_fs.rb
CHANGED
@@ -2,60 +2,57 @@ require "kaspersky/linux_fs/version"
|
|
2
2
|
require 'open3'
|
3
3
|
|
4
4
|
module Kaspersky
|
5
|
-
|
5
|
+
class LinuxFs
|
6
|
+
SKIP_ACTION = 'Skip'
|
7
|
+
|
8
|
+
def initialize(bin, use_sudo = false)
|
9
|
+
@bin = bin
|
10
|
+
@use_sudo = use_sudo
|
11
|
+
@default_options = {
|
12
|
+
action: SKIP_ACTION
|
13
|
+
}
|
14
|
+
end
|
6
15
|
|
7
|
-
|
8
|
-
|
16
|
+
def fast_scan(path_to_file, options = {})
|
17
|
+
command = "#{build_base_request}#{build_options(options.to_hash.merge({ scan_file: path_to_file.to_s }))}"
|
18
|
+
output = nil
|
19
|
+
success = false
|
9
20
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@default_options = {
|
14
|
-
action: SKIP_ACTION
|
15
|
-
}
|
16
|
-
end
|
21
|
+
Open3.popen3(command) do |stdin, stdout, stderr, thread|
|
22
|
+
process = thread.value
|
23
|
+
output = stderr.read
|
17
24
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
Open3.popen3(command) do |stdin, stdout, stderr, thread|
|
24
|
-
process = thread.value
|
25
|
-
output = stderr.read
|
26
|
-
|
27
|
-
# "sudo -n ..." exit with code 0 when password is incorrect
|
28
|
-
# so, checking stderr is required
|
29
|
-
if process.success? && output.size.zero?
|
30
|
-
output = stdout.read
|
31
|
-
success = true
|
32
|
-
end
|
25
|
+
# "sudo -n ..." exit with code 0 when password is incorrect
|
26
|
+
# so, checking stderr is required
|
27
|
+
if process.success? && output.size.zero?
|
28
|
+
output = stdout.read
|
29
|
+
success = true
|
33
30
|
end
|
31
|
+
end
|
34
32
|
|
35
|
-
|
33
|
+
fail "#{output}" unless success
|
36
34
|
|
37
|
-
|
38
|
-
|
35
|
+
Kaspersky::LinuxFs::Response::FastScan.new(output)
|
36
|
+
end
|
39
37
|
|
40
|
-
|
38
|
+
private
|
41
39
|
|
42
|
-
|
43
|
-
|
40
|
+
def build_base_request
|
41
|
+
request = @bin
|
44
42
|
|
45
|
-
|
46
|
-
|
43
|
+
# n - non-interactive
|
44
|
+
request.prepend('sudo -n ') if @use_sudo
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
request
|
47
|
+
end
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
options
|
49
|
+
def build_options(data)
|
50
|
+
data = @default_options.merge(data)
|
51
|
+
options = ''
|
52
|
+
data.each do |key, value|
|
53
|
+
options += " --#{key.to_s.tr('_', '-')} #{value}"
|
58
54
|
end
|
55
|
+
options
|
59
56
|
end
|
60
57
|
end
|
61
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaspersky-linux_fs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LightSuner
|
@@ -64,14 +64,14 @@ require_paths:
|
|
64
64
|
- lib
|
65
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - "
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
69
|
+
version: '2.0'
|
70
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- - "
|
72
|
+
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
74
|
+
version: '1.8'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
77
|
rubygems_version: 2.4.5
|