1 from __future__ import print_function |
|
2 |
|
3 import base64 |
|
4 from cubicweb.server.utils import crypt_password |
|
5 |
|
6 dbdriver = config.system_source_config['db-driver'] |
|
7 from logilab.database import get_db_helper |
|
8 dbhelper = get_db_helper(driver) |
|
9 |
|
10 insert = ('INSERT INTO cw_cwuser (cw_creation_date,' |
|
11 ' cw_eid,' |
|
12 ' cw_modification_date,' |
|
13 ' cw_login,' |
|
14 ' cw_firstname,' |
|
15 ' cw_surname,' |
|
16 ' cw_last_login_time,' |
|
17 ' cw_upassword,' |
|
18 ' cw_cwuri) ' |
|
19 "VALUES (%(mtime)s, %(eid)s, %(mtime)s, %(login)s, " |
|
20 " %(firstname)s, %(surname)s, %(mtime)s, %(pwd)s, 'foo');") |
|
21 update = "UPDATE entities SET source='system' WHERE eid=%(eid)s;" |
|
22 rset = sql("SELECT eid,type,source,extid,mtime FROM entities WHERE source!='system'", ask_confirm=False) |
|
23 for eid, type, source, extid, mtime in rset: |
|
24 if type != 'CWUser': |
|
25 print("don't know what to do with entity type", type) |
|
26 continue |
|
27 if not source.lower().startswith('ldap'): |
|
28 print("don't know what to do with source type", source) |
|
29 continue |
|
30 extid = base64.decodestring(extid) |
|
31 ldapinfos = [x.strip().split('=') for x in extid.split(',')] |
|
32 login = ldapinfos[0][1] |
|
33 firstname = login.capitalize() |
|
34 surname = login.capitalize() |
|
35 args = dict(eid=eid, type=type, source=source, login=login, |
|
36 firstname=firstname, surname=surname, mtime=mtime, |
|
37 pwd=dbhelper.binary_value(crypt_password('toto'))) |
|
38 print(args) |
|
39 sql(insert, args) |
|
40 sql(update, args) |
|
41 |
|
42 commit() |
|