switching to argument based domain for mail script
This commit is contained in:
parent
5ffeebbd1d
commit
b8f206ee32
25
ovh-mail.py
25
ovh-mail.py
@ -6,19 +6,19 @@ import pycurl
|
|||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
def writeRedirectionsToFile(client):
|
def writeRedirectionsToFile(client,domain):
|
||||||
# Grab bill list
|
# Grab bill list
|
||||||
mailbox = client.get('/email/domain/hyrule.ovh/redirection')
|
mailbox = client.get('/email/domain/' + domain + '/redirection')
|
||||||
file = open(redir_file,'wt')
|
file = open(redir_file,'wt')
|
||||||
for id in mailbox:
|
for id in mailbox:
|
||||||
redirection = client.get('/email/domain/hyrule.ovh/redirection/'+str(id))
|
redirection = client.get('/email/domain/' + domain + '/redirection/'+str(id))
|
||||||
file.write(redirection['from']+','+redirection['to']+','+redirection['id']+'\n')
|
file.write(redirection['from']+','+redirection['to']+','+redirection['id']+'\n')
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def checkRedirExists(client,fr,to):
|
def checkRedirExists(client,domain, fr,to):
|
||||||
mailbox = client.get('/email/domain/hyrule.ovh/redirection')
|
mailbox = client.get('/email/domain/' + domain + '/redirection')
|
||||||
for id in mailbox:
|
for id in mailbox:
|
||||||
redirection = client.get('/email/domain/hyrule.ovh/redirection/'+str(id))
|
redirection = client.get('/email/domain/' + domain +'/redirection/'+str(id))
|
||||||
if (redirection['from'] == fr and redirection['to'] == to):
|
if (redirection['from'] == fr and redirection['to'] == to):
|
||||||
print("Redirection existante")
|
print("Redirection existante")
|
||||||
return id
|
return id
|
||||||
@ -28,18 +28,19 @@ def checkRedirExists(client,fr,to):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def addRedirection(client,fr,to):
|
def addRedirection(client,domain,fr,to):
|
||||||
result = client.post('/email/domain/hyrule.ovh/redirection',_from=fr,localCopy=False,to=to)
|
result = client.post('/email/domain/'+ domain +'/redirection',_from=fr,localCopy=False,to=to)
|
||||||
print(json.dumps(result,indent=4))
|
print(json.dumps(result,indent=4))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Process arguments')
|
parser = argparse.ArgumentParser(description='Process arguments')
|
||||||
parser.add_argument('method', metavar='method', type=str, help='Function to use')
|
parser.add_argument('method', metavar='method', type=str, help='Function to use')
|
||||||
|
parser.add_argument('domain', metavar='domain', type=str, help='domain')
|
||||||
parser.add_argument('--fr', metavar='fr', type=str, help='from mail address')
|
parser.add_argument('--fr', metavar='fr', type=str, help='from mail address')
|
||||||
parser.add_argument('--to', metavar='to', type=str, help='to mail address')
|
parser.add_argument('--to', metavar='to', type=str, help='to mail address')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
redir_file = '/var/scripts/ovh_api/data/redirections.txt'
|
redir_file = './data/redirections.txt'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
input = raw_input
|
input = raw_input
|
||||||
@ -47,7 +48,7 @@ except NameError:
|
|||||||
pass
|
pass
|
||||||
client = ovh.Client()
|
client = ovh.Client()
|
||||||
if (args.method == "write"):
|
if (args.method == "write"):
|
||||||
writeRedirectionsToFile(client)
|
writeRedirectionsToFile(client,args.domain)
|
||||||
elif (args.method == "add"):
|
elif (args.method == "add"):
|
||||||
if not (checkRedirExists(client,args.fr,args.to)):
|
if not (checkRedirExists(client,args.domain,args.fr,args.to)):
|
||||||
addRedirection(client,args.fr,args.to)
|
addRedirection(client,args.domain,args.fr,args.to)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user