Exemplo n.º 1
1
 def delete_users(self, userIds, format="json", requestOrigin="", **kwargs):
     user, sMessages, fMessages = (cherrypy.session.get("user"),  [], [])
     if requestOrigin != cherrypy.session['request-origin']:
         fMessages.append("Missing request key!!")
     else:
         userIds = split_list_sanitized(userIds)
         try:
             for userId in userIds:
                 try:
                     delUser = session.query(User).filter(User.id == userId).one()
                     session.delete(delUser)
                     for flFile in session.query(File).filter(File.owner_id == delUser.id):
                         FileService.queue_for_deletion(flFile.id)
                         session.delete(flFile)
                         session.add(AuditLog(user.id, Actions.DELETE_FILE, "File %s (%s) owned by user %s has been deleted as a result of the owner being deleted. " % (flFile.name, flFile.id, delUser.id), "admin"))
                     session.add(AuditLog(user.id, Actions.DELETE_USER, "User with ID: \"%s\" deleted from system" % delUser.id, "admin"))
                     sMessages.append("Successfully deleted user %s" % userId)
                 except sqlalchemy.orm.exc.NoResultFound:
                     fMessages.append("User with ID:%s does not exist" % userId)
                 except Exception, e:
                     fMessages.append("Could not delete user: %s" % str(e))
                 session.commit()
         except Exception, e:
             session.rollback()
             cherrypy.log.error("[%s] [delete_users] [Could not delete users: %s]" % (user.id, str(e)))
             fMessages.append("Could not delete users: %s" % str(e))
Exemplo n.º 2
0
def routine_maintenance(config):
    from lib import AccountService
    expiredFiles = session.query(File).filter(
        File.date_expires < datetime.datetime.now())
    for flFile in expiredFiles:
        try:
            for share in flFile.user_shares:
                session.delete(share)
            for share in flFile.group_shares:
                session.delete(share)
            for share in flFile.public_shares:
                session.delete(share)
            for share in flFile.attribute_shares:
                session.delete(share)
            FileService.queue_for_deletion(flFile.id)
            session.add(
                AuditLog(
                    "admin", Actions.DELETE_FILE,
                    "File %s (ID:%s) has expired and has been purged by the system."
                    % (flFile.name, flFile.id), flFile.owner_id))
            session.delete(flFile)
            session.commit()
        except Exception, e:
            session.rollback()
            cherrypy.log.error(
                "[system] [routine_maintenance] [Error while deleting expired file: %s]"
                % str(e))
 def delete_roles(self, roleIds, format="json", **kwargs):
     user, sMessages, fMessages = (cherrypy.session.get("user"), [], [])
     try:
         roleIds = split_list_sanitized(roleIds)
         for roleId in roleIds:
             try:
                 role = session.query(Role).filter(Role.id == roleId).one()
                 session.delete(role)
                 for flFile in session.query(File).filter(
                         File.role_owner_id == role.id):
                     FileService.queue_for_deletion(flFile.id)
                     session.delete(flFile)
                     session.add(
                         AuditLog(
                             user.id, Actions.DELETE_FILE,
                             "File %s (%s) owned by role %s has been deleted as a result of the role owner being deleted. "
                             % (flFile.name, flFile.id, role.id), "admin"))
                 session.add(
                     AuditLog(
                         user.id, Actions.DELETE_ROLE,
                         "%s deleted role \"%s\"(%s) from the system" %
                         (user.id, role.name, role.id), None))
                 sMessages.append("Successfully deleted roles%s." %
                                  str(roleId))
             except sqlalchemy.orm.exc.NoResultFound:
                 fMessages.append("The role ID: %s does not exist" %
                                  str(roleId))
         session.commit()
     except Exception, e:
         session.rollback()
         cherrypy.log.error(
             "[%s] [delete_roles] [Problem deleting roles: %s]" %
             (user.id, str(e)))
         fMessages.append("Problem deleting roles: %s" % str(e))
