Compare commits
24 Commits
f3c3fd231c
...
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 | |||
| c17318aea4 | |||
| 4450c6e07d |
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/*
|
||||
*.yml
|
||||
*.conf
|
||||
*.swp
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
|
||||
Needed files:
|
||||
|
||||
* ovh.conf as explained here : https://github.com/ovh/python-ovh
|
||||
* creds.yml containing nextcloud credentials for bill upload
|
||||
* ovh.conf as explained here : https://github.com/ovh/python-ovh.
|
||||
* creds.yml containing nextcloud credentials for bill upload.
|
||||
* data directory next to scripts.
|
||||
|
||||
46
ovh-bills.py
Executable file
46
ovh-bills.py
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
import ovh
|
||||
import yaml
|
||||
import pycurl
|
||||
|
||||
try:
|
||||
input = raw_input
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
conf = yaml.load(open('creds.yml'), Loader=yaml.SafeLoader)
|
||||
username = conf['nextcloud']['username']
|
||||
password = conf['nextcloud']['password']
|
||||
client = ovh.Client()
|
||||
bills = client.get('/me/bill')
|
||||
for bill in bills:
|
||||
url = conf['nextcloud']['url_factures']
|
||||
details = client.get('/me/bill/%s' % bill)
|
||||
r = requests.get(details['pdfUrl'], stream=True)
|
||||
file_path = "/tmp/" + bill + ".pdf"
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(r.content)
|
||||
f.close()
|
||||
url += bill + ".pdf"
|
||||
with open('/dev/null', 'wb') as output:
|
||||
c = pycurl.Curl()
|
||||
c.setopt(c.URL, url)
|
||||
c.setopt(c.USERPWD, '%s:%s' %(username, password))
|
||||
c.setopt(c.CUSTOMREQUEST, 'PROPFIND')
|
||||
c.setopt(c.WRITEDATA, output)
|
||||
c.perform()
|
||||
status = c.getinfo(c.RESPONSE_CODE)
|
||||
c.close()
|
||||
output.close()
|
||||
if status == 404:
|
||||
file = open(file_path)
|
||||
c = pycurl.Curl()
|
||||
c.setopt(c.URL, url)
|
||||
c.setopt(c.USERPWD, '%s:%s' %(username, password))
|
||||
c.setopt(c.UPLOAD, 1)
|
||||
c.setopt(c.READDATA, file)
|
||||
c.perform()
|
||||
c.close()
|
||||
file.close()
|
||||
@@ -1,18 +1,41 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
import argparse
|
||||
import json
|
||||
import ovh
|
||||
import pycurl
|
||||
import argparse
|
||||
import requests
|
||||
|
||||
try:
|
||||
input = raw_input
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
parser = argparse.ArgumentParser(description='Process arguments')
|
||||
parser.add_argument('domain', metavar='method', type=str, help='Function to use')
|
||||
parser.add_argument('--method', metavar='fr', type=str, help='domain to request from')
|
||||
def addCNAME(client,domain,fr,to):
|
||||
result = client.get(base_url + "/record",fieldType="CNAME",subDomain=fr)
|
||||
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()
|
||||
|
||||
# Instantiate. Visit https://api.ovh.com/createToken/?GET=/me
|
||||
@@ -20,7 +43,13 @@ args = parser.parse_args()
|
||||
client = ovh.Client()
|
||||
|
||||
# Grab bill list
|
||||
zone = client.get('/domain/zone/' + args.domain + '/record')
|
||||
for id in zone:
|
||||
entry = client.get('/domain/zone/' + args.domain + '/record/'+str(id))
|
||||
base_url = "/domain/zone/" + args.domain
|
||||
zone = client.get(base_url + "/record")
|
||||
if args.method == "list":
|
||||
for id in zone:
|
||||
entry = client.get(base_url + "/record/"+str(id))
|
||||
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)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import requests
|
||||
import ovh
|
||||
import pycurl
|
||||
import yaml
|
||||
|
||||
try:
|
||||
input = raw_input
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
conf = yaml.load(open('creds.yml'))
|
||||
user = conf['nextcloud']['username']
|
||||
password = conf['nextcloud']['password']
|
||||
client = ovh.Client()
|
||||
bills = client.get('/me/bill')
|
||||
for bill in bills:
|
||||
url = conf['nextcloud']['url_factures']
|
||||
details = client.get('/me/bill/%s' % bill)
|
||||
r = requests.get(details['pdfUrl'], stream=True)
|
||||
file_path = "/tmp/" + bill + ".pdf"
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(r.content)
|
||||
f.close()
|
||||
url += bill + ".pdf"
|
||||
file = open(file_path)
|
||||
c = pycurl.Curl()
|
||||
c.setopt(c.URL, url)
|
||||
c.setopt(c.USERPWD, '%s:%s' %(username, password))
|
||||
c.setopt(c.UPLOAD, 1)
|
||||
c.setopt(c.READDATA, file)
|
||||
c.perform()
|
||||
c.close()
|
||||
file.close()
|
||||
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.close()
|
||||
|
||||
def checkRedirExists(client,domain, fr,to):
|
||||
def checkRedirExists(client,domain,fr,to):
|
||||
mailbox = client.get('/email/domain/' + domain + '/redirection')
|
||||
for id in mailbox:
|
||||
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))
|
||||
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.add_argument('method', metavar='method', type=str, help='Function to use')
|
||||
parser.add_argument('domain', metavar='domain', type=str, help='domain')
|
||||
@@ -52,3 +61,5 @@ if (args.method == "write"):
|
||||
elif (args.method == "add"):
|
||||
if not (checkRedirExists(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