ident 0.0.1
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.
- data/COPYING +674 -0
- data/README +2 -0
- data/Rakefile +27 -0
- data/doc/Ident.html +552 -0
- data/doc/Ident/Response.html +113 -0
- data/doc/Ident/Response/BasicResponse.html +271 -0
- data/doc/Ident/Response/ERROR.html +445 -0
- data/doc/Ident/Response/USERID.html +166 -0
- data/doc/README.html +29 -0
- data/doc/all-files.html +23 -0
- data/doc/all-methods.html +126 -0
- data/doc/all-namespaces.html +32 -0
- data/doc/app.js +18 -0
- data/doc/custom.css +1 -0
- data/doc/index.html +19 -0
- data/doc/jquery.js +11 -0
- data/doc/style.css +81 -0
- data/doc/syntax_highlight.css +24 -0
- data/doc/top-level-namespace.html +25 -0
- data/examples/example.rb +34 -0
- data/lib/ident.rb +134 -0
- metadata +75 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
/* Canvas */
|
2
|
+
.source_code pre.lines { margin-right: 20px; text-align: right; color: #888; }
|
3
|
+
.docstring pre { padding: 12px; padding-left: 0; }
|
4
|
+
.docstring pre, .source_code { background: #222; padding: 12px; margin-top: 8px; border: 1px dashed #ccc; font-size: 0.9em; overflow-x: auto; }
|
5
|
+
|
6
|
+
/* Token colours. Borrowed from pastie.org's "Blackboard" theme */
|
7
|
+
pre.code, pre.lines { font-family: Monaco, Courier, monospace; }
|
8
|
+
pre.code { color: #fff; }
|
9
|
+
pre.code .info.file { color: #888; }
|
10
|
+
pre.code .val, pre.code .int, pre.code .float { color: #61CE3C; }
|
11
|
+
pre.code .dstring, pre.code .tstring_content,
|
12
|
+
pre.code .regexp_beg, pre.code .regexp_end,
|
13
|
+
pre.code .tstring_beg, pre.code .tstring_end { color: #61DE3C; }
|
14
|
+
pre.code .embexpr_beg, pre.code .tstring, pre.code .tstring .rbrace { color: #7CFE65; }
|
15
|
+
pre.code .fid, pre.code .id.new, pre.code .id.to_s,
|
16
|
+
pre.code .id.to_sym, pre.code .id.to_f,
|
17
|
+
pre.code .dot + pre.code .id,
|
18
|
+
pre.code .id.to_i pre.code .id.each { color: #FF6400; }
|
19
|
+
pre.code .comment { color: #AEAEAE; }
|
20
|
+
pre.code .constant, pre.code .const, pre.code .symbol, pre.code .symbeg { color: #D8FA3C; }
|
21
|
+
pre.code .kw { color: #FBDE2D; }
|
22
|
+
pre.code .ivar { color: #AACEFB; }
|
23
|
+
pre.code .gvar, pre.code .backref, pre.code .id.nth_ref { color: #BADEFF; }
|
24
|
+
pre.code .regexp, .dregexp { color: #EA5EFB; }
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
|
6
|
+
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
|
7
|
+
<link rel="stylesheet" href="custom.css" type="text/css" charset="utf-8" />
|
8
|
+
<link rel="stylesheet" href="syntax_highlight.css" type="text/css" charset="utf-8" />
|
9
|
+
|
10
|
+
<script src="jquery.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="app.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
<title>Top Level Namespace</title>
|
13
|
+
</head>
|
14
|
+
<body>
|
15
|
+
<div id="content">
|
16
|
+
|
17
|
+
</div>
|
18
|
+
<div id="yard_info">
|
19
|
+
Generated on Wednesday, October 14 2009 at 04:55:47 PM by
|
20
|
+
<abbr class="yard" title="Yay! A Ruby Documentation Tool"><a href="http://yard.soen.ca">YARD</a></abbr>
|
21
|
+
0.2.3.3 (ruby-1.9.1).
|
22
|
+
</div>
|
23
|
+
|
24
|
+
</body>
|
25
|
+
</html>
|
data/examples/example.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'ident'
|
2
|
+
|
3
|
+
# Note: none of this examples will work when executed directly, they
|
4
|
+
# are rather meant for giving an overview how you would use the
|
5
|
+
# library in your own server applications.
|
6
|
+
|
7
|
+
# using the class method Ident.request
|
8
|
+
begin
|
9
|
+
response = Ident.request("127.0.0.1", 12345, 12345)
|
10
|
+
# if Ident.request returned an error, userid will be nil. If you want
|
11
|
+
# to know what the error was, check Response::ERROR#type or use the
|
12
|
+
# methods like `no_user?`
|
13
|
+
username = response.userid || "fallback username"
|
14
|
+
rescue Timeout::Error, Errno::ECONNREFUSED
|
15
|
+
# we couldn't connect to an identd, use a fallback username
|
16
|
+
username = "fallback username"
|
17
|
+
end
|
18
|
+
|
19
|
+
# using an instance of Ident. basically the same as above, but you can
|
20
|
+
# set the arguments before invoking the request
|
21
|
+
begin
|
22
|
+
i = Ident.new
|
23
|
+
i.ip = "127.0.0.1"
|
24
|
+
i.outbound = 12345
|
25
|
+
i.inbound = 12345
|
26
|
+
i.timeout = 5
|
27
|
+
|
28
|
+
response = i.request
|
29
|
+
username = response.userid || "fallback username"
|
30
|
+
rescue Timeout::Error, Errno::ECONNREFUSED
|
31
|
+
username = "fallback username"
|
32
|
+
end
|
33
|
+
|
34
|
+
# you can ask for the userid, the os and the charset.
|
data/lib/ident.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
class Ident
|
2
|
+
require 'socket'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
KNOWN_ERRORS = ["INVALID-PORT" "NO-USER" "HIDDEN-USER" "UNKNOWN-ERROR"]
|
6
|
+
module Response
|
7
|
+
# This is the blankslate response which ensures that both kind of
|
8
|
+
# responses respond to all required methods. You should never have
|
9
|
+
# to work with this class directly.
|
10
|
+
class BasicResponse
|
11
|
+
# Is the response the result of an error?
|
12
|
+
def error?; false; end
|
13
|
+
def os; nil; end
|
14
|
+
def charset; nil; end
|
15
|
+
def userid; nil; end
|
16
|
+
|
17
|
+
private
|
18
|
+
def self.error_to_method_name(error)
|
19
|
+
(error.downcase.tr('-', '_') + "?").to_sym
|
20
|
+
end
|
21
|
+
|
22
|
+
public
|
23
|
+
KNOWN_ERRORS.each do |e|
|
24
|
+
define_method(error_to_method_name(e)) do
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class USERID < BasicResponse
|
31
|
+
# the operating system of the user
|
32
|
+
attr_reader :os
|
33
|
+
# the charset on the system, defaults to US-ASCII
|
34
|
+
attr_reader :charset
|
35
|
+
# the userid
|
36
|
+
attr_reader :userid
|
37
|
+
def initialize(os, userid)
|
38
|
+
@os, @charset = os.split('-')
|
39
|
+
@charset ||= 'US-ASCII'
|
40
|
+
@userid = userid
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# This class gives access to the error returned by an identd. It
|
45
|
+
# defines method for every possible kind of error: invalid_port?
|
46
|
+
# no_user? hidden_user? unknown_error?
|
47
|
+
class ERROR < BasicResponse
|
48
|
+
KNOWN_ERRORS.each do |e|
|
49
|
+
define_method(error_to_method_name(e)) do
|
50
|
+
@type == e
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :type
|
55
|
+
def initialize(type)
|
56
|
+
@type = type
|
57
|
+
end
|
58
|
+
|
59
|
+
# @see BasicResponse#error?
|
60
|
+
def error?; true; end
|
61
|
+
# Did we specify an invalid port?
|
62
|
+
def invalid_port?; @type == "INVALID-PORT"; end
|
63
|
+
# Is no user known for the given connection specification?
|
64
|
+
def no_user?; @type == "NO-USER"; end
|
65
|
+
# Does the identd hide information from us?
|
66
|
+
def hidden_user?; @type == "HIDDEN-USER"; end
|
67
|
+
# Did an unknown error occur?
|
68
|
+
def unknown_error?; @type == "UNKNOWN-ERROR"; end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns an instance of {USERID} or {ERROR}, depending on the type of
|
72
|
+
# reply.
|
73
|
+
def self.from(s)
|
74
|
+
ports, type, *addinfo = s.split(':')
|
75
|
+
klass = self.const_get(type.to_sym)
|
76
|
+
klass.new(*addinfo)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
attr_accessor :ip
|
81
|
+
attr_accessor :outbound
|
82
|
+
attr_accessor :inbound
|
83
|
+
attr_accessor :timeout
|
84
|
+
attr_reader :response
|
85
|
+
# @see Ident.request
|
86
|
+
def initialize(ip = nil, outbound = nil, inbound = nil, timeout = 10)
|
87
|
+
@ip, @outbound, @inbound, @timeout = ip, outbound, inbound, timeout
|
88
|
+
@response = nil
|
89
|
+
end
|
90
|
+
|
91
|
+
# @see Ident.request
|
92
|
+
def request
|
93
|
+
@response = self.class.request(@ip, @outbound, @inbound, @timeout)
|
94
|
+
end
|
95
|
+
|
96
|
+
# This method connects to an identd at `ip` and queries information
|
97
|
+
# for the connection `outbound`->`inbound` where `outbound` is the
|
98
|
+
# port a connection is coming from (usually anything >1024) and
|
99
|
+
# `inbound` is the port connected to, the port your service is
|
100
|
+
# listening on (e.g. 6667 in the case of an IRCd)
|
101
|
+
#
|
102
|
+
#
|
103
|
+
# @example user A connects to our server on port 23, coming from 123.123.123.123 on port 6789
|
104
|
+
# Ident.request('123.123.123.123', 6789, 23)
|
105
|
+
#
|
106
|
+
# @param [String] ip The IP of the ident server
|
107
|
+
# @param [Integer] outbound The port from which the connection is coming
|
108
|
+
# @param [Integer] inbound The port to which was connected
|
109
|
+
# @param [Integer] timeout_after The timeout, defaults to 10 seconds
|
110
|
+
#
|
111
|
+
# @raise [Timeout::Error] In case of a timeout
|
112
|
+
# @raise [Errno::ECONNREFUSED] If no identd was running at the destination host
|
113
|
+
#
|
114
|
+
# @return [Response::USERID] if we successfully queried the ident server
|
115
|
+
# @return [Response::ERROR] in case of an error
|
116
|
+
def self.request(ip, outbound, inbound, timeout_after = 10)
|
117
|
+
r = nil
|
118
|
+
timeout(timeout_after) do
|
119
|
+
t = TCPSocket.new(ip, 113)
|
120
|
+
t.puts [outbound, inbound].join(', ')
|
121
|
+
r = t.gets
|
122
|
+
t.close
|
123
|
+
end
|
124
|
+
|
125
|
+
# in case the identd just kills our connection
|
126
|
+
r ||= "#{outbound}, #{inbound}:ERROR:UNKNOWN-ERROR"
|
127
|
+
|
128
|
+
r.chomp!
|
129
|
+
Response.from(r)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ident
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dominik Honnef
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-14 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Ruby library for querying identd servers (RFC 1413)
|
17
|
+
email: dominikho@gmx.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/ident.rb
|
26
|
+
- Rakefile
|
27
|
+
- COPYING
|
28
|
+
- README
|
29
|
+
- doc/syntax_highlight.css
|
30
|
+
- doc/all-files.html
|
31
|
+
- doc/Ident
|
32
|
+
- doc/Ident/Response
|
33
|
+
- doc/Ident/Response/ERROR.html
|
34
|
+
- doc/Ident/Response/BasicResponse.html
|
35
|
+
- doc/Ident/Response/USERID.html
|
36
|
+
- doc/Ident/Response.html
|
37
|
+
- doc/custom.css
|
38
|
+
- doc/Ident.html
|
39
|
+
- doc/style.css
|
40
|
+
- doc/README.html
|
41
|
+
- doc/all-methods.html
|
42
|
+
- doc/all-namespaces.html
|
43
|
+
- doc/app.js
|
44
|
+
- doc/index.html
|
45
|
+
- doc/top-level-namespace.html
|
46
|
+
- doc/jquery.js
|
47
|
+
- examples/example.rb
|
48
|
+
has_rdoc: false
|
49
|
+
homepage: http://dominikh.fork-bomb.de
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: ident
|
70
|
+
rubygems_version: 1.3.1
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: A Ruby library for querying identd servers (RFC 1413)
|
74
|
+
test_files: []
|
75
|
+
|