Commit 85d6aac8c8469ac1ad29eb150425cef4c9cf3902
Committed by
Georg Hopp
1 parent
aab45409
further improvements on database updates and some fixes
Showing
4 changed files
with
57 additions
and
21 deletions
| 1 | require 'SystemData' | 1 | require 'SystemData' |
| 2 | 2 | ||
| 3 | class Site < SystemData | 3 | class Site < SystemData |
| 4 | - attr_accessor :name, :mailAccounts, :mailAliases | 4 | + attr_accessor :name |
| 5 | 5 | ||
| 6 | def initialize(args = {}) | 6 | def initialize(args = {}) |
| 7 | + super(args) | ||
| 8 | + | ||
| 7 | @name = args[:name] | 9 | @name = args[:name] |
| 8 | end | 10 | end |
| 9 | end | 11 | end |
| @@ -43,8 +43,7 @@ class SystemDataBackendLdap | @@ -43,8 +43,7 @@ class SystemDataBackendLdap | ||
| 43 | LDAP_LAMBDA_USER = lambda do |entry| | 43 | LDAP_LAMBDA_USER = lambda do |entry| |
| 44 | entry[:cn] = entry[:uid] | 44 | entry[:cn] = entry[:uid] |
| 45 | entry[:shadowlastchange] = (Time::now.to_i/60/60/24).to_s | 45 | entry[:shadowlastchange] = (Time::now.to_i/60/60/24).to_s |
| 46 | - entry[:shadowmax] = '99999' | ||
| 47 | - entry[:shadowwarning] = '7' | 46 | + entry[:replace] += ['shadowreplace'] if entry[:replace] |
| 48 | end | 47 | end |
| 49 | 48 | ||
| 50 | LDAP_LAMBDA = { | 49 | LDAP_LAMBDA = { |
| @@ -64,7 +63,9 @@ class SystemDataBackendLdap | @@ -64,7 +63,9 @@ class SystemDataBackendLdap | ||
| 64 | end | 63 | end |
| 65 | 64 | ||
| 66 | def load!(kind) | 65 | def load!(kind) |
| 67 | - @ldapData[kind] = @ldap.search( | 66 | + @ldapData[kind] = Hash.new if ! @ldapData[kind] |
| 67 | + | ||
| 68 | + @ldapData[kind][:internal] = @ldap.search( | ||
| 68 | :base => ldapBase(kind), | 69 | :base => ldapBase(kind), |
| 69 | :filter => LDAP_FILTER[kind] | 70 | :filter => LDAP_FILTER[kind] |
| 70 | ) | 71 | ) |
| @@ -73,7 +74,7 @@ class SystemDataBackendLdap | @@ -73,7 +74,7 @@ class SystemDataBackendLdap | ||
| 73 | def load(kind) | 74 | def load(kind) |
| 74 | load!(kind) if ! @ldapData[kind] | 75 | load!(kind) if ! @ldapData[kind] |
| 75 | 76 | ||
| 76 | - @ldapData[kind].each do |data| | 77 | + @ldapData[kind][:external] = @ldapData[kind][:internal].map do |data| |
| 77 | map = { :dn => :id } | 78 | map = { :dn => :id } |
| 78 | map.merge!(LDAP_MAP[kind]) if LDAP_MAP[kind] | 79 | map.merge!(LDAP_MAP[kind]) if LDAP_MAP[kind] |
| 79 | 80 | ||
| @@ -81,9 +82,10 @@ class SystemDataBackendLdap | @@ -81,9 +82,10 @@ class SystemDataBackendLdap | ||
| 81 | data.each do |key,value| | 82 | data.each do |key,value| |
| 82 | ydata.merge!({ map[key] || key => value.size==1?value[0]:value.to_a }) | 83 | ydata.merge!({ map[key] || key => value.size==1?value[0]:value.to_a }) |
| 83 | end | 84 | end |
| 85 | + ydata | ||
| 86 | + end if ! @ldapData[kind][:external] | ||
| 84 | 87 | ||
| 85 | - yield ydata | ||
| 86 | - end | 88 | + @ldapData[kind][:external].each{|ydata| yield ydata} |
| 87 | end | 89 | end |
| 88 | 90 | ||
| 89 | def update(kind, data) | 91 | def update(kind, data) |
| @@ -91,19 +93,27 @@ class SystemDataBackendLdap | @@ -91,19 +93,27 @@ class SystemDataBackendLdap | ||
| 91 | map.merge!(LDAP_MAP[kind].invert) if LDAP_MAP[kind] | 93 | map.merge!(LDAP_MAP[kind].invert) if LDAP_MAP[kind] |
| 92 | 94 | ||
| 93 | entry = Net::LDAP::Entry.new(data[:id]) | 95 | entry = Net::LDAP::Entry.new(data[:id]) |
| 94 | - data.delete(:id) | ||
| 95 | 96 | ||
| 96 | - entry[:changetype] = 'add' | ||
| 97 | - entry[:objectclass] = LDAP_OBJECTCLASS[kind] | 97 | + odata = @ldapData[kind][:external].find{|edata| edata[:id] == data[:id]} |
| 98 | + data = data.find_all{|key,value| value != odata[key]} | ||
| 99 | + data.delete(:id) | ||
| 98 | 100 | ||
| 101 | + replace = Array.new | ||
| 99 | data.each do |key,value| | 102 | data.each do |key,value| |
| 100 | key = map[key] if map[key] | 103 | key = map[key] if map[key] |
| 104 | + replace.push(key.to_s) | ||
| 101 | entry[key] = value | 105 | entry[key] = value |
| 102 | end | 106 | end |
| 103 | - | ||
| 104 | - LDAP_LAMBDA[kind].call(entry) if LDAP_LAMBDA[kind] | ||
| 105 | 107 | ||
| 106 | - puts entry.to_ldif | 108 | + if not replace.empty? |
| 109 | + entry[:changetype] = 'modify' | ||
| 110 | + entry[:replace] = replace | ||
| 111 | + LDAP_LAMBDA[kind].call(entry) if LDAP_LAMBDA[kind] | ||
| 112 | + | ||
| 113 | + puts entry.to_ldif | ||
| 114 | + else | ||
| 115 | + puts 'INFO: no changes' | ||
| 116 | + end | ||
| 107 | end | 117 | end |
| 108 | 118 | ||
| 109 | private | 119 | private |
| @@ -6,11 +6,13 @@ class User < SystemData | @@ -6,11 +6,13 @@ class User < SystemData | ||
| 6 | def initialize(args = {}) | 6 | def initialize(args = {}) |
| 7 | super(args) | 7 | super(args) |
| 8 | 8 | ||
| 9 | - @name = args[:name] | ||
| 10 | - @pass = args[:pass] | ||
| 11 | - @uid = args[:uid] | ||
| 12 | - @gid = args[:gid] | ||
| 13 | - @shell = args[:shell] | ||
| 14 | - @home = args[:home] | 9 | + @name = args[:name] |
| 10 | + @pass = args[:pass] | ||
| 11 | + @uid = args[:uid] | ||
| 12 | + @gid = args[:gid] | ||
| 13 | + @shell = args[:shell] | ||
| 14 | + @home = args[:home] | ||
| 15 | + @shadowmax = args[:shadowmax] | ||
| 16 | + @shadowwarning = args[:shadowwarning] | ||
| 15 | end | 17 | end |
| 16 | end | 18 | end |
| @@ -46,8 +46,30 @@ end | @@ -46,8 +46,30 @@ end | ||
| 46 | 46 | ||
| 47 | puts | 47 | puts |
| 48 | 48 | ||
| 49 | -backend.userByName('georg').save | 49 | +georg = backend.userByName('georg') |
| 50 | +georg.save | ||
| 50 | 51 | ||
| 51 | puts | 52 | puts |
| 52 | 53 | ||
| 53 | -backend.groupByName('wheel').save | 54 | +georg.uid = 1001 |
| 55 | +georg.save | ||
| 56 | + | ||
| 57 | +puts | ||
| 58 | + | ||
| 59 | +wheel = backend.groupByName('wheel') | ||
| 60 | +wheel.save | ||
| 61 | + | ||
| 62 | +puts | ||
| 63 | + | ||
| 64 | +wheel.gid = 100 | ||
| 65 | +wheel.save | ||
| 66 | + | ||
| 67 | +puts | ||
| 68 | + | ||
| 69 | +site = backend.siteByName('kommandozeilenchef.de') | ||
| 70 | +site.save | ||
| 71 | + | ||
| 72 | +puts | ||
| 73 | + | ||
| 74 | +site.name = 'wumbaba.de' | ||
| 75 | +site.save |
Please
register
or
login
to post a comment