mirror of
https://github.com/michivonah/adguard-ddns-client.git
synced 2025-12-22 22:26:28 +01:00
add function for getting allowed clients
This commit is contained in:
parent
bd7ed03e2c
commit
f4c18271b2
1 changed files with 20 additions and 3 deletions
23
main.py
23
main.py
|
|
@ -3,6 +3,9 @@ from dotenv import load_dotenv
|
||||||
import requests
|
import requests
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
|
|
||||||
|
# Load envirommental variables
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
# AdGuard Home API Informationen
|
# AdGuard Home API Informationen
|
||||||
API_BASE_URL = os.getenv('API_BASE_URL')
|
API_BASE_URL = os.getenv('API_BASE_URL')
|
||||||
API_USERNAME = os.getenv('API_USERNAME')
|
API_USERNAME = os.getenv('API_USERNAME')
|
||||||
|
|
@ -13,11 +16,11 @@ IP_TO_WHITELIST = "1.2.3.4"
|
||||||
|
|
||||||
def add_ip_to_whitelist(api_base_url, api_username, api_password, ip_to_whitelist):
|
def add_ip_to_whitelist(api_base_url, api_username, api_password, ip_to_whitelist):
|
||||||
# API-Endpunkt für die Whitelist
|
# API-Endpunkt für die Whitelist
|
||||||
api_endpoint = f"{api_base_url}/control/access/whitelist/add"
|
api_endpoint = f"{api_base_url}/control/access/set"
|
||||||
|
|
||||||
# Daten für die POST-Anfrage
|
# Daten für die POST-Anfrage
|
||||||
data = {
|
data = {
|
||||||
"ip": ip_to_whitelist,
|
"allowed_clients": ip_to_whitelist,
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -32,5 +35,19 @@ def add_ip_to_whitelist(api_base_url, api_username, api_password, ip_to_whitelis
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Fehler bei der Anfrage: {e}")
|
print(f"Fehler bei der Anfrage: {e}")
|
||||||
|
|
||||||
|
def getClients(api_base_url, api_username, api_password):
|
||||||
|
endpoint = f"{api_base_url}/control/access/list"
|
||||||
|
response = requests.get(endpoint, auth=HTTPBasicAuth(api_username, api_password))
|
||||||
|
result = response.json()
|
||||||
|
print(result["allowed_clients"])
|
||||||
|
|
||||||
|
def getIPAdress(domainname, dnsServer):
|
||||||
|
endpoint = ""
|
||||||
|
ip = "1.1.1.1"
|
||||||
|
return ip
|
||||||
|
|
||||||
|
|
||||||
# Funktion aufrufen
|
# Funktion aufrufen
|
||||||
add_ip_to_whitelist(API_BASE_URL, API_USERNAME, API_PASSWORD, IP_TO_WHITELIST)
|
#add_ip_to_whitelist(API_BASE_URL, API_USERNAME, API_PASSWORD, IP_TO_WHITELIST)
|
||||||
|
getClients(API_BASE_URL, API_USERNAME, API_PASSWORD)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue