Compare commits
5 Commits
a1a2bf34b3
...
49cb37eda2
Author | SHA1 | Date | |
---|---|---|---|
49cb37eda2 | |||
e19fc234f4 | |||
334716f370 | |||
4a9b8ae755 | |||
e15c309e71 |
30
README.md
Normal file
30
README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# LGit (pronounced "legit")
|
||||||
|
|
||||||
|
python library that allows to use LDAP user database, based on luser project with git-like functions
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
Following script copies changes made on 192.168.1.13 LDAP server to the 192.168.1.21 server
|
||||||
|
|
||||||
|
```
|
||||||
|
import lgit
|
||||||
|
|
||||||
|
server1 = lgit.logserver("192.168.1.13", "cn=admin,dc=example,dc=com", "adminpass", "ou=Users,dc=example,dc=com")
|
||||||
|
server2 = lgit.logserver("192.168.1.21", "ou=bob,ou=Users,dc=example,dc=com", "pasSw0rd", "ou=Users,dc=example,dc=com")
|
||||||
|
|
||||||
|
server1.pull(server2)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Following script pulls all user changes from both servers to each other
|
||||||
|
|
||||||
|
```
|
||||||
|
import lgit
|
||||||
|
|
||||||
|
server1 = lgit.logserver("192.168.1.13", "cn=admin,dc=example,dc=com", "adminpass", "ou=Users,dc=example,dc=com")
|
||||||
|
server2 = lgit.logserver("192.168.1.21", "ou=bob,ou=Users,dc=example,dc=com", "pasSw0rd", "ou=Users,dc=example,dc=com")
|
||||||
|
|
||||||
|
lg = lgit.lgit()
|
||||||
|
lg.sync()
|
||||||
|
|
||||||
|
```
|
@ -256,8 +256,8 @@ l dc values from base
|
|||||||
|
|
||||||
return basecopy
|
return basecopy
|
||||||
|
|
||||||
def pullfrom(self, source)->int:
|
def fetchfrom(self, source)->int:
|
||||||
pulled = 0
|
fetched = 0
|
||||||
basecopy = self.getbasecopy(source)
|
basecopy = self.getbasecopy(source)
|
||||||
|
|
||||||
self.refreshtotal(basecopy)
|
self.refreshtotal(basecopy)
|
||||||
@ -273,9 +273,9 @@ l dc values from base
|
|||||||
attributes = log['attributes']
|
attributes = log['attributes']
|
||||||
|
|
||||||
self.setlog(attributes, basecopy)
|
self.setlog(attributes, basecopy)
|
||||||
pulled += 1
|
fetched += 1
|
||||||
|
|
||||||
return pulled
|
return fetched
|
||||||
|
|
||||||
def applyfrom(self, source)->int:
|
def applyfrom(self, source)->int:
|
||||||
basecopy = self.getbasecopy(source)
|
basecopy = self.getbasecopy(source)
|
||||||
@ -284,6 +284,25 @@ l dc values from base
|
|||||||
|
|
||||||
return appliedlogs
|
return appliedlogs
|
||||||
|
|
||||||
|
def applyto(self, destination)->int:
|
||||||
|
basecopy = destination.getbasecopy(self)
|
||||||
|
|
||||||
|
appliedlogs = destination.applylogs(basecopy)
|
||||||
|
|
||||||
|
return appliedlogs
|
||||||
|
|
||||||
|
def pullfrom(self, source)->int:
|
||||||
|
self.fetchfrom(source)
|
||||||
|
applied = self.applyfrom(source)
|
||||||
|
|
||||||
|
return applied
|
||||||
|
|
||||||
|
def pushto(self, destination)->int:
|
||||||
|
destination.pullfrom(self)
|
||||||
|
pushed = destination.pullfrom(self)
|
||||||
|
|
||||||
|
return pushed
|
||||||
|
|
||||||
def lastpwchangenow(self):
|
def lastpwchangenow(self):
|
||||||
'''
|
'''
|
||||||
Return time of last password change for the user set to current time
|
Return time of last password change for the user set to current time
|
||||||
@ -292,7 +311,7 @@ l dc values from base
|
|||||||
|
|
||||||
return str((datetime.utcnow() - datetime(1970,1,1)).days)
|
return str((datetime.utcnow() - datetime(1970,1,1)).days)
|
||||||
|
|
||||||
class ldapsync():
|
class lgit():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.servers = []
|
self.servers = []
|
||||||
|
|
||||||
@ -304,22 +323,22 @@ class ldapsync():
|
|||||||
self.servers.remove(log_server)
|
self.servers.remove(log_server)
|
||||||
return self.servers
|
return self.servers
|
||||||
|
|
||||||
def pullfromall(self, log_server: logserver)->int:
|
def fetchfromall(self, log_server: logserver)->int:
|
||||||
pulledlogs = 0
|
fetchedlogs = 0
|
||||||
|
|
||||||
for source in self.servers:
|
for source in self.servers:
|
||||||
if source != log_server:
|
if source != log_server:
|
||||||
pulledlogs += log_server.pullfrom(source)
|
fetchedlogs += log_server.fetchedfrom(source)
|
||||||
|
|
||||||
return pulledlogs
|
return pulledlogs
|
||||||
|
|
||||||
def pull(self)->int:
|
def fetch(self)->int:
|
||||||
pulledlogs = 0
|
fetchedlogs = 0
|
||||||
|
|
||||||
for server in self.servers:
|
for server in self.servers:
|
||||||
pulledlogs += self.pullfromall(server)
|
fetchedlogs += self.fetchfromall(server)
|
||||||
|
|
||||||
return pulledlogs
|
return fetchedlogs
|
||||||
|
|
||||||
def applyfromall(self, log_server: logserver)->int:
|
def applyfromall(self, log_server: logserver)->int:
|
||||||
appliedlogs = 0
|
appliedlogs = 0
|
||||||
@ -330,6 +349,15 @@ class ldapsync():
|
|||||||
|
|
||||||
return appliedlogs
|
return appliedlogs
|
||||||
|
|
||||||
|
def applytoall(self, log_server: logserver)->int:
|
||||||
|
appliedlogs = 0
|
||||||
|
|
||||||
|
for destination in self.servers:
|
||||||
|
if destination != log_server:
|
||||||
|
appliedlogs += log_server.applyto(destination)
|
||||||
|
|
||||||
|
return appliedlogs
|
||||||
|
|
||||||
def apply(self)->int:
|
def apply(self)->int:
|
||||||
appliedlogs = 0
|
appliedlogs = 0
|
||||||
|
|
||||||
@ -338,8 +366,31 @@ class ldapsync():
|
|||||||
|
|
||||||
return appliedlogs
|
return appliedlogs
|
||||||
|
|
||||||
|
def pullfromall(self, log_server: logserver)->int:
|
||||||
|
self.fetchfromall(log_server)
|
||||||
|
pulled = self.applyfromall(log_server)
|
||||||
|
|
||||||
|
return pulled
|
||||||
|
|
||||||
|
def pushtoall(self, log_server: logserver)->int:
|
||||||
|
pushed = 0
|
||||||
|
|
||||||
|
for destination in self.servers:
|
||||||
|
if destination != log_server:
|
||||||
|
pushed += log_server.pushto(destination)
|
||||||
|
|
||||||
|
return pushed
|
||||||
|
|
||||||
|
def pull(self)->int:
|
||||||
|
self.fetch()
|
||||||
|
pulled = self.apply()
|
||||||
|
|
||||||
|
return pulled
|
||||||
|
|
||||||
|
def push(self)->int:
|
||||||
|
return self.pull()
|
||||||
|
|
||||||
def sync(self)->int:
|
def sync(self)->int:
|
||||||
pulledlogs = self.pull()
|
pulledlogs = self.pull()
|
||||||
appliedlogs = self.apply()
|
|
||||||
|
|
||||||
return appliedlogs
|
return pulledlogs
|
Loading…
Reference in New Issue
Block a user