Created
July 15, 2014 07:30
-
-
Save schaary/34f3bc15d9dc0fb52cb9 to your computer and use it in GitHub Desktop.
push studip user to ilias_ea
This file contains hidden or 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
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'net/ldap' | |
require 'awesome_print' | |
require 'csv' | |
def fetch_from_ldap uid | |
connect_ldap | |
filter = Net::LDAP::Filter.eq 'uid', uid | |
basedn = 'ou=studip,o=mlu,c=de' | |
attr = ['userPassword'] | |
password = nil | |
@ldap.search(base: basedn, filter: filter, attributes: attr) do |entry| | |
password = entry[:userPassword][0] | |
end | |
password | |
end | |
def connect_ldap | |
unless @ldap | |
@ldap ||= Net::LDAP.new | |
@ldap.host = ENV.fetch('LDAP1_ITZ_HOST') | |
@ldap.port = ENV.fetch('LDAP1_ITZ_PORT') | |
@ldap.encryption :simple_tls | |
@ldap.auth ENV.fetch('LDAP1_ITZ_USER'), ENV.fetch('LDAP1_ITZ_PASSWORD') | |
end | |
end | |
CSV.read('teilnehmer.csv').map do |tn| | |
puts "dn: uid=#{tn.first},ou=ilias_ea,o=mlu,c=de" | |
puts "changeType: modify" | |
puts "replace: userPassword" | |
puts "userPassword: " + fetch_from_ldap(tn.first) | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment