Skip to content

Instantly share code, notes, and snippets.

@johnivanoff
Created July 26, 2012 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnivanoff/3179899 to your computer and use it in GitHub Desktop.
Save johnivanoff/3179899 to your computer and use it in GitHub Desktop.
require 'sinatra'
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = '192.168.1.1'
ldap.port = 389
ldap.auth "username", "password"
get '/people/:id' do
filter = Net::LDAP::Filter.eq('cn', params[:id] + '*')
treebase = "dc=reputablecompany, dc=com"
@b = Hash.new
ldap.search(:base => treebase, :filter => filter) do |entry|
department = ""
if entry.respond_to?("department")
department = entry.department
end
name = ""
if entry.respond_to?("cn")
name = entry.cn
end
@b[name] = {:department => department}
end
erb :people
end
__END__
@@people
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="user-scalable=yes, width=device-width" />
<title>Home | AD Listing</title>
</head>
<body>
<% @b.each do |attribute, values| %>
<h1><%= attribute.first %></h1>
<ul>
<% values.each do |name, value|%>
<% if !value[0].nil? %>
<li><%= name.capitalize %>:
<%= value[0] %></li>
<% end %>
<% end %>
</ul>
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment