diff --git a/app/controllers/auth.rb b/app/controllers/auth.rb index 12f1a4d..71cc7df 100644 --- a/app/controllers/auth.rb +++ b/app/controllers/auth.rb @@ -13,12 +13,11 @@ class Webdap end post '/login' do - ldap = Net::LDAP.new - ldap.host = cnf['ldap']['server_url'] - ldap.port = 389 - ldap.auth(params[:login_username], params[:login_password]) - if ldap.bind() - session['ldap_uid'] = params[:username] + ldap = Net::LDAP.new(:host => $conf.get('ldap.server_url'), :port => 389) + ldap_bind_dn = "#{$conf.get('ldap.user_uid_attr')}=#{params[:auth_username]},#{$conf.get('ldap.user_ou')}" + + if ldap.bind(:method => :simple, :username => ldap_bind_dn, :password => params[:auth_password]) + session['ldap_uid'] = params[:auth_username] redirect '/account/view' else # Authentication failure diff --git a/app/controllers/index.rb b/app/controllers/index.rb index fc57f75..ab97d76 100644 --- a/app/controllers/index.rb +++ b/app/controllers/index.rb @@ -7,6 +7,7 @@ class Webdap get '/' do erb :index, locals: { title: 'Home', + server: $conf.get('ldap.server_url'), } end diff --git a/config/defaults.yaml b/config/defaults.yaml index 52a5154..9daa232 100644 --- a/config/defaults.yaml +++ b/config/defaults.yaml @@ -1,6 +1,8 @@ ldap: server_url: 'ldap://ldap.example.com' port: 389 + user_uid_attr: 'uid' + user_ou: 'ou=People,dc=example,dc=com' server: address: '127.0.0.1' diff --git a/config/puma.rb b/config/puma.rb index 4e5fe8a..4283bdd 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,6 +1,6 @@ # Load application config require './app/config.rb' -$conf = Config.new(File.join(__dir__, 'config/config.yaml')) +$conf = Config.new(File.join(__dir__, '../config/config.yaml')) bind_address = "tcp://#{$conf.get('server.address')}:#{$conf.get('server.port')}" bind bind_address diff --git a/views/index.erb b/views/index.erb index a0682a4..f5b2d87 100644 --- a/views/index.erb +++ b/views/index.erb @@ -4,5 +4,7 @@

You can use this site to manage your network account.

Click here to login.

+ +

Server URL: <%= server %>