diff --git a/UserAd_class.py b/UserAd_class.py index ccebb4a..23b932b 100755 --- a/UserAd_class.py +++ b/UserAd_class.py @@ -146,12 +146,12 @@ def main(): lp.load(samba.param.default_path()) # или lp.load("/etc/samba/smb.conf") sam = SamDB(lp=lp, session_info=system_session()) test_usr = UserAd(sam, base, domainName, 'tst', "secret34daD") - print test_usr.memberOf - print "Set disable error: ", test_usr.disable() + print(test_usr.memberOf) + print("Set disable error: ", test_usr.disable()) time.sleep(1) - print "Set enable error: ", test_usr.enable() + print("Set enable error: ", test_usr.enable()) time.sleep(1) - print "Set remove error: ", test_usr.remove() + print("Set remove error: ", test_usr.remove()) if __name__ == '__main__': diff --git a/crontab b/crontab new file mode 100644 index 0000000..d866a5a --- /dev/null +++ b/crontab @@ -0,0 +1,5 @@ +7 * * * * root /opt/zayavka-samba-ad/zayavka_reader.py /tmp/mailboxes.csv && scp /tmp/mailboxes.csv 10.2.2.13:/tmp/ && ssh 10.2.2.13 'php -f /root/importMailBoxes.php /tmp/mailboxes.csv' +37 * * * * root /opt/zayavka-samba-ad/zayavka_reader.py /tmp/mailboxes.csv && scp /tmp/mailboxes.csv 10.2.2.13:/tmp/ && ssh 10.2.2.13 'php -f /root/importMailBoxes.php /tmp/mailboxes.csv' + +2 * * * * root /opt/zayavka_samba_ad/importer.py +32 * * * * root /opt/zayavka_samba_ad/importer.py \ No newline at end of file diff --git a/zayavka_reader.py b/zayavka_reader.py index 8a810b2..e7cc319 100755 --- a/zayavka_reader.py +++ b/zayavka_reader.py @@ -1,9 +1,11 @@ -#!/usr/bin/python2 +#!/usr/bin/python3 # coding=utf-8 +import csv +import sys import MySQLdb -dbconn = {'host': '10.3.11.177', +dbconn = {'host': '10.3.11.226', 'user': 'readonlyuser', 'pass': 'Readonly@2006', 'base': 'techgrow'} @@ -80,18 +82,31 @@ def users_make_zayavka(users): return res +def mailboxes(data): + mboxes = [] + for user in data: + domain = user['LoginEmail'].split('@')[1] + name = user['LoginEmail'].split('@')[0] + mbox = ["Администратор", domain, name, user['Pass'], user['Changes'], user['Delete']] + mboxes.append(mbox) + return mboxes def main(): data, err = mysql_reader(dbconn, sql) - if not err: - users = users_make_zayavka(data) - x = '' - for user in users: - print(user, users[user]) - input(x) + if len(sys.argv) == 1: + if not err: + users = users_make_zayavka(data) + x = '' + for user in users: + print(user, users[user]) + input(x) + else: + print(err) else: - print(err) - + csvFile = sys.argv[1]; + with open(csvFile, 'w') as f: + write = csv.writer(f, quoting=csv.QUOTE_ALL) + write.writerows(mailboxes(data)) if __name__ == '__main__': main()