ionis 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +77 -0
- data/lib/ionis.rb +4 -0
- data/lib/ionisauthentication.rb +82 -0
- data/lib/ionisexceptions.rb +16 -0
- data/lib/ionisnetsoul.rb +50 -0
- metadata +89 -0
data/README.rdoc
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= IONIS
|
2
|
+
|
3
|
+
* https://github.com/corbeau-web/Ruby-IONIS-Info-Class
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
IONIS::Authentication is a pure-Ruby implementation of the original PHP IONIS Class. This allow you to implement authentication using IONIS login and PPP password.
|
8
|
+
IONIS::Netsoul help you to get information about online students.
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
* Provide password verification
|
13
|
+
* Get user informations like Login, UID, GID, City, Avatar URL, State
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
In a nutshell:
|
18
|
+
|
19
|
+
require 'ionis'
|
20
|
+
|
21
|
+
begin
|
22
|
+
hIonis = IONIS::Authentication.new 'login_l', 'unix_password'
|
23
|
+
puts hIonis.chkPass 'login_l', 'ppp_password'
|
24
|
+
puts hIonis.getUser 'meyer_t'
|
25
|
+
puts hIonis.getUser 'cassan_c'
|
26
|
+
puts hIonis.getUser 'not_exist'
|
27
|
+
puts hIonis.getUser nil
|
28
|
+
puts hIonis.getUser -1
|
29
|
+
|
30
|
+
hNetsoul = IONIS::Netsoul.new
|
31
|
+
puts hNetsoul.getUser 'meyer_t'
|
32
|
+
puts hNetsoul.getUser 'adam_p'
|
33
|
+
rescue IONIS::Exception::HostNotFound => e
|
34
|
+
puts e.reason
|
35
|
+
rescue IONIS::Exception::ConnectionRefused => e
|
36
|
+
puts e.reason
|
37
|
+
rescue IONIS::Exception::BadAuthentication => e
|
38
|
+
puts e.reason
|
39
|
+
rescue IONIS::Exception::FileGrabber => e
|
40
|
+
puts e.reason
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
== REQUIREMENTS:
|
45
|
+
|
46
|
+
* Net::SSH 2
|
47
|
+
* Net::SCP 1
|
48
|
+
* bcrypt 3
|
49
|
+
|
50
|
+
== INSTALL:
|
51
|
+
|
52
|
+
* gem install ionis (might need sudo privileges)
|
53
|
+
|
54
|
+
== LICENSE:
|
55
|
+
|
56
|
+
(The MIT License)
|
57
|
+
|
58
|
+
Copyright (c) 2012 Thibault MEYER <meyer.thibault@hotmail.fr>
|
59
|
+
|
60
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
61
|
+
a copy of this software and associated documentation files (the
|
62
|
+
'Software'), to deal in the Software without restriction, including
|
63
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
64
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
65
|
+
permit persons to whom the Software is furnished to do so, subject to
|
66
|
+
the following conditions:
|
67
|
+
|
68
|
+
The above copyright notice and this permission notice shall be
|
69
|
+
included in all copies or substantial portions of the Software.
|
70
|
+
|
71
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
72
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
73
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
74
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
75
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
76
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
77
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/ionis.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'net/ssh'
|
4
|
+
require 'net/scp'
|
5
|
+
require 'bcrypt'
|
6
|
+
require 'ionisexceptions'
|
7
|
+
|
8
|
+
module IONIS
|
9
|
+
class Authentication
|
10
|
+
@tmpDir = nil
|
11
|
+
@lstStudent = nil
|
12
|
+
|
13
|
+
def initialize sshUserName, sshUserPass, forceUpdate = false
|
14
|
+
@tmpDir = File.join Dir.tmpdir, 'ionis_auth/'
|
15
|
+
@lstStudent = Hash.new
|
16
|
+
Dir.mkdir @tmpDir if !File.directory? @tmpDir
|
17
|
+
if !File.exist? File.join(@tmpDir, 'ppp.blowfish') or forceUpdate == true
|
18
|
+
begin
|
19
|
+
Net::SCP.start('ssh.epitech.eu', sshUserName, :password => sshUserPass) do |scp|
|
20
|
+
scp.download! '/afs/epitech.net/site/etc/ppp.blowfish', @tmpDir
|
21
|
+
scp.download! '/afs/epitech.net/site/etc/passwd', @tmpDir
|
22
|
+
scp.download! '/afs/epitech.net/site/etc/location', @tmpDir
|
23
|
+
end
|
24
|
+
rescue SocketError
|
25
|
+
raise IONIS::Exception::HostNotFound.new 405, "Can't resolve ssh.epitech.eu"
|
26
|
+
rescue Errno::ECONNREFUSED
|
27
|
+
raise IONIS::Exception::ConnectionRefused.new 403, "Connection refused to ssh.epitech.eu"
|
28
|
+
rescue Net::SSH::AuthenticationFailed
|
29
|
+
raise IONIS::Exception::BadAuthentication.new 402, "Bad authentication"
|
30
|
+
rescue Net::SCP::Error
|
31
|
+
raise IONIS::Exception::FileGrabber.new 404, "Can't copy file from ssh.epitech.eu..."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
hFile = File.new (File.join @tmpDir, 'ppp.blowfish'), 'r'
|
36
|
+
while line = hFile.gets
|
37
|
+
line = line.split ' '
|
38
|
+
@lstStudent[line[0]] = Hash.new
|
39
|
+
if line[0]
|
40
|
+
@lstStudent[line[0]][:login]= line[0]
|
41
|
+
@lstStudent[line[0]][:password]= line[1]
|
42
|
+
@lstStudent[line[0]][:picture]= "http://www.epitech.eu/intra/picture/#{line[0]}.jpg"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
hFile.close
|
46
|
+
hFile = File.new (File.join @tmpDir, 'passwd'), 'r'
|
47
|
+
while line = hFile.gets
|
48
|
+
line = line.split ':'
|
49
|
+
if @lstStudent[line[0]]
|
50
|
+
@lstStudent[line[0]][:uid] = line[2]
|
51
|
+
@lstStudent[line[0]][:gid] = line[3]
|
52
|
+
if line[4].length > 0
|
53
|
+
line[4] = line[4].split ' '
|
54
|
+
line[4][0].capitalize!
|
55
|
+
line[4][1].upcase!
|
56
|
+
@lstStudent[line[0]][:fullname] = "#{line[4][0]} #{line[4][1]}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
hFile.close
|
61
|
+
hFile = File.new (File.join @tmpDir, 'location'), 'r'
|
62
|
+
while line = hFile.gets
|
63
|
+
line = line.split ':'
|
64
|
+
if @lstStudent[line[0]]
|
65
|
+
@lstStudent[line[0]][:city] = line[1].strip
|
66
|
+
end
|
67
|
+
end
|
68
|
+
hFile.close
|
69
|
+
end
|
70
|
+
|
71
|
+
def chkPass userName, userPass
|
72
|
+
false if @lstStudent == nil
|
73
|
+
return @lstStudent[userName] if BCrypt::Engine.hash_secret(userPass , @lstStudent[userName][:password]) == @lstStudent[userName][:password]
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
77
|
+
def getUser userName
|
78
|
+
false if @lstStudent == nil
|
79
|
+
return @lstStudent[userName]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module IONIS
|
2
|
+
module Exception
|
3
|
+
class Exception < ::RuntimeError
|
4
|
+
attr_reader :code, :reason
|
5
|
+
|
6
|
+
def initialize(code, reason)
|
7
|
+
@code, @reason = code, reason
|
8
|
+
super "#{reason} (#{code})"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
class BadAuthentication < Exception; end
|
12
|
+
class HostNotFound < Exception; end
|
13
|
+
class ConnectionRefused < Exception; end
|
14
|
+
class FileGrabber < Exception; end
|
15
|
+
end
|
16
|
+
end
|
data/lib/ionisnetsoul.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'socket'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'ionisexceptions'
|
5
|
+
|
6
|
+
module IONIS
|
7
|
+
class Netsoul
|
8
|
+
@tmpDir = nil
|
9
|
+
@usrData = nil
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@tmpDir = File.join Dir.tmpdir, 'ionis_auth/nsUser'
|
13
|
+
if !File.exist? @tmpDir or (File.mtime(@tmpDir).to_i + 300) < Time.now.to_i
|
14
|
+
begin
|
15
|
+
hSock = TCPSocket.open('ns-server.epita.fr', 4242)
|
16
|
+
line = hSock.gets
|
17
|
+
if /salut (.*)/.match(line)
|
18
|
+
hSock.write "list_users\n"
|
19
|
+
@usrData = Hash.new
|
20
|
+
while line = hSock.gets
|
21
|
+
line.strip!
|
22
|
+
break if line == 'rep 002 -- cmd end'
|
23
|
+
line = line.split ' '
|
24
|
+
@usrData[line[1]] = Hash.new
|
25
|
+
@usrData[line[1]]['login'] = line[1]
|
26
|
+
@usrData[line[1]]['ip'] = line[2]
|
27
|
+
line[10] = line[10].split ':'
|
28
|
+
@usrData[line[1]]['state'] = line[10][0]
|
29
|
+
@usrData[line[1]]['since'] = line[10][1]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
hSock.close
|
33
|
+
rescue SocketError
|
34
|
+
raise IONIS::Exception::HostNotFound.new 405, "Can't resolve ns-server.epita.fr"
|
35
|
+
rescue Errno::ECONNREFUSED
|
36
|
+
raise IONIS::Exception::ConnectionRefused.new 403, "Connection refused to ns-server.epita.fr"
|
37
|
+
end
|
38
|
+
File.open(@tmpDir, "wb") {|f| Marshal.dump(@usrData, f)}
|
39
|
+
else
|
40
|
+
@usrData = File.open(@tmpDir, "rb") {|f| Marshal.load(f)}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def getUser login
|
45
|
+
return false if !@usrData
|
46
|
+
@usrData[login]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ionis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thibault MEYER
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net-ssh
|
16
|
+
requirement: &14220780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.3.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *14220780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: net-scp
|
27
|
+
requirement: &14220020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.4
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *14220020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bcrypt-ruby
|
38
|
+
requirement: &14218700 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.0.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *14218700
|
47
|
+
description: A Ruby set of Classes to get informations about students in Ionis group
|
48
|
+
email: meyer.thibault@hotmail.fr
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- lib/ionis.rb
|
54
|
+
- lib/ionisauthentication.rb
|
55
|
+
- lib/ionisnetsoul.rb
|
56
|
+
- lib/ionisexceptions.rb
|
57
|
+
- README.rdoc
|
58
|
+
homepage: https://github.com/corbeau-web/Ruby-IONIS-Info-Class
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --line-numbers
|
63
|
+
- --inline-source
|
64
|
+
- --title
|
65
|
+
- Net-scp
|
66
|
+
- --main
|
67
|
+
- README.rdoc
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.17
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: IONIS Epitech/Epita class set
|
88
|
+
test_files: []
|
89
|
+
has_rdoc:
|