netsoul 1.9.2 → 1.9.3

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: 7ba483e648ea01d6f10b2c42ea661f5ee98085b4
4
- data.tar.gz: 17f6d3cdf47b0de26124d9d59170665a27ba334c
3
+ metadata.gz: 40ae5cdd054a7d3eb6d72265a45714d49367e18f
4
+ data.tar.gz: 6046d54fe9e388c0dd33ffde354d69205c1bc062
5
5
  SHA512:
6
- metadata.gz: 13c93b8cf7130261149892a6f199ea35226b6d1c6dfd2869d0ded7afca827305940761e0aef1367d3f270cfb0cff28b8deaf121ef01d735561c932dfb881da68
7
- data.tar.gz: 4c7277563962d8f88f4a107ea9bd7a9f56da000907576a0ad22cde8867dc43d657e0bdba88a1061cca4215cc2ce3ef9d629ada7c8c30f80168b16b0b1033f521
6
+ metadata.gz: e4937e3a77f5d7a3fdd3cf916a5d1d235c05baaf2622ebdcd9d68741f136f97d00d0b39f815b72eef8346e0c6bb9d426ed450edc4978273c1ee6313616014830
7
+ data.tar.gz: 87271293e474120ff9d712135250b2bcd166bf22c45dbc7a37b60298601ba98c4a7e83de32bf8d483e6ad360293675775d8d41ec21ec4060855fbdb1e2b02740
data/README.md CHANGED
@@ -86,7 +86,24 @@ netsoul-ruby -config netsoul-config.yml
86
86
  ## Use the library in custom Netsoul Ruby client
87
87
 
88
88
  Look at the client implementation in this gem: [https://github.com/fenicks/netsoul-ruby/blob/master/bin/netsoul-ruby]().
89
- This client is implemented in less than 150 lines of code ; including option parser, client reconnection, ...
89
+ This client is implemented in less than 80 lines of code ; including option parser, client reconnection, ...
90
+
91
+ ```ruby
92
+ require 'netsou/client'
93
+
94
+ c = Netsoul::Client.new options[:user_opts]
95
+ c.connect
96
+ # ...
97
+ if c.started
98
+ # ...
99
+ c.sock_send str
100
+ # ...
101
+ msg = c.sock_get
102
+ #...
103
+ end
104
+ # ...
105
+ c.disconnect
106
+ ```
90
107
 
91
108
  ## Contributing
92
109
 
data/bin/netsoul-ruby CHANGED
@@ -3,90 +3,7 @@
3
3
  lib = File.expand_path('../../lib', __FILE__)
4
4
  $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
5
 
6
- require 'netsoul/config'
7
- require 'netsoul/errors'
8
- require 'netsoul/logging'
9
- require 'netsoul/message'
10
- require 'socket'
11
-
12
- module Netsoul
13
- class Client
14
- include Logging
15
- attr_reader :started
16
- SOCKET_READ_TIMEOUT = 12 * 60
17
- SOCKET_WRITE_TIMEOUT = 10
18
-
19
- def initialize(*args)
20
- opts = args.last.is_a?(Hash) ? args.last : {}
21
- @config = Config.new(opts)
22
- @started = false
23
- end
24
-
25
- def auth_ag
26
- sock_send(Message.auth_ag)
27
- fail Netsoul::IdentificationError, 'Identification failed.'.freeze unless sock_get.split(' ')[1] == '002'.freeze
28
- end
29
- private :auth_ag
30
-
31
- def auth_method
32
- if @config.auth_method == :krb5
33
- sock_send(Message.kerberos_auth(@config))
34
- else
35
- sock_send(Message.standard_auth(@config))
36
- end
37
- fail Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables'.freeze unless sock_get.split(' ')[1] == '002'
38
- end
39
- private :auth_method
40
-
41
- def auth_status
42
- sock_send(Message.attach)
43
- sock_send(Message.user_state(@config.state, Time.now.to_i))
44
- end
45
- private :auth_status
46
-
47
- def connect
48
- @sock = TCPSocket.new(@config.server_host, @config.server_port)
49
- fail Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @sock
50
- _cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = sock_get.split
51
-
52
- @config.build_user_connection_info md5_hash: md5_hash, client_ip: client_ip, client_port: client_port
53
-
54
- auth_ag
55
- auth_method
56
- auth_status
57
-
58
- @started = true
59
- end
60
-
61
- def disconnect
62
- sock_send(Message.ns_exit)
63
- ensure
64
- sock_close
65
- end
66
-
67
- def sock_send(str)
68
- _, sock = IO.select(nil, [@sock], nil, SOCKET_WRITE_TIMEOUT)
69
- fail Netsoul::SocketError, 'Timeout or fail on write socket' if sock.nil? || sock.empty?
70
- sock.first.puts str
71
- log :info, "[send] #{str.chomp}"
72
- end
73
-
74
- def sock_get
75
- sock, = IO.select([@sock], nil, nil, SOCKET_READ_TIMEOUT)
76
- fail Netsoul::SocketError, 'Timeout or fail on read socket' if sock.nil? || sock.empty?
77
- res = sock.first.gets
78
- log :info, "[get ] #{res.chomp}" if res
79
- res || ''
80
- end
81
-
82
- def sock_close
83
- @started = false
84
- @sock.close
85
- rescue
86
- nil
87
- end
88
- end
89
- end
6
+ require 'netsoul/client'
90
7
 
91
8
  $stderr.sync = true
92
9
  require 'optparse'
@@ -110,6 +27,7 @@ OptionParser.new do |opts|
110
27
  exit 42
111
28
  end
112
29
  end.parse!
30
+
113
31
  if options.empty? || options[:user_opts].size == 0
114
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
115
33
  puts '[ERROR] You have to specify a configuration file or environment variables'
@@ -118,8 +36,8 @@ if options.empty? || options[:user_opts].size == 0
118
36
  end
119
37
 
120
38
  retry_count = 10
121
- retry_wait_time = 10.0
122
- RETRY_WAIT_FACTOR = 1.50 # Each time retry is called in Exception, current 'retry_wait_time' is increased with this factor
39
+ retry_wait_time = 1.0
40
+ RETRY_WAIT_FACTOR = 2.0 # Each time retry is called in Exception block, current 'retry_wait_time' is increased with this factor
123
41
  begin
124
42
  c = Netsoul::Client.new options[:user_opts]
125
43
  c.connect
@@ -0,0 +1,81 @@
1
+ require_relative '../netsoul'
2
+ require 'socket'
3
+
4
+ module Netsoul
5
+ class Client
6
+ include Logging
7
+ attr_reader :started
8
+ SOCKET_READ_TIMEOUT = 12 * 60
9
+ SOCKET_WRITE_TIMEOUT = 10
10
+
11
+ def initialize(*args)
12
+ opts = args.last.is_a?(Hash) ? args.last : {}
13
+ @config = Config.new(opts)
14
+ @started = false
15
+ end
16
+
17
+ def auth_ag
18
+ sock_send(Message.auth_ag)
19
+ fail Netsoul::IdentificationError, 'Identification failed.'.freeze unless sock_get.split(' ')[1] == '002'.freeze
20
+ end
21
+ private :auth_ag
22
+
23
+ def auth_method
24
+ if @config.auth_method == :krb5
25
+ sock_send(Message.kerberos_auth(@config))
26
+ else
27
+ sock_send(Message.standard_auth(@config))
28
+ end
29
+ fail Netsoul::AuthenticationError, 'Authentication failed. See your config file or environment variables'.freeze unless sock_get.split(' ')[1] == '002'
30
+ end
31
+ private :auth_method
32
+
33
+ def auth_status
34
+ sock_send(Message.attach)
35
+ sock_send(Message.user_state(@config.state, Time.now.to_i))
36
+ end
37
+ private :auth_status
38
+
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
43
+
44
+ @config.build_user_connection_info md5_hash: md5_hash, client_ip: client_ip, client_port: client_port
45
+
46
+ auth_ag
47
+ auth_method
48
+ auth_status
49
+
50
+ @started = true
51
+ end
52
+
53
+ def disconnect
54
+ sock_send(Message.ns_exit)
55
+ ensure
56
+ sock_close
57
+ end
58
+
59
+ def sock_send(str)
60
+ _, sock = IO.select(nil, [@sock], nil, SOCKET_WRITE_TIMEOUT)
61
+ fail Netsoul::SocketError, 'Timeout or fail on write socket' if sock.nil? || sock.empty?
62
+ sock.first.puts str
63
+ log :info, "[send] #{str.chomp}"
64
+ end
65
+
66
+ def sock_get
67
+ sock, = IO.select([@sock], nil, nil, SOCKET_READ_TIMEOUT)
68
+ fail Netsoul::SocketError, 'Timeout or fail on read socket' if sock.nil? || sock.empty?
69
+ res = sock.first.gets
70
+ log :info, "[get ] #{res.chomp}" if res
71
+ res || ''
72
+ end
73
+
74
+ def sock_close
75
+ @started = false
76
+ @sock.close
77
+ rescue
78
+ nil
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
1
  module Netsoul
2
- VERSION = '1.9.2'.freeze
2
+ VERSION = '1.9.3'.freeze
3
3
  end
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.2
4
+ version: 1.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa
@@ -153,6 +153,7 @@ files:
153
153
  - ext/netsoul_kerberos/kerberos.h
154
154
  - ext/netsoul_kerberos/netsoul_kerberos.c
155
155
  - lib/netsoul.rb
156
+ - lib/netsoul/client.rb
156
157
  - lib/netsoul/config.rb
157
158
  - lib/netsoul/errors.rb
158
159
  - lib/netsoul/location.rb