1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
from time import sleep
from gandi_tool import gandi_tool
from get_list_by_sql import individual_member_list, board_member_list, fsij_member_list
def string_repr(l):
return u'\n'.join(sorted(l))
if __name__ == "__main__":
url='https://rpc.gandi.net/xmlrpc/'
encrypted_key_file='api-key-info.json.gpg'
domain='fsij.org'
encrypted_list_file='fsij_list.json.gpg'
import subprocess, json
command=['gpg', '--decrypt', '-o', '-', encrypted_list_file]
p = subprocess.Popen(command, stdout=subprocess.PIPE)
listdata_string = p.communicate()[0]
fsij_aliases = json.loads(listdata_string)
g=gandi_tool(url, encrypted_key_file, domain)
print("API Version: %s" % g.api_version()['api_version'])
info=g.info()
print("Domain owner handle: %s" % info['contacts']['owner']['handle'])
print("Current number of forwards %d" % g.forward_count())
for i in fsij_aliases.items():
l = g.forward_list({ 'source' : i[0]})
dest = i[1]
if l:
if string_repr(l[0]['destinations']) == string_repr(dest):
print("Skip: %s" % i[0])
else:
print("Update: %s" % i[0])
g.forward_update(i[0], {'destinations': dest})
else:
print("Create: %s" % i[0])
g.forward_create(i[0], {'destinations': dest})
for i in individual_member_list:
l = g.forward_list({ 'source' : i[0]})
dest = i[1]
if l:
if string_repr(l[0]['destinations']) == string_repr(dest):
print("Skip: %s" % i[0])
else:
print("Update: %s" % i[0])
g.forward_update(i[0], {'destinations': dest})
else:
print("Create: %s" % i[0])
g.forward_create(i[0], {'destinations': dest})
l = g.forward_list({ 'source' : 'board' })
dest = board_member_list
if l:
if string_repr(l[0]['destinations']) == string_repr(dest):
print("Skip: %s" % 'board')
else:
print("Update: %s" % 'board')
# g.forward_update('board', {'destinations': dest})
else:
print("Create: %s" % 'board')
g.forward_create('board', {'destinations': dest})
l = g.forward_list({ 'source' : 'members' })
dest = fsij_member_list
if l:
if string_repr(l[0]['destinations']) == string_repr(dest):
print("Skip: %s" % 'members')
else:
print("Update: %s" % 'members')
g.forward_update('members', {'destinations': dest})
else:
print("Create: %s" % 'members')
g.forward_create('members', {'destinations': dest})
print("Current number of forwards %d" % g.forward_count())
for entry in g.forward_list():
print("%s -> %s" % (entry['source'], entry['destinations']))
|