From d6e853158c93deeed2d326629b6cae9827818f3d Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Mon, 11 Mar 2019 21:01:47 -0400 Subject: [PATCH] Fix revoke expired and remove disconnected Fix revoke expired and remove disconnected --- bumper.py | 16 +++++----------- bumper/__init__.py | 15 +++++++++++++-- bumper/xmppserver.py | 3 +-- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/bumper.py b/bumper.py index 32b628b..bf0fbae 100644 --- a/bumper.py +++ b/bumper.py @@ -89,17 +89,11 @@ def main(): while True: try: - time.sleep(0.25) - - # WIP: Remove clients that have disconnected - # remove_clients = bumper.bumper_removeclients_var.get() - # if len(remove_clients) > 0: - # for uid in remove_clients: - # if uid != "": - # xmpp_server.remove_client_byuid(uid) #Remove clients from xmpp server - # remove_clients.remove(uid) - - # bumper.bumper_removeclients_var.set(remove_clients) + time.sleep(30) + bumper.revoke_expired_tokens() + disconnected_clients = bumper.get_disconnected_xmpp_clients() + for client in disconnected_clients: + xmpp_server.remove_client_byuid(client['userid']) except KeyboardInterrupt: bumper.bumperlog.info("Bumper Exiting - Keyboard Interrupt") diff --git a/bumper/__init__.py b/bumper/__init__.py index 3af072d..a803240 100644 --- a/bumper/__init__.py +++ b/bumper/__init__.py @@ -162,7 +162,6 @@ def user_revoke_expired_tokens(userid): tokens = db_get().table('tokens') tsearch = tokens.search(Query().userid == userid) for i in tsearch: - bumperlog.debug("Checking expiration of token {}: Is Current Time: {} >= Expiration: {}".format(i['token'],datetime.fromisoformat(i['expiration']), datetime.now())) if datetime.now() >= datetime.fromisoformat(i['expiration']): bumperlog.debug("Removing token {} due to expiration".format(i['token'])) tokens.remove(doc_ids=[i.doc_id]) @@ -234,6 +233,11 @@ class VacBotClient(object): "xmpp_connection": self.xmpp_connection } +def get_disconnected_xmpp_clients(): + clients = db_get().table('clients') + Client = Query() + return clients.search(Client.xmpp_connection == False) + def check_authcode(uid, authcode): bumperlog.debug("Checking for authcode: {}".format(authcode)) @@ -257,7 +261,14 @@ def check_token(uid, token): if tmpauth: return True - return False + return False + +def revoke_expired_tokens(): + tokens = db_get().table('tokens').all() + for i in tokens: + if datetime.now() >= datetime.fromisoformat(i['expiration']): + bumperlog.debug("Removing token {} due to expiration".format(i['token'])) + db_get().table('tokens').remove(doc_ids=[i.doc_id]) def bot_add(sn, did, devclass, resource, company): diff --git a/bumper/xmppserver.py b/bumper/xmppserver.py index 3261093..a9021ef 100644 --- a/bumper/xmppserver.py +++ b/bumper/xmppserver.py @@ -803,8 +803,7 @@ class Client(threading.Thread): if self.log_incoming_data: xmppserverlog.debug( "Unparsed Item - {}".format(str(ET.tostring(item, encoding="utf-8").decode("utf-8")).replace("ns0:","")) - ) - print("e") + ) except ET.ParseError as e: if (