Beispiel #1
0
    def post(self, request):

        readfile = FileNotepad()
        writenewfile = FileNotepad()
        encrypt = EncryptionPath()
        validator = FileValidator()  # validate input

        if "username" in request.session:
            requestCon = json.loads(request.body)
            validator.setfileName(requestCon['fn'])
            if validator.verifyfileName() == True:
                with FileModel() as filemodel:
                    filemodel.setUsername(request.session["username"])
                    userID = filemodel.queryUserID()[0]
                hashMD5 = encrypt.creatMD5(requestCon['fn'], "", userID)
                hashSHA1 = encrypt.creatSHA1("")
                completePath = encrypt.writePath("get")
                validator.setfilePath(completePath)
                if validator.verifyfilePath() == False:
                    # write the file if not detected
                    logging.info("Adding a new fileContent at: {0}".format(
                        completePath))
                    writenewfile.setFilepath(completePath)
                    writenewfile.writeNewFile("")
                    with FileModel() as filemodel:
                        filemodel.setUsername(request.session["username"])
                        filemodel.setFileName(requestCon['fn'])
                        filemodel.setUserID(userID)
                        filemodel.setHashCode(hashMD5, hashSHA1)
                        filemodel.insertFile()
                        newRow = filemodel.queryFile()
                        fileID = newRow["ID"]

                    # write log
                    with FileActivityLog() as activitylog:
                        activitylog.setUserID(newRow["userID"])
                        activitylog.setFileID(fileID)
                        activitylog.setCurName(requestCon['fn'])
                        activitylog.insertCreate()

                    return HttpResponse(json.dumps(newRow),
                                        content_type="application/json")
                else:
                    return HttpResponse(json.dumps('exist'),
                                        content_type="application/json")
            else:
                return HttpResponse(json.dumps('notvalid'),
                                    content_type="application/json")
        else:
            return HttpResponse(json.dumps('notlogin'),
                                content_type="application/json")
Beispiel #2
0
    def post(self, request):

        readfile = FileNotepad()
        writenewfile = FileNotepad()
        encrypt = EncryptionPath()
        validator = FileValidator() # validate input

        if "username" in request.session:
            requestCon = json.loads(request.body)
            validator.setfileName(requestCon['fn'])
            if validator.verifyfileName() == True:
                with FileModel() as filemodel:
                    filemodel.setUsername(request.session["username"])
                    userID = filemodel.queryUserID()[0]
                hashMD5 = encrypt.creatMD5(requestCon['fn'], "", userID)
                hashSHA1 = encrypt.creatSHA1("")
                completePath = encrypt.writePath("get")
                validator.setfilePath(completePath)
                if validator.verifyfilePath() == False:
                    # write the file if not detected
                    logging.info("Adding a new fileContent at: {0}".format(completePath))
                    writenewfile.setFilepath(completePath)
                    writenewfile.writeNewFile("")
                    with FileModel() as filemodel:
                        filemodel.setUsername(request.session["username"])
                        filemodel.setFileName(requestCon['fn'])
                        filemodel.setUserID(userID)
                        filemodel.setHashCode(hashMD5, hashSHA1)
                        filemodel.insertFile()
                        newRow = filemodel.queryFile()
                        fileID = newRow["ID"]

                    # write log
                    with FileActivityLog() as activitylog:
                        activitylog.setUserID(newRow["userID"])
                        activitylog.setFileID(fileID)
                        activitylog.setCurName(requestCon['fn'])
                        activitylog.insertCreate()

                    return HttpResponse(json.dumps(newRow), content_type="application/json")
                else:
                    return HttpResponse(json.dumps('exist'), content_type="application/json")
            else:
                return HttpResponse(json.dumps('notvalid'), content_type="application/json")
        else:
            return HttpResponse(json.dumps('notlogin'), content_type="application/json")
Beispiel #3
0
    def post(self, request):
        readfile = FileNotepad()
        writenewfile = FileNotepad()
        filevalidator = FileValidator()
        encrypt = EncryptionPath()

        Filename = request.POST.get("Filename")
        rawData = request.FILES["Filedata"]
        if filevalidator.verifyfileSize(rawData) == False:
            return HttpResponse("exceed", content_type="text/plain")
        else:
            filevalidator.setfileName(Filename)
            if filevalidator.verifyfileName() == False:
                return HttpResponse("namenotvalid", content_type="text/plain")
            else:
                tempFile = self.saveFile(Filename, rawData)
                readfile.setFilepath(tempFile)
                Filedata = readfile.readRawFile()
                Filecontent = readfile.processRawFile(Filedata)
                if "username" in request.session:	
                    with FileModel() as filemodel:
                        filemodel.setUsername(request.session["username"])
                        results = filemodel.queryUserID()
                        userID = results[0]
                        filemodel.setFileName(Filename)
                        rows = filemodel.queryHashCode()
                    if rows != None:
                        os.remove(tempFile)
                        return HttpResponse("exist", content_type="text/plain")

                    hashMD5 = encrypt.creatMD5(Filename, Filecontent, userID)
                    hashSHA1 = encrypt.creatSHA1(Filecontent)
                    completePath = encrypt.writePath("get")
                    filevalidator.setfilePath(completePath)
                    if filevalidator.verifyfilePath() == False:
                        # write the file if not detected
                        logging.info("Adding a new fileContent at: {0}".format(completePath))
                        writenewfile.setFilepath(completePath)
                        writenewfile.writeNewFile(Filecontent)
                        with FileModel() as filemodel:
                            filemodel.setUserID(userID)
                            filemodel.setUsername(request.session["username"])
                            filemodel.setFileName(Filename)
                            filemodel.setHashCode(hashMD5, hashSHA1)
                            filemodel.insertFile()
                            fileID = filemodel.queryHashCode()[3]

                        # write log
                        with FileActivityLog() as activitylog:
                            activitylog.setUserID(userID)
                            activitylog.setFileID(fileID)
                            activitylog.setCurName(Filename)
                            activitylog.setOwnerID(userID)
                            activitylog.insertUpload()

                        # read the file again and verify it is hashed correctly
                        if filevalidator.verifyfileContent(hashSHA1) == True:
                            os.remove(tempFile)
                            return HttpResponse("success", content_type="text/plain")
                        else:
                            os.remove(tempFile)
                            logging.error("Something is weird about the provided: {0}".format(completePath))
                            return HttpResponse("internalerror", content_type="text/plain")
                    else:
                        os.remove(tempFile)
                        return HttpResponse("exist", content_type="text/plain")
                else:
                    os.remove(tempFile)
                    return HttpResponse("notlogin", content_type="text/plain")
Beispiel #4
0
    def post(self, request):
        readfile = FileNotepad()
        writenewfile = FileNotepad()
        filevalidator = FileValidator()
        encrypt = EncryptionPath()

        if "username" in request.session:
            requestCon = json.loads(request.body)
            if requestCon["owner"] == "Yourself":
                ownerName = request.session["username"]
            else:
                ownerName = requestCon["owner"]

            with FileModel() as filemodel:
                filemodel.setUsername(ownerName)
                filemodel.setFileName(requestCon["filename"])
                rows = filemodel.queryHashCode()
                fileID = rows[3]
                ownerID = rows[0]
                filemodel.setUsername(request.session["username"])
                userID = filemodel.queryUserID()[0]
            if rows == None:
                return HttpResponse("notfound", content_type="text/plain")
            else:
                encrypt.setHashCode(rows[1], rows[2])
                completePath = encrypt.writePath("get")
                dirpath = encrypt.writePath("delete")
                filevalidator.setfilePath(completePath)
                if filevalidator.verifyfileContent(rows[2]) == False:
                    logging.error(
                        "Something is weird about the provided: {0}".format(
                            completePath))
                    return HttpResponse("internalerror",
                                        content_type="text/plain")
                else:
                    newMD5 = encrypt.creatMD5(requestCon["filename"],
                                              requestCon["content"], rows[0])
                    newSHA1 = encrypt.creatSHA1(requestCon["content"])
                    logging.info("newMD5: {0}".format(newMD5))
                    logging.info("newSHA1: {0}".format(newSHA1))
                    newPath = encrypt.writePath("get")
                    filevalidator.setfilePath(newPath)
                    if filevalidator.verifyfilePath() == False:
                        # write the file if not detected
                        logging.info(
                            "Adding a new fileContent at: {0}".format(newPath))
                        writenewfile.setFilepath(newPath)
                        writenewfile.writeNewFile(requestCon["content"])
                        with FileModel() as filemodel:
                            filemodel.setUsername(ownerName)
                            filemodel.setFileName(requestCon["filename"])
                            filemodel.setHashCode(newMD5, newSHA1)
                            filemodel.updateFile()

                        # read the file again and verify it is hashed correctly
                        if filevalidator.verifyfileContent(newSHA1) == True:
                            shutil.rmtree(dirpath)
                            logging.info(
                                "Deleting the old fileContent at: {0}".format(
                                    completePath))

                            # write log
                            with FileActivityLog() as activitylog:
                                activitylog.setUserID(userID)
                                activitylog.setFileID(fileID)
                                activitylog.setCurName(requestCon["filename"])
                                activitylog.setOwnerID(ownerID)
                                activitylog.insertEdit()

                            return HttpResponse("success",
                                                content_type="text/plain")
                        else:
                            logging.error(
                                "Something is weird about the provided: {0}".
                                format(newPath))
                            return HttpResponse("internalerror",
                                                content_type="text/plain")
                    else:
                        return HttpResponse("exist", content_type="text/plain")
        else:
            return HttpResponse("notlogin", content_type="text/plain")
