-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from rdia9/feat/delete-crysalide
Feat/delete crysalide
- Loading branch information
Showing
18 changed files
with
460 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
OVH_APPLICATION_KEY= | ||
OVH_APPLICATION_SECRET= | ||
OVH_CONSUMER_KEY= | ||
OVH_ENDPOINT= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.