|
|
@ -14,6 +14,8 @@ ad_groups = ['vpn-users', 'gogs'] |
|
|
|
|
|
|
|
|
|
|
|
def mysql_reader(dbconn, sql): |
|
|
|
data = tuple |
|
|
|
err = False |
|
|
|
try: |
|
|
|
conn = MySQLdb.connect(host=dbconn['host'], user=dbconn['user'], |
|
|
|
passwd=dbconn['pass'], db=dbconn['base'], charset="utf8") |
|
|
@ -21,12 +23,13 @@ def mysql_reader(dbconn, sql): |
|
|
|
cur.execute(sql) |
|
|
|
data = cur.fetchall() |
|
|
|
cur.close() |
|
|
|
except MySQLdb.Error as err: |
|
|
|
except MySQLdb.Error as exc: |
|
|
|
print("Connection error: {}".format(err)) |
|
|
|
conn.close() |
|
|
|
err = exc |
|
|
|
else: |
|
|
|
conn.close() |
|
|
|
return data |
|
|
|
return data, err |
|
|
|
|
|
|
|
|
|
|
|
def users_make_zayavka(users, memberOf): |
|
|
@ -42,7 +45,8 @@ def users_make_zayavka(users, memberOf): |
|
|
|
pwChange = True |
|
|
|
if i['Delete'] == 'Y': |
|
|
|
toRemove = True |
|
|
|
res[usrName] = {'samAccountName': usrName, |
|
|
|
res[usrName] = {'id': str(i['ID']), |
|
|
|
'samAccountName': usrName, |
|
|
|
'memberOf': memberOf, |
|
|
|
'usrPass': str(i['Pass']), |
|
|
|
'groupSet': str(i['Otdel']), |
|
|
@ -54,9 +58,13 @@ def users_make_zayavka(users, memberOf): |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
users = users_make_zayavka(mysql_reader(dbconn, sql), ad_groups) |
|
|
|
for user in users: |
|
|
|
print user, users[user] |
|
|
|
data, err = mysql_reader(dbconn, sql) |
|
|
|
if not err: |
|
|
|
users = users_make_zayavka(data, ad_groups) |
|
|
|
for user in users: |
|
|
|
print user, users[user] |
|
|
|
else: |
|
|
|
print err |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|