Beispiel #1
0
def exportDb(targetDir, password=None, hostname=None):
    dbSysInst = dbSys.dbSysSmart()
    startTime = findLastTimestamp(targetDir, hostname)
    endTime = dbSysInst.getTimeStamp()
    finalRes = dbSysInst.exportDb(startTime, endTime, hostname)
    if len(finalRes) == 0:
        print "no update need to be exported"
        return
    finalRes = dictListDecryptor(finalRes)
    timeStampName = "%s-%s" % (startTime, endTime)
    package = {"backup-id": unicode(str(uuid.uuid4())), "time-duration": timeStampName}
    if password is None:
        package["add"] = finalRes
        fullname = "%s_%s.noenc.json" % (hostname, timeStampName)
    else:
        fullname = "%s_%s.json" % (hostname, timeStampName)
        en = enc.encryptorBase64Out(password)
        finalRes = dictListEncryptor(finalRes, en)
        package["encPass"] = unicode(str(md5.new(password + timeStampName).hexdigest()))
        package["add"] = finalRes
    targetFullPath = os.path.join(targetDir, fullname)
    s = json.dumps(package, sort_keys=True, indent=4)
    # s = json.dumps(package)
    f = open(targetFullPath, "w")
    f.write(s)
    f.close()
Beispiel #2
0
def importDb(input, password = None):
    dbSysInst = dbSys.dbSysSmart()
    sf = open(input, 'r')
    package = json.load(sf)
    en = enc.encryptorBase64Out(password)
    l = package["add"]
    if (password is None) and package.has_key("encPass"):
        print 'need password for importing'
        return
    if (not (password is None)):
        if unicode(str(md5.new(password).hexdigest())) != package["encPass"]:
            print 'pass not match:', unicode(str(md5.new(password+package["time-duration"]).hexdigest())), package["encPass"]
            return
        else:
            l = listEncryptor.dictListDecryptor(l, en)
    l = listEncryptor.dictListEncryptor(l)
    dbSysInst.importDb(l)
Beispiel #3
0
def decryptBackup(sourceFullPath, target, password = None):
    sf = open(sourceFullPath, 'r')
    l = json.load(sf)
    if l.has_key("encPass"):
        if password is None:
            print 'need password'
            return
        else:
            en = enc.encryptorBase64Out(password)
            if str(md5.new(password+l["time-duration"]).hexdigest()) != l["encPass"]:
                print 'pass not match:', str(md5.new(password+l["time-duration"]).hexdigest()), l["encPass"]
                return
            res = dbExporterV3.dictListDecryptor(l["add"], en)
    else:
        res = l["add"]
    l["add"] = res
    del l["encPass"]
    s = json.dumps(l, sort_keys=True, indent=4)
    f = open(target,'w')
    f.write(s)
    f.close()
Beispiel #4
0
def importDb(input, username, targetPasswd, password = None):
    dbSysInst = dbSys.dbSysSmart()
    sf = open(input, 'r')
    package = json.load(sf)
    en = enc.encryptorBase64Out(password)
    l = package["add"]
    if (password is None) and package.has_key("encPass"):
        print 'need password for importing'
        return
    if (not (password is None)):
        if unicode(str(md5.new(password).hexdigest())) != package["encPass"]:
            print 'pass not match:', unicode(str(md5.new(password+package["time-duration"]).hexdigest())), package["encPass"]
            return
        else:
            l = listEncryptor.dictListDecryptor(l, en)
    sysUser = service.ufsUser(u'system.user', u'system.pass')
    if userMan.userManager().verifyPasswd(username, targetPasswd, dbSys.dbSysSmart(sysUser).getDb("passwdDb")):
        print 'importing'
        l = listEncryptor.dictListEncryptor(l, xorEnc.encryptorTxtOut(targetPasswd))
        #print l
        l = listEncryptor.setUser(l, username)
        #print l
        dbSysInst.importDb(l)