class Ucert::T24Tracker
Class to handle T24 user account IDs
Attributes
file_user_map[RW]
Class constant variables
t24_2_ad_user[R]
t24_group_entitlement[R]
t24_group_entitlement_report[RW]
Class constant variables
t24_user_entitlement[R]
t24_user_entitlement_report[RW]
Class constant variables
verbose[RW]
Class constant variables
Public Class Methods
new(params ={})
click to toggle source
Instance default variables
# File lib/ucert/t24_tracker.rb, line 19 def initialize (params ={}) @verbose=params.fetch(:verbose, false) # T24 user entitlement report in CSV format, generated by T24 web portal -> Tools -> MB Admin Menu -> # Business Tools -> Security management system -> System Users Managment -> # List of System User Info -> Find -> Save As CSV @t24_user_entitlement_report = File.dirname(__FILE__)+"/../../data/t24/T24_User_Rpt.csv" @t24_user_entitlement_xml_report = File.dirname(__FILE__)+"/../../data/t24/t24_usr.xml" # T24 group entitlement report in xml format, generated by T24 web portal -> Tools -> MB Admin Menu -> # Business Tools -> Security management system -> System Users Managment -> # List of User SMS Group Info -> Find -> Save As CSV @t24_group_entitlement_report = File.dirname(__FILE__)+"/../../data/t24/T24_Grp_Rpt.csv" @t24_group_entitlement_xml_report = File.dirname(__FILE__)+"/../../data/t24/t24_grp.xml" # T24 to AD user map file @file_user_map = File.dirname(__FILE__)+"/../../data/t24/t24_user_map.txt" # Load the user map file to an instance variable (for performance gain) @t24_2_ad_user=load_known_user_map_from_file(@file_user_map) # Load the user entitlement instance variable from the native T24 user entitlement report #@t24_user_entitlement=parse_t24_user_report(@t24_user_entitlement_report) @t24_user_entitlement=parse_t24_user_xml_report(@t24_user_entitlement_xml_report) # Insert DN field into the user entitlement data structure insert_dn # Load the group entitlement instance variable from the native T24 group entitlement report #@t24_group_entitlement=parse_t24_group_report(@t24_group_entitlement_report) @t24_group_entitlement=parse_t24_group_xml_report(@t24_group_entitlement_xml_report) save! end
Public Instance Methods
print_group_entitlement()
click to toggle source
Print out the group entitlement table in plain text, to be imported into database
# File lib/ucert/t24_tracker.rb, line 293 def print_group_entitlement begin puts "Group Entitlement Report in Plain-text Format" if @verbose puts "@ID | DESCRIPTION | APPLICATION" if @verbose @t24_group_entitlement.values.map do |record| puts "#{record['ID']}|#{record['DESCRIPTION']}|#{record['APPLICATION']}"# "\t#{record['VERSION']}\t#{record['FUNCTION']}" end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: print_group
print_user_entitlement()
click to toggle source
Print out the user entitlement table in plain text, to be imported into database
# File lib/ucert/t24_tracker.rb, line 279 def print_user_entitlement begin puts "User Entitlement Report in Plain-text Format" if @verbose puts "@ID USER.NAME APPLICATION GROUP START.DATE.PROFILE END.DATE.PROFILE DN" if @verbose @t24_user_entitlement.values.map do |record| puts "#{record['ID']}|#{record['USER.NAME']}|#{record['APPLICATION']}|#{record['GROUP']}|#{record['START.DATE.PROFILE']}|#{record['END.DATE.PROFILE']}|#{record['DN']}" end rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: print_user
save_t24_user_map!(file=@file_user_map)
click to toggle source
Save the T24 to AD user mapping relation into the cache file
# File lib/ucert/t24_tracker.rb, line 307 def save_t24_user_map!(file=@file_user_map) puts "Saving the known T24 to AD user mapping relationship to file: #{file} ..." if @verbose begin timestamp=Time.now f=File.open(file, 'w') f.write "# local T24 to AD user map file created by the #{self.class} class #{__method__} method at: #{timestamp}" @t24_user_entitlement.values.map do |record| key = record['ID'].upcase + ':' + record['USER.NAME'].upcase value = record['DN'] f.write "\n#{key}|#{value}" end f.close puts "T24 to AD user map file is successfully saved to: #{file}" if @verbose rescue => ee puts "Exception on method #{__method__}: #{ee}" if @verbose end end
Also aliased as: save!
t24_search_by_dn(dn)
click to toggle source
Search user entitlement record by AD DN
# File lib/ucert/t24_tracker.rb, line 327 def t24_search_by_dn (dn) begin puts "Perform search on the user entitlement record by AD DN: #{dn}" if @verbose @t24_user_entitlement.each do |key, val| return val if @t24_user_entitlement[key]['DN'].eql? dn end return nil rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
Also aliased as: search_by_dn
Private Instance Methods
insert_dn()
click to toggle source
Procedures to add additonal field 'dn' into the @t24_user_entitlement data structure, by person the AD search
# File lib/ucert/t24_tracker.rb, line 243 def insert_dn begin tracker = Ucert::AdTracker.new(:verbose=>false) @t24_user_entitlement.each do |index, record| puts "\n\nPerform DN lookup for record: #{record}" if @verbose key1 = record['USER.NAME'] if record['USER.NAME'] key2 = record['ID'] if record['ID'] my_key = record['ID'].upcase + ":" + record['USER.NAME'].upcase puts "Perform 1st order search from the local cache: #{my_key}" if @verbose if @t24_2_ad_user.key?(my_key) dn=@t24_2_ad_user[my_key] # additional logic to update the existing DN record unless tracker.ad_person_records.key?(dn) dn = update_dn(tracker,dn) end puts "Found in the local cache file: #{dn}" if @verbose else if dn.nil? and !key1.nil? puts "Perform 2nd order search only if the 1st one fail, by using: #{key1}" if @verbose dn = tracker.ad_search_by_text(key1, "person") end if dn.nil? and !key2.nil? puts "Perform 3rd order search only if the last fail, by using: #{key2}" if @verbose dn = tracker.ad_search_by_text(key2, "person") end end @t24_user_entitlement[index]['DN'] = dn end tracker=nil rescue => ee puts "Exception on method #{__method__}: #{ee}" tracker=nil end end
parse_t24_group_report(file)
click to toggle source
Parsing the T24 group entitlement report in CSV format
# File lib/ucert/t24_tracker.rb, line 157 def parse_t24_group_report (file) begin t24_entitlement=Hash.new group_index=0 line_cnt=0 File.open(file,'r').each do |line| puts "Processing line number #{line_cnt.inspect}" if @verbose # skip the 1st line of the file (header line) if line_cnt == 0 line_cnt+=1 next end entry=line.chomp.split(',').map {|x| x.gsub("\"","")} # clean the entry data puts entry.inspect if @verbose # Determine the start of a user_record entry[0].strip! if entry[0].nil? #do nothing elsif entry[0].empty? #do nothing else group_index+=1 end puts group_index.inspect if @verbose t24_entitlement[group_index]=Hash.new unless t24_entitlement.key?(group_index) t24_entitlement[group_index]['ID']=entry[0] unless t24_entitlement[group_index]['ID'] t24_entitlement[group_index]['DESCRIPTION']=entry[1] unless t24_entitlement[group_index]['DESCRIPTION'] t24_entitlement[group_index]['APPLICATION']=Hash.new unless t24_entitlement[group_index]['APPLICATION'] puts t24_entitlement.inspect if @verbose unless entry[2].nil? app=Hash.new app[entry[2]]=Hash.new unless app.key?(entry[2]) app[entry[2]]['VERSION']=entry[3] app[entry[2]]['FUNCTION']=entry[4] t24_entitlement[group_index]['APPLICATION'].merge!(app) end line_cnt+=1 end return t24_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_t24_group_xml_report(file=@t24_group_entitlement_xml_report)
click to toggle source
Parsing the T24 group entitlement report in xml format
# File lib/ucert/t24_tracker.rb, line 205 def parse_t24_group_xml_report (file=@t24_group_entitlement_xml_report) #begin t24_entitlement=Hash.new group_index=0 #line_cnt=0 #File.open(file,'r').each do |line| xml_doc=Nokogiri::XML(File.open(file)) xml_doc.css("row").map do |row| #puts "Processing row: #{row}" if @verbose # Determine the start of a user_record columns = row.css("column") entry = columns.map {|x| x.text} #puts "Processing column A: #{entry[0]}" if @verbose group_index += 1 unless entry[0].empty? puts "Group Index: #{group_index.inspect}" if @verbose t24_entitlement[group_index]=Hash.new unless t24_entitlement.key?(group_index) t24_entitlement[group_index]['ID']=entry[0] unless t24_entitlement[group_index]['ID'] t24_entitlement[group_index]['DESCRIPTION']=entry[1] unless t24_entitlement[group_index]['DESCRIPTION'] t24_entitlement[group_index]['APPLICATION']=Hash.new unless t24_entitlement[group_index]['APPLICATION'] #puts t24_entitlement.inspect if @verbose unless entry[2].empty? app=Hash.new cur_key=entry[2]+":"+entry[3] app[cur_key]=Hash.new unless app.key?(cur_key) app[cur_key]['APPLICATION']=entry[2] app[cur_key]['VERSION']=entry[3] app[cur_key]['FUNCTION']=entry[4] t24_entitlement[group_index]['APPLICATION'].merge!(app) end end return t24_entitlement #rescue => ee # puts "Exception on method #{__method__}: #{ee}" #end end
parse_t24_user_report(file)
click to toggle source
Parsing the T24 user entitlement report in CSV format
# File lib/ucert/t24_tracker.rb, line 48 def parse_t24_user_report (file) begin t24_entitlement=Hash.new user_record=0 line_cnt=0 File.open(file,'r').each do |line| puts "Processing line number #{line_cnt.inspect}" if @verbose # skip the 1st line of the file (header line) if line_cnt == 0 line_cnt+=1 next end # entry=line.chomp.split(/(\t|\,)/).map {|x| x.gsub("\"","")} # clean the entry data entry=line.chomp.split(",").map {|x| x.gsub("\"","")} # clean the entry data puts entry.inspect if @verbose # Determine the start of a user_user_record entry[0].strip! if entry[0].nil? line_cnt+=1 next elsif entry[0].empty? line_cnt+=1 #app=Hash.new else user_record+=1 end t24_entitlement[user_record]=Hash.new unless t24_entitlement.key?(user_record) t24_entitlement[user_record]['ID']=entry[0] unless t24_entitlement[user_record]['ID'] t24_entitlement[user_record]['USER.NAME']=entry[1] unless t24_entitlement[user_record]['USER.NAME'] t24_entitlement[user_record]['APPLICATION']=Hash.new unless t24_entitlement[user_record]['APPLICATION'] unless entry[2].nil? if entry[2].include?("@") t24_entitlement[user_record]['GROUP']=Array.new unless t24_entitlement[user_record]['GROUP'] t24_entitlement[user_record]['GROUP'].push(entry[2]) else app=Hash.new app[entry[2]]=entry[3] t24_entitlement[user_record]['APPLICATION'].merge!(app) end end t24_entitlement[user_record]['START.DATE.PROFILE']=entry[4] unless t24_entitlement[user_record]['START.DATE.PROFILE'] t24_entitlement[user_record]['END.DATE.PROFILE']=entry[5] unless t24_entitlement[user_record]['END.DATE.PROFILE'] t24_entitlement[user_record]['PASSWORD.VALIDITY']=entry[6] unless t24_entitlement[user_record]['PASSWORD.VALIDITY'] t24_entitlement[user_record]['ATTRIBUTES']=entry[7] unless t24_entitlement[user_record]['ATTRIBUTES'] t24_entitlement[user_record]['INIT.APPLICATION']=entry[8] unless t24_entitlement[user_record]['INIT.APPLICATION'] t24_entitlement[user_record]['ATTEMPTS']=entry[9] unless t24_entitlement[user_record]['ATTEMPTS'] t24_entitlement[user_record]['COMPANY.CODE']=entry[10] unless t24_entitlement[user_record]['COMPANY.CODE'] t24_entitlement[user_record]['SECURITY.MGMT.L']=entry[11] unless t24_entitlement[user_record]['SECURITY.MGMT.L'] t24_entitlement[user_record]['TIME.OUT.MINUTES']=entry[12] unless t24_entitlement[user_record]['TIME.OUT.MINUTES'] t24_entitlement[user_record]['DATE.LAST.SIGN.ON']=entry[13] unless t24_entitlement[user_record]['DATE.LAST.SIGN.ON'] t24_entitlement[user_record]['PASSW.CHANGE.DATE']=entry[14] unless t24_entitlement[user_record]['PASSW.CHANGE.DATE'] line_cnt+=1 #return if line_cnt==3 end return t24_entitlement rescue => ee puts "Exception on method #{__method__}: #{ee}" end end
parse_t24_user_xml_report(file=@t24_user_entitlement_xml_report)
click to toggle source
Parsing the T24 user entitlement report in XML format
# File lib/ucert/t24_tracker.rb, line 109 def parse_t24_user_xml_report (file=@t24_user_entitlement_xml_report) #begin t24_entitlement=Hash.new user_record=0 xml_doc=Nokogiri::XML(File.open(file)) xml_doc.css("row").map do |row| #line_cnt=0 #File.open(file,'r').each do |line| puts "Processing row: #{row.inspect}" if @verbose # entry=line.chomp.split(/(\t|\,)/).map {|x| x.gsub("\"","")} # clean the entry data entry=row.css("column").map {|x| x.text } # clean the entry data puts entry.inspect if @verbose # Determine the start of a user_user_record entry[0].strip! user_record+=1 unless entry[0].empty? t24_entitlement[user_record]=Hash.new unless t24_entitlement.key?(user_record) t24_entitlement[user_record]['ID']=entry[0] unless t24_entitlement[user_record]['ID'] t24_entitlement[user_record]['USER.NAME']=entry[1] unless t24_entitlement[user_record]['USER.NAME'] t24_entitlement[user_record]['APPLICATION']=Hash.new unless t24_entitlement[user_record]['APPLICATION'] unless entry[2].nil? if entry[2].include?("@") t24_entitlement[user_record]['GROUP']=Array.new unless t24_entitlement[user_record]['GROUP'] t24_entitlement[user_record]['GROUP'].push(entry[2]) else app=Hash.new app[entry[2]]=entry[3] t24_entitlement[user_record]['APPLICATION'].merge!(app) end end t24_entitlement[user_record]['START.DATE.PROFILE']=entry[4] unless t24_entitlement[user_record]['START.DATE.PROFILE'] t24_entitlement[user_record]['END.DATE.PROFILE']=entry[5] unless t24_entitlement[user_record]['END.DATE.PROFILE'] t24_entitlement[user_record]['PASSWORD.VALIDITY']=entry[6] unless t24_entitlement[user_record]['PASSWORD.VALIDITY'] t24_entitlement[user_record]['ATTRIBUTES']=entry[7] unless t24_entitlement[user_record]['ATTRIBUTES'] t24_entitlement[user_record]['INIT.APPLICATION']=entry[8] unless t24_entitlement[user_record]['INIT.APPLICATION'] t24_entitlement[user_record]['ATTEMPTS']=entry[9] unless t24_entitlement[user_record]['ATTEMPTS'] t24_entitlement[user_record]['COMPANY.CODE']=entry[10] unless t24_entitlement[user_record]['COMPANY.CODE'] t24_entitlement[user_record]['SECURITY.MGMT.L']=entry[11] unless t24_entitlement[user_record]['SECURITY.MGMT.L'] t24_entitlement[user_record]['TIME.OUT.MINUTES']=entry[12] unless t24_entitlement[user_record]['TIME.OUT.MINUTES'] t24_entitlement[user_record]['DATE.LAST.SIGN.ON']=entry[13] unless t24_entitlement[user_record]['DATE.LAST.SIGN.ON'] t24_entitlement[user_record]['PASSW.CHANGE.DATE']=entry[14] unless t24_entitlement[user_record]['PASSW.CHANGE.DATE'] end return t24_entitlement #rescue => ee # puts "Exception on method #{__method__}: #{ee}" #end end