Add LDAP user index
This commit is contained in:
36
app/controllers/ldap_users_controller.rb
Normal file
36
app/controllers/ldap_users_controller.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class LdapUsersController < ApplicationController
|
||||
def index
|
||||
attributes = %w{dn cn uid mail admin}
|
||||
filter = Net::LDAP::Filter.eq("uid", "*")
|
||||
if params[:ou]
|
||||
treebase = "ou=#{params[:ou]},cn=users,dc=kosmos,dc=org"
|
||||
else
|
||||
treebase = "ou=kosmos.org,cn=users,dc=kosmos,dc=org"
|
||||
end
|
||||
|
||||
entries = ldap_client.search(base: treebase, filter: filter, attributes: attributes)
|
||||
entries.sort_by! { |e| e.cn[0] }
|
||||
|
||||
@entries = entries.collect do |e|
|
||||
{
|
||||
uid: e.uid.first,
|
||||
mail: e.try(:mail) ? e.mail.first : nil,
|
||||
admin: e.try(:admin) ? 'admin' : nil
|
||||
}
|
||||
end
|
||||
# ldap_client.get_operation_result
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ldap_client
|
||||
ldap_client ||= Net::LDAP.new host: "ldap.kosmos.org",
|
||||
port: 636,
|
||||
encryption: :simple_tls,
|
||||
auth: {
|
||||
method: :simple,
|
||||
username: Rails.application.credentials.ldap[:username],
|
||||
password: Rails.application.credentials.ldap[:password]
|
||||
}
|
||||
end
|
||||
end
|
||||
2
app/helpers/ldap_users_helper.rb
Normal file
2
app/helpers/ldap_users_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module LdapUsersHelper
|
||||
end
|
||||
25
app/views/ldap_users/index.html.erb
Normal file
25
app/views/ldap_users/index.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<h1>LDAP users</h1>
|
||||
|
||||
<ul>
|
||||
<li><%= link_to 'kosmos.org', ldap_users_path %></li>
|
||||
<li><%= link_to '5apps.com', ldap_users_path(ou: '5apps.com') %></li>
|
||||
</ul>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>UID</th>
|
||||
<th>E-Mail</th>
|
||||
<th>Admin</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @entries.each do |entry| %>
|
||||
<tr>
|
||||
<td><%= entry[:uid] %></td>
|
||||
<td><%= entry[:mail] %></td>
|
||||
<td><%= entry[:admin] %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user