blockhosts 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/blockhosts.rb +76 -5
- metadata +22 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f05c99989ffd139291184309fcfd62a38087c6589dce286ecd888ad3c631daf
|
4
|
+
data.tar.gz: 83f046385ec592077b82d586978430de8c3e4893f3010eefbe2f69295b933696
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79bfc2e31f79338a71c3fb2a28216c8f0840b3ff8a7a8187bb9b111ab7a8bac8413f6971dd7b0a255dda035d088f79eddfbb502ce34765e09927f3065dd16673
|
7
|
+
data.tar.gz: 841a89102afbdce169b4f255a593a0d6b4fbbe1fd192b9e6b9dd1faf7af205d094eb6c782ef72f290b5f5aae948b4701eaf666a0c32dd7d8d0ec620a4010d755
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/blockhosts.rb
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
# file: blockhosts.rb
|
4
4
|
|
5
|
+
require 'sps-sub'
|
5
6
|
require 'rxfhelper'
|
6
7
|
|
7
8
|
|
8
9
|
class Host
|
10
|
+
include RXFHelperModule
|
9
11
|
|
10
12
|
@ip = '127.0.0.1'
|
11
13
|
|
@@ -16,17 +18,21 @@ class Host
|
|
16
18
|
'/etc/hosts'
|
17
19
|
end
|
18
20
|
|
19
|
-
def self.add(hostname,
|
20
|
-
hashtag=hostname.sub(/^www./,'').gsub('-','').gsub('.','dot')
|
21
|
+
def self.add(hostname,
|
22
|
+
hashtag=hostname.sub(/^www./,'').gsub('-','').gsub('.','dot'),
|
23
|
+
banlist: nil, block: false)
|
21
24
|
|
25
|
+
b = block ? '' : '#'
|
26
|
+
|
22
27
|
s = if banlist then
|
23
28
|
|
24
29
|
hashtag = hostname.sub(/^#/,'')
|
25
30
|
list, _ = RXFHelper.read(banlist)
|
26
|
-
list.lines.map {|hostx| "
|
31
|
+
list.lines.map {|hostx| "#{b}#{@ip} #{hostx.chomp} ##{hashtag}" }\
|
32
|
+
.join("\n")
|
27
33
|
|
28
34
|
else
|
29
|
-
"
|
35
|
+
"#{b}#{@ip} #{hostname} ##{hashtag}"
|
30
36
|
end
|
31
37
|
|
32
38
|
open(@file, 'a') { |f| f.puts s } unless File.read(@file).include? hostname
|
@@ -35,7 +41,7 @@ class Host
|
|
35
41
|
def self.disable(hashtag)
|
36
42
|
|
37
43
|
modify() do |line|
|
38
|
-
line.gsub(/^#([^#]+##{hashtag.sub(/^#/,'')}[^$]
|
44
|
+
line.gsub(/^#([^#]+##{hashtag.sub(/^#/,'')}[^$]+)/,'\1')
|
39
45
|
end
|
40
46
|
|
41
47
|
end
|
@@ -54,6 +60,19 @@ class Host
|
|
54
60
|
|
55
61
|
end
|
56
62
|
|
63
|
+
def self.exists?(host)
|
64
|
+
s = File.read(@file)
|
65
|
+
s.lines.grep(/\s#{host}\s/).any?
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.export(hashtag, filename=nil)
|
69
|
+
|
70
|
+
s = self.view(hashtag)
|
71
|
+
|
72
|
+
filename ? FileX.write(filename, s) : s
|
73
|
+
|
74
|
+
end
|
75
|
+
|
57
76
|
def self.block(hashtag) self.disable(hashtag) end
|
58
77
|
def self.unblock(hashtag) self.enable(hashtag) end
|
59
78
|
|
@@ -73,4 +92,56 @@ class Host
|
|
73
92
|
|
74
93
|
end
|
75
94
|
|
95
|
+
def self.view(hashtag)
|
96
|
+
|
97
|
+
File.read(@file).lines.select {|x| x =~ /##{hashtag}/}\
|
98
|
+
.map {|x| x[/(?<=#{@ip} )[^ ]+/]}.join("\n")
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
class HostsE
|
105
|
+
include RXFHelperModule
|
106
|
+
|
107
|
+
def initialize(filename='hostse.txt', sps_host: '127.0.0.1',
|
108
|
+
sps_port: '59053', hostname: Socket.gethostname,
|
109
|
+
topic: 'dnslookup/' + hostname, debug: false)
|
110
|
+
|
111
|
+
@sps_host, @sps_port, @topic, @debug = sps_host, sps_port, topic, debug
|
112
|
+
@filename = filename
|
113
|
+
@entries = FileX.read(filename).lines
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
def subscribe(topic=@topic)
|
118
|
+
|
119
|
+
sps = SPSSub.new(host: @sps_host, port: @sps_port)
|
120
|
+
|
121
|
+
sps.subscribe(topic: topic + ' or reload' ) do |host, topic|
|
122
|
+
|
123
|
+
if topic == 'reload' then
|
124
|
+
@entries = FileX.read(@filename).lines
|
125
|
+
puts 'reloaded ' if @debug
|
126
|
+
next
|
127
|
+
end
|
128
|
+
|
129
|
+
puts 'host: ' + host.inspect if @debug
|
130
|
+
|
131
|
+
@entries.each do |line|
|
132
|
+
|
133
|
+
pattern, hashtag = line.split(/\s+#/)
|
134
|
+
puts 'pattern: ' + pattern.inspect if @debug
|
135
|
+
|
136
|
+
if host =~ /#{pattern.gsub('*','.*')}/ then
|
137
|
+
puts 'adding host' if @debug
|
138
|
+
Host.add(host, hashtag, block: true) unless Host.exists? host
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
76
147
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blockhosts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
7vecf9qfrpZt4fjOajWBWWZEUQ3QKHva1uNegE75UqN77YfewLL+A+SrV0ORhL9q
|
36
36
|
/sJ0X03RC0pDp5fyhHmUoTyT
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2018-10-
|
38
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: rxfhelper
|
@@ -57,6 +57,26 @@ dependencies:
|
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: 0.9.1
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: sps-sub
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.3'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.3.7
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.3'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.3.7
|
60
80
|
description:
|
61
81
|
email: james@jamesrobertson.eu
|
62
82
|
executables: []
|
metadata.gz.sig
CHANGED
Binary file
|