daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 449 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. import MySQLdb
  4. import time
  5. from subprocess import call
  6.  
  7. config = {
  8.     'user': '########',
  9.     'passwd': '########',
  10.     'host': '########',
  11.     'db': '########',
  12. }
  13.  
  14. conn = MySQLdb.connect(**config)
  15.  
  16. cur = conn.cursor()
  17. cur.execute("SELECT * FROM list_table")
  18. data = cur.fetchall()
  19.  
  20. dbAliases = set()
  21. exAliases = set()
  22.  
  23. for row in data:
  24.     dbAliases.add(row[3])
  25.  
  26. with open("sympa_aliases") as f:
  27.     aliasesFile = f.readlines()
  28.  
  29. for line in aliasesFile:
  30.     if line[0] != '#':
  31.         xline = line.split(' ')[0]
  32.         cutFrom = xline.find('-')+1
  33.         cutTo = xline.rfind('-')
  34.         exAliases.add(xline[cutFrom:(cutTo if cutTo > cutFrom else -1)])
  35.  
  36. newAliases = list(dbAliases - exAliases)
  37. newAliasTemplate = '''
  38. #------------------------------ {0}: list alias created {1}
  39. ml.int.uci.umk.pl-{0}: "| /usr/libexec/sympa/queue {0}@ml.int.uci.umk.pl"
  40. ml.int.uci.umk.pl-{0}-request: "| /usr/libexec/sympa/queue {0}-request@ml.int.uci.umk.pl"
  41. ml.int.uci.umk.pl-{0}-editor: "| /usr/libexec/sympa/queue {0}-editor@ml.int.uci.umk.pl"
  42. #ml.int.uci.umk.pl-{0}-subscribe: "| /usr/libexec/sympa/queue {0}-subscribe@ml.int.uci.umk.pl"
  43. ml.int.uci.umk.pl-{0}-unsubscribe: "| /usr/libexec/sympa/queue {0}-unsubscribe@ml.int.uci.umk.pl"
  44. ml.int.uci.umk.pl-{0}-owner: "| /usr/libexec/sympa/queue {0}@ml.int.uci.umk.pl"'''
  45. newAliasVirtualTemplate = '''
  46. #------------------------------ {0}: list alias created {1}
  47. {0}@ml.int.uci.umk.pl                    ml.int.uci.umk.pl-{0}
  48. {0}-request@ml.int.uci.umk.pl                    ml.int.uci.umk.pl-{0}-request
  49. {0}-editor@ml.int.uci.umk.pl                    ml.int.uci.umk.pl-{0}-editor
  50. {0}-unsubscribe@ml.int.uci.umk.pl                    ml.int.uci.umk.pl-{0}-unsubscribe
  51. {0}-owner@ml.int.uci.umk.pl                    ml.int.uci.umk.pl-{0}-owner'''
  52.  
  53. for alias in newAliases:
  54.     with open("sympa_aliases", "a") as f:
  55.         f.write(newAliasTemplate.format(alias, time.strftime("%x")))
  56.     with open("sympa_virtual", "a") as f:
  57.         f.write(newAliasVirtualTemplate.format(alias, time.strftime("%x")))
  58.  
  59. call(['postalias', 'sympa_aliases'])
  60. call(['postmap', 'sympa_virtual'])
  61. call(['systemctl', 'restart', 'postfix'])
  62. cur.close()
  63. conn.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top