Line | |
---|
1 | import ldap |
---|
2 | import ldap.sasl |
---|
3 | import ldap.modlist |
---|
4 | import xmlrpclib |
---|
5 | import os |
---|
6 | import json |
---|
7 | class Matrix: |
---|
8 | |
---|
9 | def __init__(self): |
---|
10 | self.first_run = True |
---|
11 | #def __init__ |
---|
12 | |
---|
13 | def n4d_cron(self,minute): |
---|
14 | if self.first_run or ( minute % 60 == 0 ) : |
---|
15 | if self.first_run: |
---|
16 | self.first_run = False |
---|
17 | self.update_from_matrix() |
---|
18 | #def n4d_cron |
---|
19 | |
---|
20 | def startup(self,options): |
---|
21 | try: |
---|
22 | self.update_from_matrix() |
---|
23 | except: |
---|
24 | pass |
---|
25 | |
---|
26 | def update_from_matrix(self): |
---|
27 | try: |
---|
28 | if not objects['SlapdManager'].test_ldap_connection(): |
---|
29 | if not objects['SlapdManager'].connection_ldap(): |
---|
30 | return {"status":False,"msg":"Connection with ldap is not create"} |
---|
31 | except: |
---|
32 | return 'Not initialized' |
---|
33 | aux_file = open('/etc/matrix_config','r') |
---|
34 | matrix_options = json.load(aux_file) |
---|
35 | c = xmlrpclib.ServerProxy("https://" + matrix_options['server_ip'] + ":9779") |
---|
36 | try: |
---|
37 | list_changes = c.get_users('','Matrix') |
---|
38 | except: |
---|
39 | return "Server is down" |
---|
40 | if list_changes[0][0] == 'ou=llxadmin,dc=ma5,dc=lliurex,dc=net': |
---|
41 | objects['SlapdManager'].recursive_delete(list_changes[0][0]) |
---|
42 | |
---|
43 | for x in list_changes: |
---|
44 | aux_dic = {} |
---|
45 | aux_dic[x[0]]= x[1] |
---|
46 | objects['SlapdManager'].insert_dictionary(aux_dic) |
---|
47 | return "Ok" |
---|
48 | #return list_changes[0] |
---|
49 | |
---|
50 | |
---|
51 | if __name__ == '__main__': |
---|
52 | a = Matrix() |
---|
53 | a.update_from_matrix() |
---|
Note: See
TracBrowser
for help on using the repository browser.