hosts_updater 1.0.2 → 1.0.3
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/CHANGELOG.md +4 -0
- data/bin/hosts-updater +4 -1
- data/lib/hosts_updater.rb +13 -9
- data/lib/hosts_updater/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2eb07e28d3e57d43aafd0040ad133a48af96d9a
|
4
|
+
data.tar.gz: e9c767da9dfedb5cb372efb3c41c3896dc825f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af37d143427cfe6b4971f41a816b103360d3d5884c14c572715142ed534d144e53865338888100d654f018a0e220919313fe5bb3e795c442bf5ed92e3af649b4
|
7
|
+
data.tar.gz: 58a9c208f8e45379014d7e7d75f6ab61c930595f6a42867fb14c2fe91995bed6ced67761ae250abf4de7cf2db84fc753d6e0d01fa11a4b66fa2786c25299135d
|
data/CHANGELOG.md
CHANGED
data/bin/hosts-updater
CHANGED
@@ -13,6 +13,10 @@ OptionParser.new do |opts|
|
|
13
13
|
exit
|
14
14
|
end
|
15
15
|
|
16
|
+
opts.on("-c", "--clear", "Clear all blacklisted hosts") do |clear|
|
17
|
+
options[:clear] = clear
|
18
|
+
end
|
19
|
+
|
16
20
|
opts.on("--hosts-file [PATH]", "Path to hosts file to write (default: /etc/hosts)") do |file|
|
17
21
|
options[:hosts_file] = file
|
18
22
|
end
|
@@ -33,7 +37,6 @@ OptionParser.new do |opts|
|
|
33
37
|
options[:hosts_whitelist_name] = file
|
34
38
|
end
|
35
39
|
|
36
|
-
|
37
40
|
opts.on("-i", "--ip", "Redirect all blacklisted domains to following IP (default: 0.0.0.0)") do |ip|
|
38
41
|
options[:id] = ip
|
39
42
|
end
|
data/lib/hosts_updater.rb
CHANGED
@@ -13,6 +13,7 @@ class HostsUpdater
|
|
13
13
|
}
|
14
14
|
|
15
15
|
DEFAULT_OPTIONS = {
|
16
|
+
:clear => false,
|
16
17
|
:hosts_file => '/etc/hosts',
|
17
18
|
:hosts_directory => '/etc/hosts.d/',
|
18
19
|
:hosts_auto_name => 'hosts.auto',
|
@@ -106,17 +107,20 @@ class HostsUpdater
|
|
106
107
|
# Combine hosts.custom and hosts.auto files into one and write to hosts_location.
|
107
108
|
# Domains listed in hosts.whitelist are ommited from hosts.auto list, but not from hosts.custom
|
108
109
|
def update_hosts_file
|
109
|
-
auto = Hosts::File.read(hosts_auto_location).elements
|
110
|
-
auto.reject! { |el| ! el.is_a? Aef::Hosts::Entry }
|
111
|
-
auto.reject! { |el| whitelist.include? el.name }
|
112
|
-
auto.each do |el|
|
113
|
-
el.address = @options[:ip]
|
114
|
-
end
|
115
|
-
|
116
110
|
hosts = Hosts::File.new(@options[:hosts_file])
|
117
111
|
hosts.elements = Hosts::File.read(hosts_custom_location).elements
|
118
|
-
|
119
|
-
|
112
|
+
|
113
|
+
unless @options[:clear]
|
114
|
+
auto = Hosts::File.read(hosts_auto_location).elements
|
115
|
+
auto.reject! { |el| ! el.is_a? Aef::Hosts::Entry }
|
116
|
+
auto.reject! { |el| whitelist.include? el.name }
|
117
|
+
auto.each do |el|
|
118
|
+
el.address = @options[:ip]
|
119
|
+
end
|
120
|
+
hosts.elements << Hosts::EmptyElement.new
|
121
|
+
hosts.elements << Hosts::Section.new('HOSTS-UPDATER', :elements => auto)
|
122
|
+
end
|
123
|
+
|
120
124
|
logger.debug "Writing to #{@options[:hosts_file]}"
|
121
125
|
hosts.write
|
122
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hosts_updater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Potocki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hosts
|
@@ -62,8 +62,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
64
|
rubyforge_project:
|
65
|
-
rubygems_version: 2.
|
65
|
+
rubygems_version: 2.4.5
|
66
66
|
signing_key:
|
67
67
|
specification_version: 4
|
68
68
|
summary: Update your /etc/hosts with list of unwanted domains
|
69
69
|
test_files: []
|
70
|
+
has_rdoc:
|