mirror of
https://github.com/michivonah/adguard-ddns-client.git
synced 2025-12-22 14:16:29 +01:00
add validation and checks
This commit is contained in:
parent
68ed453b03
commit
ff4eab2be2
1 changed files with 13 additions and 6 deletions
19
main.py
19
main.py
|
|
@ -36,15 +36,23 @@ def addClient(api_base_url, api_username, api_password, domainname):
|
|||
currentBlockedHosts = currentList["blocked_hosts"]
|
||||
|
||||
clientId = getIPAdress(domainname)
|
||||
allowedList = currentAllowList + [clientId]
|
||||
if not clientId in currentAllowList:
|
||||
allowedList = currentAllowList + [clientId]
|
||||
|
||||
data = {
|
||||
data = {
|
||||
"allowed_clients":allowedList,
|
||||
"disallowed_clients":currentDisallowList,
|
||||
"blocked_hosts":currentBlockedHosts
|
||||
}
|
||||
response = requests.post(endpoint, auth=HTTPBasicAuth(api_username, api_password), json=data)
|
||||
return response
|
||||
}
|
||||
|
||||
response = requests.post(endpoint, auth=HTTPBasicAuth(api_username, api_password), json=data)
|
||||
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
|
||||
def getIPAdress(domainname):
|
||||
|
|
@ -55,5 +63,4 @@ def getIPAdress(domainname):
|
|||
|
||||
# Main programm
|
||||
if __name__ == '__main__':
|
||||
#print(getClients(API_BASE_URL, API_USERNAME, API_PASSWORD))
|
||||
print(addClient(API_BASE_URL, API_USERNAME, API_PASSWORD, DOMAIN_NAME))
|
||||
Loading…
Add table
Add a link
Reference in a new issue