dansguardian_denied_action 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +181 -0
- data/Rakefile +6 -0
- data/dansguardian_denied_action.gemspec +32 -0
- data/lib/dansguardian_denied_action.rb +18 -0
- data/lib/dansguardian_denied_action/access_log.rb +66 -0
- data/lib/dansguardian_denied_action/constants.rb +21 -0
- data/lib/dansguardian_denied_action/log.rb +82 -0
- data/lib/dansguardian_denied_action/logs/csv_log.rb +42 -0
- data/lib/dansguardian_denied_action/logs/dansguardian_log.rb +13 -0
- data/lib/dansguardian_denied_action/logs/protex_blanked_log.rb +14 -0
- data/lib/dansguardian_denied_action/logs/protex_log.rb +13 -0
- data/lib/dansguardian_denied_action/logs/squid_log.rb +13 -0
- data/lib/dansguardian_denied_action/logs/tab_log.rb +13 -0
- data/lib/dansguardian_denied_action/version.rb +3 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ace5b17c7f5429de27c04ec60a82b59f093e61b2
|
4
|
+
data.tar.gz: a7476158f612a47de22df23de8a9615599f9adfd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6c1c0dafd4c54b73f31d67f4db76bec33f6c26e281251c09cd25a10981490c75594ce52874bb1ff41ca90444baa1a6e63119ab6659e51a799055b91a650f0f3
|
7
|
+
data.tar.gz: 4a7aba0a7e4bf48305362aab57fdd28f70142d3a502d8627839a1aacedd4d9e4bb66f760136979a36f2012a693aca682750fbc41190b34317c400d457967d17b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Eric Terry
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
# Dansguardian Denied Action
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/dansguardian_denied_action.svg)](https://badge.fury.io/rb/dansguardian_denied_action)
|
4
|
+
|
5
|
+
Triggers a custom action when a site is blocked/denied. Works by monitoring the access log of Dansguardian or e2guardian.
|
6
|
+
|
7
|
+
[DansGuardian](http://dansguardian.org) is an award winning Open Source web content filter. It filters the actual content of pages based on many methods including phrase matching, PICS filtering and URL filtering. It does not purely filter based on a banned list of sites like lesser totally commercial filters.
|
8
|
+
|
9
|
+
[e2guardian](http://e2guardian.org) is a fork of Dansguardian Project with many improvements and bug fixes, e2guardian is a web content filtering proxy that works in conjunction with another caching proxy such as Squid.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install dansguardian_denied_action
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
`dansguardian_denied_action` follows the Observer pattern. See more information from the [Ruby Rdocs](http://ruby-doc.org/stdlib-2.1.0/libdoc/observer/rdoc/Observable.html). You can add as many observers as you'd like that are triggered when a denied action log is added to the access log. An observer is an instance of a class that has an `update` method defined. The `update` method is called whenever the observer is notified (when there is a denied log).
|
20
|
+
|
21
|
+
Currently only log file format 2 (CSV-style format) is supported. Please contribute if you'd like more formats supported. Make sure your `/etc/dansguardian/dansguardian.conf` has the `logfileformat` set as `2`. For example:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
# Log File Format
|
25
|
+
# 1 = DansGuardian format (space delimited)
|
26
|
+
# 2 = CSV-style format
|
27
|
+
# 3 = Squid Log File Format
|
28
|
+
# 4 = Tab delimited
|
29
|
+
# 5 = Protex format
|
30
|
+
# 6 = Protex format with server field blanked
|
31
|
+
|
32
|
+
logfileformat = 2
|
33
|
+
```
|
34
|
+
|
35
|
+
### Example
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
require 'dansguardian_denied_action'
|
39
|
+
|
40
|
+
# An observer class that outputs to the screen
|
41
|
+
class OutputToScreen
|
42
|
+
def update( log )
|
43
|
+
puts "IP: #{log.requesting_ip}"
|
44
|
+
puts "URL: #{log.requested_url}"
|
45
|
+
puts "Category: #{log.category}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# An observer class that sends an email
|
50
|
+
class SendEmail
|
51
|
+
def update( log )
|
52
|
+
message = "Denied page accessed!\n\n"
|
53
|
+
message << "IP: #{log.requesting_ip}\n"
|
54
|
+
message << "URL: #{log.requested_url}\n"
|
55
|
+
message << "Category: #{log.category}"
|
56
|
+
`echo "#{message}" | mail -s "Denied page" admin@example.com`
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Initialize the access log class and select the format of dansguardian
|
61
|
+
@access_log = DansguardianDeniedAction::AccessLog.new( format: DansguardianDeniedAction::LOG_FORMAT_CSV )
|
62
|
+
|
63
|
+
# Add as many observers as you'd like
|
64
|
+
@access_log.add_observer( OutputToScreen.new )
|
65
|
+
@access_log.add_observer( SendEmail.new )
|
66
|
+
|
67
|
+
# Call the monitor method to monitor the log and notify
|
68
|
+
# your observers when a blocked page is accessed
|
69
|
+
@access_log.monitor
|
70
|
+
```
|
71
|
+
|
72
|
+
## Customization
|
73
|
+
|
74
|
+
If you want to trigger your observers on an action other than `DENIED`, you can specify one like so:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
@access_log = DansguardianDeniedAction::AccessLog.new(
|
78
|
+
format: DansguardianDeniedAction::LOG_FORMAT_CSV,
|
79
|
+
action: 'INFECTED'
|
80
|
+
)
|
81
|
+
```
|
82
|
+
|
83
|
+
### e2guardian
|
84
|
+
|
85
|
+
If you are using e2guardian rather than dansguardian, you want to point to the correct log path. For example:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
@access_log = DansguardianDeniedAction::AccessLog.new(
|
89
|
+
format: DansguardianDeniedAction::LOG_FORMAT_CSV,
|
90
|
+
path: '/var/log/e2guardian/access.log'
|
91
|
+
)
|
92
|
+
```
|
93
|
+
|
94
|
+
## Log methods
|
95
|
+
|
96
|
+
Your observer class which as the `update` method defined accepts a `log` as it's sole argument. This is an instance of `DansguardianDeniedAction::Log`. The accessor methods available include:
|
97
|
+
|
98
|
+
* raw
|
99
|
+
* date_time
|
100
|
+
* requesting_user
|
101
|
+
* requesting_ip
|
102
|
+
* requested_url
|
103
|
+
* actions
|
104
|
+
* reason
|
105
|
+
* subreason
|
106
|
+
* method
|
107
|
+
* size
|
108
|
+
* weight
|
109
|
+
* category
|
110
|
+
* filter_group_number
|
111
|
+
* http_code
|
112
|
+
* mime_type
|
113
|
+
* client_name
|
114
|
+
* filter_group_name
|
115
|
+
* user_agent
|
116
|
+
|
117
|
+
More information on the data within these accessor methods can be found on the [DansGuardian Documentation Wiki](http://contentfilter.futuragts.com/wiki/doku.php?id=the_access.log_files).
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eterry1388/dansguardian_denied_action. Please make sure
|
122
|
+
all tests pass before making a pull request. The tests require an OS with a `/tmp` directory.
|
123
|
+
|
124
|
+
### How to run system tests
|
125
|
+
|
126
|
+
```bash
|
127
|
+
rspec
|
128
|
+
```
|
129
|
+
|
130
|
+
The output should look something like this:
|
131
|
+
|
132
|
+
```
|
133
|
+
DansguardianDeniedAction
|
134
|
+
DansguardianDeniedAction::AccessLog
|
135
|
+
Updates observer for every new log
|
136
|
+
logs
|
137
|
+
DansguardianDeniedAction::CsvLog
|
138
|
+
raw
|
139
|
+
should eq "\"2016.1.8 19:46:10\",\"fred\",\"192.168.0.1\",\"http://example.com\",\"*DENIED* Banned site: example.com\",\"GET\",\"3804\",\"0\",\"Pornography\",\"1\",\"403\",\"text/html\",\"fred.example.com\",\"group-name\",\"Mozilla/5.0\""
|
140
|
+
date_time
|
141
|
+
should eq "2016.1.8 19:46:10"
|
142
|
+
requesting_user
|
143
|
+
should eq "fred"
|
144
|
+
requesting_ip
|
145
|
+
should eq "192.168.0.1"
|
146
|
+
requested_url
|
147
|
+
should eq "http://example.com"
|
148
|
+
actions
|
149
|
+
should eq "DENIED"
|
150
|
+
reason
|
151
|
+
should eq "Banned site: example.com"
|
152
|
+
subreason
|
153
|
+
should eq "Banned site: example.com"
|
154
|
+
method
|
155
|
+
should eq "GET"
|
156
|
+
size
|
157
|
+
should eq 3804
|
158
|
+
weight
|
159
|
+
should eq 0
|
160
|
+
category
|
161
|
+
should eq "Pornography"
|
162
|
+
filter_group_number
|
163
|
+
should eq 1
|
164
|
+
http_code
|
165
|
+
should eq 403
|
166
|
+
mime_type
|
167
|
+
should eq "text/html"
|
168
|
+
client_name
|
169
|
+
should eq "fred.example.com"
|
170
|
+
filter_group_name
|
171
|
+
should eq "group-name"
|
172
|
+
user_agent
|
173
|
+
should eq "Mozilla/5.0"
|
174
|
+
|
175
|
+
Finished in 4.03 seconds (files took 0.10009 seconds to load)
|
176
|
+
19 examples, 0 failures
|
177
|
+
```
|
178
|
+
|
179
|
+
## License
|
180
|
+
|
181
|
+
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,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path( '../lib', __FILE__ )
|
3
|
+
$LOAD_PATH.unshift( lib ) unless $LOAD_PATH.include?( lib )
|
4
|
+
require 'dansguardian_denied_action/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dansguardian_denied_action'
|
8
|
+
spec.version = DansguardianDeniedAction::VERSION
|
9
|
+
spec.authors = ['Eric Terry']
|
10
|
+
spec.email = ['eterry1388@aol.com']
|
11
|
+
|
12
|
+
spec.summary = 'Dansguardian Denied Action'
|
13
|
+
spec.description = "Triggers a custom action when a site is blocked/denied. Works by monitoring the access log of Dansguardian or e2guardian."
|
14
|
+
spec.homepage = 'http://eterry1388.github.io/dansguardian_denied_action'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split( "\x0" ).reject { |f| f.match( %r{^(test|spec|features)/} ) }
|
18
|
+
spec.executables = spec.files.grep( %r{^bin/} ) { |f| File.basename( f ) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.1.0'
|
22
|
+
|
23
|
+
spec.add_dependency 'filewatch'
|
24
|
+
spec.add_dependency 'activesupport'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.3'
|
29
|
+
spec.add_development_dependency 'rspec-its'
|
30
|
+
spec.add_development_dependency 'fakefs'
|
31
|
+
spec.add_development_dependency 'byebug'
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
require 'dansguardian_denied_action/access_log'
|
3
|
+
require 'dansguardian_denied_action/logs/dansguardian_log'
|
4
|
+
require 'dansguardian_denied_action/logs/csv_log'
|
5
|
+
require 'dansguardian_denied_action/logs/squid_log'
|
6
|
+
require 'dansguardian_denied_action/logs/tab_log'
|
7
|
+
require 'dansguardian_denied_action/logs/protex_log'
|
8
|
+
require 'dansguardian_denied_action/logs/protex_blanked_log'
|
9
|
+
require 'dansguardian_denied_action/constants'
|
10
|
+
|
11
|
+
# Dansguardian Denied Action. Triggers a custom action when a site is
|
12
|
+
# blocked/denied. Works by monitoring the access log of Dansguardian
|
13
|
+
# or e2guardian.
|
14
|
+
#
|
15
|
+
# @author {mailto:eterry1388@aol.com Eric Terry}
|
16
|
+
# @see https://github.com/eterry1388/dansguardian_denied_action
|
17
|
+
module DansguardianDeniedAction
|
18
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'observer'
|
2
|
+
require 'timeout'
|
3
|
+
require 'filewatch/tail'
|
4
|
+
|
5
|
+
module DansguardianDeniedAction
|
6
|
+
|
7
|
+
# Main interface to the gem
|
8
|
+
class AccessLog
|
9
|
+
include Observable
|
10
|
+
|
11
|
+
# @param format [Integer] The log file format specified on the "logfileformat" property
|
12
|
+
# in /etc/dansguardian/dansguardian.conf. Options include: 1 = Dansguardian format
|
13
|
+
# (space delimited), 2 = CSV-style format, 3 = Squid Log File Format, 4 = Tab delimited,
|
14
|
+
# 5 = Protex format, 6 = Protex format with server field blanked.
|
15
|
+
# @param path [String] File path to access.log
|
16
|
+
# @param action [String] Action string to trigger notifications of observers
|
17
|
+
# @raise [ArgumentError] if an unsupported format is passed in
|
18
|
+
# @note Only format 2 is currently supported!
|
19
|
+
def initialize( format:, path: '/var/log/dansguardian/access.log', action: 'DENIED' )
|
20
|
+
raise ArgumentError, "Unsupported format: #{format}" unless SUPPORTED_FORMATS.include?( format )
|
21
|
+
@format = format
|
22
|
+
@path = path
|
23
|
+
@action = action
|
24
|
+
@log_class = LOG_CLASSES[format]
|
25
|
+
end
|
26
|
+
|
27
|
+
# Monitors the access.log by tailing the file watching for blocked pages accessed
|
28
|
+
#
|
29
|
+
# @param timeout [Integer, NilClass] Specify a timeout for monitoring the access
|
30
|
+
# logs. If not specified, it will monitor the logs indefinitely.
|
31
|
+
def monitor( timeout: nil )
|
32
|
+
if timeout
|
33
|
+
begin
|
34
|
+
Timeout::timeout( timeout ) { tail_file }
|
35
|
+
rescue Timeout::Error
|
36
|
+
# Do nothing
|
37
|
+
end
|
38
|
+
else
|
39
|
+
tail_file
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Tail the log files
|
46
|
+
def tail_file
|
47
|
+
file_watch = FileWatch::Tail.new
|
48
|
+
file_watch.tail( "#{@path}*" )
|
49
|
+
file_watch.subscribe do |_, line|
|
50
|
+
process_line( line )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Notifies the observers if a line in the log matches the action
|
55
|
+
#
|
56
|
+
# @param line [String] Log line
|
57
|
+
def process_line( line )
|
58
|
+
if line =~ /\*#{@action}\*/
|
59
|
+
changed
|
60
|
+
log = @log_class.new( line )
|
61
|
+
notify_observers( log )
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DansguardianDeniedAction
|
2
|
+
LOG_FORMAT_DANSGUARDIAN = 1
|
3
|
+
LOG_FORMAT_CSV = 2
|
4
|
+
LOG_FORMAT_SQUID = 3
|
5
|
+
LOG_FORMAT_TAB = 4
|
6
|
+
LOG_FORMAT_PROTEX = 5
|
7
|
+
LOG_FORMAT_PROTEX_BLANKED = 6
|
8
|
+
|
9
|
+
SUPPORTED_FORMATS = [
|
10
|
+
LOG_FORMAT_CSV
|
11
|
+
]
|
12
|
+
|
13
|
+
LOG_CLASSES = {
|
14
|
+
LOG_FORMAT_DANSGUARDIAN => DansguardianLog,
|
15
|
+
LOG_FORMAT_CSV => CsvLog,
|
16
|
+
LOG_FORMAT_SQUID => SquidLog,
|
17
|
+
LOG_FORMAT_TAB => TabLog,
|
18
|
+
LOG_FORMAT_PROTEX => ProtexLog,
|
19
|
+
LOG_FORMAT_PROTEX_BLANKED => ProtexBlankedLog
|
20
|
+
}
|
21
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module DansguardianDeniedAction
|
2
|
+
|
3
|
+
# Represents a single log line in the access logs
|
4
|
+
#
|
5
|
+
# @note Documentation about attribute accessors of this class was taken
|
6
|
+
# from http://contentfilter.futuragts.com/wiki/doku.php?id=the_access.log_files
|
7
|
+
# @see http://contentfilter.futuragts.com/wiki/doku.php?id=the_access.log_files
|
8
|
+
class Log
|
9
|
+
|
10
|
+
# @return [String] Raw log line string that will be parsed
|
11
|
+
attr_reader :raw
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :date_time
|
15
|
+
|
16
|
+
# @return [String] Requesting user or computer. If an "authplugin" has not
|
17
|
+
# identified a user or computer, this will return just a dash.
|
18
|
+
attr_reader :requesting_user
|
19
|
+
|
20
|
+
# @return [String] Requesting IP address. Watch out for DHCP networks where
|
21
|
+
# computers sometimes change IP addresses.
|
22
|
+
attr_reader :requesting_ip
|
23
|
+
|
24
|
+
# @return [String] Complete requested URL. Often much of this is hidden from the
|
25
|
+
# user. Typically includes search terms.
|
26
|
+
attr_reader :requested_url
|
27
|
+
|
28
|
+
# @return [String] Items like *URLMOD*, *CONTENTMOD*, *SCANNED*, *INFECTED*, ending with
|
29
|
+
# either *DENIED* or *EXCEPTED* (*URLMOD* means urlregexplist tweaked the outgoing request,
|
30
|
+
# often used to force "safesearch" on) (*CONTENTMOD* means contentregexplist tweaked
|
31
|
+
# the incoming content, sometimes used to replace ofensive words with less offensive
|
32
|
+
# ones [but its use probably interferes with downloads, thus precluding them])
|
33
|
+
attr_reader :actions
|
34
|
+
|
35
|
+
# @return [String] An elaboration on the action
|
36
|
+
attr_reader :reason
|
37
|
+
|
38
|
+
# @return [String] More details about the action, for example the actual regular expressions
|
39
|
+
attr_reader :subreason
|
40
|
+
|
41
|
+
# @return [String] The HTTP request verb, usually either GET or POST (or HEAD)
|
42
|
+
attr_reader :method
|
43
|
+
|
44
|
+
# @return [Integer] The size in bytes of document (if it was fetched)
|
45
|
+
attr_reader :size
|
46
|
+
|
47
|
+
# @return [Integer] The sum of all the weighted phrase scores, which is the calculated
|
48
|
+
# naughtyness value
|
49
|
+
attr_reader :weight
|
50
|
+
|
51
|
+
# @return [String] Contents of the #listcategory tag (if any) in the list that's most
|
52
|
+
# relevant to the action
|
53
|
+
attr_reader :category
|
54
|
+
|
55
|
+
# @return [Integer] The filter group (1 => f1, 2 => f2, etc). the request was assigned to
|
56
|
+
attr_reader :filter_group_number
|
57
|
+
|
58
|
+
# @return [Integer] Always a three digit number, usually 200 if everything went okay
|
59
|
+
attr_reader :http_code
|
60
|
+
|
61
|
+
# @return [String] The MIME type of the document according to the website, usually
|
62
|
+
# "text/html" for webpages
|
63
|
+
attr_reader :mime_type
|
64
|
+
|
65
|
+
# @return [String] If configured, the result of performing a reverse DNS IP lookup on
|
66
|
+
# the requestor's IP address. Highly network dependent, meaningful on only some networks.
|
67
|
+
attr_reader :client_name
|
68
|
+
|
69
|
+
# @return [String] A more convenient presentation of the same information in filter group
|
70
|
+
# number. Only present if "groupname = ..." is specified in each dansguardianfN.conf file.
|
71
|
+
attr_reader :filter_group_name
|
72
|
+
|
73
|
+
# @return [String] Sometimes interesting and useful information. Note though that because
|
74
|
+
# this is so easily spoofed, it should not be used for any sort of security.
|
75
|
+
attr_reader :user_agent
|
76
|
+
|
77
|
+
# @param raw [String] Raw log line string that will be parsed
|
78
|
+
def initialize( raw )
|
79
|
+
@raw = raw
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'dansguardian_denied_action/log'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module DansguardianDeniedAction
|
5
|
+
|
6
|
+
# Represents a single log line in the access logs with the CSV (2) log file format
|
7
|
+
class CsvLog < Log
|
8
|
+
|
9
|
+
# @param raw [String] Raw log line string that will be parsed
|
10
|
+
def initialize( raw )
|
11
|
+
super
|
12
|
+
|
13
|
+
begin
|
14
|
+
@parsed = raw.parse_csv
|
15
|
+
rescue CSV::MalformedCSVError
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
@date_time = @parsed[0]
|
20
|
+
@requesting_user = @parsed[1]
|
21
|
+
@requesting_ip = @parsed[2]
|
22
|
+
@requested_url = @parsed[3]
|
23
|
+
action_reason = @parsed[4].try( :split, '*' ).try( :reject!, &:empty? ).try( :map!, &:strip )
|
24
|
+
if action_reason
|
25
|
+
@actions = action_reason.first # TODO: This is not getting all the actions, but only the first!
|
26
|
+
@reason = action_reason.last
|
27
|
+
@subreason = action_reason.last # TODO: What should the subreason be?
|
28
|
+
end
|
29
|
+
@method = @parsed[5]
|
30
|
+
@size = @parsed[6].to_i
|
31
|
+
@weight = @parsed[7].to_i
|
32
|
+
@category = @parsed[8]
|
33
|
+
@filter_group_number = @parsed[9].to_i
|
34
|
+
@http_code = @parsed[10].to_i
|
35
|
+
@mime_type = @parsed[11]
|
36
|
+
@client_name = @parsed[12]
|
37
|
+
@filter_group_name = @parsed[13]
|
38
|
+
@user_agent = @parsed[14]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dansguardian_denied_action/log'
|
2
|
+
|
3
|
+
module DansguardianDeniedAction
|
4
|
+
|
5
|
+
# Represents a single log line in the access logs with the DansGuardian (1) log file format
|
6
|
+
class DansguardianLog < Log
|
7
|
+
|
8
|
+
# @param raw [String] Raw log line string that will be parsed
|
9
|
+
def initialize( raw )
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'dansguardian_denied_action/log'
|
2
|
+
|
3
|
+
module DansguardianDeniedAction
|
4
|
+
|
5
|
+
# Represents a single log line in the access logs with the Protex
|
6
|
+
# format with server field blanked (6) log file format
|
7
|
+
class ProtexBlankedLog < Log
|
8
|
+
|
9
|
+
# @param raw [String] Raw log line string that will be parsed
|
10
|
+
def initialize( raw )
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dansguardian_denied_action/log'
|
2
|
+
|
3
|
+
module DansguardianDeniedAction
|
4
|
+
|
5
|
+
# Represents a single log line in the access logs with the Protex (5) log file format
|
6
|
+
class ProtexLog < Log
|
7
|
+
|
8
|
+
# @param raw [String] Raw log line string that will be parsed
|
9
|
+
def initialize( raw )
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dansguardian_denied_action/log'
|
2
|
+
|
3
|
+
module DansguardianDeniedAction
|
4
|
+
|
5
|
+
# Represents a single log line in the access logs with the Squid (3) log file format
|
6
|
+
class SquidLog < Log
|
7
|
+
|
8
|
+
# @param raw [String] Raw log line string that will be parsed
|
9
|
+
def initialize( raw )
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'dansguardian_denied_action/log'
|
2
|
+
|
3
|
+
module DansguardianDeniedAction
|
4
|
+
|
5
|
+
# Represents a single log line in the access logs with the Tab delimited (4) log file format
|
6
|
+
class TabLog < Log
|
7
|
+
|
8
|
+
# @param raw [String] Raw log line string that will be parsed
|
9
|
+
def initialize( raw )
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dansguardian_denied_action
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Terry
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: filewatch
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-its
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fakefs
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Triggers a custom action when a site is blocked/denied. Works by monitoring
|
126
|
+
the access log of Dansguardian or e2guardian.
|
127
|
+
email:
|
128
|
+
- eterry1388@aol.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- dansguardian_denied_action.gemspec
|
140
|
+
- lib/dansguardian_denied_action.rb
|
141
|
+
- lib/dansguardian_denied_action/access_log.rb
|
142
|
+
- lib/dansguardian_denied_action/constants.rb
|
143
|
+
- lib/dansguardian_denied_action/log.rb
|
144
|
+
- lib/dansguardian_denied_action/logs/csv_log.rb
|
145
|
+
- lib/dansguardian_denied_action/logs/dansguardian_log.rb
|
146
|
+
- lib/dansguardian_denied_action/logs/protex_blanked_log.rb
|
147
|
+
- lib/dansguardian_denied_action/logs/protex_log.rb
|
148
|
+
- lib/dansguardian_denied_action/logs/squid_log.rb
|
149
|
+
- lib/dansguardian_denied_action/logs/tab_log.rb
|
150
|
+
- lib/dansguardian_denied_action/version.rb
|
151
|
+
homepage: http://eterry1388.github.io/dansguardian_denied_action
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: 2.1.0
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.4.8
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Dansguardian Denied Action
|
175
|
+
test_files: []
|