本文整理汇总了Python中Tardis.Util.getPassword方法的典型用法代码示例。如果您正苦于以下问题:Python Util.getPassword方法的具体用法?Python Util.getPassword怎么用?Python Util.getPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tardis.Util
的用法示例。
在下文中一共展示了Util.getPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
global logger
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('')
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordprog)
(_, _, crypto) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)
data = args.names
if not data:
tty = os.isatty(0)
if not tty:
data = list(map(str.strip, sys.stdin.readlines()))
else:
data = reader(args.quiet)
for i in data:
if i:
if not args.quiet:
print(i, " \t => \t", end=' ')
try:
if (args.encrypt):
print(crypto.encryptPath(i))
else:
print(crypto.decryptPath(i))
except Exception as e:
print("Caught exception: " + str(e))
示例2: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
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)
示例3: getDB
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
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)
示例4: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
global logger
args = processArgs()
kwargs = processMountOpts(args.mountopts)
logger = Util.setupLogging(args.verbose)
try:
argsDict = vars(args)
def getarg(name):
""" Extract a value from either the kwargs, or the regular args """
return kwargs.get(name) or argsDict.get(name)
# Extract the password file and program, if they exist. Names differ, so getarg doesn't work.
pwfile = kwargs.get('pwfile') or argsDict.get('passwordfile')
pwprog = kwargs.get('pwprog') or argsDict.get('passwordprog')
password = Util.getPassword(getarg('password'), pwfile, pwprog, prompt="Password for %s: " % (getarg('client')))
args.password = None
(tardis, cache, crypt) = Util.setupDataConnection(getarg('database'), getarg('client'), password, getarg('keys'), getarg('dbname'), getarg('dbdir'))
except TardisDB.AuthenticationException as e:
logger.error("Authentication failed. Bad password")
#if args.exceptions:
#logger.exception(e)
sys.exit(1)
except Exception as e:
logger.error("DB Connection failed: %s", e)
sys.exit(1)
delTardisKeys(kwargs)
fs = TardisFS(tardis, cache, crypt, args)
FUSE(fs, args.mountpoint[0], debug=args.debug, nothreads=True, foreground=args.foreground, **kwargs)
示例5: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
global logger
try:
parseArgs()
logger = Util.setupLogging(args.verbose)
if len(args.backup) > 2:
logger.error(args.backup)
logger.error("Too many backups (%d) specified. Only one or two allowed", len(args.backup))
sys.exit(1)
password = Util.getPassword(
args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client)
)
args.password = None
(tardis, cache, crypt) = Util.setupDataConnection(
args.database, args.client, password, args.keys, args.dbname, args.dbdir
)
password = None
bsets = []
for i in args.backup:
bset = getBackupSet(tardis, i)
if bset:
logger.debug("Got backupset %s", str(bset))
logger.debug("backupset: %s", bset["backupset"])
bsets.append(bset)
else:
sys.exit(1)
if len(bsets) == 1:
bsets.append(None)
r = Regenerator.Regenerator(cache, tardis, crypt)
then = time.asctime(time.localtime(float(bsets[0]["starttime"]))) + " (" + bsets[0]["name"] + ")"
if bsets[1]:
now = time.asctime(time.localtime(float(bsets[1]["starttime"]))) + " (" + bsets[1]["name"] + ")"
else:
now = time.asctime() + " (filesystem)"
for f in args.files:
if bsets[1] is None and os.path.isdir(f):
diffDir(os.path.abspath(f), r, bsets, tardis, crypt, args.reduce, now, then, recurse=args.recurse)
else:
(i0, _) = getFileInfo(os.path.abspath(f), bsets[0]["backupset"], tardis, crypt, args.reduce)
if i0 and i0["dir"]:
(i1, _) = getFileInfo(os.path.abspath(f), bsets[1]["backupset"], tardis, crypt, args.reduce)
if i1 and i1["dir"]:
diffDir(
os.path.abspath(f), r, bsets, tardis, crypt, args.reduce, now, then, recurse=args.recurse
)
continue
diffFile(f, r, bsets, tardis, crypt, args.reduce, args.recurse, now, then)
except KeyboardInterrupt:
pass
except Exception as e:
logger.error("Caught exception: %s", str(e))
logger.exception(e)
示例6: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
logging.basicConfig(level=logging.INFO)
crypto = None
token = None
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordurl, args.passwordprog)
if password:
crypto = TardisCrypto.TardisCrypto(password, args.client)
token = crypto.createToken()
path = os.path.join(args.database, args.client, args.dbname)
db = TardisDB.TardisDB(path, token=token, backup=False)
if crypto:
(a, b) = db.getKeys()
crypto.setKeys(a, b)
conn = db.conn
dirs = conn.execute("SELECT Name as name, Inode AS inode, Device AS device, FirstSet as firstset, LastSet AS lastset FROM Files JOIN Names ON Files.NameId = Names.NameId WHERE Dir = 1")
while True:
batch = dirs.fetchmany(1000)
if not batch:
break
for d in batch:
name = d['name']
inode = d['inode']
device = d['device']
firstset = d['firstset']
lastset = d['lastset']
files = db.readDirectory((inode, device), current=lastset)
names = [x['name'] for x in files]
nfiles = len(names)
if nfiles:
if crypto:
names = map(crypto.decryptFilename, names)
name = crypto.decryptFilename(name)
names = sorted(names)
m = hashlib.md5()
for f in names:
m.update(f)
checksum = m.hexdigest()
else:
checksum = 'd41d8cd98f00b204e9800998ecf8427e'
print("%-20s (%d, %d) [%d %d] -- %s %d") % (name, inode, device, firstset, lastset, checksum, nfiles)
ckinfo = db.getChecksumInfo(checksum)
if ckinfo:
cksid = ckinfo['checksumid']
else:
cksid = db.insertChecksumFile(checksum, size=nfiles, isFile=False)
db.updateDirChecksum((inode, device), cksid, current=lastset)
conn.commit()
示例7: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
logging.basicConfig(level=logging.DEBUG)
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordurl, args.passwordprog)
crypto = TardisCrypto.TardisCrypto(password, args.client)
token = createToken(crypto, args.client)
path = os.path.join(args.database, args.client, args.dbname)
db = TardisDB.TardisDB(path, backup=False)
db.setToken(token)
示例8: changePassword
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def changePassword(crypt, oldpw) :
try:
(db, _, crypt) = getDB(crypt, oldpw)
# Get the new password
try:
newpw = Util.getPassword(args.newpw, args.newpwf, args.newpwp, prompt="New Password for %s: " % (args.client),
allowNone=False, confirm=True, strength=True)
except Exception as e:
logger.critical(str(e))
if args.exceptions:
logger.exception(e)
return -1
crypt2 = TardisCrypto.TardisCrypto(newpw, args.client)
# Load the keys, and insert them into the crypt object, to decyrpt them
if args.keys:
(f, c) = Util.loadKeys(args.keys, db.getConfigValue('ClientID'))
# No need to check here, loadKeys() throws exception if nothing set.
else:
(f, c) = db.getKeys()
if f is None or c is None:
logger.critical("No keys loaded from database. Please specify --keys as appropriate")
raise Exception("No keys loaded")
crypt.setKeys(f, c)
# Grab the keys from one crypt object.
# Need to do this because getKeys/setKeys assumes they're encrypted, and we need the raw
# versions
crypt2._filenameKey = crypt._filenameKey
crypt2._contentKey = crypt._contentKey
# Now get the encrypted versions
(f, c) = crypt2.getKeys()
(salt, vkey) = srp.create_salted_verification_key(args.client, newpw)
if args.keys:
db.beginTransaction()
db.setSrpValues(salt, vkey)
Util.saveKeys(args.keys, db.getConfigValue('ClientID'), f, c)
db.commit()
else:
db.setKeys(salt, vkey, f, c)
return 0
except Exception as e:
logger.error(str(e))
if args.exceptions:
logger.exception(e)
return 1
示例9: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
global args, logger
tardis = None
try:
args = processArgs()
logger = Util.setupLogging(args.verbose)
setColors(Defaults.getDefault('TARDIS_LS_COLORS'))
# Load any password info
password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client))
args.password = None
(tardis, _, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)
setupDisplay(tardis)
if args.headers:
doprint("Client: %s DB: %s" %(args.client, args.database), color=colors['name'], eol=True)
if args.glob:
directories = []
for d in args.directories:
if not Util.isMagic(d):
directories.append(d)
else:
directories += globPath(os.path.abspath(d), tardis, crypt)
else:
directories = args.directories
for d in directories:
d = os.path.abspath(d)
if args.realpath:
d = os.path.realpath(d)
fInfos = collectFileInfo(d, tardis, crypt)
recurse = args.maxdepth if args.recurse else 0
processFile(d, fInfos, tardis, crypt, printContents=(not args.dirinfo), recurse=recurse)
except KeyboardInterrupt:
pass
except TardisDB.AuthenticationException as e:
logger.error("Authentication failed. Bad password")
if args.exceptions:
logger.exception(e)
except Exception as e:
logger.error("Caught exception: %s", str(e))
if args.exceptions:
logger.exception(e)
finally:
if tardis:
tardis.close()
示例10: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
global args
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client))
(tardis, _, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)
(f, c) = crypt.getKeys()
client = tardis.getConfigValue('ClientID')
data = Util.mkKeyString(client, f, c)
qrfile = mkQrFile(data)
makePdf(args.output, qrfile.name, data, args.client)
return 0
示例11: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
global args, logger
try:
FORMAT = "%(levelname)s : %(message)s"
logging.basicConfig(stream=sys.stderr, format=FORMAT, level=logging.INFO)
logger = logging.getLogger("")
args = processArgs()
setColors(Defaults.getDefault('TARDIS_LS_COLORS'))
# Load any password info
password = Util.getPassword(args.password, args.passwordfile, args.passwordprog, prompt="Password for %s: " % (args.client))
args.password = None
(tardis, _, crypt) = Util.setupDataConnection(args.database, args.client, password, args.keys, args.dbname, args.dbdir)
setupDisplay(tardis)
if args.headers:
doprint("Client: %s DB: %s" %(args.client, args.database), color=colors['name'], eol=True)
if args.glob:
directories = []
for d in args.directories:
if not Util.isMagic(d):
directories.append(d)
else:
directories += globPath(os.path.abspath(d), tardis, crypt)
else:
directories = args.directories
for d in directories:
d = os.path.abspath(d)
if args.realpath:
d = os.path.realpath(d)
fInfos = collectFileInfo(d, tardis, crypt)
recurse = args.maxdepth if args.recurse else 0
processFile(d, fInfos, tardis, crypt, printContents=(not args.dirinfo), recurse=recurse)
except KeyboardInterrupt:
pass
except Exception as e:
logger.error("Caught exception: %s", str(e))
logger.exception(e)
示例12: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
logging.basicConfig(level=logging.INFO)
crypto = None
token = None
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordurl, args.passwordprog)
if password:
crypto = TardisCrypto.TardisCrypto(password, args.client)
path = os.path.join(args.database, args.client, args.dbname)
db = TardisDB.TardisDB(path, token=token, backup=False)
if crypto:
(a, b) = db.getKeys()
crypto.setKeys(a, b)
conn = db.conn
dirs = conn.execute("SELECT Name as name, Inode AS inode, Device AS device, FirstSet as firstset, LastSet AS lastset FROM Files JOIN Names ON Files.NameId = Names.NameId WHERE Dir = 1")
while True:
batch = dirs.fetchmany(1000)
if not batch:
break
for d in batch:
name = d['name']
inode = d['inode']
device = d['device']
firstset = d['firstset']
lastset = d['lastset']
files = db.readDirectory((inode, device), current=lastset)
(checksum, nfiles) = Util.hashDir(crypto, files, True)
print(("%-20s (%d, %d) [%d %d] -- %s %d") % (name, inode, device, firstset, lastset, checksum, nfiles))
ckinfo = db.getChecksumInfo(checksum)
if ckinfo:
cksid = ckinfo['checksumid']
else:
cksid = db.insertChecksumFile(checksum, size=nfiles, isFile=False)
db.updateDirChecksum((inode, device), cksid, current=lastset)
conn.commit()
示例13: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
crypto = None
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordurl, args.passwordprog)
if password:
crypto = TardisCrypto.TardisCrypto(password, args.client)
path = os.path.join(args.database, args.client, args.dbname)
db = TardisDB.TardisDB(path, backup=False)
token = createToken(crypto, args.client)
if not checkToken(db, token):
logger.error("Password does not match")
sys.exit(1)
salt, vkey = srp.create_salted_verification_key(args.client, password)
db.setSrpValues(salt, vkey)
db._setConfigValue('Token', None)
示例14: main
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def main():
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('')
args = processArgs()
password = Util.getPassword(args.password, args.passwordfile, args.passwordurl, args.passwordprog)
crypto = TardisCrypto.TardisCrypto(password, args.client)
token = crypto.createToken()
logger.info("Created token: %s", token)
path = os.path.join(args.database, args.client, args.dbname)
db = TardisDB.TardisDB(path, token=token, backup=False)
(f, c) = db.getKeys()
crypto.setKeys(f, c)
cacheDir = CacheDir.CacheDir(os.path.join(args.database, args.client))
if args.filenames:
encryptFilenames(db, crypto)
if args.files:
encryptFiles(db, crypto, cacheDir)
示例15: __init__
# 需要导入模块: from Tardis import Util [as 别名]
# 或者: from Tardis.Util import getPassword [as 别名]
def __init__(self, *args, **kw):
super(TardisFS, self).__init__(*args, **kw)
try:
client = Defaults.getDefault('TARDIS_CLIENT')
database = Defaults.getDefault('TARDIS_DB')
dbdir = Defaults.getDefault('TARDIS_DBDIR') % { 'TARDIS_DB': database } # HACK
dbname = Defaults.getDefault('TARDIS_DBNAME')
current = Defaults.getDefault('TARDIS_RECENT_SET')
# Parameters
self.database = database
self.client = client
self.repoint = False
self.password = None
self.pwfile = None
self.pwprog = None
self.keys = None
self.dbname = dbname
self.dbdir = dbdir
self.cachetime = 60
self.nocrypt = False
self.noauth = False
self.current = current
self.authenticate = True
self.crypt = None
logging.basicConfig(level=logging.WARNING)
self.log = logging.getLogger("TardisFS")
self.parser.add_option("--database", '-D', help="Path to the Tardis database directory")
self.parser.add_option("--client", '-C', help="Client to load database for")
self.parser.add_option("--password", '-P', help="Password for this archive (use '-o password=' to prompt for password)")
self.parser.add_option("--keys", help="Load keys from the specified file")
self.parser.add_option(mountopt="database", help="Path to the Tardis database directory")
self.parser.add_option(mountopt="client", help="Client to load database for")
self.parser.add_option(mountopt="password", help="Password for this archive (use '-o password=' to prompt for password)")
self.parser.add_option(mountopt="pwfile", help="Read password for this archive from the file. Can be a URL (HTTP/HTTPS or FTP)")
self.parser.add_option(mountopt="pwprog", help="Use the specified program to generate the password on stdout")
self.parser.add_option(mountopt="keys", help="Load keys from the specified file")
self.parser.add_option(mountopt="repoint", help="Make absolute links relative to backupset")
self.parser.add_option(mountopt="dbname", help="Database Name")
self.parser.add_option(mountopt="dbdir", help="Database Directory (if different from data directory")
self.parser.add_option(mountopt="cachetime", help="Lifetime of cached elements in seconds")
self.parser.add_option(mountopt='nocrypt', help="Disable encryption")
self.parser.add_option(mountopt='noauth', help="Disable authentication")
self.parser.add_option(mountopt='current', help="Name to use for most recent complete backup")
res = self.parse(values=self, errex=1)
self.mountpoint = res.mountpoint
self.name = "TardisFS:<{}/{}>".format(self.database, self.client)
password = Util.getPassword(self.password, self.pwfile, self.pwprog, prompt="Password for %s: " % (self.client))
self.password = None
self.cache = Cache.Cache(0, float(self.cachetime))
self.fileCache = Cache.Cache(0, float(self.cachetime), 'FileCache')
#if password:
# self.crypt = TardisCrypto.TardisCrypto(password, self.client)
(self.tardis, self.cacheDir, self.crypt) = Util.setupDataConnection(self.database, self.client, password, self.keys, self.dbname, self.dbdir)
password = None
# Remove the crypto object if not encyrpting files.
if self.nocrypt or self.nocrypt is None:
self.crypt = None
if self.noauth or self.noauth is None:
self.authenticate = False
# Create a regenerator.
self.regenerator = Regenerator.Regenerator(self.cacheDir, self.tardis, crypt=self.crypt)
self.files = {}
# Fuse variables
self.flags = 0
self.multithreaded = 0
except Exception as e:
self.log.exception(e)
sys.exit(2)