You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/python2
  2. # coding=utf-8
  3. import MySQLdb
  4. dbconn = {'host': '10.1.11.26',
  5. 'user': 'LDAP2018',
  6. 'pass': 'Pr4t7UEZITwW1AYG',
  7. 'base': 'sitemanager0'}
  8. sql = 'select * from LDAP'
  9. ad_groups = ['vpn-users', 'gogs']
  10. def mysql_reader(dbconn, sql):
  11. data = tuple
  12. err = False
  13. try:
  14. conn = MySQLdb.connect(host=dbconn['host'], user=dbconn['user'],
  15. passwd=dbconn['pass'], db=dbconn['base'], charset="utf8")
  16. cur = conn.cursor(MySQLdb.cursors.DictCursor)
  17. cur.execute(sql)
  18. data = cur.fetchall()
  19. cur.close()
  20. except MySQLdb.Error as exc:
  21. print("Connection error: {}".format(err))
  22. conn.close()
  23. err = exc
  24. else:
  25. conn.close()
  26. return data, err
  27. def users_make_zayavka(users, memberOf):
  28. res = {}
  29. for i in users:
  30. usrName = str(i['LoginEmail']).split('@')[0]
  31. enabled = False
  32. pwChange = False
  33. toRemove = False
  34. if i['Activ'] == 'Y':
  35. enabled = True
  36. if i['Changes'] == 'Y':
  37. pwChange = True
  38. if i['Delete'] == 'Y':
  39. toRemove = True
  40. res[usrName] = {'id': str(i['ID']),
  41. 'samAccountName': usrName,
  42. 'memberOf': memberOf,
  43. 'usrPass': str(i['Pass']),
  44. 'groupSet': str(i['Otdel']),
  45. 'enabled': enabled,
  46. 'pwChange': pwChange,
  47. 'toRemove': toRemove
  48. }
  49. return res
  50. def main():
  51. data, err = mysql_reader(dbconn, sql)
  52. if not err:
  53. users = users_make_zayavka(data, ad_groups)
  54. for user in users:
  55. print user, users[user]
  56. else:
  57. print err
  58. if __name__ == '__main__':
  59. main()

Powered by TurnKey Linux.