diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..7394366 --- /dev/null +++ b/.env.dist @@ -0,0 +1,4 @@ +OVH_APPLICATION_KEY= +OVH_APPLICATION_SECRET= +OVH_CONSUMER_KEY= +OVH_ENDPOINT= diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fad4592..6693223 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,7 +3,6 @@ version: 2 updates: - # Maintain dependencies for GitHub Actions - package-ecosystem: "github-actions" directory: "/" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 53da2a2..170e83f 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -55,4 +55,4 @@ jobs: ANSIBLE_DIRECTORY: . VALIDATE_PYTHON_ISORT: false VALIDATE_PYTHON_FLAKE8: false - VALIDATE_PYTHON_BLACK: false \ No newline at end of file + VALIDATE_PYTHON_BLACK: false diff --git a/.gitignore b/.gitignore index b0a49cd..15755a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.csv *.log +megalinter-reports/ # Created by https://www.toptal.com/developers/gitignore/api/git,notepadpp,vs,python # Edit at https://www.toptal.com/developers/gitignore?templates=git,notepadpp,vs,python @@ -522,12 +523,7 @@ MigrationBackup/ # Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode ### VisualStudioCode ### -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets +.vscode/ # Local History for Visual Studio Code .history/ diff --git a/Delete-A-Batily-test.py b/Delete-A-Batily-test.py new file mode 100644 index 0000000..1a2c053 --- /dev/null +++ b/Delete-A-Batily-test.py @@ -0,0 +1,78 @@ +import json +import os # pour récupérer les variables d'env +from typing import List + +import ovh # export ovh api +from decouple import config + +############################################################### +# RENSEIGNEZ LE(S) NOM(S) DE DOMAINES # +############################################################### +include_domains = ["batily.org"] + +############################################################### +# RENSEIGNEZ L'ADRESSE IP A SUPPRIMER # +############################################################### +address_to_delete = "7.7.7.7" + + +class OVHClient: + def __init__(self, application_key, application_secret, consumer_key): + self.client = ovh.Client( + endpoint="ovh-eu", + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), + ) + + def get_record_type_a(self, zone): + records = self.client.get("/domain/zone/%s/record?fieldType=A" % zone) + valid_records = [] + for record in records: + r = self.get_record(zone, record) + if r["target"] == address_to_delete: + valid_records.append(record) + return valid_records + + def get_record(self, zone: str, record: str): + return self.client.get("/domain/zone/%s/record/%s" % (zone, record)) + + def delete_record(self, zone: str, record_id: str): + return self.client.delete( + "/domain/zone/%s/record/%s" % (zone, record_id), + ) + + def refresh_zone(self, zone: str): + return self.client.post("/domain/zone/%s/refresh" % zone) + + def set_all(self): + for zo in include_domains: + print() + print("#####################################") + print("Zone :", zo) + print("#####################################") + print() + # print("type of zones : ", type(zo)) + print("List of records ID to delete:", self.get_record_type_a(zo)) + print("") + # print("type of records", type(self.get_record_type_a(zo))) + for record_a in self.get_record_type_a(zo): + print("---------------------------") + print("Record", record_a, "details :") + print("---------------------------") + display = self.get_record(zo, record_a) + print(json.dumps(display, indent=4, sort_keys=True)) + print() + self.delete_record(zo, record_a) + print("All records in the list have been successfully deleted.") + print() + print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") + print("Refreshing zone :", zo) + print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + print() + self.refresh_zone(zo) + print("Script ended successfully") + +client = OVHClient(application_key="", application_secret="", consumer_key="") +client.set_all() + diff --git a/Delete-A-Crysalide_Releveplus.py b/Delete-A-Crysalide_Releveplus.py new file mode 100644 index 0000000..b504e53 --- /dev/null +++ b/Delete-A-Crysalide_Releveplus.py @@ -0,0 +1,76 @@ +import json +import os # pour récupérer les variables d'env +from typing import List + +import ovh # export ovh api +from decouple import config + +############################################################### +# RENSEIGNEZ LE(S) NOM(S) DE DOMAINES # +############################################################### +include_domains = ["crysalide.fr"] + +############################################################### +# RENSEIGNEZ L'ADRESSE IP A SUPPRIMER # +############################################################### +address_to_delete = "37.59.56.80" + +class OVHClient: + def __init__(self, application_key, application_secret, consumer_key): + self.client = ovh.Client( + endpoint="ovh-eu", + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), + ) + + def get_record_type_a(self, zone): + records = self.client.get("/domain/zone/%s/record?fieldType=A" % zone) + valid_records = [] + for record in records: + r = self.get_record(zone, record) + if r["target"] == address_to_delete: + valid_records.append(record) + return valid_records + + def get_record(self, zone: str, record: str): + return self.client.get("/domain/zone/%s/record/%s" % (zone, record)) + + def delete_record(self, zone: str, record_id: str): + return self.client.delete( + "/domain/zone/%s/record/%s" % (zone, record_id), + ) + + def refresh_zone(self, zone: str): + return self.client.post("/domain/zone/%s/refresh" % zone) + + def set_all(self): + for zo in include_domains: + print() + print("#####################################") + print("Zone :", zo) + print("#####################################") + print() + # print("type of zones : ", type(zo)) + print("List of records ID to delete:", self.get_record_type_a(zo)) + print("") + # print("type of records", type(self.get_record_type_a(zo))) + for record_a in self.get_record_type_a(zo): + print("---------------------------") + print("Record", record_a, "details :") + print("---------------------------") + display = self.get_record(zo, record_a) + print(json.dumps(display, indent=4, sort_keys=True)) + print() + self.delete_record(zo, record_a) + print("All records in the list have been successfully deleted.") + print() + print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<") + print("Refreshing zone :", zo) + print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + print() + self.refresh_zone(zo) + print("Script ended successfully") + +client = OVHClient(application_key="", application_secret="", consumer_key="") +client.set_all() diff --git a/Delete-SPFrecords_typeSPF.py.txt b/Delete-SPFrecords_typeSPF.py.txt index ff1ce75..a73e578 100644 --- a/Delete-SPFrecords_typeSPF.py.txt +++ b/Delete-SPFrecords_typeSPF.py.txt @@ -10,9 +10,9 @@ # def __init__(self, application_key, application_secret, consumer_key): # self.client = ovh.Client( # endpoint="ovh-eu", -# application_key=config('ovh_application_key'), -# application_secret=config('ovh_application_secret'), -# consumer_key=config('ovh_consumer_key'), +# application_key=config('OVH_APPLICATION_KEY'), +# application_secret=config('OVH_APPLICATION_SECRET'), +# consumer_key=config('OVH_CONSUMER_KEY'), # ) # def get_zones(self) -> List[str]: diff --git a/Delete-SPFrecords_typeTXT.py.txt b/Delete-SPFrecords_typeTXT.py.txt index e32d0b9..8214172 100644 --- a/Delete-SPFrecords_typeTXT.py.txt +++ b/Delete-SPFrecords_typeTXT.py.txt @@ -10,9 +10,9 @@ # def __init__(self, application_key, application_secret, consumer_key): # self.client = ovh.Client( # endpoint="ovh-eu", -# application_key=config('ovh_application_key'), -# application_secret=config('ovh_application_secret'), -# consumer_key=config('ovh_consumer_key'), +# application_key=config('OVH_APPLICATION_KEY'), +# application_secret=config('OVH_APPLICATION_SECRET'), +# consumer_key=config('OVH_CONSUMER_KEY'), # ) # def get_zones(self) -> List[str]: diff --git a/Enable-DNSSEC.py b/Enable-DNSSEC.py deleted file mode 100644 index 528ded2..0000000 --- a/Enable-DNSSEC.py +++ /dev/null @@ -1,43 +0,0 @@ - -import os # pour récupérer les variables d'env -import ovh # export ovh api -from decouple import config -from typing import List - -included_domains = ["navalcheck.fr"] - - -class OVHClient: - def __init__(self, application_key, application_secret, consumer_key): - self.client = ovh.Client( - endpoint="ovh-eu", - application_key=config('ovh_application_key'), - application_secret=config('ovh_application_secret'), - consumer_key=config('ovh_consumer_key'), - ) - - def get_zones(self) -> List[str]: - zones = self.client.get("/domain/zone") - return [i for i in zones if i in included_domains] - - def get_dnssec(self, zone): - print("Getting DNSSEC for domain %s" % (zone)) - return self.client.get('/domain/zone/%s/dnssec' % zone) - - def set_dnssec(self, zone: str): - record = self.get_dnssec(zone) - if not record: - print("Setting DNSSEC for domain %s" % (zone)) - return self.client.post('/domain/zone/%s/dnssec' % zone) - else: - print(" DNSSEC for domain %s already activated" % (zone)) - return - - def set_dnssec_all(self): - for zzone in self.get_zones(): - self.set_dnssec(zzone) - - -client = OVHClient(application_key="", application_secret="", - consumer_key="") -client.set_dnssec_all() \ No newline at end of file diff --git a/Enable-DNSSEC_exclude.py b/Enable-DNSSEC_exclude.py new file mode 100644 index 0000000..e35a7b0 --- /dev/null +++ b/Enable-DNSSEC_exclude.py @@ -0,0 +1,41 @@ +import os # pour récupérer les variables d'env +from typing import List + +import ovh # export ovh api +from decouple import config + +excluded_domains = ["btp-consultants.fr"] + + +class OVHClient: + def __init__(self, application_key, application_secret, consumer_key): + self.client = ovh.Client( + endpoint="ovh-eu", + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), + ) + + def get_zones(self) -> List[str]: + zones = self.client.get("/domain/zone") + return [i for i in zones if i not in excluded_domains] + + def set_dnssec(self, zone: str): + print("Getting DNSSEC for domain %s" % (zone)) + status_dnssec = str(self.client.get("/domain/zone/%s/dnssec" % zone)) + print(status_dnssec) + if "enableInProgress" in status_dnssec: + print("DNSSEC is already in progress for domain %s" % (zone)) + elif "disabled" in status_dnssec: + print("Enabling DNSSEC for domain %s" % (zone)) + return self.client.post("/domain/zone/%s/dnssec" % zone) + else: + print("DNSSEC is already activated for domain %s" % (zone)) + + def set_dnssec_all(self): + for zzone in self.get_zones(): + self.set_dnssec(zzone) + + +client = OVHClient(application_key="", application_secret="", consumer_key="") +client.set_dnssec_all() diff --git a/Enable-DNSSEC_include.py b/Enable-DNSSEC_include.py new file mode 100644 index 0000000..c5c7ce2 --- /dev/null +++ b/Enable-DNSSEC_include.py @@ -0,0 +1,41 @@ +import os # pour récupérer les variables d'env +from typing import List + +import ovh # export ovh api +from decouple import config + +included_domains = ["parkyze.in", "bet-access.com", "mbacity.fr"] + + +class OVHClient: + def __init__(self, application_key, application_secret, consumer_key): + self.client = ovh.Client( + endpoint="ovh-eu", + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), + ) + + def get_zones(self) -> List[str]: + zones = self.client.get("/domain/zone") + return [i for i in zones if i in included_domains] + + def set_dnssec(self, zone: str): + print("Getting DNSSEC for domain %s" % (zone)) + status_dnssec = str(self.client.get("/domain/zone/%s/dnssec" % zone)) + print(status_dnssec) + if "enableInProgress" in status_dnssec: + print("DNSSEC is already in progress for domain %s" % (zone)) + elif "disabled" in status_dnssec: + print("Enabling DNSSEC for domain %s" % (zone)) + return self.client.post("/domain/zone/%s/dnssec" % zone) + else: + print("DNSSEC is already activated for domain %s" % (zone)) + + def set_dnssec_all(self): + for zzone in self.get_zones(): + self.set_dnssec(zzone) + + +client = OVHClient(application_key="", application_secret="", consumer_key="") +client.set_dnssec_all() diff --git a/List-DNSZonesInDomains.py b/List-DNSZonesInDomains.py index eae3ca9..d7bc6b9 100644 --- a/List-DNSZonesInDomains.py +++ b/List-DNSZonesInDomains.py @@ -1,12 +1,13 @@ # -*- encoding: utf-8 -*- # -''' +""" First, install the latest release of Python wrapper: $ pip install ovh -''' +""" import json -import ovh # export ovh api import os # pour récupérer les variables d'env import re # import regex + +import ovh # export ovh api from decouple import config # if service expired, you need to exclude them. @@ -15,10 +16,10 @@ # Instantiate. Visit https://api.ovh.com/createToken/?GET=/me # # to get your credentials client = ovh.Client( - endpoint=config('ovh_endpoint'), - application_key=config('ovh_application_key'), - application_secret=config('ovh_application_secret'), - consumer_key=config('ovh_consumer_key'), + endpoint=config("OVH_ENDPOINT"), + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), ) # print headers @@ -26,13 +27,13 @@ # Print dns zone for each domain -domains = client.get('/domain/zone/') -for domain in domains : - if domain not in exclude_domains : - details = client.get('/domain/zone/%s/export' % domain) - detailssansovh = re.sub('.*.ovh.net.*', '', details) - regex1 = '.*IN.A.*' - regex2 = '.*IN.CNAME.*' +domains = client.get("/domain/zone/") +for domain in domains: + if domain not in exclude_domains: + details = client.get("/domain/zone/%s/export" % domain) + detailssansovh = re.sub(".*.ovh.net.*", "", details) + regex1 = ".*IN.A.*" + regex2 = ".*IN.CNAME.*" regexList = [regex1, regex2] for regex in regexList: @@ -41,17 +42,17 @@ tmp = finding.split() # cas sous domaine vide - if (tmp[0] == 'IN'): - tmp.insert(0, '') + if tmp[0] == "IN": + tmp.insert(0, "") # remove 'IN' - tmp.remove('IN') + tmp.remove("IN") # add domain tmp.insert(0, domain) for i, elem in enumerate(tmp): - print('"' + elem + '"', end='') - if (i != len(tmp)-1): - print(';', end='') + print('"' + elem + '"', end="") + if i != len(tmp) - 1: + print(";", end="") print() diff --git a/List-Domains.py b/List-Domains.py index f4b4368..bc762a8 100644 --- a/List-Domains.py +++ b/List-Domains.py @@ -2,25 +2,25 @@ # import json -import ovh # export ovh api -import os # pour récupérer les variables d'env +import os # pour récupérer les variables d'env + +import ovh # export ovh api from decouple import config # Instantiate. Visit https://api.ovh.com/createToken/?GET=/me # # to get your credentials client = ovh.Client( - endpoint= config('ovh_endpoint') , - application_key= config('ovh_application_key') , - application_secret= config('ovh_application_secret') , - consumer_key= config('ovh_consumer_key') , + endpoint=config("OVH_ENDPOINT"), + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), ) # print headers print('"domain"') # Print dns zone for each domain -domains = client.get('/domain/zone/') +domains = client.get("/domain/zone/") for i, elem in enumerate(domains): - print('"' + elem + '"', end='') - print() - + print('"' + elem + '"', end="") + print() diff --git a/README.md b/README.md index b1cf751..3d1fef1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # OVH API -[![GitHub Super-Linter](https://github.com/rdia9/ovh-api/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/marketplace/actions/super-linter) +[![GitHub Super-Linter](https://github.com/rdia9/ovh-api/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/rdia9/ovh-api/actions/workflows/linter.yml) Ce repository permet des extractions simplifiées via l'API OVH @@ -20,29 +20,71 @@ IP from OVH or SQY - ovh_application_secret (keepass) - ovh_consumer_key (keepass) -To create OVH API credentials go there -// It needs the following Endpoints : -// - GET /domain/zone -// - GET /domain/zone/*/record -// - GET /domain/zone/*/record/* -// - PUT /domain/zone/*/record/* -// - POST /domain/zone/*/record +To create OVH API credentials go there \ + It needs the following Endpoints : + +- GET /domain/zone +- GET /domain/zone/*/record +- GET /domain/zone/*/record/* +- PUT /domain/zone/*/record/* +- POST /domain/zone/*/record + +### Python + +```pip3 install -r requirement.txt``` ## Execution +- Inventorier + ```bash -pip3 install -r requirement.txt +# Lister les domaines python3 List-Domains.py > DomainsList.csv +``` + +```bash +# Lister les Urls publiées python3 List-DNSZoneIsnDomains.py > DNSZonesList.csv -python3 Update-SPFrecords_include.py > UpdateSPFrecords_include.log # Noter dans le script les domaines à inclure -python3 Update-SPFrecords_exclude.py > UpdateSPFrecords_exclude.log # Noter dans le script les domaines à exclure -python3 Update-DMARCrecords_include.py > UpdateDMARCrecords_include.log # Noter dans le script les domaines à inclure -python3 Update-DMARCrecords_exclude.py > UpdateDMARCrecords_exluded.log # Noter dans le script les domaines à exclure -python3 Enable-DNSSEC.py > EnableDNSSEC.log +``` + +- Action sur les SPF + +```bash +python3 Update-SPFrecords_include.py > UpdateSPFrecords_include.log +# Noter dans le script les domaines à inclure + +python3 Update-SPFrecords_exclude.py > UpdateSPFrecords_exclude.log +# Noter dans le script les domaines à exclure +``` + +- Action sur les DMARC + +```bash +python3 Update-DMARCrecords_include.py > UpdateDMARCrecords_include.log +# Noter dans le script les domaines à inclure + +python3 Update-DMARCrecords_exclude.py > UpdateDMARCrecords_exluded.log +# Noter dans le script les domaines à exclure +``` + +- Action sur les DNSSEC + +```bash +python3 Enable-DNSSEC_exclude > EnableDNSSEC_excluded.log +# Noter dans le script les domaines à exclure + +python3 Enable-DNSSEC_include > EnableDNSSEC_included.log +# Noter dans le script les domaines à inclure +``` + +- Action sur une IP spécifique + +```bash +python3 Delete-Releveplus-Crysalide.py > delete-Releveplus.log +# Renseigner le/les domaine(s) dans le script ainsi que l'IP à supprimer ``` ## ✒️ Authors [Raphaël Diacamille](https://github.com/rdia9) \ -[Paul Baudrier](https://github.com/paulbaudrier) \ -[Paul Waldburger](https://github.com/Paul-Waldburger-BTPConsultants) +[Paul Baudrier](https://github.com/paulbaudrier) diff --git a/Update-DMARCrecords_exclude.py b/Update-DMARCrecords_exclude.py index 8056535..1970432 100644 --- a/Update-DMARCrecords_exclude.py +++ b/Update-DMARCrecords_exclude.py @@ -1,19 +1,39 @@ +import os # pour récupérer les variables d'env from typing import List + import ovh # export ovh api -import os # pour récupérer les variables d'env from decouple import config -exclude_domains = ["bimscreen.fr","btp-consultants.fr", "citae.fr", "mbacity.com", "btp-diagnostics.fr", "navalcheck.fr","parkyze.com","btp-mornings.fr","citybuild.fr","databuildr.com","formactu.fr","groupe-btpconsultants.fr","nextiim.com","novalian.com","novalian.fr","novalian.io"] -dmarc_value = str("v=DMARC1; p=reject; rua=mailto:rsi@btp-consultants.fr; ruf=mailto:rsi@btp-consultants.fr; rf=afrf; pct=100; ri=86400") +exclude_domains = [ + "bimscreen.fr", + "btp-consultants.fr", + "citae.fr", + "mbacity.com", + "btp-diagnostics.fr", + "navalcheck.fr", + "parkyze.com", + "btp-mornings.fr", + "citybuild.fr", + "databuildr.com", + "formactu.fr", + "groupe-btpconsultants.fr", + "nextiim.com", + "novalian.com", + "novalian.fr", + "novalian.io", +] +dmarc_value = str( + "v=DMARC1; p=reject; rua=mailto:rsi@btp-consultants.fr; ruf=mailto:rsi@btp-consultants.fr; rf=afrf; pct=100; ri=86400" +) class DMARCClient: def __init__(self, application_key, application_secret, consumer_key): self.client = ovh.Client( endpoint="ovh-eu", - application_key=config('ovh_application_key'), - application_secret=config('ovh_application_secret'), - consumer_key=config('ovh_consumer_key'), + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), ) def get_zones(self) -> List[str]: @@ -21,8 +41,7 @@ def get_zones(self) -> List[str]: return [i for i in zones if i not in exclude_domains] def get_dmarc(self, zone): - records = self.client.get('/domain/zone/%s/record?fieldType=DMARC' - % zone) + records = self.client.get("/domain/zone/%s/record?fieldType=DMARC" % zone) for record in records: r = self.get_record(zone, record) if r["target"].startswith("v=DMARC1"): @@ -30,14 +49,16 @@ def get_dmarc(self, zone): return def get_record(self, zone: str, record: str): - return self.client.get('/domain/zone/%s/record/%s' % (zone, record)) + return self.client.get("/domain/zone/%s/record/%s" % (zone, record)) def set_record(self, zone, value): - return self.client.post('/domain/zone/%s/record' % zone, - target=value, - fieldType="DMARC", - ttl=3600, - subDomain="_dmarc") + return self.client.post( + "/domain/zone/%s/record" % zone, + target=value, + fieldType="DMARC", + ttl=3600, + subDomain="_dmarc", + ) def set_dmarc(self, zone: str, dmarc: str): record = self.get_dmarc(zone) @@ -50,13 +71,13 @@ def set_dmarc(self, zone: str, dmarc: str): return def update_record(self, zone: str, value: str, record_id: str): - return self.client.put('/domain/zone/%s/record/%s' % (zone, record_id), - target=value, - ttl=3600) + return self.client.put( + "/domain/zone/%s/record/%s" % (zone, record_id), target=value, ttl=3600 + ) def refresh_zone(self, zone: str): print("Refresh zone %s" % (zone)) - return self.client.post('/domain/zone/%s/refresh' % zone) + return self.client.post("/domain/zone/%s/refresh" % zone) def set_dmarc_all(self, dmarc: str): for zo in self.get_zones(): @@ -64,6 +85,5 @@ def set_dmarc_all(self, dmarc: str): self.refresh_zone(zo) -client = DMARCClient(application_key="", application_secret="", - consumer_key="") +client = DMARCClient(application_key="", application_secret="", consumer_key="") client.set_dmarc_all(dmarc_value) diff --git a/Update-DMARCrecords_include.py b/Update-DMARCrecords_include.py index b544435..81bd1d7 100644 --- a/Update-DMARCrecords_include.py +++ b/Update-DMARCrecords_include.py @@ -1,21 +1,24 @@ +import os # pour récupérer les variables d'env from typing import List + import ovh # export ovh api -import os # pour récupérer les variables d'env from decouple import config -print ("This script only works on OVH or SQY network.") +print("This script only works on OVH or SQY network.") -include_domains = ["citybuildr.io"] -dmarc_value = str("v=DMARC1; p=reject; rua=mailto:rsi@btp-consultants.fr; ruf=mailto:rsi@btp-consultants.fr; rf=afrf; pct=100; ri=86400") +include_domains = ["navalcheck.com"] +dmarc_value = str( + "v=DMARC1; p=reject; rua=mailto:rsi@btp-consultants.fr; ruf=mailto:rsi@btp-consultants.fr; rf=afrf; pct=100; ri=86400" +) class DMARCClient: def __init__(self, application_key, application_secret, consumer_key): self.client = ovh.Client( endpoint="ovh-eu", - application_key=config('ovh_application_key'), - application_secret=config('ovh_application_secret'), - consumer_key=config('ovh_consumer_key'), + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), ) def get_zones(self) -> List[str]: @@ -23,8 +26,7 @@ def get_zones(self) -> List[str]: return [i for i in zones if i in include_domains] def get_dmarc(self, zone): - records = self.client.get('/domain/zone/%s/record?fieldType=DMARC' - % zone) + records = self.client.get("/domain/zone/%s/record?fieldType=DMARC" % zone) for record in records: r = self.get_record(zone, record) if r["target"].startswith("v=DMARC1"): @@ -32,14 +34,16 @@ def get_dmarc(self, zone): return def get_record(self, zone: str, record: str): - return self.client.get('/domain/zone/%s/record/%s' % (zone, record)) + return self.client.get("/domain/zone/%s/record/%s" % (zone, record)) def set_record(self, zone, value): - return self.client.post('/domain/zone/%s/record' % zone, - target=value, - fieldType="DMARC", - ttl=3600, - subDomain="_dmarc") + return self.client.post( + "/domain/zone/%s/record" % zone, + target=value, + fieldType="DMARC", + ttl=3600, + subDomain="_dmarc", + ) def set_dmarc(self, zone: str, dmarc: str): record = self.get_dmarc(zone) @@ -52,13 +56,13 @@ def set_dmarc(self, zone: str, dmarc: str): return def update_record(self, zone: str, value: str, record_id: str): - return self.client.put('/domain/zone/%s/record/%s' % (zone, record_id), - target=value, - ttl=3600) + return self.client.put( + "/domain/zone/%s/record/%s" % (zone, record_id), target=value, ttl=3600 + ) def refresh_zone(self, zone: str): print("Refresh zone %s" % (zone)) - return self.client.post('/domain/zone/%s/refresh' % zone) + return self.client.post("/domain/zone/%s/refresh" % zone) def set_dmarc_all(self, dmarc: str): for zo in self.get_zones(): @@ -66,6 +70,5 @@ def set_dmarc_all(self, dmarc: str): self.refresh_zone(zo) -client = DMARCClient(application_key="", application_secret="", - consumer_key="") -client.set_dmarc_all(dmarc_value) \ No newline at end of file +client = DMARCClient(application_key="", application_secret="", consumer_key="") +client.set_dmarc_all(dmarc_value) diff --git a/Update-SPFrecords_exclude.py b/Update-SPFrecords_exclude.py index fd73183..2494819 100644 --- a/Update-SPFrecords_exclude.py +++ b/Update-SPFrecords_exclude.py @@ -1,19 +1,39 @@ +import os # pour récupérer les variables d'env from typing import List + import ovh # export ovh api -import os # pour récupérer les variables d'env from decouple import config -exclude_domains = ["bimscreen.fr","btp-consultants.fr", "citae.fr", "mbacity.com", "btp-diagnostics.fr", "navalcheck.fr","parkyze.com","btp-mornings.fr","citybuild.fr","databuildr.com","formactu.fr","groupe-btpconsultants.fr","nextiim.com","novalian.com","novalian.fr","novalian.io"] -spf_value = str("v=spf1 ip4:37.59.248.160/28 ip4:185.183.65.201 include:_spf.google.com include:amazonses.com -all") +exclude_domains = [ + "bimscreen.fr", + "btp-consultants.fr", + "citae.fr", + "mbacity.com", + "btp-diagnostics.fr", + "navalcheck.fr", + "parkyze.com", + "btp-mornings.fr", + "citybuild.fr", + "databuildr.com", + "formactu.fr", + "groupe-btpconsultants.fr", + "nextiim.com", + "novalian.com", + "novalian.fr", + "novalian.io", +] +spf_value = str( + "v=spf1 ip4:37.59.248.160/28 ip4:185.183.65.201 include:_spf.google.com include:amazonses.com include:spf.mailjet.com include:spf.sendinblue.com -all" +) class SPFClient: def __init__(self, application_key, application_secret, consumer_key): self.client = ovh.Client( endpoint="ovh-eu", - application_key=config('ovh_application_key'), - application_secret=config('ovh_application_secret'), - consumer_key=config('ovh_consumer_key'), + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), ) def get_zones(self) -> List[str]: @@ -21,18 +41,20 @@ def get_zones(self) -> List[str]: return [i for i in zones if i not in exclude_domains] def get_spf(self, zone): - records = self.client.get('/domain/zone/%s/record?fieldType=SPF' % zone) + records = self.client.get("/domain/zone/%s/record?fieldType=SPF" % zone) for record in records: r = self.get_record(zone, record) - if r["target"].startswith("\"v=spf1"): + if r["target"].startswith('"v=spf1'): return record return def get_record(self, zone: str, record: str): - return self.client.get('/domain/zone/%s/record/%s' % (zone, record)) + return self.client.get("/domain/zone/%s/record/%s" % (zone, record)) def set_record(self, zone, value): - return self.client.post('/domain/zone/%s/record' % zone, target=value, fieldType="SPF", ttl=3600) + return self.client.post( + "/domain/zone/%s/record" % zone, target=value, fieldType="SPF", ttl=3600 + ) def set_spf(self, zone: str, spf: str): record = self.get_spf(zone) @@ -45,11 +67,13 @@ def set_spf(self, zone: str, spf: str): return def update_record(self, zone: str, value: str, record_id: str): - return self.client.put('/domain/zone/%s/record/%s' % (zone, record_id), target=value, ttl=3600) + return self.client.put( + "/domain/zone/%s/record/%s" % (zone, record_id), target=value, ttl=3600 + ) def refresh_zone(self, zone: str): print("Refresh zone %s" % (zone)) - return self.client.post('/domain/zone/%s/refresh' % zone) + return self.client.post("/domain/zone/%s/refresh" % zone) def set_spf_all(self, spf: str): for zo in self.get_zones(): @@ -57,6 +81,5 @@ def set_spf_all(self, spf: str): self.refresh_zone(zo) -client = SPFClient(application_key="", application_secret="", - consumer_key="") +client = SPFClient(application_key="", application_secret="", consumer_key="") client.set_spf_all(spf_value) diff --git a/Update-SPFrecords_include.py b/Update-SPFrecords_include.py index a51e29d..1a0d769 100644 --- a/Update-SPFrecords_include.py +++ b/Update-SPFrecords_include.py @@ -1,19 +1,22 @@ +import os # pour récupérer les variables d'env from typing import List + import ovh # export ovh api -import os # pour récupérer les variables d'env from decouple import config -include_domains = ["mbacity.com"] -spf_value = str("v=spf1 ip4:37.59.248.160/28 ip4:185.183.65.201 include:_spf.google.com include:amazonses.com ~all") +include_domains = ["navalcheck.com"] +spf_value = str( + "v=spf1 ip4:37.59.248.160/28 ip4:185.183.65.201 include:_spf.google.com include:amazonses.com include:spf.mailjet.com include:spf.sendinblue.com -all" +) class SPFClient: def __init__(self, application_key, application_secret, consumer_key): self.client = ovh.Client( endpoint="ovh-eu", - application_key=config('ovh_application_key'), - application_secret=config('ovh_application_secret'), - consumer_key=config('ovh_consumer_key'), + application_key=config("OVH_APPLICATION_KEY"), + application_secret=config("OVH_APPLICATION_SECRET"), + consumer_key=config("OVH_CONSUMER_KEY"), ) def get_zones(self) -> List[str]: @@ -21,18 +24,20 @@ def get_zones(self) -> List[str]: return [i for i in zones if i in include_domains] def get_spf(self, zone): - records = self.client.get('/domain/zone/%s/record?fieldType=SPF' % zone) + records = self.client.get("/domain/zone/%s/record?fieldType=SPF" % zone) for record in records: r = self.get_record(zone, record) - if r["target"].startswith("\"v=spf1"): + if r["target"].startswith('"v=spf1'): return record return def get_record(self, zone: str, record: str): - return self.client.get('/domain/zone/%s/record/%s' % (zone, record)) + return self.client.get("/domain/zone/%s/record/%s" % (zone, record)) def set_record(self, zone, value): - return self.client.post('/domain/zone/%s/record' % zone, target=value, fieldType="SPF", ttl=3600) + return self.client.post( + "/domain/zone/%s/record" % zone, target=value, fieldType="SPF", ttl=3600 + ) def set_spf(self, zone: str, spf: str): record = self.get_spf(zone) @@ -45,11 +50,13 @@ def set_spf(self, zone: str, spf: str): return def update_record(self, zone: str, value: str, record_id: str): - return self.client.put('/domain/zone/%s/record/%s' % (zone, record_id), target=value, ttl=3600) + return self.client.put( + "/domain/zone/%s/record/%s" % (zone, record_id), target=value, ttl=3600 + ) def refresh_zone(self, zone: str): print("Refresh zone %s" % (zone)) - return self.client.post('/domain/zone/%s/refresh' % zone) + return self.client.post("/domain/zone/%s/refresh" % zone) def set_spf_all(self, spf: str): for zo in self.get_zones(): @@ -57,6 +64,5 @@ def set_spf_all(self, spf: str): self.refresh_zone(zo) -client = SPFClient(application_key="", application_secret="", - consumer_key="") +client = SPFClient(application_key="", application_secret="", consumer_key="") client.set_spf_all(spf_value)