Class: IONIS::Authentication
- Inherits:
-
Object
- Object
- IONIS::Authentication
- Defined in:
- lib/ionisauthentication.rb
Instance Method Summary collapse
-
#chkPass(userName, userPass) ⇒ Mixed
Check PPP Password of given user.
-
#getUser(userName) ⇒ Hash
Get informations about one user.
-
#initialize(sshUserName, sshUserPass, forceUpdate = false) ⇒ Authentication
constructor
Instance of Authentication - sshUserName and sshUserPass are needed to update IONIS Auth.
Constructor Details
#initialize(sshUserName, sshUserPass, forceUpdate = false) ⇒ Authentication
Instance of Authentication - sshUserName and sshUserPass are needed to update IONIS Auth. file from IONIS Server.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ionisauthentication.rb', line 18 def initialize sshUserName, sshUserPass, forceUpdate = false @tmpDir = File.join Dir.tmpdir, 'ionis_auth/' @lstStudent = Hash.new Dir.mkdir @tmpDir if !File.directory? @tmpDir if !File.exist? File.join(@tmpDir, 'ppp.blowfish') or forceUpdate == true begin Net::SCP.start('ssh.epitech.eu', sshUserName, :password => sshUserPass) do |scp| scp.download! '/afs/epitech.net/site/etc/ppp.blowfish', @tmpDir scp.download! '/afs/epitech.net/site/etc/passwd', @tmpDir scp.download! '/afs/epitech.net/site/etc/location', @tmpDir end rescue SocketError raise IONIS::Exception::HostNotFound.new 405, "Can't resolve ssh.epitech.eu" rescue Errno::ECONNREFUSED raise IONIS::Exception::ConnectionRefused.new 403, "Connection refused to ssh.epitech.eu" rescue Net::SSH::AuthenticationFailed raise IONIS::Exception::BadAuthentication.new 402, "Bad authentication" rescue Net::SCP::Error raise IONIS::Exception::FileGrabber.new 404, "Can't copy file from ssh.epitech.eu..." end end hFile = File.new((File.join @tmpDir, 'ppp.blowfish'), 'r') while line = hFile.gets line = line.split ' ' @lstStudent[line[0]] = Hash.new if line[0] @lstStudent[line[0]][:login]= line[0] @lstStudent[line[0]][:password]= line[1] @lstStudent[line[0]][:picture]= "http://www.epitech.eu/intra/picture/#{line[0]}.jpg" end end hFile.close hFile = File.new((File.join @tmpDir, 'passwd'), 'r') while line = hFile.gets line = line.split ':' if @lstStudent[line[0]] @lstStudent[line[0]][:uid] = line[2] @lstStudent[line[0]][:gid] = line[3] if line[4].length > 0 line[4] = line[4].split ' ' line[4][0].capitalize! line[4][1].upcase! @lstStudent[line[0]][:fullname] = "#{line[4][0]} #{line[4][1]}" end end end hFile.close hFile = File.new((File.join @tmpDir, 'location'), 'r') while line = hFile.gets line = line.split ':' if @lstStudent[line[0]] @lstStudent[line[0]][:city] = line[1].strip end end hFile.close end |
Instance Method Details
#chkPass(userName, userPass) ⇒ Mixed
Check PPP Password of given user
80 81 82 83 84 |
# File 'lib/ionisauthentication.rb', line 80 def chkPass userName, userPass false if @lstStudent == nil return @lstStudent[userName] if BCrypt::Engine.hash_secret(userPass , @lstStudent[userName][:password]) == @lstStudent[userName][:password] false end |
#getUser(userName) ⇒ Hash
Get informations about one user
89 90 91 92 |
# File 'lib/ionisauthentication.rb', line 89 def getUser userName false if @lstStudent == nil return @lstStudent[userName] end |