Fix revoke expired and remove disconnected
Fix revoke expired and remove disconnected
This commit is contained in:
parent
09e41cbc6e
commit
d6e853158c
3 changed files with 19 additions and 15 deletions
16
bumper.py
16
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")
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue