diff --git a/plexpy/database.py b/plexpy/database.py index ee075387..3b56f33b 100644 --- a/plexpy/database.py +++ b/plexpy/database.py @@ -332,10 +332,11 @@ def optimize_db(): optimize() -def db_filename(filename=FILENAME): +def db_filename(filename=None): """ Returns the filepath to the db """ - - return os.path.join(plexpy.DATA_DIR, filename) + if filename is None: + return os.path.join(plexpy.DATA_DIR, FILENAME) + return filename def make_backup(cleanup=False, scheduler=False): @@ -404,9 +405,9 @@ def dict_factory(cursor, row): class MonitorDatabase(object): - def __init__(self, filename=FILENAME): - self.filename = filename - self.connection = sqlite3.connect(db_filename(filename), timeout=20) + def __init__(self, filename=None): + self.filename = db_filename(filename) + self.connection = sqlite3.connect(self.filename, timeout=20) # Set database synchronous mode (default NORMAL) self.connection.execute("PRAGMA synchronous = %s" % plexpy.CONFIG.SYNCHRONOUS_MODE) # Set database journal mode (default WAL) diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 50fecaf4..579d4d05 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -4852,16 +4852,26 @@ class WebInterface(object): def download_database(self, **kwargs): """ Download the Tautulli database file. """ database_file = database.FILENAME + database_copy = os.path.join(plexpy.CONFIG.CACHE_DIR, database_file) try: db = database.MonitorDatabase() db.connection.execute('begin immediate') - shutil.copyfile(plexpy.DB_FILE, os.path.join(plexpy.CONFIG.CACHE_DIR, database_file)) + shutil.copyfile(plexpy.DB_FILE, database_copy) db.connection.rollback() except: pass - return serve_download(os.path.join(plexpy.CONFIG.CACHE_DIR, database_file), name=database_file) + # Remove tokens + db = database.MonitorDatabase(database_copy) + try: + db.action('UPDATE users SET user_token = NULL, server_token = NULL') + except: + logger.error('Failed to remove tokens from downloaded database.') + cherrypy.response.status = 500 + return 'Error downloading database. Check the logs.' + + return serve_download(database_copy, name=database_file) @cherrypy.expose @requireAuth(member_of("admin"))