Remove tokens from downloaded database

This commit is contained in:
JonnyWong16 2022-01-15 16:13:53 -08:00
parent 6742ce613a
commit ce0cdf9ce6
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
2 changed files with 19 additions and 8 deletions

View file

@ -332,10 +332,11 @@ def optimize_db():
optimize() optimize()
def db_filename(filename=FILENAME): def db_filename(filename=None):
""" Returns the filepath to the db """ """ Returns the filepath to the db """
if filename is None:
return os.path.join(plexpy.DATA_DIR, filename) return os.path.join(plexpy.DATA_DIR, FILENAME)
return filename
def make_backup(cleanup=False, scheduler=False): def make_backup(cleanup=False, scheduler=False):
@ -404,9 +405,9 @@ def dict_factory(cursor, row):
class MonitorDatabase(object): class MonitorDatabase(object):
def __init__(self, filename=FILENAME): def __init__(self, filename=None):
self.filename = filename self.filename = db_filename(filename)
self.connection = sqlite3.connect(db_filename(filename), timeout=20) self.connection = sqlite3.connect(self.filename, timeout=20)
# Set database synchronous mode (default NORMAL) # Set database synchronous mode (default NORMAL)
self.connection.execute("PRAGMA synchronous = %s" % plexpy.CONFIG.SYNCHRONOUS_MODE) self.connection.execute("PRAGMA synchronous = %s" % plexpy.CONFIG.SYNCHRONOUS_MODE)
# Set database journal mode (default WAL) # Set database journal mode (default WAL)

View file

@ -4852,16 +4852,26 @@ class WebInterface(object):
def download_database(self, **kwargs): def download_database(self, **kwargs):
""" Download the Tautulli database file. """ """ Download the Tautulli database file. """
database_file = database.FILENAME database_file = database.FILENAME
database_copy = os.path.join(plexpy.CONFIG.CACHE_DIR, database_file)
try: try:
db = database.MonitorDatabase() db = database.MonitorDatabase()
db.connection.execute('begin immediate') 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() db.connection.rollback()
except: except:
pass 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 @cherrypy.expose
@requireAuth(member_of("admin")) @requireAuth(member_of("admin"))