Tinydb added #11

Merged
bmartin5692 merged 5 commits from tinydb into master 2019-03-12 02:05:18 +01:00
3 changed files with 19 additions and 15 deletions
Showing only changes of commit d6e853158c - Show all commits

View file

@ -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")

View file

@ -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):

View file

@ -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 (