Browse Source

commit changes

master
root 4 years ago
parent
commit
480dbac2ce
2 changed files with 17 additions and 18 deletions
  1. +6
    -8
      importer.py
  2. +11
    -10
      zayavka_reader.py

+ 6
- 8
importer.py View File

@ -26,9 +26,9 @@ sql_update_changes = "update LDAP set Changes = 'N' where ID = '%s'"
sql_delete = "delete from LDAP where Delete = 'Y' and ID = '%s'"
ad_groups = ['vpn-users', 'gogs']
ad_groups_users = ['vpn-users', 'gogs', 'Пользователи удаленного рабочего стола']
ad_groups_users = ['vpn-users', 'gogs']
ad_groups_bitrix = ['vpn-web-vpn', 'gogs']
ad_groups_1c = ['vpn-1c-vpn', 'Domain Users', 'Пользователи удаленного рабочего стола']
ad_groups_1c = ['vpn-1c-vpn', 'Domain Users']
ad_group_xserv = 'ics'
ad_group_rdp = 'Пользователи удаленного рабочего стола'
@ -56,21 +56,20 @@ def main():
lp.load(samba.param.default_path()) # или lp.load("/etc/samba/smb.conf")
sam = SamDB(lp=lp, session_info=system_session())
res, err = z_reader.mysql_reader(dbconn, sql)
print(res)
if err:
print err
print(err)
exit(0)
z_users = z_reader.users_make_zayavka(res)
print(z_users)
i = 0
for z_user in z_users:
print z_user, z_users[z_user]['memberOf']
ad_user = UserAd(sam, base, domainName, z_users[z_user]['samAccountName'], z_users[z_user]['usrPass'])
if z_users[z_user]['toRemove']: # удаляем, если такой есть
if ad_user.exists:
ad_user.remove()
dat, err = z_reader.mysql_reader(dbconn, sql_delete % z_users[z_user]['id'])
if err:
print err
print(err)
continue
if not ad_user.exists:
ad_user.add()
@ -78,14 +77,13 @@ def main():
ad_user.set_passwd()
dat, err = z_reader.mysql_reader(dbconn, sql_update_changes % z_users[z_user]['id'])
if err:
print err
print(err)
if z_users[z_user]['enabled']: # инаблим или дисаблим
ad_user.enable()
else:
ad_user.disable()
for group in z_users[z_user]['memberOf']:
ad_user.add_in_group(group)
break
if __name__ == '__main__':


+ 11
- 10
zayavka_reader.py View File

@ -41,6 +41,8 @@ def users_make_zayavka(users):
res = {}
for i in users:
usrname = str(i['LoginEmail']).split('@')[0]
if usrname in res:
continue
enabled = False
pwchange = False
toremove = False
@ -54,17 +56,16 @@ def users_make_zayavka(users):
toremove = True
# размечаем группы, в которых должен быть пользователь
memberof = []
print(memberof)
if str(i['Otdel']) == 'Users':
memberof = ad_groups_users
memberof = ad_groups_users[:]
elif str(i['Otdel']) == '1C':
memberof = ad_groups_1c
memberof = ad_groups_1c[:]
elif str(i['Otdel']) == 'Bitrix':
memberof = ad_groups_bitrix
else:
memberof = []
if i['XServ'] == 1:
memberof = ad_groups_bitrix[:]
if str(i['XServ']) == '1':
memberof.append(ad_group_xserv)
if i['RDP'] == 1:
if str(i['RDP']) == '1':
memberof.append(ad_group_rdp)
# собственно добавляем в мапу
res[usrname] = {'id': str(i['ID']),
@ -77,6 +78,7 @@ def users_make_zayavka(users):
'toRemove': toremove,
'email': i['LoginEmail']
}
return res
@ -85,10 +87,9 @@ def main():
if not err:
users = users_make_zayavka(data)
for user in users:
if '1' in users[user]['groupSet']:
print user, users[user]
print(user, users[user])
else:
print err
print(err)
if __name__ == '__main__':


Loading…
Cancel
Save

Powered by TurnKey Linux.