Hey Andreas,
This will be fixed in the next version. But in the meantime, you can use this API script to do this.
import requests
import time
import random
def auth(username, password, url):
authurl = url + "/api/v1/auth/authenticate-user"
myobj = {'username': username, 'password': password}
try:
data = requests.post(authurl, json=myobj, timeout=5)
data.raise_for_status() # Raise an exception for HTTP errors
refreshToken = data.json().get('refreshToken')
accessToken = data.json().get('accessToken')
accessTokenExpiration = data.json().get('accessTokenExpiration')
access_info = {
'accessToken': accessToken,
'accessTokenExpiration': accessTokenExpiration,
'refreshToken': refreshToken
}
return access_info
except requests.exceptions.RequestException as e:
print(f"Connection error: {e}")
return None
def gateway_put(url, access_info):
gatewayurl = url + "/api/v1/settings/sysadmin/gateway-put"
headers = {
'Authorization': f"Bearer {access_info['accessToken']}"
}
myobj = {"gatewayConfig":{"id":None,"address":"1.1.1.1","port":465,"shouldAuthenticate":False,"authUsername":"","authPassword":"","encryptionType":0,"type":0,"description":"","isSmarterMailServer":False,"smUrl":"","smUserName":"","smPassword":"","isEnabled":True,"verifyConnection":False}}
try:
response = requests.post(gatewayurl, json=myobj, headers=headers, timeout=5)
return response.status_code
except requests.exceptions.RequestException as e:
print(f"Connection error: {e}")
return None
if __name__ == "__main__":
url = "http://localhost:17017"
username = "admin"
password = "admin"
print(f"Attempting to authenticate user: {username}")
access_info = auth(username, password, url)
if access_info:
print("Successfully authenticated.")
print(f"Access Info: {access_info}")
status_code = gateway_put(url, access_info)
if status_code == 200:
print("Successfully sent gateway configuration.")
else:
print(f"Failed to send gateway configuration with status code {status_code}")
else:
print("Authentication failed.")
print("Process completed.")
To run the script, first, ensure that Python is installed on your computer. You can download it from python.org. Next, install the required `requests` library by using the command `pip install requests`. Save the provided script into a file named `script.py`. Open your command prompt (Windows) or terminal (macOS/Linux), navigate to the directory where `script.py` is saved, and run the script by typing `python script.py`.
You can edit the URL, username, and password directly in the script in the `__main__` block. For example, change the `url` variable to your server's URL, and update the `username` and `password` variables with your credentials. The authentication function uses the `authurl` endpoint, which combines the `url` with `"/api/v1/auth/authenticate-user"`. The gateway configuration function uses the `gatewayurl` endpoint, combining the `url` with `"/api/v1/settings/sysadmin/gateway-put"`. The headers include the `accessToken` for authorization, and the `myobj` variable contains the JSON object sent in the POST request.
You can edit the values of `myobj` within the `gateway_put` function to match your desired configuration, such as changing the `address`, `port`, `authUsername`, `authPassword`, and other settings. By following these instructions, you should be able to run the script and modify it to suit your needs.
Let me know if you have any questions.
Thanks,