Created
July 26, 2012 02:25
-
-
Save johnivanoff/3179905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'net/ldap' | |
ldap = Net::LDAP.new | |
ldap.host = '192.168.1.1' | |
ldap.port = 389 | |
ldap.auth "username", "password" | |
treebase = "dc=reputablecompany, dc=com" | |
['/people/:id', '/title/:id', '/email/:id', '/department/:id', '/location/:id', '/phone/:id'].each do |route| | |
get route do | |
case route | |
when /title/ then search_in = "title" | |
when /email/ then search_in = "mail" | |
when /department/ then search_in = "department" | |
when /location/ then search_in = "l" | |
when /phone/ then search_in = "telephonenumber" | |
when /people/ then search_in = "cn" | |
else search_in = "cn" | |
end | |
@searching_in = route.gsub(/\//, '').gsub(/:id/ , '').capitalize | |
@search_for = params[:id] | |
filter = Net::LDAP::Filter.eq(search_in, @search_for+'*') | |
@b = Hash.new | |
ldap.search(:base => treebase, :filter => filter) do |entry| | |
if entry.respond_to?("l") | |
title = "" | |
if entry.respond_to?("title") | |
title = entry.title | |
end | |
email = "" | |
if entry.respond_to?("mail") | |
email = entry.mail | |
end | |
telephonenumber = "" | |
if entry.respond_to?("telephonenumber") | |
telephonenumber = entry.telephonenumber | |
end | |
location = "" | |
if entry.respond_to?("l") | |
location = entry.l | |
end | |
department = "" | |
if entry.respond_to?("department") | |
department = entry.department | |
end | |
name = "" | |
if entry.respond_to?("cn") | |
name = entry.cn | |
end | |
@b[name] = {:email => email, :phone => telephonenumber, :location => location, :department => department, :title => title}#, :useraccountcontrol => useraccountcontrol} | |
end | |
end | |
erb :detail | |
end | |
end | |
__END__ | |
@@detail | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="user-scalable=yes, width=device-width" /> | |
<title>AD Listing</title> | |
</head> | |
<body> | |
<% @b.each do |attribute, values| %> | |
<div class="content"> | |
<p><%= attribute.first %></p> | |
<dl> | |
<% values.each do |name, value|%> | |
<% if !value[0].nil? %> | |
<dt><%= name.capitalize %></dt> | |
<% if name.to_s == 'email' %> | |
<dd><a href="mailto:<%= value[0] %>"><%= value[0] %></a></dd> | |
<% elsif name.to_s == 'phone' %> | |
<dd><%= value[0] %></dd> | |
<% else %> | |
<dd><a href="/<%= name %>/<%= value[0] %>"><%= value[0] %></a></dd> | |
<% end %> | |
<% end %> | |
<% end %> | |
</dl> | |
</div> | |
<% end %> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment