netsoul 1.6.0 → 1.7.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76d7e890a2801a29cd2835cf4528573cbf0ad4a1
4
- data.tar.gz: 58b5fd02eb6dd305dc57fc4d9c40bc41ecc20a47
3
+ metadata.gz: b43af38649f019edff2b067bc66257487e243e2f
4
+ data.tar.gz: b0633c0e8827bce922e290cc79fc401dd9c081fb
5
5
  SHA512:
6
- metadata.gz: bd4c9bf443fe70f1cd359bf8b2c165e69167c542a27b7979dd679222a8b7b69f5387b9e706006159664c3fc786d6d703b818b460b551a7ff8546963f0ec857b3
7
- data.tar.gz: d67b8225613e175b8c73af662894a7864ea2942cb2f8c786c6d60f2e4f5b2601e52cb6071dcfbe55a88fecc84a805360eb3a8f4b618ccba4563461522189acca
6
+ metadata.gz: 8e1bff48bdd2697033abc87d4cde2a0f5748c362fe36a0dc35b27aef055f0ca29a2da13707c85a2c234db10a125a2fc3c8cc8cb023b8b31ddf081f7670b0e702
7
+ data.tar.gz: 50973addb57c1e059eaee7617a52f13cbf454d72506d3052dea556df1ffcb8a9032c599726ba9712bd5d64fbc55eabbf1e02482fee79a3f5400d8415cae6f3af
data/bin/netsoul-ruby CHANGED
@@ -51,10 +51,13 @@ module Netsoul
51
51
  @sock = TCPSocket.new(@config.server_host, @config.server_port)
52
52
  fail Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @sock
53
53
  _cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = sock_get.split
54
+
54
55
  @config.build_user_connection_info md5_hash: md5_hash, client_ip: client_ip, client_port: client_port
56
+
55
57
  auth_ag
56
58
  auth_method
57
59
  auth_status
60
+
58
61
  @started = true
59
62
  end
60
63
 
@@ -75,8 +78,8 @@ module Netsoul
75
78
  sock, = IO.select([@sock], nil, nil, SOCKET_READ_TIMEOUT)
76
79
  fail Netsoul::SocketError, 'Timeout or fail on read socket' if sock.nil? || sock.empty?
77
80
  res = sock.first.gets
78
- log :info, "[get ] #{res.chomp}"
79
- res
81
+ log :info, "[get ] #{res.chomp}" if res
82
+ res || ''
80
83
  end
81
84
 
82
85
  def sock_close
@@ -99,12 +102,7 @@ OptionParser.new do |opts|
99
102
  opts.separator 'Netsoul-Ruby options:'.freeze
100
103
 
101
104
  opts.on('-c'.freeze, '--config FILE'.freeze, 'Configuration file in YAML'.freeze) do |file|
102
- options[:config] = file
103
- unless File.file?(options[:config])
104
- puts '[ERROR] Configuration is not a valid file'
105
- exit
106
- end
107
- options[:user_opts] = YAML.load_file(options[:config])
105
+ options[:user_opts] = YAML.load_file(file) if File.file?(file)
108
106
  end
109
107
 
110
108
  opts.on('-h', '--help', 'Display this screen') do
@@ -113,8 +111,9 @@ OptionParser.new do |opts|
113
111
  end
114
112
  end.parse!
115
113
 
116
- unless options.include?(:config)
117
- puts '[ERROR] Configuration file is not provided'
114
+ unless ENV.to_a.count { |k, _v| %w(NETSOUL_LOGIN NETSOUL_SOCKS_PASSWORD).include?(k) } == 2 ||
115
+ ENV.to_a.count { |k, _v| %w(NETSOUL_LOGIN NETSOUL_UNIX_PASSWORD NETSOUL_AUTH_METHOD).include?(k) } == 3
116
+ puts '[ERROR] You have to specify a configuration file or environment variables'
118
117
  exit
119
118
  end
120
119
 
@@ -17,20 +17,33 @@ module Netsoul
17
17
 
18
18
  attr_reader :client_name
19
19
 
20
- # rubocop:disable Metrics/AbcSize
20
+ # Supported environment variables:
21
+ #
22
+ # +NETSOUL_SERVER_HOST+: Netsoul server host, default 'ns-server.epita.fr'
23
+ # +NETSOUL_SERVER_PORT+: Netsoul server port, default 4242
24
+ # +NETSOUL_LOGIN+: IONIS account name
25
+ # +NETSOUL_SOCKS_PASSWORD+: IONIS socks password
26
+ # +NETSOUL_UNIX_PASSWORD+: IONIS unix password
27
+ # +NETSOUL_AUTH_METHOD+: Authentication method, default :std. Valid options are => @see +Config::AUTH_METHODS+
28
+ # +NETSOUL_STATE+: User status, default is :none. Valid options are => @see +Config::USER_STATES+
29
+ # +NETSOUL_LOCATION+: User location is free text of your position. If you ar in IONIS network an automatic mapping is proceed to detect your location
30
+ # +NETSOUL_USER_GROUP+: Free text specifying your promo or whatever else
31
+ # +NETSOUL_CLIENT_NAME+: Redefine the client name exposed to the Netsoul server
32
+ #
33
+ # rubocop:disable all
21
34
  def initialize(opts = {})
22
- @server_host = opts.fetch(:server_host, 'ns-server.epita.fr'.freeze)
23
- @server_port = Integer(opts.fetch(:server_port, 4242))
24
- @login = opts.fetch(:login, 'ionis'.freeze)
25
- @socks_password = opts.fetch(:socks_password, 'socks_password'.freeze)
26
- @unix_password = opts.fetch(:unix_password, 'unix_password'.freeze)
27
- @auth_method = AUTH_METHODS.include?(opts[:auth_method]) ? opts[:auth_method] : :std
28
- @state = USER_STATES.include?(opts[:state]) ? opts[:state] : :none
29
- @location = opts.fetch(:location, 'Home'.freeze)
30
- @user_group = opts.fetch(:user_group, 'ETNA_2008'.freeze)
35
+ @server_host = ENV['NETSOUL_SERVER_HOST'] || opts.fetch(:server_host, 'ns-server.epita.fr'.freeze)
36
+ @server_port = Integer(ENV['NETSOUL_SERVER_PORT'] || opts.fetch(:server_port, 4242))
37
+ @login = ENV['NETSOUL_LOGIN'] || opts.fetch(:login, 'ionis'.freeze)
38
+ @socks_password = ENV['NETSOUL_SOCKS_PASSWORD'] || opts.fetch(:socks_password, 'socks_password'.freeze)
39
+ @unix_password = ENV['NETSOUL_UNIX_PASSWORD'] || opts.fetch(:unix_password, 'unix_password'.freeze)
40
+ @auth_method = (ENV['NETSOUL_AUTH_METHOD'] || (AUTH_METHODS.include?(opts[:auth_method]) ? opts[:auth_method] : :std)).to_sym
41
+ @state = (ENV['NETSOUL_STATE'] || (USER_STATES.include?(opts[:state]) ? opts[:state] : :none)).to_sym
42
+ @location = ENV['NETSOUL_LOCATION'] || opts.fetch(:location, 'Home'.freeze)
43
+ @user_group = ENV['NETSOUL_USER_GROUP'] || opts.fetch(:user_group, 'ETNA_2008'.freeze)
31
44
  @user_connection_info = {}
32
45
 
33
- @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) -> { Christian Kakesa, since 2009}'.freeze)
34
47
  end
35
48
 
36
49
  def build_user_connection_info(opts = {})
@@ -1,3 +1,3 @@
1
1
  module Netsoul
2
- VERSION = '1.6.0'.freeze
2
+ VERSION = '1.7.0'.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.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa