ezproxy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +30 -0
- data/Rakefile +2 -0
- data/ezproxy.gemspec +23 -0
- data/lib/ezproxy.rb +6 -0
- data/lib/ezproxy/log.rb +32 -0
- data/lib/ezproxy/log/format.rb +63 -0
- data/lib/ezproxy/version.rb +3 -0
- data/spec/ezproxy/log/format_spec.rb +29 -0
- data/spec/ezproxy/log_spec.rb +17 -0
- data/spec/ezproxy/test.log +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +82 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# EZproxy
|
2
|
+
|
3
|
+
This is a general purpose gem for working with OCLC's EZproxy
|
4
|
+
|
5
|
+
## Supported File Formats
|
6
|
+
|
7
|
+
The following formats are currently supported:
|
8
|
+
|
9
|
+
* %h
|
10
|
+
* %l
|
11
|
+
* %u
|
12
|
+
* %t
|
13
|
+
* %r
|
14
|
+
* %s
|
15
|
+
* %b
|
16
|
+
* %U
|
17
|
+
* %{ezproxy-session}i
|
18
|
+
|
19
|
+
## Examples
|
20
|
+
|
21
|
+
require 'ezproxy'
|
22
|
+
|
23
|
+
@log = EZproxy::Log.new(:format => '%h %{ezproxy-session}i %u %t "%r" %s %b')
|
24
|
+
@log.parse_file('ezp201104.log') do |line|
|
25
|
+
puts line.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
Will output something like the following for each line
|
29
|
+
|
30
|
+
{"remote_host"=>"127.0.0.1", "ezproxy_session"=>"-", "username"=>"-", "happened_at"=>"19/Apr/2011:13:31:38 -0500", "http_request"=>"GET https://localhost:443/favicon.ico HTTP/1.1", "http_status"=>"404", "http_bytes"=>"0"}
|
data/Rakefile
ADDED
data/ezproxy.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ezproxy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ezproxy"
|
7
|
+
s.version = EZproxy::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Brice Stacey"]
|
10
|
+
s.email = ["bricestacey@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{General use library for OCLC's EZproxy}
|
13
|
+
s.description = %q{General use library for OCLC's EZproxy}
|
14
|
+
|
15
|
+
s.rubyforge_project = "ezproxy"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_development_dependency('rspec')
|
23
|
+
end
|
data/lib/ezproxy.rb
ADDED
data/lib/ezproxy/log.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module EZproxy
|
2
|
+
class Log
|
3
|
+
attr_accessor :format
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
@format = EZproxy::Log::Format.new(attributes[:format])
|
7
|
+
end
|
8
|
+
|
9
|
+
# Load and parse `filename`
|
10
|
+
def parse_file(filename)
|
11
|
+
matcher = @format.to_regex
|
12
|
+
defined_attributes = @format.defined_attributes
|
13
|
+
|
14
|
+
File.open(filename) do |file|
|
15
|
+
file.each_line do |line|
|
16
|
+
m = line.match(matcher).to_a
|
17
|
+
|
18
|
+
r = {}
|
19
|
+
m[1..m.count].zip(defined_attributes).each do |match, attr|
|
20
|
+
r[attr[:label]] = match
|
21
|
+
end
|
22
|
+
|
23
|
+
if block_given?
|
24
|
+
yield r
|
25
|
+
else
|
26
|
+
r
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module EZproxy
|
2
|
+
class Log
|
3
|
+
class Format
|
4
|
+
attr_accessor :format
|
5
|
+
|
6
|
+
# Array containing each log format
|
7
|
+
# An attribute must contain a :token, :regexp, and :label.
|
8
|
+
# Optional keys include :post
|
9
|
+
ATTRIBUTES = [
|
10
|
+
{:token => '%h',
|
11
|
+
:regexp => /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/,
|
12
|
+
:label => 'remote_host'},
|
13
|
+
{:token => '%l',
|
14
|
+
:regexp => /(-)/,
|
15
|
+
:label => nil},
|
16
|
+
{:token => '%u',
|
17
|
+
:regexp => /(.*)/,
|
18
|
+
:label => 'username'},
|
19
|
+
{:token => '%t',
|
20
|
+
:regexp => /\[(.*)\]/,
|
21
|
+
:post => Proc.new {|x| x[11] = ' '},
|
22
|
+
:label => 'happened_at'},
|
23
|
+
{:token => '%r',
|
24
|
+
:regexp => /(.*)/,
|
25
|
+
:label => 'http_request'},
|
26
|
+
{:token => '%s',
|
27
|
+
:regexp => /(\d+)/,
|
28
|
+
:label => 'http_status'},
|
29
|
+
{:token => '%b',
|
30
|
+
:regexp => /(\d+)/,
|
31
|
+
:label => 'http_bytes'},
|
32
|
+
{:token => '%U',
|
33
|
+
:regexp => /([^ ]+)/,
|
34
|
+
:label => 'http_url'},
|
35
|
+
{:token => '%{ezproxy-session}i',
|
36
|
+
:regexp => /(.*)/,
|
37
|
+
:label => 'ezproxy_session'}
|
38
|
+
]
|
39
|
+
|
40
|
+
def initialize(s)
|
41
|
+
@format = s
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_regex
|
45
|
+
regex = @format.clone
|
46
|
+
ATTRIBUTES.each do |regexp|
|
47
|
+
regex.gsub!(regexp[:token], regexp[:regexp].source)
|
48
|
+
end
|
49
|
+
|
50
|
+
Regexp.compile(regex)
|
51
|
+
end
|
52
|
+
|
53
|
+
def defined_attributes
|
54
|
+
l = []
|
55
|
+
ATTRIBUTES.each do |attr|
|
56
|
+
l[@format.index(attr[:token])] = attr if @format.include? attr[:token]
|
57
|
+
end
|
58
|
+
|
59
|
+
l.compact
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EZproxy::Log::Format do
|
4
|
+
it "should have a format accessor" do
|
5
|
+
@format = EZproxy::Log::Format.new('%h %{ezproxy-session}i %u %t "%r" %s %b')
|
6
|
+
@format.format.should == '%h %{ezproxy-session}i %u %t "%r" %s %b'
|
7
|
+
|
8
|
+
@format.format = '%h %u %t "%r" %s %b'
|
9
|
+
@format.format.should == '%h %u %t "%r" %s %b'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should convert to a regular expression" do
|
13
|
+
@format = EZproxy::Log::Format.new('%h %{ezproxy-session}i %u %t "%r" %s %b')
|
14
|
+
@format.to_regex.class.should == Regexp
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should properly identify which match is which attribute" do
|
18
|
+
@format = EZproxy::Log::Format.new('%h %{ezproxy-session}i %u %t "%r" %s %b')
|
19
|
+
defined_attributes = @format.defined_attributes
|
20
|
+
|
21
|
+
defined_attributes[0][:label].should == 'remote_host'
|
22
|
+
defined_attributes[1][:label].should == 'ezproxy_session'
|
23
|
+
defined_attributes[2][:label].should == 'username'
|
24
|
+
defined_attributes[3][:label].should == 'happened_at'
|
25
|
+
defined_attributes[4][:label].should == 'http_request'
|
26
|
+
defined_attributes[5][:label].should == 'http_status'
|
27
|
+
defined_attributes[6][:label].should == 'http_bytes'
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EZproxy::Log do
|
4
|
+
it "should load a log from a file" do
|
5
|
+
@log = EZproxy::Log.new(:format => '%h %{ezproxy-session}i %u %t "%r" %s %b')
|
6
|
+
|
7
|
+
@log.parse_file('spec/ezproxy/test.log') do |line|
|
8
|
+
line['remote_host'].should == '127.0.0.1'
|
9
|
+
line['ezproxy_session'].should == 'itiFqehv7PMNRYl'
|
10
|
+
line['username'].should == 'brice'
|
11
|
+
line['happened_at'].should == '18/May/2009:12:55:27 -0500'
|
12
|
+
line['http_request'].should == 'GET http://localhost:80/connect?session=sitiFqehv7PMNRYl&url=http://localhost/admin HTTP/1.1'
|
13
|
+
line['http_status'].should == "302"
|
14
|
+
line['http_bytes'].should == "0"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
127.0.0.1 itiFqehv7PMNRYl brice [18/May/2009:12:55:27 -0500] "GET http://localhost:80/connect?session=sitiFqehv7PMNRYl&url=http://localhost/admin HTTP/1.1" 302 0
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ezproxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brice Stacey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-04-19 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
description: General use library for OCLC's EZproxy
|
28
|
+
email:
|
29
|
+
- bricestacey@gmail.com
|
30
|
+
executables: []
|
31
|
+
|
32
|
+
extensions: []
|
33
|
+
|
34
|
+
extra_rdoc_files: []
|
35
|
+
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README
|
40
|
+
- Rakefile
|
41
|
+
- ezproxy.gemspec
|
42
|
+
- lib/ezproxy.rb
|
43
|
+
- lib/ezproxy/log.rb
|
44
|
+
- lib/ezproxy/log/format.rb
|
45
|
+
- lib/ezproxy/version.rb
|
46
|
+
- spec/ezproxy/log/format_spec.rb
|
47
|
+
- spec/ezproxy/log_spec.rb
|
48
|
+
- spec/ezproxy/test.log
|
49
|
+
- spec/spec_helper.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: ""
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project: ezproxy
|
74
|
+
rubygems_version: 1.6.2
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: General use library for OCLC's EZproxy
|
78
|
+
test_files:
|
79
|
+
- spec/ezproxy/log/format_spec.rb
|
80
|
+
- spec/ezproxy/log_spec.rb
|
81
|
+
- spec/ezproxy/test.log
|
82
|
+
- spec/spec_helper.rb
|