rclam 0.2.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 59b97381697ed5e1005e15cd0b8e2a63c718368f
4
+ data.tar.gz: c3c1a43620cb8653fa67edf3e308b8272f50be65
5
+ SHA512:
6
+ metadata.gz: cad232e9ac09a60f12df014390166edb7c2fc999c0aa74187acc1a7baf6684b637843a7b4103081172a05236cbf4ee440d8b2218d825cbe216431e1daddad5a1
7
+ data.tar.gz: d2ae8a33a8e5bc49570160b5dc75be19538cf89543814dd4741d2dc667c6453310de376ab56304db46ed55a631140323f13f463634d7e45c3e40703360d54b9e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rclam.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Roby Parr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Rclam
2
+
3
+ This is a small command-line utility that wraps around clamscan that
4
+ makes it easier to use for systems maintenance.
5
+
6
+ ## Installation
7
+
8
+ `$ gem install rclam`
9
+
10
+ *Note that this is not meant to be used as a library, but a command-line utility.*
11
+
12
+ ## Usage
13
+
14
+ To run a scan of your entire computer:
15
+
16
+ `rclam scan /`
17
+
18
+ ## Development
19
+
20
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
21
+
22
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
23
+
24
+ ## Contributing
25
+
26
+ Bug reports and pull requests are welcome on GitHub at https://github.com/robyparr/rclam.
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rclam"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rclam ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "rclam"
4
+ Rclam::CLI.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/rclam ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rclam"
4
+ Rclam::CLI.start(ARGV)
data/lib/rclam.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "thor"
2
+ require "date"
3
+ require "open3"
4
+
5
+ require "rclam/version"
6
+ require "rclam/clamav"
7
+ require "rclam/helpers"
8
+
9
+ module Rclam
10
+ class CLI < Thor
11
+ desc "scan [location]", "Runs clamscan against the specified location."
12
+ def scan(location = '/')
13
+ not_installed unless Rclam::ClamAV.installed?
14
+ Rclam::ClamAV.update unless Rclam::ClamAV.up_to_date?
15
+
16
+ puts "Scanning #{File.expand_path(location)}..."
17
+ result = Rclam::ClamAV.scan location
18
+ puts Rclam::Helpers.clamscan_report(result)
19
+ end
20
+
21
+ private
22
+
23
+ def not_installed
24
+ puts "ClamAV is not installed. Please install before running."
25
+ exit 1
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ module Rclam
2
+ module ClamAV
3
+
4
+ def self.installed?
5
+ executable_location = %x{which clamscan}
6
+ !executable_location.empty?
7
+ end
8
+
9
+ def self.up_to_date?
10
+ last_update = Rclam::Helpers.last_signatures_update
11
+ Rclam::Helpers.date_within_a_day?(last_update)
12
+ end
13
+
14
+ def self.update
15
+ %x{freshclam}
16
+ end
17
+
18
+ def self.scan(location)
19
+ output, err, status = Open3.capture3("clamscan -ri #{location}")
20
+ output
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ module Rclam
2
+ module Helpers
3
+ FRESHCLAM_REGEX = /^.+\/(\D{3} \D{3} \d{2} \d{2}:\d{2}:\d{2} \d{4})$/
4
+ INFECTED_FILES_REGEX = /^Infected files: (\d+)$/
5
+ SCANNED_FILES_REGEX = /^Scanned files: (\d+)$/
6
+ TIME_REGEX = /^Time: .+\((\d \w{1} \d \w{1})\)$/
7
+ SIGNATURES_REGEX = /^Known viruses: (\d+)$/
8
+
9
+ def self.first_regex_capture(regex, value)
10
+ match = regex.match(value)
11
+ return nil if match.nil?
12
+ match.captures.first
13
+ end
14
+
15
+ def self.last_signatures_update
16
+ version_header = %x{freshclam --version}
17
+ DateTime.parse self.first_regex_capture(FRESHCLAM_REGEX, version_header)
18
+ end
19
+
20
+ def self.date_within_a_day?(date)
21
+ hours_difference = ((DateTime.now.to_time - date.to_time) / 3600).to_i
22
+ hours_difference <= 24
23
+ end
24
+
25
+ def self.clamscan_report(results)
26
+ infected_files = first_regex_capture(INFECTED_FILES_REGEX, results).to_i
27
+ scanned_files = first_regex_capture(SCANNED_FILES_REGEX, results)
28
+ signatures = first_regex_capture(SIGNATURES_REGEX, results)
29
+ result = infected_files > 0 ? "!!INFECTED!!" : "CLEAN"
30
+
31
+ result = %Q{
32
+ Result: #{result}
33
+ Infections: #{infected_files}
34
+ Scanned Files: #{scanned_files}
35
+ Signatures: #{signatures}
36
+ }
37
+
38
+ # Remove tabs from each line
39
+ # https://stackoverflow.com/a/31345870
40
+ result.each_line.map(&:strip).join("\n")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Rclam
2
+ VERSION = "0.2.0"
3
+ end
data/rclam.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rclam/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rclam"
8
+ spec.version = Rclam::VERSION
9
+ spec.authors = ["Roby Parr"]
10
+ spec.email = ["roby.parr@gmail.com"]
11
+
12
+ spec.summary = "A small command-line wrapper around clamscan."
13
+ spec.description = %q{
14
+ This is a small command-line utility that wraps around clamscan to
15
+ make it easier to use for systems maintenance.
16
+ }
17
+ spec.homepage = "https://github.com/robyparr/rclam"
18
+ spec.license = "MIT"
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ f.match(%r{^(test|spec|features)/})
31
+ end
32
+ spec.bindir = "exe"
33
+ spec.executables = ["rclam"]
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.15"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "minitest", "~> 5.0"
39
+
40
+ spec.add_runtime_dependency "thor", "~> 0.20.0"
41
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rclam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Roby Parr
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.20.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.20.0
69
+ description: "\n This is a small command-line utility that wraps around clamscan
70
+ to\n make it easier to use for systems maintenance.\n "
71
+ email:
72
+ - roby.parr@gmail.com
73
+ executables:
74
+ - rclam
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/rclam
86
+ - bin/setup
87
+ - exe/rclam
88
+ - lib/rclam.rb
89
+ - lib/rclam/clamav.rb
90
+ - lib/rclam/helpers.rb
91
+ - lib/rclam/version.rb
92
+ - rclam.gemspec
93
+ homepage: https://github.com/robyparr/rclam
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: https://rubygems.org
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.6.13
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: A small command-line wrapper around clamscan.
118
+ test_files: []