usermanager.rb 1.12 KB
Newer Older
Thomas Schneider's avatar
Thomas Schneider committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
require 'sinatra/base'
require 'sinatra/asset_pipeline'
require 'sinatra/config_file'
require 'net/ldap'
require 'bootstrap'
require 'font-awesome-sass'

# Main UserManager application class
class UserManager < Sinatra::Base
  set :assets_css_compressor, :sass
  set :assets_js_compressor, :uglify
  set :assets_paths, %w[assets assets/stylesheets assets/javascripts]
  register Sinatra::AssetPipeline

  register Sinatra::ConfigFile
  config_file 'config.yml'

  set :haml, format: :xhtml, content_type: :xhtml, escape_html: true

  configure :development do
    enable :logging
  end

  configure do
    ldap = Net::LDAP.new(
      host: settings.ldap[:host],
      port: 636,
      encryption: :simple_tls,
      auth: {
        method: :simple,
        username: settings.ldap[:bind_dn],
        password: settings.ldap[:password]
      },
      base: settings.ldap[:base]
    )
    set :ldap, ldap
  end

  get '/' do
    haml :index
  end

  get '/list' do
    users = settings.ldap.search(
      filter: Net::LDAP::Filter.eq('objectClass', 'user')
    )

    haml :list, locals: { users: users }
  end

  run! if app_file == $PROGRAM_NAME
end