From f006843c0e140e2c8b73a3cc18c62b1a9be3ec9e Mon Sep 17 00:00:00 2001 From: DewGew Date: Mon, 5 Feb 2024 07:26:04 +0100 Subject: [PATCH 1/6] Update api.py --- modules/api.py | 62 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/modules/api.py b/modules/api.py index 33b00d2..1150649 100644 --- a/modules/api.py +++ b/modules/api.py @@ -18,14 +18,30 @@ def modifyServerSettings(request): dbsettings = Settings.query.get_or_404(1) - dbsettings.client_id = request.args.get('aogclient', '') - dbsettings.client_secret = request.args.get('aogsecret', '') - dbsettings.api_key = request.args.get('aogapi', '') - dbsettings.tempunit = request.args.get('tempunit', '') - dbsettings.language = request.args.get('language', '') - dbsettings.use_ssl = (request.args.get('ssl', '') == 'true') - dbsettings.ssl_cert = request.args.get('sslcert', '') - dbsettings.ssl_key = request.args.get('sslkey', '') + client_id = request.args.get('aogclient', None) + if client_id: + dbsettings.client_id = client_id + client_secret = request.args.get('aogsecret', None) + if client_secret: + dbsettings.client_secret = client_secret + api_key = request.args.get('aogapi', None) + if api_key: + dbsettings.api_key = api_key + tempunit = request.args.get('tempunit', None) + if tempunit: + dbsettings.tempunit = tempunit + language = request.args.get('language', None) + if language: + dbsettings.language = language + use_ssl = request.args.get('ssl', None) + if use_ssl: + dbsettings.use_ssl =(True if use_ssl else False) + ssl_cert = request.args.get('sslcert', None) + if ssl_cert + dbsettings.ssl_cert = ssl_cert + ssl_key = request.args.get('sslkey', None) + if ssl_key: + dbsettings.ssl_key = ssl_key db.session.add(dbsettings) db.session.commit() @@ -36,13 +52,27 @@ def modifyServerSettings(request): def modifyUserSettings(username, request): dbuser = User.query.filter_by(username=username).first() - - dbuser.domo_url = request.args.get('domourl', '') - dbuser.domouser = request.args.get('domouser', '') - dbuser.domopass = request.args.get('domopass', '') - dbuser.roomplan = request.args.get('roomplan', '') - dbuser.password = request.args.get('uipassword', '') - dbuser.googleassistant = (request.args.get('googleassistant', '') == 'true') + + logger.info(request) + + domo_url = request.args.get('domourl', None) + if domo_url: + dbuser.domo_url = domo_url + domouser = request.args.get('domouser', None) + if domouser: + dbuser.domouser = domouser + domopass = request.args.get('domopass', None) + if domopass: + dbuser.domopass = domopass + roomplan = request.args.get('roomplan', None) + if roomplan: + dbuser.roomplan = roomplan + password = request.args.get('uipassword', None) + if password: + dbuser.password = password + googleassistant = request.args.get('googleassistant', None) + if googleassistant: + dbuser.googleassistant = (True if googleassistant == 'true' else False) db.session.add(dbuser) db.session.commit() @@ -85,10 +115,12 @@ def gateway(): elif custom == "server_settings": modifyServerSettings(request) + return "Server settings saved", 200 elif custom == "user_settings": modifyUserSettings(flask_login.current_user.username, request) + return "User settings saved", 200 elif custom == "removeuser": userToRemove = request.args.get('user', '') From 7bf4b6754c753eea5ce8ffa649676a3836331452 Mon Sep 17 00:00:00 2001 From: DewGew Date: Mon, 5 Feb 2024 07:35:00 +0100 Subject: [PATCH 2/6] Update api.py --- modules/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/api.py b/modules/api.py index 1150649..ba7ecf9 100644 --- a/modules/api.py +++ b/modules/api.py @@ -37,7 +37,7 @@ def modifyServerSettings(request): if use_ssl: dbsettings.use_ssl =(True if use_ssl else False) ssl_cert = request.args.get('sslcert', None) - if ssl_cert + if ssl_cert: dbsettings.ssl_cert = ssl_cert ssl_key = request.args.get('sslkey', None) if ssl_key: From a428544486eb1afaa53df03b4067e1fcbfa10a2b Mon Sep 17 00:00:00 2001 From: DewGew Date: Mon, 5 Feb 2024 07:43:31 +0100 Subject: [PATCH 3/6] Update api.py --- modules/api.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/api.py b/modules/api.py index ba7ecf9..58af7aa 100644 --- a/modules/api.py +++ b/modules/api.py @@ -52,8 +52,6 @@ def modifyServerSettings(request): def modifyUserSettings(username, request): dbuser = User.query.filter_by(username=username).first() - - logger.info(request) domo_url = request.args.get('domourl', None) if domo_url: From 17043d68334bfca2e74be4c83f9a23b2c56bb213 Mon Sep 17 00:00:00 2001 From: DewGew Date: Mon, 5 Feb 2024 07:56:09 +0100 Subject: [PATCH 4/6] Update api.py --- modules/api.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/modules/api.py b/modules/api.py index 58af7aa..40f7bb5 100644 --- a/modules/api.py +++ b/modules/api.py @@ -101,9 +101,9 @@ def gateway(): return "Devices synced with domoticz", 200 elif custom == "restart": - - logger.info('Restarts smarthome server') - os.execv(sys.executable, ['python'] + sys.argv) + if dbuser.admin: + logger.info('Restarts smarthome server') + os.execv(sys.executable, ['python'] + sys.argv) elif custom == "setArmLevel": armLevel = request.args.get('armLevel', '') @@ -111,9 +111,9 @@ def gateway(): result = queryDomoticz(flask_login.current_user.username, '?type=command¶m=setsecstatus&secstatus=' + armLevel + '&seccode=' + hashlib.md5(str.encode(seccode)).hexdigest()) elif custom == "server_settings": - - modifyServerSettings(request) - return "Server settings saved", 200 + if dbuser.admin: + modifyServerSettings(request) + return "Server settings saved", 200 elif custom == "user_settings": @@ -121,16 +121,18 @@ def gateway(): return "User settings saved", 200 elif custom == "removeuser": - userToRemove = request.args.get('user', '') + if dbuser.admin: + userToRemove = request.args.get('user', '') - removeuser = User.query.filter_by(username=userToRemove).first() + removeuser = User.query.filter_by(username=userToRemove).first() - db.session.delete(removeuser) - db.session.commit() - remove_user(userToRemove) - logger.info("User " + userToRemove + " is deleted") + db.session.delete(removeuser) + db.session.commit() + remove_user(userToRemove) + logger.info("User " + userToRemove + " is deleted") - return "User removed", 200 + return "User removed", 200 + elif '?type' in requestedUrl[1]: result = queryDomoticz(flask_login.current_user.username, requestedUrl[1]) From 485bc122aeccc7d583b68a36921557d16ec8edae Mon Sep 17 00:00:00 2001 From: DewGew Date: Mon, 5 Feb 2024 14:14:42 +0100 Subject: [PATCH 5/6] Update api.py --- modules/api.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/api.py b/modules/api.py index 40f7bb5..12acea6 100644 --- a/modules/api.py +++ b/modules/api.py @@ -98,7 +98,7 @@ def gateway(): else: getDomoticzDevices(flask_login.current_user.username) flash("Devices synced with domoticz") - return "Devices synced with domoticz", 200 + result = '{"title": "RequestedSync", "status": "OK"}' elif custom == "restart": if dbuser.admin: @@ -113,13 +113,13 @@ def gateway(): elif custom == "server_settings": if dbuser.admin: modifyServerSettings(request) - return "Server settings saved", 200 + result = '{"title": "ServerSettingsChanged", "status": "OK"}' elif custom == "user_settings": modifyUserSettings(flask_login.current_user.username, request) - return "User settings saved", 200 - + result = '{"title": "UserSettingsChanged", "status": "OK"}' + elif custom == "removeuser": if dbuser.admin: userToRemove = request.args.get('user', '') @@ -131,13 +131,13 @@ def gateway(): remove_user(userToRemove) logger.info("User " + userToRemove + " is deleted") - return "User removed", 200 + result = '{"title": "UserRemoved", "status": "OK"}' elif '?type' in requestedUrl[1]: result = queryDomoticz(flask_login.current_user.username, requestedUrl[1]) try: - return json.loads(result) + return json.loads(result), 200 except Exception: - return "No results returned", 404 + return {"title": "No results returned", "status": "ERR"}, 404 From 25948ee48ce98b374fae1626c7a7dfe23b19772a Mon Sep 17 00:00:00 2001 From: DewGew Date: Mon, 5 Feb 2024 17:46:34 +0100 Subject: [PATCH 6/6] Update VERSION.md --- VERSION.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/VERSION.md b/VERSION.md index f61208c..646dc82 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1,6 +1,4 @@ -24.6 -- Fixed "Deprecated RType () for API request" error -- Fixed camerastream not working +24.7 +- Added REST API read more in wiki - Add Security device -- UI improvments - Add more selectable device types