netsoul 1.9.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40ae5cdd054a7d3eb6d72265a45714d49367e18f
4
- data.tar.gz: 6046d54fe9e388c0dd33ffde354d69205c1bc062
3
+ metadata.gz: c3867b9a41505375037c2a9dab38d767b1ff3fec
4
+ data.tar.gz: accfa0351a8f3702a6b528d09c5871ea5cd3e8bf
5
5
  SHA512:
6
- metadata.gz: e4937e3a77f5d7a3fdd3cf916a5d1d235c05baaf2622ebdcd9d68741f136f97d00d0b39f815b72eef8346e0c6bb9d426ed450edc4978273c1ee6313616014830
7
- data.tar.gz: 87271293e474120ff9d712135250b2bcd166bf22c45dbc7a37b60298601ba98c4a7e83de32bf8d483e6ad360293675775d8d41ec21ec4060855fbdb1e2b02740
6
+ metadata.gz: b9d49424ebfdb9417801d8307190b02f9c433d789863f9c5106471ee36df2d17a5c769a3ffe78d52de7d7f98a8eab390d875d446573a4540f4d36d133f5fad6c
7
+ data.tar.gz: f0f98ab4eede97c75ea6b44c95369a998b98397c90ed8b2c4cb2765a41e48168a189e4217e4b337ce39e7afb7eea36cca9fa0f09057774ee1bf35fa931359bb6
data/bin/netsoul-ruby CHANGED
@@ -22,7 +22,7 @@ OptionParser.new do |opts|
22
22
  options[:user_opts] = YAML.load_file(file) if File.file?(file)
23
23
  end
24
24
 
25
- opts.on('-h', '--help', 'Display this screen') do
25
+ opts.on('-h'.freeze, '--help', 'Display this screen'.freeze) do
26
26
  puts opts
27
27
  exit 42
28
28
  end
@@ -30,7 +30,7 @@ end.parse!
30
30
 
31
31
  if options.empty? || options[:user_opts].size == 0
32
32
  unless ENV.to_a.count { |k, _v| %w(NETSOUL_LOGIN NETSOUL_SOCKS_PASSWORD NETSOUL_LOGIN NETSOUL_UNIX_PASSWORD NETSOUL_AUTH_METHOD).include?(k) } >= 2
33
- puts '[ERROR] You have to specify a configuration file or environment variables'
33
+ puts '[ERROR] You have to specify a configuration file or environment variables'.freeze
34
34
  exit 42
35
35
  end
36
36
  end
@@ -45,14 +45,14 @@ begin
45
45
  retry_count = 10
46
46
  retry_wait_time = 1.0
47
47
  loop do
48
- res = c.sock_get
49
- c.sock_send res if res.to_s.match(/^ping.*/)
48
+ res = c.get
49
+ c.send res if res.to_s.match(/^ping.*/)
50
50
  sleep 1
51
51
  end
52
52
  end
53
53
  rescue Interrupt
54
54
  begin c.disconnect; end
55
- puts '!!! [SIGINT] !!!'
55
+ puts '!!! [SIGINT] !!!'.freeze
56
56
  exit 42
57
57
  rescue => e
58
58
  puts "[ERROR]: #{e}"
@@ -61,7 +61,8 @@ rescue => e
61
61
  if retry_count > 0
62
62
  retry_count -= 1
63
63
  retry_wait_time *= RETRY_WAIT_FACTOR
64
- sleep(retry_wait_time) && retry
64
+ sleep(retry_wait_time)
65
+ retry
65
66
  end
66
67
  exit 42
67
68
  end
@@ -15,31 +15,31 @@ module Netsoul
15
15
  end
16
16
 
17
17
  def auth_ag
18
- sock_send(Message.auth_ag)
19
- fail Netsoul::IdentificationError, 'Identification failed.'.freeze unless sock_get.split(' ')[1] == '002'.freeze
18
+ send(Message.auth_ag)
19
+ fail Netsoul::IdentificationError, 'Identification failed.'.freeze unless get.split(' ')[1] == '002'.freeze
20
20
  end
21
21
  private :auth_ag
22
22
 
23
23
  def auth_method
24
24
  if @config.auth_method == :krb5
25
- sock_send(Message.kerberos_auth(@config))
25
+ send(Message.kerberos_auth(@config))
26
26
  else
27
- sock_send(Message.standard_auth(@config))
27
+ send(Message.standard_auth(@config))
28
28
  end
29
- fail Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables'.freeze unless sock_get.split(' ')[1] == '002'
29
+ fail Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables'.freeze unless get.split(' ')[1] == '002'
30
30
  end
31
31
  private :auth_method
32
32
 
33
33
  def auth_status
34
- sock_send(Message.attach)
35
- sock_send(Message.user_state(@config.state, Time.now.to_i))
34
+ send(Message.attach)
35
+ send(Message.user_state(@config.state, Time.now.to_i))
36
36
  end
37
37
  private :auth_status
38
38
 
39
39
  def connect
40
- @sock = TCPSocket.new(@config.server_host, @config.server_port)
41
- fail Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @sock
42
- _cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = sock_get.split
40
+ @socket = TCPSocket.new(@config.server_host, @config.server_port)
41
+ fail Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @socket
42
+ _cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = get.split
43
43
 
44
44
  @config.build_user_connection_info md5_hash: md5_hash, client_ip: client_ip, client_port: client_port
45
45
 
@@ -51,29 +51,29 @@ module Netsoul
51
51
  end
52
52
 
53
53
  def disconnect
54
- sock_send(Message.ns_exit)
54
+ send(Message.ns_exit)
55
55
  ensure
56
- sock_close
56
+ close
57
57
  end
58
58
 
59
- def sock_send(str)
60
- _, sock = IO.select(nil, [@sock], nil, SOCKET_WRITE_TIMEOUT)
59
+ def send(str)
60
+ _, sock = IO.select(nil, [@socket], nil, SOCKET_WRITE_TIMEOUT)
61
61
  fail Netsoul::SocketError, 'Timeout or fail on write socket' if sock.nil? || sock.empty?
62
62
  sock.first.puts str
63
63
  log :info, "[send] #{str.chomp}"
64
64
  end
65
65
 
66
- def sock_get
67
- sock, = IO.select([@sock], nil, nil, SOCKET_READ_TIMEOUT)
66
+ def get
67
+ sock, = IO.select([@socket], nil, nil, SOCKET_READ_TIMEOUT)
68
68
  fail Netsoul::SocketError, 'Timeout or fail on read socket' if sock.nil? || sock.empty?
69
69
  res = sock.first.gets
70
70
  log :info, "[get ] #{res.chomp}" if res
71
71
  res || ''
72
72
  end
73
73
 
74
- def sock_close
74
+ def close
75
75
  @started = false
76
- @sock.close
76
+ @socket.close
77
77
  rescue
78
78
  nil
79
79
  end
@@ -43,7 +43,7 @@ module Netsoul
43
43
  @user_group = ENV['NETSOUL_USER_GROUP'] || opts.fetch(:user_group, 'ETNA_2008'.freeze)
44
44
  @user_connection_info = {}
45
45
 
46
- @client_name = ENV['NETSOUL_CLIENT_NAME'] || opts.fetch(:client_name, '(Netsoul-Ruby) -> { Christian Kakesa, since 2009}'.freeze)
46
+ @client_name = ENV['NETSOUL_CLIENT_NAME'] || opts.fetch(:client_name, "(Netsoul-Ruby v#{Netsoul::VERSION}) -> { Christian Kakesa, since 2009}".freeze)
47
47
  end
48
48
 
49
49
  def build_user_connection_info(opts = {})
@@ -2,8 +2,6 @@ require 'base64'
2
2
  require 'digest/md5'
3
3
  require 'uri'
4
4
 
5
- require_relative 'location'
6
-
7
5
  module Netsoul
8
6
  class Message
9
7
  class << self
@@ -119,4 +117,54 @@ module Netsoul
119
117
  end
120
118
  end
121
119
  end
120
+
121
+ class Location
122
+ class << self
123
+ def get(ip)
124
+ locations.each do |key, val|
125
+ return "#{key}".freeze if ip.match(/^#{val}/)
126
+ end
127
+ 'ext'.freeze
128
+ end
129
+
130
+ # rubocop:disable all
131
+ def locations
132
+ @locations ||= {
133
+ :'lab-cisco-mid-sr' => '10.251.'.freeze,
134
+ etna: '10.245.'.freeze,
135
+ lse: '10.227.42.'.freeze,
136
+ :'sda-1' => '10.227.4.'.freeze,
137
+ lab: '10.227.'.freeze,
138
+ :'lab-tcom' => '10.226.7.'.freeze,
139
+ :'lab-acu' => '10.226.6.'.freeze,
140
+ :'lab-console' => '10.226.5.'.freeze,
141
+ :'lab-mspe' => '10.226.'.freeze,
142
+ epitanim: '10.225.19.'.freeze,
143
+ epidemic: '10.225.18.'.freeze,
144
+ :'sda-2' => '10.225.10.'.freeze,
145
+ cycom: '10.225.8.'.freeze,
146
+ epx: '10.225.7.'.freeze,
147
+ prologin: '10.225.6.'.freeze,
148
+ nomad: '10.225.2.'.freeze,
149
+ assos: '10.225.'.freeze,
150
+ sda: '10.224.14.'.freeze,
151
+ www: '10.223.106.'.freeze,
152
+ episport: '10.223.104.'.freeze,
153
+ epicom: '10.223.103.'.freeze,
154
+ :'bde-epita' => '10.223.100.'.freeze,
155
+ omatis: '10.223.42.'.freeze,
156
+ ipsa: '10.223.15.'.freeze,
157
+ lrde: '10.223.13.'.freeze,
158
+ cvi: '10.223.7.'.freeze,
159
+ epi: '10.223.1.'.freeze,
160
+ pasteur: '10.223.'.freeze,
161
+ bocal: '10.42.42.'.freeze,
162
+ sm: '10.42.'.freeze,
163
+ vpn: '10.10.'.freeze,
164
+ adm: '10.1.'.freeze,
165
+ epita: '10.'.freeze
166
+ }
167
+ end
168
+ end
169
+ end
122
170
  end
@@ -1,3 +1,3 @@
1
1
  module Netsoul
2
- VERSION = '1.9.3'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
data/lib/netsoul.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require_relative 'netsoul/config'
2
2
  require_relative 'netsoul/errors'
3
- require_relative 'netsoul/location'
4
3
  require_relative 'netsoul/logging'
5
4
  require_relative 'netsoul/message'
6
5
  require_relative 'netsoul/version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsoul
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa
@@ -156,7 +156,6 @@ files:
156
156
  - lib/netsoul/client.rb
157
157
  - lib/netsoul/config.rb
158
158
  - lib/netsoul/errors.rb
159
- - lib/netsoul/location.rb
160
159
  - lib/netsoul/logging.rb
161
160
  - lib/netsoul/message.rb
162
161
  - lib/netsoul/version.rb
@@ -1,51 +0,0 @@
1
- module Netsoul
2
- class Location
3
- class << self
4
- def get(ip)
5
- locations.each do |key, val|
6
- return "#{key}".freeze if ip.match(/^#{val}/)
7
- end
8
- 'ext'.freeze
9
- end
10
-
11
- # rubocop:disable all
12
- def locations
13
- {
14
- :'lab-cisco-mid-sr' => '10.251.'.freeze,
15
- etna: '10.245.'.freeze,
16
- lse: '10.227.42.'.freeze,
17
- :'sda-1' => '10.227.4.'.freeze,
18
- lab: '10.227.'.freeze,
19
- :'lab-tcom' => '10.226.7.'.freeze,
20
- :'lab-acu' => '10.226.6.'.freeze,
21
- :'lab-console' => '10.226.5.'.freeze,
22
- :'lab-mspe' => '10.226.'.freeze,
23
- epitanim: '10.225.19.'.freeze,
24
- epidemic: '10.225.18.'.freeze,
25
- :'sda-2' => '10.225.10.'.freeze,
26
- cycom: '10.225.8.'.freeze,
27
- epx: '10.225.7.'.freeze,
28
- prologin: '10.225.6.'.freeze,
29
- nomad: '10.225.2.'.freeze,
30
- assos: '10.225.'.freeze,
31
- sda: '10.224.14.'.freeze,
32
- www: '10.223.106.'.freeze,
33
- episport: '10.223.104.'.freeze,
34
- epicom: '10.223.103.'.freeze,
35
- :'bde-epita' => '10.223.100.'.freeze,
36
- omatis: '10.223.42.'.freeze,
37
- ipsa: '10.223.15.'.freeze,
38
- lrde: '10.223.13.'.freeze,
39
- cvi: '10.223.7.'.freeze,
40
- epi: '10.223.1.'.freeze,
41
- pasteur: '10.223.'.freeze,
42
- bocal: '10.42.42.'.freeze,
43
- sm: '10.42.'.freeze,
44
- vpn: '10.10.'.freeze,
45
- adm: '10.1.'.freeze,
46
- epita: '10.'.freeze
47
- }
48
- end
49
- end
50
- end
51
- end