Skip to content

@johnivanoff /gist:3179901
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
get '/department/: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
Something went wrong with that request. Please try again.