Beispiel #5
0
    def post(self, request):
        readfile = FileNotepad()
        writenewfile = FileNotepad()
        filevalidator = FileValidator()
        encrypt = EncryptionPath()

        Filename = request.POST.get("Filename")
        rawData = request.FILES["Filedata"]
        if filevalidator.verifyfileSize(rawData) == False:
            return HttpResponse("exceed", content_type="text/plain")
        else:
            filevalidator.setfileName(Filename)
            if filevalidator.verifyfileName() == False:
                return HttpResponse("namenotvalid", content_type="text/plain")
            else:
                tempFile = self.saveFile(Filename, rawData)
                readfile.setFilepath(tempFile)
                Filedata = readfile.readRawFile()
                Filecontent = readfile.processRawFile(Filedata)
                if "username" in request.session:
                    with FileModel() as filemodel:
                        filemodel.setUsername(request.session["username"])
                        results = filemodel.queryUserID()
                        userID = results[0]
                        filemodel.setFileName(Filename)
                        rows = filemodel.queryHashCode()
                    if rows != None:
                        os.remove(tempFile)
                        return HttpResponse("exist", content_type="text/plain")

                    hashMD5 = encrypt.creatMD5(Filename, Filecontent, userID)
                    hashSHA1 = encrypt.creatSHA1(Filecontent)
                    completePath = encrypt.writePath("get")
                    filevalidator.setfilePath(completePath)
                    if filevalidator.verifyfilePath() == False:
                        # write the file if not detected
                        logging.info("Adding a new fileContent at: {0}".format(
                            completePath))
                        writenewfile.setFilepath(completePath)
                        writenewfile.writeNewFile(Filecontent)
                        with FileModel() as filemodel:
                            filemodel.setUserID(userID)
                            filemodel.setUsername(request.session["username"])
                            filemodel.setFileName(Filename)
                            filemodel.setHashCode(hashMD5, hashSHA1)
                            filemodel.insertFile()
                            fileID = filemodel.queryHashCode()[3]

                        # write log
                        with FileActivityLog() as activitylog:
                            activitylog.setUserID(userID)
                            activitylog.setFileID(fileID)
                            activitylog.setCurName(Filename)
                            activitylog.setOwnerID(userID)
                            activitylog.insertUpload()

                        # read the file again and verify it is hashed correctly
                        if filevalidator.verifyfileContent(hashSHA1) == True:
                            os.remove(tempFile)
                            return HttpResponse("success",
                                                content_type="text/plain")
                        else:
                            os.remove(tempFile)
                            logging.error(
                                "Something is weird about the provided: {0}".
                                format(completePath))
                            return HttpResponse("internalerror",
                                                content_type="text/plain")
                    else:
                        os.remove(tempFile)
                        return HttpResponse("exist", content_type="text/plain")
                else:
                    os.remove(tempFile)
                    return HttpResponse("notlogin", content_type="text/plain")
Beispiel #6
0
    def post(self, request):
        readfile = FileNotepad()
        writenewfile = FileNotepad()
        filevalidator = FileValidator()
        encrypt = EncryptionPath()

        if "username" in request.session:
            requestCon = json.loads(request.body)
            if requestCon["owner"] == "Yourself":
                ownerName = request.session["username"]
            else:
                ownerName = requestCon["owner"]

            with FileModel() as filemodel:
                filemodel.setUsername(ownerName)
                filemodel.setFileName(requestCon["filename"])
                rows = filemodel.queryHashCode()
                fileID  = rows[3]
                ownerID  = rows[0]
                filemodel.setUsername(request.session["username"])
                userID = filemodel.queryUserID()[0]
            if rows == None:
                return HttpResponse("notfound", content_type="text/plain")
            else:
                encrypt.setHashCode(rows[1], rows[2])
                completePath = encrypt.writePath("get")
                dirpath = encrypt.writePath("delete")
                filevalidator.setfilePath(completePath)
                if filevalidator.verifyfileContent(rows[2]) == False:
                    logging.error("Something is weird about the provided: {0}".format(completePath))
                    return HttpResponse("internalerror", content_type="text/plain")
                else:
                    newMD5 = encrypt.creatMD5(requestCon["filename"], requestCon["content"], rows[0])
                    newSHA1 = encrypt.creatSHA1(requestCon["content"])
                    logging.info("newMD5: {0}".format(newMD5))
                    logging.info("newSHA1: {0}".format(newSHA1))
                    newPath = encrypt.writePath("get")
                    filevalidator.setfilePath(newPath)
                    if filevalidator.verifyfilePath() == False:
                        # write the file if not detected
                        logging.info("Adding a new fileContent at: {0}".format(newPath))
                        writenewfile.setFilepath(newPath)
                        writenewfile.writeNewFile(requestCon["content"])
                        with FileModel() as filemodel:
                            filemodel.setUsername(ownerName)
                            filemodel.setFileName(requestCon["filename"])
                            filemodel.setHashCode(newMD5, newSHA1)
                            filemodel.updateFile()

                        # read the file again and verify it is hashed correctly
                        if filevalidator.verifyfileContent(newSHA1) == True:
                            shutil.rmtree(dirpath)
                            logging.info("Deleting the old fileContent at: {0}".format(completePath))

                            # write log
                            with FileActivityLog() as activitylog:
                                activitylog.setUserID(userID)
                                activitylog.setFileID(fileID)
                                activitylog.setCurName(requestCon["filename"])
                                activitylog.setOwnerID(ownerID)
                                activitylog.insertEdit()

                            return HttpResponse("success", content_type="text/plain")
                        else:
                            logging.error("Something is weird about the provided: {0}".format(newPath))
                            return HttpResponse("internalerror", content_type="text/plain")
                    else:
                        return HttpResponse("exist", content_type="text/plain")
        else:
            return HttpResponse("notlogin", content_type="text/plain")
Beispiel #7
0
    def post(self, request):
        readfile = FileNotepad()
        writenewfile = FileNotepad()
        filevalidator = FileValidator()
        encrypt = EncryptionPath()

        if "username" in request.session:
            requestCon = json.loads(request.body)
            if requestCon["owner"] == "self":
                ownerName = request.session["username"]
                with FileModel() as filemodel:
                    filemodel.setUsername(ownerName)
                    filemodel.setFileName(requestCon["oldname"])
                    rows = filemodel.queryHashCode()
                    fileID = rows[3]
                    userID = rows[0]
                    ownerID = rows[0]
                    hashMD5 = rows[1]
                    hashSHA1 = rows[2]
            else:
                ownerName = requestCon["owner"]
                with ShareFileModel() as sharefilemodel:
                    sharefilemodel.setFileAlias(requestCon["oldname"])
                    sharefilemodel.setOwner(ownerName)
                    sharefilemodel.setSharedWith(request.session["username"])
                    rows = sharefilemodel.queryShareFile_fileAlias()
                    fileID = rows[1]
                    userID = rows[4]
                    ownerID = rows[3]
            if rows == None:
                return HttpResponse(json.dumps(["notfound"]), content_type="application/json")
            else:
                privilege = ""
                if requestCon["owner"] != "self":
                    with ShareFileModel() as sharefilemodel:
                        sharefilemodel.setFileID(fileID)
                        sharefilemodel.setOwner(ownerName)
                        sharefilemodel.setSharedWith(request.session["username"])
                        privilege = sharefilemodel.queryShareFile()[5]
                    with FileModel() as filemodel:
                        filemodel.setFileID(fileID)
                        result = filemodel.queryFile_fileID()
                        hashMD5 = result[1]
                        hashSHA1 = result[2]
                if privilege == 11 or privilege == 21 or privilege == 12 or privilege == 22:
                    with ShareFileModel() as sharefilemodel:
                        sharefilemodel.setFileID(fileID)
                        sharefilemodel.setOwner(ownerName)
                        sharefilemodel.setSharedWith(request.session["username"])
                        sharefilemodel.setFileAlias(requestCon["newname"])
                        sharefilemodel.setPrivilege(privilege)
                        sharefilemodel.updateShareFile()
                    if privilege == 11 or privilege == 21:
                        # write log
                        with FileActivityLog () as activitylog:
                            activitylog.setUserID(userID)
                            activitylog.setFileID(fileID)
                            activitylog.setCurName(requestCon["newname"]+"/"+requestCon["oldname"])
                            activitylog.setOwnerID(ownerID)
                            activitylog.insertRename()
                        return HttpResponse(json.dumps(["success"]), content_type="application/json")
                if requestCon["owner"] == "self" or privilege == 12 or privilege == 22:
                    encrypt.setHashCode(hashMD5, hashSHA1)
                    completePath = encrypt.writePath("get")
                    dirpath = encrypt.writePath("delete")
                    filevalidator.setfilePath(completePath)
                    if filevalidator.verifyfileContent(hashSHA1) == False:
                        logging.error("Something is weird about the provided: {0}".format(completePath))
                        return HttpResponse(json.dumps(["internalerror"]), content_type="application/json")
                    else:
                        readfile.setFilepath(completePath)
                        fileContent = readfile.readFile()
                        newMD5 = encrypt.creatMD5(requestCon["newname"], fileContent, ownerID)
                        newSHA1 = encrypt.creatSHA1(fileContent)
                        logging.info("newMD5: {0}".format(newMD5))
                        logging.info("newSHA1: {0}".format(newSHA1))
                        newPath = encrypt.writePath("get")
                        filevalidator.setfilePath(newPath)
                        logging.info("newfile: {0}".format(newPath))
                        if filevalidator.verifyfilePath() == False:
                            # write the file if not detected
                            logging.info("Adding a new fileContent at: {0}".format(newPath))
                            writenewfile.setFilepath(newPath)
                            writenewfile.writeNewFile(fileContent)
                            with FileModel() as filemodel:
                                filemodel.setUsername(request.session["username"])
                                filemodel.setFileName(requestCon["newname"])
                                filemodel.setHashCode(newMD5, newSHA1)
                                filemodel.updateFile(requestCon["oldname"])
                            # read the file again and verify it is hashed correctly
                            if filevalidator.verifyfileContent(newSHA1) == True:
                                shutil.rmtree(dirpath)
                                logging.info("Deleting the old fileContent at: {0}".format(completePath))

                                # write log
                                with FileActivityLog () as activitylog:
                                    activitylog.setUserID(userID)
                                    activitylog.setFileID(fileID)
                                    activitylog.setCurName(requestCon["newname"]+"/"+requestCon["oldname"])
                                    activitylog.setOwnerID(ownerID)
                                    activitylog.insertRename()

                                return HttpResponse(json.dumps(["success"]), content_type="application/json")
                            else:
                                logging.error("Something is weird about the provided: {0}".format(newPath))
                                return HttpResponse(json.dumps(["internalerror"]), content_type="application/json")
                        else:
                            return HttpResponse(json.dumps(["exist"]), content_type="application/json")
        else:
            return HttpResponse(json.dumps(["notlogin"]), content_type="application/json")
