Skip to content

Commit

Permalink
Merge pull request #23 from rdia9/feat/delete-crysalide
Browse files Browse the repository at this point in the history
Feat/delete crysalide
  • Loading branch information
rdia9 authored Dec 12, 2022
2 parents d8f57de + aea9286 commit 5d2dcaf
Show file tree
Hide file tree
Showing 18 changed files with 460 additions and 173 deletions.
4 changes: 4 additions & 0 deletions .env.dist
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=
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
ANSIBLE_DIRECTORY: .
VALIDATE_PYTHON_ISORT: false
VALIDATE_PYTHON_FLAKE8: false
VALIDATE_PYTHON_BLACK: false
VALIDATE_PYTHON_BLACK: false
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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/
Expand Down
78 changes: 78 additions & 0 deletions Delete-A-Batily-test.py
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()

76 changes: 76 additions & 0 deletions Delete-A-Crysalide_Releveplus.py
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()
6 changes: 3 additions & 3 deletions Delete-SPFrecords_typeSPF.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
6 changes: 3 additions & 3 deletions Delete-SPFrecords_typeTXT.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
43 changes: 0 additions & 43 deletions Enable-DNSSEC.py

This file was deleted.

41 changes: 41 additions & 0 deletions Enable-DNSSEC_exclude.py
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()
41 changes: 41 additions & 0 deletions Enable-DNSSEC_include.py
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()
Loading

0 comments on commit 5d2dcaf

Please sign in to comment.