Exemplo n.º 4
0
 def delete_files(self, fileIds, format="json", requestOrigin="", **kwargs):
     user, role, sMessages, fMessages = (cherrypy.session.get("user"),cherrypy.session.get("current_role"), [], [])
     if requestOrigin != cherrypy.session['request-origin']:
         fMessages.append("Missing request key!!")
     else:
         fileIds = split_list_sanitized(fileIds)
         for fileId in fileIds:
             try:
                 fileId = int(fileId)
                 flFile = session.query(File).filter(File.id == fileId).one()
                 if flFile.role_owner_id is not None and role is not None and flFile.role_owner_id == role.id:
                     FileService.queue_for_deletion(flFile.id)
                     session.delete(flFile)
                     session.add(AuditLog(user.id, Actions.DELETE_FILE, "File %s (%s) owned by role %s has been deleted by user %s. " % (flFile.name, flFile.id, role.name, user.id)))
                     session.commit()
                     sMessages.append("File %s deleted successfully" % flFile.name)
                 elif flFile.owner_id == user.id or AccountService.user_has_permission(user, "admin"):
                     FileService.queue_for_deletion(flFile.id)
                     session.delete(flFile)
                     session.add(AuditLog(user.id, Actions.DELETE_FILE, "File %s (%s) has been deleted" % (flFile.name, flFile.id)))
                     session.commit()
                     sMessages.append("File %s deleted successfully" % flFile.name)
                 else:
                     fMessages.append("You do not have permission to delete file %s" % flFile.name)
             except sqlalchemy.orm.exc.NoResultFound, nrf:
                 fMessages.append("Could not find file with ID: %s" % str(fileId))
             except Exception, e:
                 session.rollback()
                 cherrypy.log.error("[%s] [delete_files] [Could not delete file: %s]" % (user.id, str(e)))
                 fMessages.append("File not deleted: %s" % str(e))
Exemplo n.º 5
0
def routine_maintenance(config):
    from lib import AccountService

    expiredFiles = session.query(File).filter(File.date_expires < datetime.datetime.now())
    for flFile in expiredFiles:
        try:
            for share in flFile.user_shares:
                session.delete(share)
            for share in flFile.group_shares:
                session.delete(share)
            for share in flFile.public_shares:
                session.delete(share)
            for share in flFile.attribute_shares:
                session.delete(share)
            FileService.queue_for_deletion(flFile.id)
            session.add(
                AuditLog(
                    "admin",
                    Actions.DELETE_FILE,
                    "File %s (ID:%s) has expired and has been purged by the system." % (flFile.name, flFile.id),
                    flFile.owner_id,
                )
            )
            session.delete(flFile)
            session.commit()
        except Exception, e:
            session.rollback()
            cherrypy.log.error("[system] [routine_maintenance] [Error while deleting expired file: %s]" % str(e))
Exemplo n.º 6
0
 def delete_files(self, fileIds, format="json", requestOrigin="", **kwargs):
     user, role, sMessages, fMessages = (
         cherrypy.session.get("user"), cherrypy.session.get("current_role"),
         [], [])
     if requestOrigin != cherrypy.session['request-origin']:
         fMessages.append("Missing request key!!")
     else:
         fileIds = split_list_sanitized(fileIds)
         for fileId in fileIds:
             try:
                 fileId = int(fileId)
                 flFile = session.query(File).filter(
                     File.id == fileId).one()
                 if flFile.role_owner_id is not None and role is not None and flFile.role_owner_id == role.id:
                     FileService.queue_for_deletion(flFile.id)
                     session.delete(flFile)
                     session.add(
                         AuditLog(
                             user.id, Actions.DELETE_FILE,
                             "File %s (%s) owned by role %s has been deleted by user %s. "
                             %
                             (flFile.name, flFile.id, role.name, user.id)))
                     session.commit()
                     sMessages.append("File %s deleted successfully" %
                                      flFile.name)
                 elif flFile.owner_id == user.id or AccountService.user_has_permission(
                         user, "admin"):
                     FileService.queue_for_deletion(flFile.id)
                     session.delete(flFile)
                     session.add(
                         AuditLog(
                             user.id, Actions.DELETE_FILE,
                             "File %s (%s) has been deleted" %
                             (flFile.name, flFile.id)))
                     session.commit()
                     sMessages.append("File %s deleted successfully" %
                                      flFile.name)
                 else:
                     fMessages.append(
                         "You do not have permission to delete file %s" %
                         flFile.name)
             except sqlalchemy.orm.exc.NoResultFound, nrf:
                 fMessages.append("Could not find file with ID: %s" %
                                  str(fileId))
             except Exception, e:
                 session.rollback()
                 cherrypy.log.error(
                     "[%s] [delete_files] [Could not delete file: %s]" %
                     (user.id, str(e)))
                 fMessages.append("File not deleted: %s" % str(e))