Beispiel #8
0
    def post(self, request):
        logging.info("Appending file...")
        readfile = FileNotepad()
        writenewfile = FileNotepad()
        filevalidator = FileValidator()
        encrypt = EncryptionPath()

        if "username" in request.session:
            requestCon = json.loads(request.body)

            if requestCon["owner"] == "self":
                ownerName = request.session["username"]
                with FileModel() as filemodel:
                    filemodel.setUsername(ownerName)
                    filemodel.setFileName(requestCon["filename"])
                    rows = filemodel.queryHashCode()
                    userid = filemodel.queryUserID()[0]
                    fileID = rows[3]

            else:
                ownerName = requestCon["owner"]
                with ShareFileModel() as sharefilemodel:
                    sharefilemodel.setFileAlias(requestCon["filename"])
                    sharefilemodel.setOwner(ownerName)
                    sharefilemodel.setSharedWith(request.session["username"])
                    fileID = sharefilemodel.queryShareFile_fileAlias()[1]

                with FileModel() as filemodel:
                    filemodel.setFileID(fileID)
                    rows = filemodel.queryFile_fileID()
                    filemodel.setUsername(request.session["username"])
                    userid = filemodel.queryUserID()[0]

            encrypt.setHashCode(rows[1], rows[2])
            completePath = encrypt.writePath("get")
            filevalidator.setfilePath(completePath)
            if filevalidator.verifyfileContent(rows[2]) == False:
                logging.error("Something is weird about the provided: {0}".format(completePath))
                return HttpResponse(json.dumps(["internalerror"]), content_type="application/json")
            else:
                readfile.setFilepath(completePath)
                fileContent = readfile.readFile()
                count = 1
                newName = requestCon["filename"]
                while rows != None:
                    with FileModel() as filemodel:
                        filemodel.setUsername(request.session["username"])
                        newName = requestCon["filename"][:-4] + " - Copy (" + str(count) + ").txt"
                        filemodel.setFileName(newName)
                        rows = filemodel.queryHashCode()
                    count += 1
                newMD5 = encrypt.creatMD5(newName, fileContent, userid)
                newSHA1 = encrypt.creatSHA1(fileContent)
                logging.info("newMD5: {0}".format(newMD5))
                logging.info("newSHA1: {0}".format(newSHA1))
                newPath = encrypt.writePath("get")
                filevalidator.setfilePath(newPath)
                logging.info("newfile: {0}".format(newPath))
                if filevalidator.verifyfilePath() == False:
                    # write the file if not detected
                    logging.info("Adding a new fileContent at: {0}".format(newPath))
                    writenewfile.setFilepath(newPath)
                    writenewfile.writeNewFile(fileContent)
                    with FileModel() as filemodel:
                        filemodel.setUsername(request.session["username"])
                        filemodel.setFileName(newName)
                        filemodel.setUserID(userid)
                        filemodel.setHashCode(newMD5, newSHA1)
                        filemodel.insertFile()
                        newfileID = filemodel.queryFile()["ID"]

                    # write log
                    with FileActivityLog() as activitylog:
                        activitylog.setUserID(userid)
                        activitylog.setFileID(newfileID)
                        activitylog.setCurName(newName)
                        activitylog.insertCreate()

                    return HttpResponse(json.dumps(["success"]), content_type="application/json")
                else:
                    return HttpResponse(json.dumps(["exist"]), content_type="application/json")
        else:
            return HttpResponse(json.dumps(["notlogin"]), content_type="application/json")
Beispiel #9
0
    def post(self, request):
        readfile = FileNotepad()
        writenewfile = FileNotepad()
        filevalidator = FileValidator()
        encrypt = EncryptionPath()

        if "username" in request.session:
            requestCon = json.loads(request.body)
            if requestCon["owner"] == "self":
                ownerName = request.session["username"]
                with FileModel() as filemodel:
                    filemodel.setUsername(ownerName)
                    filemodel.setFileName(requestCon["oldname"])
                    rows = filemodel.queryHashCode()
                    fileID = rows[3]
                    userID = rows[0]
                    ownerID = rows[0]
                    hashMD5 = rows[1]
                    hashSHA1 = rows[2]
            else:
                ownerName = requestCon["owner"]
                with ShareFileModel() as sharefilemodel:
                    sharefilemodel.setFileAlias(requestCon["oldname"])
                    sharefilemodel.setOwner(ownerName)
                    sharefilemodel.setSharedWith(request.session["username"])
                    rows = sharefilemodel.queryShareFile_fileAlias()
                    fileID = rows[1]
                    userID = rows[4]
                    ownerID = rows[3]
            if rows == None:
                return HttpResponse(json.dumps(["notfound"]),
                                    content_type="application/json")
            else:
                privilege = ""
                if requestCon["owner"] != "self":
                    with ShareFileModel() as sharefilemodel:
                        sharefilemodel.setFileID(fileID)
                        sharefilemodel.setOwner(ownerName)
                        sharefilemodel.setSharedWith(
                            request.session["username"])
                        privilege = sharefilemodel.queryShareFile()[5]
                    with FileModel() as filemodel:
                        filemodel.setFileID(fileID)
                        result = filemodel.queryFile_fileID()
                        hashMD5 = result[1]
                        hashSHA1 = result[2]
                if privilege == 11 or privilege == 21 or privilege == 12 or privilege == 22:
                    with ShareFileModel() as sharefilemodel:
                        sharefilemodel.setFileID(fileID)
                        sharefilemodel.setOwner(ownerName)
                        sharefilemodel.setSharedWith(
                            request.session["username"])
                        sharefilemodel.setFileAlias(requestCon["newname"])
                        sharefilemodel.setPrivilege(privilege)
                        sharefilemodel.updateShareFile()
                    if privilege == 11 or privilege == 21:
                        # write log
                        with FileActivityLog() as activitylog:
                            activitylog.setUserID(userID)
                            activitylog.setFileID(fileID)
                            activitylog.setCurName(requestCon["newname"] +
                                                   "/" + requestCon["oldname"])
                            activitylog.setOwnerID(ownerID)
                            activitylog.insertRename()
                        return HttpResponse(json.dumps(["success"]),
                                            content_type="application/json")
                if requestCon[
                        "owner"] == "self" or privilege == 12 or privilege == 22:
                    encrypt.setHashCode(hashMD5, hashSHA1)
                    completePath = encrypt.writePath("get")
                    dirpath = encrypt.writePath("delete")
                    filevalidator.setfilePath(completePath)
                    if filevalidator.verifyfileContent(hashSHA1) == False:
                        logging.error(
                            "Something is weird about the provided: {0}".
                            format(completePath))
                        return HttpResponse(json.dumps(["internalerror"]),
                                            content_type="application/json")
                    else:
                        readfile.setFilepath(completePath)
                        fileContent = readfile.readFile()
                        newMD5 = encrypt.creatMD5(requestCon["newname"],
                                                  fileContent, ownerID)
                        newSHA1 = encrypt.creatSHA1(fileContent)
                        logging.info("newMD5: {0}".format(newMD5))
                        logging.info("newSHA1: {0}".format(newSHA1))
                        newPath = encrypt.writePath("get")
                        filevalidator.setfilePath(newPath)
                        logging.info("newfile: {0}".format(newPath))
                        if filevalidator.verifyfilePath() == False:
                            # write the file if not detected
                            logging.info(
                                "Adding a new fileContent at: {0}".format(
                                    newPath))
                            writenewfile.setFilepath(newPath)
                            writenewfile.writeNewFile(fileContent)
                            with FileModel() as filemodel:
                                filemodel.setUsername(
                                    request.session["username"])
                                filemodel.setFileName(requestCon["newname"])
                                filemodel.setHashCode(newMD5, newSHA1)
                                filemodel.updateFile(requestCon["oldname"])
                            # read the file again and verify it is hashed correctly
                            if filevalidator.verifyfileContent(
                                    newSHA1) == True:
                                shutil.rmtree(dirpath)
                                logging.info(
                                    "Deleting the old fileContent at: {0}".
                                    format(completePath))

                                # write log
                                with FileActivityLog() as activitylog:
                                    activitylog.setUserID(userID)
                                    activitylog.setFileID(fileID)
                                    activitylog.setCurName(
                                        requestCon["newname"] + "/" +
                                        requestCon["oldname"])
                                    activitylog.setOwnerID(ownerID)
                                    activitylog.insertRename()

                                return HttpResponse(
                                    json.dumps(["success"]),
                                    content_type="application/json")
                            else:
                                logging.error(
                                    "Something is weird about the provided: {0}"
                                    .format(newPath))
                                return HttpResponse(
                                    json.dumps(["internalerror"]),
                                    content_type="application/json")
                        else:
                            return HttpResponse(
                                json.dumps(["exist"]),
                                content_type="application/json")
        else:
            return HttpResponse(json.dumps(["notlogin"]),
                                content_type="application/json")