memory: auto-update configuration file with libervia's passphrase when migrating the database
This commit is contained in:
parent
ae45889d50
commit
c68b147398
2 changed files with 22 additions and 20 deletions
|
|
@ -21,7 +21,6 @@ from sat.core.i18n import _
|
|||
|
||||
import os.path
|
||||
import csv
|
||||
from xdg import BaseDirectory
|
||||
from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
|
||||
from uuid import uuid4
|
||||
from sat.core.log import getLogger
|
||||
|
|
@ -35,6 +34,7 @@ from sat.memory.persistent import PersistentDict
|
|||
from sat.memory.params import Params
|
||||
from sat.memory.disco import Discovery
|
||||
from sat.memory.crypto import BlockCipher
|
||||
from sat.tools.config import fixConfigOption
|
||||
|
||||
|
||||
class Sessions(object):
|
||||
|
|
@ -180,25 +180,7 @@ def fixLocalDir(silent=True):
|
|||
if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE):
|
||||
if not silent:
|
||||
log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)"))
|
||||
config = SafeConfigParser()
|
||||
target_file = None
|
||||
for file_ in C.CONFIG_FILES[::-1]:
|
||||
# we will eventually update the existing file with the highest priority, if it's a user personal file...
|
||||
if not silent:
|
||||
log.debug(_("Testing file %s") % file_)
|
||||
if os.path.isfile(file_):
|
||||
if file_.startswith(os.path.expanduser('~')):
|
||||
config.read([file_])
|
||||
target_file = file_
|
||||
break
|
||||
if not target_file:
|
||||
# ... otherwise we create a new config file for that user
|
||||
target_file = BaseDirectory.save_config_path('sat') + '/sat.conf'
|
||||
config.set('', 'local_dir', old_default)
|
||||
with open(target_file, 'wb') as configfile:
|
||||
config.write(configfile) # for the next time that user launches sat
|
||||
if not silent:
|
||||
log.warning(_("Auto-update: local_dir set to %(path)s in the file %(config_file)s") % {'path': old_default, 'config_file': target_file})
|
||||
fixConfigOption('', 'local_dir', old_default)
|
||||
|
||||
|
||||
class Memory(object):
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ from sat.core import exceptions
|
|||
from sat.core.log import getLogger
|
||||
log = getLogger(__name__)
|
||||
from sat.memory.crypto import BlockCipher, PasswordHasher
|
||||
from sat.tools.config import fixConfigOption
|
||||
from twisted.enterprise import adbapi
|
||||
from twisted.internet import defer
|
||||
from collections import OrderedDict
|
||||
|
|
@ -798,6 +799,25 @@ class Updater(object):
|
|||
d_list.addCallback(lambda dummy: ret)
|
||||
return d_list
|
||||
|
||||
def updateLiberviaConf(values):
|
||||
try:
|
||||
profile_id = values[0][0]
|
||||
except IndexError:
|
||||
return # no profile called "libervia"
|
||||
|
||||
def cb(selected):
|
||||
try:
|
||||
password = selected[0][0]
|
||||
except IndexError:
|
||||
log.error("Libervia profile exists but no password is set! Update Libervia configuration will be skipped.")
|
||||
return
|
||||
fixConfigOption('libervia', 'passphrase', password, False)
|
||||
d = self.dbpool.runQuery("SELECT value FROM param_ind WHERE category=? AND name=? AND profile_id=?", xmpp_pass_path + (profile_id,))
|
||||
d.addCallback(cb)
|
||||
|
||||
d = self.dbpool.runQuery("SELECT id FROM profiles WHERE name='libervia'")
|
||||
d.addCallback(updateLiberviaConf)
|
||||
|
||||
d = self.dbpool.runQuery("SELECT profile_id,value FROM param_ind WHERE category=? AND name=?", xmpp_pass_path)
|
||||
d.addCallback(encrypt_values)
|
||||
return d
|
||||
|
|
|
|||
Loading…
Reference in a new issue