def load_session_hack(cli_token): """ Loads a session manually for a certain cli_token """ # Attempt to load local session - this only works for file system sessions # See https://github.com/pallets/werkzeug/blob/master/werkzeug/contrib/cache.py for format # XXX FIXME replace this by a custom session handler for Flask from werkzeug.contrib.cache import FileSystemCache import pickle cache = FileSystemCache(app.config['SESSION_FILE_DIR'], threshold=app.config['SESSION_FILE_THRESHOLD'], mode=app.config['SESSION_FILE_MODE']) found = False for fn in cache._list_dir(): with open(fn, 'rb') as f: fot = pickle.load(f) del fot # Unused local_session = pickle.load(f) if type(local_session) is not dict: continue if local_session.get('cli_token') == cli_token: found = True break if not found: return None return local_session
def wipe_old_sessions_hack(ap_session, cli_token): """ Finds all prior sessions for this cli_token that do not match the current session (current session, aka 'ap_session') and drop them as they're now invalid """ from werkzeug.contrib.cache import FileSystemCache import pickle cache = FileSystemCache(app.config['SESSION_FILE_DIR'], threshold=app.config['SESSION_FILE_THRESHOLD'], mode=app.config['SESSION_FILE_MODE']) for fn in cache._list_dir(): with open(fn, 'rb') as f: fot = pickle.load(f) del fot # Unused local_session = pickle.load(f) if type(local_session) is not dict: continue if (local_session.get('cli_token') == cli_token) and ( local_session.get('ap_session') != ap_session): os.remove(fn) app.logger.debug( 'Removed now invalidated session data for cli_token {}'. format(cli_token)) continue return