mirror of
https://github.com/michivonah/adguard-ddns-client.git
synced 2025-12-22 22:26:28 +01:00
add validation and checks
This commit is contained in:
parent
68ed453b03
commit
ff4eab2be2
1 changed files with 13 additions and 6 deletions
11
main.py
11
main.py
|
|
@ -36,6 +36,7 @@ def addClient(api_base_url, api_username, api_password, domainname):
|
||||||
currentBlockedHosts = currentList["blocked_hosts"]
|
currentBlockedHosts = currentList["blocked_hosts"]
|
||||||
|
|
||||||
clientId = getIPAdress(domainname)
|
clientId = getIPAdress(domainname)
|
||||||
|
if not clientId in currentAllowList:
|
||||||
allowedList = currentAllowList + [clientId]
|
allowedList = currentAllowList + [clientId]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
|
|
@ -43,8 +44,15 @@ def addClient(api_base_url, api_username, api_password, domainname):
|
||||||
"disallowed_clients":currentDisallowList,
|
"disallowed_clients":currentDisallowList,
|
||||||
"blocked_hosts":currentBlockedHosts
|
"blocked_hosts":currentBlockedHosts
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(endpoint, auth=HTTPBasicAuth(api_username, api_password), json=data)
|
response = requests.post(endpoint, auth=HTTPBasicAuth(api_username, api_password), json=data)
|
||||||
return response
|
if response.status_code == 200:
|
||||||
|
return f"{clientId} successfully added to the list of allowed clients."
|
||||||
|
else:
|
||||||
|
return f"An error occured while adding {clientId} to the list of allowed clients. Error message: {response.text}"
|
||||||
|
else:
|
||||||
|
return f"{clientId} already in list of allowed clients. Nothing was changed."
|
||||||
|
|
||||||
|
|
||||||
# Resolves the ip address of a domainname
|
# Resolves the ip address of a domainname
|
||||||
def getIPAdress(domainname):
|
def getIPAdress(domainname):
|
||||||
|
|
@ -55,5 +63,4 @@ def getIPAdress(domainname):
|
||||||
|
|
||||||
# Main programm
|
# Main programm
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#print(getClients(API_BASE_URL, API_USERNAME, API_PASSWORD))
|
|
||||||
print(addClient(API_BASE_URL, API_USERNAME, API_PASSWORD, DOMAIN_NAME))
|
print(addClient(API_BASE_URL, API_USERNAME, API_PASSWORD, DOMAIN_NAME))
|
||||||
Loading…
Add table
Add a link
Reference in a new issue