ipaccess 0.0.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +15 -0
  2. checksums.yaml.gz.sig +1 -0
  3. data.tar.gz.sig +0 -0
  4. data/.gemtest +0 -0
  5. data/.rspec +1 -0
  6. data/.yardopts +12 -0
  7. data/ChangeLog +1495 -0
  8. data/{docs/LGPL-LICENSE → LGPL-LICENSE} +0 -0
  9. data/Manifest.txt +76 -0
  10. data/README.md +96 -0
  11. data/Rakefile +65 -42
  12. data/docs/COPYING +41 -45
  13. data/docs/FAQ +12 -0
  14. data/docs/HISTORY +17 -0
  15. data/docs/LEGAL +1 -1
  16. data/docs/LGPL +166 -0
  17. data/docs/TODO +150 -7
  18. data/docs/images/ipaccess.png +0 -0
  19. data/docs/images/ipaccess_ac_for_args.png +0 -0
  20. data/docs/images/ipaccess_ac_for_socket.png +0 -0
  21. data/docs/images/ipaccess_logo.png +0 -0
  22. data/docs/images/ipaccess_relations.png +0 -0
  23. data/docs/images/ipaccess_setup_origin.png +0 -0
  24. data/docs/images/ipaccess_setup_origin_tab.png +0 -0
  25. data/docs/images/ipaccess_view.png +0 -0
  26. data/docs/rdoc.css +22 -0
  27. data/examples/ftp.rb +62 -0
  28. data/examples/http.rb +81 -0
  29. data/examples/imap.rb +37 -0
  30. data/examples/pop.rb +31 -0
  31. data/examples/smtp.rb +26 -0
  32. data/examples/tcp_server.rb +32 -0
  33. data/examples/tcp_socket.rb +7 -3
  34. data/examples/telnet.rb +32 -0
  35. data/examples/text_message.rb +45 -0
  36. data/lib/ipaccess.rb +557 -7
  37. data/lib/ipaccess/arm_sockets.rb +7 -4
  38. data/lib/ipaccess/ghost_doc/ghost_doc.rb +23 -0
  39. data/lib/ipaccess/ghost_doc/ghost_doc_acl.rb +54 -0
  40. data/lib/ipaccess/ghost_doc/ghost_doc_net_ftp.rb +213 -0
  41. data/lib/ipaccess/ghost_doc/ghost_doc_net_http.rb +272 -0
  42. data/lib/ipaccess/ghost_doc/ghost_doc_net_smtp.rb +186 -0
  43. data/lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb +227 -0
  44. data/lib/ipaccess/ghost_doc/ghost_doc_p_blacklist.rb +36 -0
  45. data/lib/ipaccess/ghost_doc/ghost_doc_p_blacklist_e.rb +7 -0
  46. data/lib/ipaccess/ghost_doc/ghost_doc_p_unblacklist.rb +36 -0
  47. data/lib/ipaccess/ghost_doc/ghost_doc_p_unblacklist_e.rb +7 -0
  48. data/lib/ipaccess/ghost_doc/ghost_doc_p_unwhitelist.rb +36 -0
  49. data/lib/ipaccess/ghost_doc/ghost_doc_p_unwhitelist_e.rb +7 -0
  50. data/lib/ipaccess/ghost_doc/ghost_doc_p_whitelist.rb +36 -0
  51. data/lib/ipaccess/ghost_doc/ghost_doc_p_whitelist_e.rb +7 -0
  52. data/lib/ipaccess/ghost_doc/ghost_doc_patched_usage.rb +64 -0
  53. data/lib/ipaccess/ghost_doc/ghost_doc_sockets.rb +571 -0
  54. data/lib/ipaccess/ip_access_check.rb +508 -0
  55. data/lib/ipaccess/ip_access_errors.rb +186 -40
  56. data/lib/ipaccess/ip_access_list.rb +955 -1122
  57. data/lib/ipaccess/ip_access_set.rb +212 -0
  58. data/lib/ipaccess/net/ftp.rb +39 -0
  59. data/lib/ipaccess/net/http.rb +39 -0
  60. data/lib/ipaccess/net/https.rb +30 -0
  61. data/lib/ipaccess/net/imap.rb +39 -0
  62. data/lib/ipaccess/net/pop.rb +46 -0
  63. data/lib/ipaccess/net/smtp.rb +39 -0
  64. data/lib/ipaccess/net/telnet.rb +38 -0
  65. data/lib/ipaccess/patches/generic.rb +807 -0
  66. data/lib/ipaccess/patches/net_ftp.rb +165 -0
  67. data/lib/ipaccess/patches/net_http.rb +175 -0
  68. data/lib/ipaccess/patches/net_https.rb +29 -0
  69. data/lib/ipaccess/patches/net_imap.rb +117 -0
  70. data/lib/ipaccess/patches/net_pop.rb +171 -0
  71. data/lib/ipaccess/patches/net_smtp.rb +130 -0
  72. data/lib/ipaccess/patches/net_telnet.rb +103 -0
  73. data/lib/ipaccess/{netaddr_patch.rb → patches/netaddr.rb} +20 -11
  74. data/lib/ipaccess/patches/sockets.rb +586 -0
  75. data/lib/ipaccess/socket.rb +52 -1
  76. data/lib/ipaccess/sockets.rb +4 -30
  77. data/spec/ip_access_list_spec.rb +33 -21
  78. data/spec/spec.opts +2 -2
  79. metadata +289 -63
  80. metadata.gz.sig +0 -0
  81. data/docs/DOWNLOAD +0 -17
  82. data/docs/README +0 -95
  83. data/docs/WELCOME +0 -8
  84. data/lib/ipaccess/ghost_doc.rb +0 -206
  85. data/lib/ipaccess/ghost_doc_acl.rb +0 -31
  86. data/lib/ipaccess/ip_access.rb +0 -456
  87. data/lib/ipaccess/ip_access_patches.rb +0 -431
  88. data/spec/core_spec.rb +0 -5
@@ -0,0 +1,212 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
+ # Copyright:: Copyright (c) 2009-2014 by Paweł Wilk
5
+ # License:: This program is licensed under the terms of {GNU Lesser General Public License}[link:docs/LGPL.html] or {Ruby License}[link:docs/COPYING.html].
6
+ #
7
+ # This file contains IPAccess::Set class, which uses
8
+ # IPAccess::List::Check objects to implement IP input/output
9
+ # access control.
10
+ #
11
+ #--
12
+ #
13
+ # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #++
23
+
24
+ require 'socket'
25
+ require 'ipaccess'
26
+ require 'ipaccess/ip_access_list'
27
+ require 'ipaccess/ip_access_check'
28
+ require 'ipaccess/ip_access_errors'
29
+
30
+ module IPAccess
31
+
32
+ # This class maintains an access set.
33
+ #
34
+ # Objects of IPAccess::Set class, called <b>access sets</b>,
35
+ # contain two access lists which are available
36
+ # as accessible attributes: +input+ and +output+.
37
+ #
38
+ # ==== Usage examples
39
+ #
40
+ # access = IPAccess::Set.new 'myset' # create an access set
41
+ # access.input.block :private # input list: block private subnets
42
+ # access.input.permit '192.168.1.1' # input list: but permit 192.168.1.1
43
+ # access.input.check '192.168.1.1' # should pass
44
+ # access.input.check '192.168.1.2' # should raise an exception
45
+ #
46
+ # In the example above checking access is covered
47
+ # by the check_in method. It is generic, easy to use
48
+ # routine, but if you are fan of performance
49
+ # you may want to use dedicated methods designed
50
+ # to handle single IP stored in socket, file descriptor,
51
+ # NetAddr::CIDR object, sockaddr structure or IP string.
52
+ #
53
+ # require 'uri'
54
+ # require 'net/http'
55
+ #
56
+ # access = IPAccess::Set.new 'outgoing http' # create access set
57
+ # access.output.block :all # output list: block all
58
+ #
59
+ # url = URI('http://randomseed.pl/') # parse URL
60
+ # res = Net::HTTP.new(url.host, url.port) # create HTTP resource
61
+ # req = Net::HTTP::Get.new(url.path) # create HTTP request
62
+ #
63
+ # res.start do # start HTTP session
64
+ # access.check_out(res) # check access for socket extracted from HTTP object
65
+ # response = res.request(req) # read response
66
+ # end
67
+ #
68
+ # In the example above, which is probably more real
69
+ # than previous, we're using check_out method for testing
70
+ # Net::HTTP response object. The method is clever enough to
71
+ # extract IP socket from such object.
72
+ #
73
+ # Although the problem still exists because
74
+ # access for incoming connection is validated
75
+ # after the HTTP session has already started. We cannot
76
+ # be 100% sure whether any data has been sent or not.
77
+ # The cause of that problem is lack of controlled
78
+ # low-level connect operation that we can issue in
79
+ # that particular case.
80
+ #
81
+ # To fix issues like that you may want to
82
+ # globally enable IP access control for original
83
+ # Ruby's socket classes or use special versions
84
+ # of them shipped with this library. To patch original
85
+ # sockets or single objects use IPAccess.arm class method. To
86
+ # use extended version of network classes use
87
+ # <tt>IPAccess::</tt> prefix.
88
+
89
+ class Set
90
+
91
+ # Access list for incoming IP traffic. See IPAccess::List::Check class
92
+ # for more information on how to manage it.
93
+
94
+ attr_reader :input
95
+
96
+ alias_method :in, :input
97
+ alias_method :incoming, :input
98
+
99
+ # Access list for outgoing IP traffic. See IPAccess::List::Check class
100
+ # for more information on how to manage it.
101
+
102
+ attr_reader :output
103
+
104
+ alias_method :out, :output
105
+ alias_method :outgoing, :output
106
+
107
+ # Descriptive name of this object. Used in error reporting.
108
+
109
+ attr_accessor :name
110
+
111
+ # This method creates new IPAccess::Set object. It optionally takes
112
+ # two IPAccess::List::Check objects (initial data for access lists)
113
+ # and descriptive name of an access set used in error reporting.
114
+ # If there is only one argument it's assumed that it contains
115
+ # descriptive name of an access set.
116
+
117
+ def initialize(input=nil, output=nil, name=nil)
118
+ @name = nil
119
+ @name, input = input, nil if (output.nil? && name.nil?)
120
+ @input = IPAccess::List::Check.new(input)
121
+ @output = IPAccess::List::Check.new(output)
122
+ @input.exception = IPAccessDenied::Input
123
+ @output.exception = IPAccessDenied::Output
124
+ return self
125
+ end
126
+
127
+ # This method returns +true+ if all access lists are empty.
128
+ # Otherwise returns +false+.
129
+
130
+ def empty?
131
+ @input.empty? && @output.empty?
132
+ end
133
+
134
+ # This method removes all rules from both input and
135
+ # output access list.
136
+
137
+ def clear!
138
+ @input.clear!
139
+ @output.clear!
140
+ end
141
+
142
+ # This method returns true if access set works
143
+ # in bidirectional mode.
144
+
145
+ def bidirectional?
146
+ return (@output.object_id == @input.object_id)
147
+ end
148
+
149
+ # This method switches set to bidirectional
150
+ # mode if the given argument is not +false+
151
+ # and is not +nil+. When access set
152
+ # operates in this mode there is no difference
153
+ # between incoming and outgoing acceess list.
154
+ # In bidirectional mode each access check
155
+ # is performed against one list, which contains
156
+ # both input and output rules. Still the only
157
+ # way to add or delete rules is to straight
158
+ # call +input+ or +output+. The difference is
159
+ # that these lists are linked together
160
+ # in bidirectional mode.
161
+ #
162
+ # Be aware that switching mode will alter
163
+ # your access lists. When switching to
164
+ # bidirectional it will combine input and
165
+ # output rules and put it into one list.
166
+ # When switching back from bidirectional
167
+ # to normal mode input and output lists
168
+ # will have the same rules inside.
169
+ #
170
+ # It may be good idea to prune access lists before
171
+ # switching mode or to switch mode before adding
172
+ # any rules to avoid unexpected results. You may
173
+ # of course change mode anyway if you really know
174
+ # what you are doing.
175
+
176
+ def bidirectional=(enable)
177
+ enable = enable ? true : false
178
+ if enable != bidirectional?
179
+ if enable
180
+ @input.add @output
181
+ @output.clear!
182
+ @output = @input
183
+ else
184
+ @output = IPAccess::List::Check.new @input
185
+ end
186
+ end
187
+ return nil
188
+ end
189
+
190
+ # This method shows an access set in a human readable form.
191
+
192
+ def show(reasons=false)
193
+ r = ""
194
+ unless @input.empty?
195
+ r = ".=========================================.\n" +
196
+ ". Rules for incoming traffic:\n\n" +
197
+ @input.show(reasons)
198
+ r += "\n" if @output.empty?
199
+ end
200
+ unless @output.empty?
201
+ r += "\n" unless @input.empty?
202
+ r += ".=========================================.\n" +
203
+ ". Rules for outgoing traffic:\n\n" +
204
+ @output.show(reasons) + "\n"
205
+ end
206
+ return r
207
+ end
208
+
209
+ end # class Set
210
+
211
+ end # module IPAccess
212
+
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
+ # Copyright:: Copyright (c) 2009-2014 by Paweł Wilk
5
+ # License:: This program is licensed under the terms of {GNU Lesser General Public License}[link:docs/LGPL.html] or {Ruby License}[link:docs/COPYING.html].
6
+ #
7
+ # Classes contained in this file are subclasses
8
+ # of Ruby FTP handling classes equipped
9
+ # with IP access control.
10
+ #
11
+ #--
12
+ #
13
+ # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #
23
+ # See ipaccess/ghost_doc/ghost_doc.rb for documentation of this classes.
24
+ #
25
+ #++
26
+
27
+ require 'net/ftp'
28
+ require 'ipaccess/ip_access_set'
29
+ require 'ipaccess/patches/net_ftp'
30
+
31
+
32
+ module IPAccess::Net
33
+
34
+ class FTP < ::Net::FTP
35
+ include IPAccess::Patches::Net::FTP
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
+ # Copyright:: Copyright (c) 2009-2014 by Paweł Wilk
5
+ # License:: This program is licensed under the terms of {GNU Lesser General Public License}[link:docs/LGPL.html] or {Ruby License}[link:docs/COPYING.html].
6
+ #
7
+ # Classes contained in this file are subclasses
8
+ # of Ruby HTTP handling classes equipped
9
+ # with IP access control.
10
+ #
11
+ #--
12
+ #
13
+ # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #
23
+ # See ipaccess/ghost_doc/ghost_doc.rb for documentation of this classes.
24
+ #
25
+ #++
26
+
27
+ require 'net/http'
28
+ require 'ipaccess/ip_access_set'
29
+ require 'ipaccess/patches/net_http'
30
+
31
+
32
+ module IPAccess::Net
33
+
34
+ class HTTP < ::Net::HTTP
35
+ include IPAccess::Patches::Net::HTTP
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
+ # Copyright:: Copyright (c) 2009-2014 by Paweł Wilk
5
+ # License:: This program is licensed under the terms of {GNU Lesser General Public License}[link:docs/LGPL.html] or {Ruby License}[link:docs/COPYING.html].
6
+ #
7
+ # Classes contained in this file are subclasses
8
+ # of Ruby HTTPS handling classes equipped
9
+ # with IP access control.
10
+ #
11
+ #--
12
+ #
13
+ # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #
23
+ # See ipaccess/ghost_doc/ghost_doc.rb for documentation of this classes.
24
+ #
25
+ #++
26
+
27
+ require 'net/https'
28
+ require 'ipaccess/ip_access_set'
29
+ require 'ipaccess/patches/net_https'
30
+
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
+ # Copyright:: Copyright (c) 2009-2014 by Paweł Wilk
5
+ # License:: This program is licensed under the terms of {GNU Lesser General Public License}[link:docs/LGPL.html] or {Ruby License}[link:docs/COPYING.html].
6
+ #
7
+ # Classes contained in this file are subclasses
8
+ # of Ruby's IMAP handling classes equipped
9
+ # with IP access control.
10
+ #
11
+ #--
12
+ #
13
+ # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #
23
+ # See ipaccess/ghost_doc/ghost_doc.rb for documentation of this classes.
24
+ #
25
+ #++
26
+
27
+ require 'net/imap'
28
+ require 'ipaccess/ip_access_set'
29
+ require 'ipaccess/patches/net_imap'
30
+
31
+
32
+ module IPAccess::Net
33
+
34
+ class IMAP < ::Net::IMAP
35
+ include IPAccess::Patches::Net::IMAP
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
+ # Copyright:: Copyright (c) 2009-2014 by Paweł Wilk
5
+ # License:: This program is licensed under the terms of {GNU Lesser General Public License}[link:docs/LGPL.html] or {Ruby License}[link:docs/COPYING.html].
6
+ #
7
+ # Classes contained in this file are subclasses
8
+ # of Ruby's POP3 handling classes equipped
9
+ # with IP access control.
10
+ #
11
+ #--
12
+ #
13
+ # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #
23
+ # See ipaccess/ghost_doc/ghost_doc.rb for documentation of this classes.
24
+ #
25
+ #++
26
+
27
+ require 'net/pop'
28
+ require 'ipaccess/ip_access_set'
29
+ require 'ipaccess/patches/net_pop'
30
+
31
+
32
+ module IPAccess::Net
33
+
34
+ class POP3 < ::Net::POP3
35
+ include IPAccess::Patches::Net::POP3
36
+ end
37
+
38
+ class APOP < IPAccess::Net::POP3
39
+ # Always returns true.
40
+ def apop?
41
+ true
42
+ end
43
+ end
44
+
45
+ end
46
+
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ #
3
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
4
+ # Copyright:: Copyright (c) 2009-2014 by Paweł Wilk
5
+ # License:: This program is licensed under the terms of {GNU Lesser General Public License}[link:docs/LGPL.html] or {Ruby License}[link:docs/COPYING.html].
6
+ #
7
+ # Classes contained in this file are subclasses
8
+ # of Ruby's SMTP handling classes equipped
9
+ # with IP access control.
10
+ #
11
+ #--
12
+ #
13
+ # Copyright (C) 2009 by Paweł Wilk. All Rights Reserved.
14
+ #
15
+ # This program is free software; you can redistribute it and/or modify
16
+ # it under the terms of either: 1) the GNU Lesser General Public License
17
+ # as published by the Free Software Foundation; either version 3 of the
18
+ # License, or (at your option) any later version; or 2) Ruby's License.
19
+ #
20
+ # See the file COPYING for complete licensing information.
21
+ #
22
+ #
23
+ # See ipaccess/ghost_doc/ghost_doc.rb for documentation of this classes.
24
+ #
25
+ #++
26
+
27
+ require 'net/smtp'
28
+ require 'ipaccess/ip_access_set'
29
+ require 'ipaccess/patches/net_smtp'
30
+
31
+
32
+ module IPAccess::Net
33
+
34
+ class SMTP < ::Net::SMTP
35
+ include IPAccess::Patches::Net::SMTP
36
+ end
37
+
38
+ end
39
+