#!/usr/bin/env ruby require 'rubygems' require 'sinatra' require 'treequel' require 'pathname' # A barebones web-based company directory LDAP_URL = "ldap://ldap.yourcompany.com/dc=yourcompany,dc=com" configure do # Borrow the CSS and images from the 'ldap-monitor' example set :root, Pathname( __FILE__ ).dirname + 'ldap-monitor' end before do $stderr.puts "Connecting to #{LDAP_URL}" @ldap ||= Treequel.directory( LDAP_URL ) end ### GET / get '/' do # Get every entry under ou=people that has an email address and sort them # by last name, first name, and UID. people = @ldap.ou( :people ).filter( :mail ).sort_by do |person| [ person[:sn], person[:givenName], person[:uid] ] end erb :index, :locals => { :people => people } end ### GET /uid get '/:uid' do # Look up the person associated with the given UID, returning NOT FOUND if # there isn't any such entry uid = params[:uid] person = @ldap.ou( :people ).uid( uid ) halt 404, "No such person" unless person.exists? erb :details, :locals => { :person => person } end __END__ @@layout
Name | Badge # | |
---|---|---|
<%= person[:cn] %> | <%= person[:mail] %> | <%= person[:employeeNumber] %> |
<%= person.to_ldif %>