Exemplo n.º 1
0
def getDB(crypt, password, new=False, allowRemote=True, allowUpgrade=False):
    loc = urlparse.urlparse(args.database)
    # This is basically the same code as in Util.setupDataConnection().  Should consider moving to it.
    if (loc.scheme == 'http') or (loc.scheme == 'https'):
        if not allowRemote:
            raise Exception("This command cannot be executed remotely.  You must execute it on the server directly.")
        # If no port specified, insert the port
        if loc.port is None:
            netloc = loc.netloc + ":" + Defaults.getDefault('TARDIS_REMOTE_PORT')
            dbLoc = urlparse.urlunparse((loc.scheme, netloc, loc.path, loc.params, loc.query, loc.fragment))
        else:
            dbLoc = args.database
        tardisdb = RemoteDB.RemoteDB(dbLoc, args.client)
        cache = tardisdb
    else:
        basedir = os.path.join(args.database, args.client)
        if not args.dbdir:
            dbdir = os.path.join(args.database, args.client)
        else:
            dbdir = os.path.join(args.dbdir, args.client)
        dbfile = os.path.join(dbdir, args.dbname)
        if new and os.path.exists(dbfile):
            raise Exception("Database for client %s already exists." % (args.client))

        cache = CacheDir.CacheDir(basedir, 2, 2, create=new)
        schema = args.schema if new else None
        tardisdb = TardisDB.TardisDB(dbfile, backup=False, initialize=schema, allow_upgrade=allowUpgrade)

    if tardisdb.needsAuthentication():
        if password is None:
            password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client), allowNone=False, confirm=False)
        Util.authenticate(tardisdb, args.client, password)

    return (tardisdb, cache)
Exemplo n.º 2
0
def main():
    global logger
    progressbar.streams.wrap_stderr()
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger('')
    args = processArgs()
    password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, allowNone=False)

    crypto = TardisCrypto.TardisCrypto(password, args.client)

    path = os.path.join(args.database, args.client, args.dbname)
    db = TardisDB.TardisDB(path, backup=False)

    Util.authenticate(db, args.client, password)
    (f, c) = db.getKeys()
    crypto.setKeys(f, c)

    cacheDir = CacheDir.CacheDir(os.path.join(args.database, args.client))

    if args.names or args.all:
        encryptFilenames(db, crypto)
    if args.dirs or args.all:
        generateDirHashes(db, crypto, cacheDir)
    if args.sigs or args.all:
        generateSignatures(db, crypto, cacheDir)
    if args.files or args.all:
        encryptFiles(db, crypto, cacheDir)
    if args.meta or args.all:
        generateMetadata(db, cacheDir)
Exemplo n.º 3
0
def main():
    global logger
    progressbar.streams.wrap_stderr()
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger('')
    args = processArgs()
    password = Util.getPassword(args.password, args.passwordfile, args.passwordprog)

    crypto = TardisCrypto.TardisCrypto(password, args.client)

    path = os.path.join(args.database, args.client, args.dbname)
    db = TardisDB.TardisDB(path, backup=False)

    Util.authenticate(db, args.client, password)
    (f, c) = db.getKeys()
    crypto.setKeys(f, c)

    cacheDir = CacheDir.CacheDir(os.path.join(args.database, args.client))

    if args.names or args.all:
        encryptFilenames(db, crypto)
    if args.dirs or args.all:
        generateDirHashes(db, crypto, cacheDir)
    if args.sigs or args.all:
        generateSignatures(db, crypto, cacheDir)
    if args.files or args.all:
        encryptFiles(db, crypto, cacheDir)
    if args.meta or args.all:
        generateMetadata(db, cacheDir)
Exemplo n.º 4
0
def getDB(crypt, password, new=False, allowRemote=True, allowUpgrade=False):
    loc = urllib.parse.urlparse(args.database)
    # This is basically the same code as in Util.setupDataConnection().  Should consider moving to it.
    if (loc.scheme == 'http') or (loc.scheme == 'https'):
        if not allowRemote:
            raise Exception("This command cannot be executed remotely.  You must execute it on the server directly.")
        # If no port specified, insert the port
        if loc.port is None:
            netloc = loc.netloc + ":" + Defaults.getDefault('TARDIS_REMOTE_PORT')
            dbLoc = urllib.parse.urlunparse((loc.scheme, netloc, loc.path, loc.params, loc.query, loc.fragment))
        else:
            dbLoc = args.database
        tardisdb = RemoteDB.RemoteDB(dbLoc, args.client)
        cache = tardisdb
    else:
        basedir = os.path.join(args.database, args.client)
        if not args.dbdir:
            dbdir = os.path.join(args.database, args.client)
        else:
            dbdir = os.path.join(args.dbdir, args.client)
        dbfile = os.path.join(dbdir, args.dbname)
        if new and os.path.exists(dbfile):
            raise Exception("Database for client %s already exists." % (args.client))

        cache = CacheDir.CacheDir(basedir, 2, 2, create=new)
        schema = args.schema if new else None
        tardisdb = TardisDB.TardisDB(dbfile, backup=False, initialize=schema, allow_upgrade=allowUpgrade)

    if tardisdb.needsAuthentication():
        if password is None:
            password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client), allowNone=False, confirm=False)
            crypt = TardisCrypto.TardisCrypto(password, args.client)
        Util.authenticate(tardisdb, args.client, password)

    return (tardisdb, cache, crypt)