Exemplo n.º 7
0
 def delete_roles(self, roleIds, format="json", requestOrigin="", **kwargs):
     user, sMessages, fMessages = (cherrypy.session.get("user"), [], [])
     if requestOrigin != cherrypy.session['request-origin']:
         fMessages.append("Missing request key!!")
     else:
         try:
             roleIds = split_list_sanitized(roleIds)
             for roleId in roleIds:
                 try:
                     role = session.query(Role).filter(Role.id == roleId).one()
                     session.delete(role)
                     for flFile in session.query(File).filter(File.role_owner_id == role.id):
                         FileService.queue_for_deletion(flFile.id)
                         session.delete(flFile)
                         session.add(AuditLog(user.id, Actions.DELETE_FILE, "File %s (%s) owned by role %s has been deleted as a result of the role owner being deleted. " % (flFile.name, flFile.id, role.id), "admin"))
                     session.add(AuditLog(user.id, Actions.DELETE_ROLE, "%s deleted role \"%s\"(%s) from the system" % (user.id, role.name, role.id), None))
                     sMessages.append("Successfully deleted roles%s." % str(roleId))
                 except sqlalchemy.orm.exc.NoResultFound:
                     fMessages.append("The role ID: %s does not exist" % str(roleId))
             session.commit()
         except Exception, e:
             session.rollback()
             cherrypy.log.error("[%s] [delete_roles] [Problem deleting roles: %s]" % (user.id, str(e)))
             fMessages.append("Problem deleting roles: %s" % str(e))
Exemplo n.º 8
0
         if bytesRemaining >= 8192:
             block = cherrypy.request.rfile.read(8192)
         else:
             block = cherrypy.request.rfile.read(bytesRemaining)
         upFile.write(block)
         bytesRemaining -= 8192
         if bytesRemaining <= 0: break
     upFile.seek(0)
     #If the file didn't get all the way there
     if long(os.path.getsize(upFile.file_object.name)) != long(
             fileSizeBytes
     ):  #The file transfer stopped prematurely, take out of transfers and queue partial file for deletion
         cherrypy.log.error(
             "[system] [upload] [File upload was prematurely stopped, rejected]"
         )
         FileService.queue_for_deletion(tempFileName)
         fMessages.append(
             "The file %s did not upload completely before the transfer ended"
             % fileName)
         if cherrypy.file_uploads.has_key(uploadKey):
             for fileTransfer in cherrypy.file_uploads[uploadKey]:
                 if fileTransfer.file_object.name == upFile.file_object.name:
                     cherrypy.file_uploads[uploadKey].remove(
                         fileTransfer)
             if len(cherrypy.file_uploads[uploadKey]) == 0:
                 del cherrypy.file_uploads[uploadKey]
         raise cherrypy.HTTPError(
             "412 Precondition Failed",
             "The file transfer completed, but the file appears to be missing data. If you did not intentionally cancel the file, please try re-uploading."
         )
 else:
Exemplo n.º 9
0
                 "admin", Actions.DELETE_FILE,
                 "File %s (ID:%s) has expired and has been purged by the system."
                 % (flFile.name, flFile.id), flFile.owner_id))
         session.delete(flFile)
         session.commit()
     except Exception, e:
         session.rollback()
         cherrypy.log.error(
             "[system] [routine_maintenance] [Error while deleting expired file: %s]"
             % str(e))
 expiredMessages = session.query(Message).filter(
     Message.date_expires < datetime.datetime.now())
 for message in expiredMessages:
     try:
         session.delete(message)
         FileService.queue_for_deletion("m%s" % str(message.id))
         session.add(
             AuditLog(
                 "admin", Actions.DELETE_MESSAGE,
                 "Message %s (ID:%s) has expired and has been deleted by the system."
                 % (message.messageSubject, message.messageId),
                 message.owner_id))
         session.commit()
     except Exception, e:
         session.rollback()
         cherrypy.log.error(
             "[system] [routine_maintenance] [Error while deleting expired message: %s]"
             % str(e))
 expiredUploadRequests = session.query(UploadRequest).filter(
     UploadRequest.date_expires < datetime.datetime.now())
 for uploadRequest in expiredUploadRequests:
Exemplo n.º 10
0
     else:
         cherrypy.file_uploads[uploadKey] = [upFile,]
     bytesRemaining = fileSizeBytes
     while True:
         if bytesRemaining >= 8192:
             block = cherrypy.request.rfile.read(8192)
         else:
             block = cherrypy.request.rfile.read(bytesRemaining)
         upFile.write(block)
         bytesRemaining -= 8192
         if bytesRemaining <= 0: break
     upFile.seek(0)
     #If the file didn't get all the way there
     if long(os.path.getsize(upFile.file_object.name)) != long(fileSizeBytes): #The file transfer stopped prematurely, take out of transfers and queue partial file for deletion
         cherrypy.log.error("[system] [upload] [File upload was prematurely stopped, rejected]")
         FileService.queue_for_deletion(tempFileName)
         fMessages.append("The file %s did not upload completely before the transfer ended" % fileName)
         if cherrypy.file_uploads.has_key(uploadKey):
             for fileTransfer in cherrypy.file_uploads[uploadKey]:
                 if fileTransfer.file_object.name == upFile.file_object.name:
                     cherrypy.file_uploads[uploadKey].remove(fileTransfer)
             if len(cherrypy.file_uploads[uploadKey]) == 0:
                 del cherrypy.file_uploads[uploadKey]
         raise cherrypy.HTTPError("412 Precondition Failed", "The file transfer completed, but the file appears to be missing data. If you did not intentionally cancel the file, please try re-uploading.")
 else:
     cherrypy.request.headers['uploadindex'] = uploadIndex
     # Cherrypy 3.2+ _cpreqbody replaces usage of standard lib cgi, safemime, and cpcgifs
     # I have no clue when we would be reaching this code, so, for the moment I am going to break it and see if I can't find a way to hit it :)
     #forms = cherrypy._cpcgifs.FieldStorage(fp=cherrypy.request.rfile, headers=lcHDRS,
         # FieldStorage only recognizes POST.  environ={'REQUEST_METHOD': "POST"}, keep_blank_values=1)
     cherrypy.log.error("!!!!!!!!!!!!!!!!!!! LOOK !!!!!!!!!!!!!!!!!")
Exemplo n.º 11
0
                 "admin",
                 Actions.DELETE_FILE,
                 "File %s (ID:%s) has expired and has been purged by the system." % (flFile.name, flFile.id),
                 flFile.owner_id,
             )
         )
         session.delete(flFile)
         session.commit()
     except Exception, e:
         session.rollback()
         cherrypy.log.error("[system] [routine_maintenance] [Error while deleting expired file: %s]" % str(e))
 expiredMessages = session.query(Message).filter(Message.date_expires < datetime.datetime.now())
 for message in expiredMessages:
     try:
         session.delete(message)
         FileService.queue_for_deletion("m%s" % str(message.id))
         session.add(
             AuditLog(
                 "admin",
                 Actions.DELETE_MESSAGE,
                 "Message %s (ID:%s) has expired and has been deleted by the system."
                 % (message.messageSubject, message.messageId),
                 message.owner_id,
             )
         )
         session.commit()
     except Exception, e:
         session.rollback()
         cherrypy.log.error("[system] [routine_maintenance] [Error while deleting expired message: %s]" % str(e))
 expiredUploadRequests = session.query(UploadRequest).filter(UploadRequest.date_expires < datetime.datetime.now())
 for uploadRequest in expiredUploadRequests: