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:
|
while True:
|
||||||
try:
|
try:
|
||||||
time.sleep(0.25)
|
time.sleep(30)
|
||||||
|
bumper.revoke_expired_tokens()
|
||||||
# WIP: Remove clients that have disconnected
|
disconnected_clients = bumper.get_disconnected_xmpp_clients()
|
||||||
# remove_clients = bumper.bumper_removeclients_var.get()
|
for client in disconnected_clients:
|
||||||
# if len(remove_clients) > 0:
|
xmpp_server.remove_client_byuid(client['userid'])
|
||||||
# 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)
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
bumper.bumperlog.info("Bumper Exiting - Keyboard Interrupt")
|
bumper.bumperlog.info("Bumper Exiting - Keyboard Interrupt")
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,6 @@ def user_revoke_expired_tokens(userid):
|
||||||
tokens = db_get().table('tokens')
|
tokens = db_get().table('tokens')
|
||||||
tsearch = tokens.search(Query().userid == userid)
|
tsearch = tokens.search(Query().userid == userid)
|
||||||
for i in tsearch:
|
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']):
|
if datetime.now() >= datetime.fromisoformat(i['expiration']):
|
||||||
bumperlog.debug("Removing token {} due to expiration".format(i['token']))
|
bumperlog.debug("Removing token {} due to expiration".format(i['token']))
|
||||||
tokens.remove(doc_ids=[i.doc_id])
|
tokens.remove(doc_ids=[i.doc_id])
|
||||||
|
|
@ -234,6 +233,11 @@ class VacBotClient(object):
|
||||||
"xmpp_connection": self.xmpp_connection
|
"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):
|
def check_authcode(uid, authcode):
|
||||||
bumperlog.debug("Checking for authcode: {}".format(authcode))
|
bumperlog.debug("Checking for authcode: {}".format(authcode))
|
||||||
|
|
@ -257,7 +261,14 @@ def check_token(uid, token):
|
||||||
if tmpauth:
|
if tmpauth:
|
||||||
return True
|
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):
|
def bot_add(sn, did, devclass, resource, company):
|
||||||
|
|
|
||||||
|
|
@ -803,8 +803,7 @@ class Client(threading.Thread):
|
||||||
if self.log_incoming_data:
|
if self.log_incoming_data:
|
||||||
xmppserverlog.debug(
|
xmppserverlog.debug(
|
||||||
"Unparsed Item - {}".format(str(ET.tostring(item, encoding="utf-8").decode("utf-8")).replace("ns0:",""))
|
"Unparsed Item - {}".format(str(ET.tostring(item, encoding="utf-8").decode("utf-8")).replace("ns0:",""))
|
||||||
)
|
)
|
||||||
print("e")
|
|
||||||
|
|
||||||
except ET.ParseError as e:
|
except ET.ParseError as e:
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue