예제 #1
0
    def post(self, request):
        validator = FileValidator() # validate input
        if "username" in request.session:
            requestCon = json.loads(request.body)
            if requestCon["owner"] == "self":
                ownerName = request.session["username"]

            else:
                ownerName = requestCon["owner"]
                with ShareFileModel() as sharefilemodel:
                    sharefilemodel.setFileAlias(requestCon['fn'])
                    sharefilemodel.setOwner(ownerName )
                    sharefilemodel.setSharedWith(request.session["username"])
                    sharerows = sharefilemodel.queryShareFile_fileAlias()
            validator.setfileName(requestCon['fn'])
            if validator.verifyfileName() == True:
                with FileModel() as filemodel:
                    filemodel.setFileName(requestCon['fn'])
                    filemodel.setUsername(ownerName)
                    rows = filemodel.queryHashCode()
                if requestCon["owner"] == "self":
                    if rows == None:
                        return HttpResponse(json.dumps(['success']), content_type="application/json")
                    else:
                        return HttpResponse(json.dumps(['exist']), content_type="application/json")
                else:
                    if rows == None and sharerows == None:
                        return HttpResponse(json.dumps(['success']), 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")
예제 #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")
예제 #3
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")
예제 #4
0
 def post(self, request):
     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.setFileName(requestCon["fn"])
                 filemodel.setUsername(request.session["username"])
                 rows = filemodel.queryHashCode()
             if rows == None:
                 return HttpResponse(json.dumps(["success"]), 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")
예제 #5
0
 def post(self, request):
     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.setFileName(requestCon['fn'])
                 filemodel.setUsername(request.session["username"])
                 rows = filemodel.queryHashCode()
             if rows == None:
                 return HttpResponse(json.dumps(['success']),
                                     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")
예제 #6
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")
예제 #7
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")