Compare commits
22 Commits
c17318aea4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 49f39726e5 | |||
| b762463de9 | |||
| f81c156097 | |||
| 1e621d3ab9 | |||
| f28ef80208 | |||
| ea3d47a9bc | |||
| c808018c21 | |||
| 7001dbe550 | |||
| 584ad86f33 | |||
| 46883644b2 | |||
| 0db7f68ae8 | |||
| 72530e2db5 | |||
| 43a2ddc152 | |||
| 6d98a877e1 | |||
| 834b214dcf | |||
| 4d125b09cf | |||
| 5c91678ac6 | |||
| 0d9360c809 | |||
| 93b83f08d0 | |||
| 93ee76e130 | |||
| 5c8238bed3 | |||
| f1bbd0c274 |
17
.drone.yml
Normal file
17
.drone.yml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: syntax
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: arm
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: syntax
|
||||||
|
pull: if-not-exists
|
||||||
|
image: python:3.7-slim-buster
|
||||||
|
commands:
|
||||||
|
- apt update
|
||||||
|
- apt install -y pylint libcurl4-openssl-dev libssl-dev python-dev gcc
|
||||||
|
- pip3 install -r requirements.txt
|
||||||
|
- pylint *.py
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,6 @@
|
|||||||
|
!.drone.yml
|
||||||
|
# IGNORE
|
||||||
data/*
|
data/*
|
||||||
*.yml
|
*.yml
|
||||||
*.conf
|
*.conf
|
||||||
|
*.swp
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
Needed files:
|
Needed files:
|
||||||
|
|
||||||
* ovh.conf as explained here : https://github.com/ovh/python-ovh
|
* ovh.conf as explained here : https://github.com/ovh/python-ovh.
|
||||||
* creds.yml containing nextcloud credentials for bill upload
|
* creds.yml containing nextcloud credentials for bill upload.
|
||||||
|
* data directory next to scripts.
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
import ovh
|
import ovh
|
||||||
import pycurl
|
|
||||||
import yaml
|
import yaml
|
||||||
|
import pycurl
|
||||||
|
|
||||||
try:
|
try:
|
||||||
input = raw_input
|
input = raw_input
|
||||||
@@ -24,7 +24,7 @@ for bill in bills:
|
|||||||
f.write(r.content)
|
f.write(r.content)
|
||||||
f.close()
|
f.close()
|
||||||
url += bill + ".pdf"
|
url += bill + ".pdf"
|
||||||
with open('/dev/null','wb') as output:
|
with open('/dev/null', 'wb') as output:
|
||||||
c = pycurl.Curl()
|
c = pycurl.Curl()
|
||||||
c.setopt(c.URL, url)
|
c.setopt(c.URL, url)
|
||||||
c.setopt(c.USERPWD, '%s:%s' %(username, password))
|
c.setopt(c.USERPWD, '%s:%s' %(username, password))
|
||||||
@@ -34,7 +34,7 @@ for bill in bills:
|
|||||||
status = c.getinfo(c.RESPONSE_CODE)
|
status = c.getinfo(c.RESPONSE_CODE)
|
||||||
c.close()
|
c.close()
|
||||||
output.close()
|
output.close()
|
||||||
if (status == 404):
|
if status == 404:
|
||||||
file = open(file_path)
|
file = open(file_path)
|
||||||
c = pycurl.Curl()
|
c = pycurl.Curl()
|
||||||
c.setopt(c.URL, url)
|
c.setopt(c.URL, url)
|
||||||
|
|||||||
@@ -1,18 +1,41 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import requests
|
import argparse
|
||||||
|
import json
|
||||||
import ovh
|
import ovh
|
||||||
import pycurl
|
import pycurl
|
||||||
import argparse
|
import requests
|
||||||
|
|
||||||
try:
|
try:
|
||||||
input = raw_input
|
input = raw_input
|
||||||
except NameError:
|
except NameError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Process arguments')
|
def addCNAME(client,domain,fr,to):
|
||||||
parser.add_argument('domain', metavar='method', type=str, help='Function to use')
|
result = client.get(base_url + "/record",fieldType="CNAME",subDomain=fr)
|
||||||
parser.add_argument('--method', metavar='fr', type=str, help='domain to request from')
|
if not result:
|
||||||
|
result = client.post(base_url + "/record",fieldType="CNAME",subDomain=fr,target=to)
|
||||||
|
print(json.dumps(result,indent=4))
|
||||||
|
result = client.post(base_url+ "/refresh")
|
||||||
|
print("Refresh zone trigger")
|
||||||
|
else:
|
||||||
|
print("CNAME already existing")
|
||||||
|
|
||||||
|
def addA(client,domain,fr,to):
|
||||||
|
result = client.get(base_url + "/record",fieldType="A",subDomain=fr)
|
||||||
|
if not result:
|
||||||
|
result = client.post(base_url + "/record",fieldType="A",subDomain=fr,target=to)
|
||||||
|
print(json.dumps(result,indent=4))
|
||||||
|
result = client.post(base_url+ "/refresh")
|
||||||
|
print("Refresh zone trigger")
|
||||||
|
else:
|
||||||
|
print("A record already existing")
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Process arguments")
|
||||||
|
parser.add_argument("domain", metavar="domain", type=str, help="Domain to request")
|
||||||
|
parser.add_argument("--method", metavar="type", type=str, help="Function to use. Ex: addCNAME")
|
||||||
|
parser.add_argument("--src", metavar="src", type=str, help="Source subdomain")
|
||||||
|
parser.add_argument("--dest", metavar="dst", type=str, help="Dest IP or domain")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Instantiate. Visit https://api.ovh.com/createToken/?GET=/me
|
# Instantiate. Visit https://api.ovh.com/createToken/?GET=/me
|
||||||
@@ -20,7 +43,13 @@ args = parser.parse_args()
|
|||||||
client = ovh.Client()
|
client = ovh.Client()
|
||||||
|
|
||||||
# Grab bill list
|
# Grab bill list
|
||||||
zone = client.get('/domain/zone/' + args.domain + '/record')
|
base_url = "/domain/zone/" + args.domain
|
||||||
for id in zone:
|
zone = client.get(base_url + "/record")
|
||||||
entry = client.get('/domain/zone/' + args.domain + '/record/'+str(id))
|
if args.method == "list":
|
||||||
|
for id in zone:
|
||||||
|
entry = client.get(base_url + "/record/"+str(id))
|
||||||
print(entry)
|
print(entry)
|
||||||
|
elif args.method == "addCNAME":
|
||||||
|
addCNAME(client,args.domain,args.src,args.dest)
|
||||||
|
elif args.method == "addA":
|
||||||
|
addA(client,args.domain,args.src,args.dest)
|
||||||
|
|||||||
13
ovh-mail.py
13
ovh-mail.py
@@ -15,7 +15,7 @@ def writeRedirectionsToFile(client,domain):
|
|||||||
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,domain, fr,to):
|
def checkRedirExists(client,domain,fr,to):
|
||||||
mailbox = client.get('/email/domain/' + domain + '/redirection')
|
mailbox = client.get('/email/domain/' + domain + '/redirection')
|
||||||
for id in mailbox:
|
for id in mailbox:
|
||||||
redirection = client.get('/email/domain/' + domain +'/redirection/'+str(id))
|
redirection = client.get('/email/domain/' + domain +'/redirection/'+str(id))
|
||||||
@@ -33,6 +33,15 @@ def addRedirection(client,domain,fr,to):
|
|||||||
print(json.dumps(result,indent=4))
|
print(json.dumps(result,indent=4))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def delRedirection(client,domain,fr,to):
|
||||||
|
id_redir = checkRedirExists(client,domain,fr,to)
|
||||||
|
if not id_redir:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
result = client.delete('/email/domain/'+ domain +'/redirection/' + str(id_redir))
|
||||||
|
print(json.dumps(result,indent=4))
|
||||||
|
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('domain', metavar='domain', type=str, help='domain')
|
||||||
@@ -52,3 +61,5 @@ if (args.method == "write"):
|
|||||||
elif (args.method == "add"):
|
elif (args.method == "add"):
|
||||||
if not (checkRedirExists(client,args.domain,args.fr,args.to)):
|
if not (checkRedirExists(client,args.domain,args.fr,args.to)):
|
||||||
addRedirection(client,args.domain,args.fr,args.to)
|
addRedirection(client,args.domain,args.fr,args.to)
|
||||||
|
elif (args.method == "del"):
|
||||||
|
status = delRedirection(client,args.domain,args.fr,args.to)
|
||||||
|
|||||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
argparse
|
||||||
|
pycurl
|
||||||
|
ovh
|
||||||
|
requests
|
||||||
Reference in New Issue
Block a user