Class: IPAccess::Net::Telnet

Inherits:
Net::Telnet
  • Object
show all
Includes:
Patches::Net::Telnet
Defined in:
lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb,
lib/ipaccess/net/telnet.rb

Overview

Net::Telnet class with IP access control. It uses output access lists and acts the same way as Net::Telnet class but provides provides special member called acl and a few new instance methods for controlling IP access.

:include:ghost_doc_patched_usage.rb

This documentation doesn’t cover description of all class and instance methods of the original Net::Telnet class, just the patched variants that make use of IP access control.

Examples

Global access set, using IPAccess::Net::Telnet

require 'ipaccess/net/telnet'         # load Net::Telnet version and IPAccess.arm method

opts = {}               
opts["Host"]  = 'randomseed.pl'   
opts["Port"]  = '80'

IPAccess::Set::Global.output.blacklist 'randomseed.pl' # blacklist host
t = IPAccess::Net::Telnet.new(opts)               # try to connect to remote host

Global access set, single object patched, direct blacklisting

require 'ipaccess/net/telnet'     # load Net::Telnet version and IPAccess.arm method

opts = {}
opts["Host"]  = 'randomseed.pl'
opts["Port"]  = '80'

t = Net::Telnet.new(opts)       # try to connect to remote host
IPAccess.arm t                  # arm single Telnet object (will use global access set)
t.blacklist! 'randomseed.pl'    # blacklist host while being connected

Shared access set, single object patched

require 'ipaccess/net/telnet'         # load Net::Telnet version and IPAccess.arm method

opts = {}                          
opts["Host"]  = 'randomseed.pl'    
opts["Port"]  = '80'               

t = Net::Telnet.new(opts)             # try to connect to remote host

acl = IPAccess::Set.new                    # create custom access set
acl.output.blacklist 'randomseed.pl'  # blacklist host in access set
IPAccess.arm t, acl                   # arm single Telnet object with access set passed

Shared access set, single object patched, direct blacklisting

require 'ipaccess/net/telnet'         # load Net::Telnet version and IPAccess.arm method

opts = {}                          
opts["Host"]  = 'randomseed.pl'
opts["Port"]  = '80'               

t = Net::Telnet.new(opts)             # try to connect to remote host

acl = IPAccess::Set.new                    # create custom access set
IPAccess.arm t, acl                   # arm single Telnet object with access set passed
t.blacklist 'randomseed.pl'           # blacklist host

Shared access set, class patched

require 'ipaccess/net/telnet'         # load Net::Telnet version and IPAccess.arm method

opts = {}
opts["Host"]  = 'randomseed.pl'
opts["Port"]  = '80'

IPAccess.arm Net::Telnet                      # patch Net::Telnet class  
opts['ACL'] = IPAccess::Set.new                    # create custom access set and add it to options
opts['ACL'].output.blacklist 'randomseed.pl'  # blacklist host

t = Net::Telnet.new(opts)             # try to connect to remote host

Private access set, class patched, direct blacklisting

require 'ipaccess/net/telnet'         # load Net::Telnet version and IPAccess.arm method

opts = {}
opts["Host"]  = 'randomseed.pl'
opts["Port"]  = '80'

IPAccess.arm Net::Telnet              # patch Net::Telnet class  

t = Net::Telnet.new(opts, :private)   # try to connect to remote host
t.blacklist 'randomseed.pl'           # blacklist host

Instance Attribute Summary collapse

Attributes included from Patches::ACL

#opened_on_deny

Instance Method Summary collapse

Methods included from Patches::ACL

#__ipa_wrap_socket_call, #close_on_deny, #close_on_deny=, #default_list, #terminate, #valid_acl?

Constructor Details

#initializeTelnet

:call-seq:

new(opts) <tt>{|mesg| …}</tt><br />
new(opts, acl) <tt>{|mesg| …}</tt>

Creates a new object and attempts to connect to the host (unless the Proxy option is provided). If a block is provided, it is yielded as status messages on the attempt to connect to the server. It optionally sets an access set given as the last parameter or as ACL member of opts. The access set given as an argument has precedence over access set given in options. If ACL parameter is not given it defaults to ACL to IPAccess::Set.Global.



210
211
212
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 210

def initialize
  # Real code hidden.
end

Instance Attribute Details

#aclObject

:include:ghost_doc_acl.rb

Example

require 'ipaccess/net/telnet'             # load Net::Telnet variant

opts = {}
opts["Host"] = 'randomseed.pl'
telnet = IPAccess::Net::Telnet.new(opts)  # create connected Telnet object

telnet.acl = :global                      # use global access set
telnet.acl = :private                     # create and use individual access set
telnet.acl = IPAccess::Set.new                 # use external (shared) access set


187
188
189
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 187

def acl
  @acl
end

#sockObject (readonly)

The socket the Telnet object is using, which is kind of TCPSocket and responds to all methods of IPAccess::TCPSocket. Note that this object becomes a delegate of the Telnet object, so normally you invoke its methods directly on the Telnet object.



194
195
196
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 194

def sock
  @sock
end

Instance Method Details

#acl_recheckObject

This method allows you to re-check access on demad. It uses internal socket’s address and access set assigned to an object. It will close your communication session before throwing an exception in case of denied access – you can prevent it by setting the flag opened_on_deny to true. The flag can be set while initializing object (through argument :opened_on_deny) or by setting the attribute.



223
224
225
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 223

def acl_recheck
  # Real code hidden.
end

#blacklistObject Also known as: add_black, deny, block

:include:ghost_doc_p_blacklist.rb



130
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 130

def blacklist; end

#blacklist!Object Also known as: add_black!, deny!, block!

:include:ghost_doc_p_blacklist_e.rb



127
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 127

def blacklist!; end

#blacklist_reasonable(reason, *addresses) ⇒ Object

This method works like blacklist but allows to set reason.



171
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 171

def blacklist_reasonable(reason, *addresses); end

#blacklist_reasonable!(reason, *addresses) ⇒ Object

This method works like blacklist! but allows to set reason.



167
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 167

def blacklist_reasonable!(reason, *addresses); end

#unblacklistObject Also known as: unblock, del_black

:include:ghost_doc_p_unblacklist.rb



142
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 142

def unblacklist; end

#unblacklist!Object Also known as: unblock!, del_black!

:include:ghost_doc_p_unblacklist_e.rb



139
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 139

def unblacklist!; end

#unwhitelistObject Also known as: del_white

:include:ghost_doc_p_unwhitelist.rb



133
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 133

def unwhitelist; end

#unwhitelist!Object Also known as: del_white!

:include:ghost_doc_p_unwhitelist_e.rb



136
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 136

def unwhitelist!; end

#whitelistObject

:include:ghost_doc_p_whitelist.rb



124
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 124

def whitelist; end

#whitelist!Object

:include:ghost_doc_p_whitelist_e.rb



121
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 121

def whitelist!; end

#whitelist_reasonable(reason, *addresses) ⇒ Object

This method works like whitelist but allows to set reason.



163
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 163

def whitelist_reasonable(reason, *addresses); end

#whitelist_reasonable!(reason, *addresses) ⇒ Object

This method works like whitelist! but allows to set reason.



159
# File 'lib/ipaccess/ghost_doc/ghost_doc_net_telnet.rb', line 159

def whitelist_reasonable!(reason, *addresses); end