示例#1
0
文件: task.py 项目: scorelab/OpenMF
def delete(id):
    """
    Route to handle deletion of a task by admin.
    """
    current_user = get_current_user(delete.role, delete.public_id)
    task = list(filter(lambda task: task.id == id, current_user.assigned_tasks))

    if len(task) == 0:
        response = {
            "success": False,
            "message": "Task not found."
        }
        return make_response(jsonify(response)), status.NOT_FOUND

    if task[0].is_completed:
        response = {
            "success": False,
            "message": "Task already completed."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    db.session.remove(task[0])
    db.session.commit()
    response = {
        "success": True,
        "message": "Task deleted."
    }
    return make_response(jsonify(response)), status.CREATED
示例#2
0
文件: task.py 项目: scorelab/OpenMF
def edit_title():
    """
    Route to edit title of a task.
    """
    try:
        req = request.get_json()
        id = int(req['id'])
        title = str(req['title'])

    except Exception as e:
        print(e)
        response = {
            "success": False,
            "message": "Please provide all details."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    current_user = get_current_user(edit_title.role, edit_title.public_id)
    task = list(filter(lambda task: task.id == id, current_user.assigned_tasks))

    if len(task) == 0:
        response = {
            "success": False,
            "message": "Task not found."
        }
        return make_response(jsonify(response)), status.NOT_FOUND

    task[0].title = title
    db.session.commit()
    response = {
        "success": True,
        "message": "Title updated."
    }
    return make_response(jsonify(response)), status.CREATED
示例#3
0
文件: task.py 项目: scorelab/OpenMF
def mark_complete(id):
    """
    Route to mark a task as complete by a member.
    """
    current_user = get_current_user(mark_complete.role, mark_complete.public_id)
    task = list(filter(lambda task: task.id == id, current_user.assigned_tasks))
    if len(task) == 0:
        response = {
            "success": False,
            "message": "Task not found."
        }
        return make_response(jsonify(response)), status.NOT_FOUND

    if task[0].is_completed:
        response = {
            "success": False,
            "message": "Task already completed."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    task[0].is_completed = True
    db.session.commit()
    response = {
        "success": True,
        "message": "Task marked as completed."
    }
    return make_response(jsonify(response)), status.CREATED
示例#4
0
def deleteuser():
    """
    This will be used by admin
    to delete any member's account
    """
    # Check if email is provided or not
    current_user = get_current_user(deleteuser.role, deleteuser.public_id)
    try:
        req = request.get_json()
        email = str(req['email'])
    except:
        response = {
            "success": False,
            "message": "Please provide email address of member."
        }
        return make_response(jsonify(response)), 409

    user = Extractor.query.filter_by(admin=current_user).filter_by(email=email).first() or Management.query.filter_by(admin=current_user).filter_by(email=email).first()

    if not user:
        response = {
            "success": False,
            "message": "User not found.",
        }
        return make_response(jsonify(response))
    db.session.delete(user)
    db.session.commit()
    response = {
        "success": True,
        "message": "User deleted."
    }
    return make_response(jsonify(response)), 200
示例#5
0
文件: task.py 项目: scorelab/OpenMF
def assigned_tasks():
    """
    Route to get all created tasks by an admin.
    """
    current_user = get_current_user(assigned_tasks.role, assigned_tasks.public_id)
    tasks = current_user.assigned_tasks
    response = {
        "success": True,
        "message": "Tasks found.",
        "tasks": tasks_schema.dump(tasks)
    }
    return make_response(jsonify(response)), status.OK
示例#6
0
def delete():
    """
    This route will handle user deletion.
    """
    current_user = get_current_user(delete.role, delete.public_id)
    db.session.delete(current_user)
    db.session.commit()
    response = {
        "success": True,
        "message": "User deleted."
    }
    return make_response(jsonify(response)), 200
示例#7
0
def all_users():
    """
    This handles listing of all members of an admin.
    """
    current_user = get_current_user(all_users.role, all_users.public_id)
    extractors = Extractor.query.filter_by(admin_id=current_user.id).filter_by(role="extractor").all()
    managements = Management.query.filter_by(admin_id=current_user.id).filter_by(role="management").all()

    extractors_json = extractors_schema.dump(extractors)
    managements_json = managements_schema.dump(managements)
    response = {
        "success": True,
        "message": "Extractor and management members fetched.",
        "extractor_members": extractors_json,
        "management_members": managements_json,
    }
    return make_response(jsonify(response)), 200
示例#8
0
def get_extracted_cases():
    """
    Route to get all extracted cases of an extractor,
    Accessbile by only an extractor member.
    """

    # Get current user
    current_user = get_current_user(get_extracted_cases.role, get_extracted_cases.public_id)

    # Get extracted cases
    cases = cases_schema.dump(current_user.extracted_cases)

    # create response
    response = {
        "success": True,
        "message": "Extracted cases Fetched",
        "extracted_cases": cases
    }

    # return response
    return make_response(jsonify(response)), 200
示例#9
0
def extracted_cases():
    """
    Route to get extracted cases of an extractor userd by admin.
    """
    # get Current user
    current_user = get_current_user(extracted_cases.role, extracted_cases.public_id)

    try:
        # parse request details
        req = request.get_json()
        extractor_email = str(req['email'])
    except:
        response = {
            "success": False,
            "message": "Please provide all parameters."
        }
        return make_response(jsonify(response)), 409

    # filter extractor from current user's extractor_members
    extractor = list(filter(lambda member: member.email == extractor_email, current_user.extractor_members))

    # check if extractor exists
    if len(extractor) != 1:
        resposne = {
            "success": False,
            "message": "Extractor User not Found."
        }
        return make_response(jsonify(resposne)), 404

    # get extracted_cases in json format
    _extracted_cases = cases_schema.dump(extractor[0].extracted_cases)

    #create response
    response = {
        "success": True,
        "message": "Extracted Cases fetched.",
        "extracted_cases": _extracted_cases
    }

    return make_response(jsonify(response)), 200
示例#10
0
def getUser(id):
    """
    This handles searching an admin by id.
    """
    current_user = get_current_user(getUser.role, getUser.public_id)
    if id == current_user.id:
        response = {
            "success": False,
            "message": "You can't search yourself."
        }
        return make_response(jsonify(response)), 404

    user = Admin.query.filter_by(id=id).first()

    # Check if user with that id exists
    if not user:
        response = {
            "success": False,
            "message": "Admin does not exist."
        }
        return make_response(jsonify(response))

    try:
        extractor_members = extractors_schema.dump(user.extractor_members)
        management_members = managements_schema.dump(user.management_members)
        response = {
            "success": True,
            "message": "Admin user fetched.",
            "user": admin_schema.dump(user),
            "extractor_members": extractor_members,
            "management_members": management_members
        }
        return make_response(jsonify(response)), 201
    except:
        response = {
            "success": False,
            "message": "Unable to find user, something went wrong."
        }
        return make_response(jsonify(response)), 201
示例#11
0
def profile():
    """
    This route gives profile detail.
    """
    current_user = get_current_user(profile.role, profile.public_id)
    if(current_user.role == "admin"):
        try:
            extractor_members = extractors_schema.dump(current_user.extractor_members)
            management_members = managements_schema.dump(current_user.management_members)
            response = {
                "success": True,
                "message": "admin user fetched.",
                "user": admin_schema.dump(current_user),
                "extractor_members": extractor_members,
                "management_members": management_members
            }
            return make_response(jsonify(response)), 201
        except:
            response = {
                "success": False,
                "message": "Unable to find user, something went wrong."
            }
            return make_response(jsonify(response)), 201

    elif(current_user.role == "extractor"):
        response = {
            "success": True,
            "message": "extractor user fetched.",
            "user": extractor_schema.dump(current_user)
        }
        return make_response(jsonify(response)), 201

    response = {
            "success": True,
            "message": "management user fetched.",
            "user": extractor_schema.dump(current_user)
        }
    return make_response(jsonify(response)), 201
示例#12
0
文件: task.py 项目: scorelab/OpenMF
def completed_tasks():
    """
    Route to get all completed tasks of a member.
    """
    current_user = get_current_user(completed_tasks.role, completed_tasks.public_id)

    # check for admin
    if current_user.role == "admin":
        response = {
            "success": False,
            "message": "Not found."
        }
        return make_response(jsonify(response)), status.NOT_FOUND

    tasks = list(filter(lambda task: task.is_completed==True, current_user.assigned_tasks))

    response = {
        "success": True,
        "message": "Tasks fetched.",
        "tasks": tasks_schema.dump(tasks)
    }

    return make_response(jsonify(response)), status.OK
示例#13
0
文件: task.py 项目: scorelab/OpenMF
def create():
    """
    Route to create and assign new tasks by admin.
    """
    current_user = get_current_user(create.role, create.public_id)
    try:
        req = request.get_json()
        title = str(req['title'])
        description = str(req['description'])
        extractor_email = None if str(req['extractor_email']) == "none" else str(req['extractor_email'])
        management_email = None if str(req['management_email']) == "none" else str(req['management_email'])
    except Exception as e:
        print(e)
        response = {
            "success": False,
            "message": "Please provide all parameters"
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY
    extractor = None
    management = None
    # if no member selected
    if not extractor_email and not management_email:
        response = {
            "success": False,
            "message": "Please select atleast one member."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY
    elif extractor_email and management_email:
        response = {
            "success": False,
            "message": "Please select only one member."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    # Check for extractor member
    elif extractor_email != None:
        extractor = Extractor.query.filter_by(email = extractor_email).first()
        if not extractor:
            response = {
                "success": False,
                "message": "Extractor member not found."
            }
            return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    # check for manageement member
    elif management_email != None:
        management = Management.query.filter_by(email=management_email).first()
        if not management:
            response = {
                "success": False,
                "message": "management member not found."
            }
            return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    # Create new task
    new_task = Task(title=title, description=description, admin=current_user, extractor=extractor, management=management)
    try:
        db.session.add(new_task)
        db.session.commit()

    except Extractor as e:
        response = {
            "success": False,
            "message": e
        }
        return make_response(jsonify(response)), status.INTERNAL_SERVER_ERROR
    response = {
        "success": True,
        "message": "Task created.",
        "task": task_schema.dump(new_task)
    }
    return make_response(jsonify(response)), status.CREATED
示例#14
0
def extract():
    '''
    This Route handles data extraction
    from the connected device.
    '''
    # current extractor
    current_user = get_current_user(extract.role, extract.public_id)
    # if no data is provided at all
    try:
        req = request.get_json()
    except:
        return 'please provide id, case_name and data'

    # If a key is missing
    try:
        device_id = str(req['device_id'])
        case_name = str(req['case_name'])
        data = str(req['data'])
        tags = str(req['tags'])
        tags = tags.split(',')

    except KeyError as err:
        # Create failed response
        response = {"success": False, "message": f"Please Provide {str(err)}."}
        return make_response(jsonify(response)), 400

    # Check if case with similar name exits
    case = Case.query.filter_by(case_name=case_name).first()
    if case:
        response = {
            "success":
            False,
            "message":
            "case name already exists, please try again with a diffrent case name."
        }
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    sys.path.append(dirname + '../../../../apiUtility')
    from apiUtils import apiExtactAll, apiExtractFb, apiExtractWa, apiExtractPhone, apiReport, apiExtractSMS, apiExtractBrowser, apiExtractBluetooth, apiExtractLocation, apiExtractMedia

    if (data == 'all'):
        apiExtactAll(case_name)
        apiReport(case_name, tags)
    elif (data == 'facebook'):
        apiExtractFb(case_name)
        apiReport(case_name, tags)
    elif (data == 'whatsapp'):
        apiExtractWa(case_name)
        apiReport(case_name, tags)
    elif (data == 'message'):
        apiExtractSMS(case_name)
        apiReport(case_name, tags)
    elif (data == 'phone'):
        apiExtractPhone(case_name)
        apiReport(case_name, tags)
    elif (data == 'browser'):
        apiExtractBrowser(case_name)
        apiReport(case_name, tags)
    elif (data == 'report'):
        apiReport(case_name, tags)
    elif (data == 'bluetooth'):
        apiExtractBluetooth(case_name)
        apiReport(case_name, tags)
    elif (data == 'location'):
        apiExtractLocation(case_name)
        apiReport(case_name, tags)
    elif (data == 'media'):
        apiExtractMedia(case_name)
        apiReport(case_name, tags)
    else:
        response = {"success": False, "message": "Wrong data provided."}
        return make_response(jsonify(response)), status.UNPROCESSABLE_ENTITY

    # store the case path to Database
    new_case_path = cases_path + f"\{case_name}"
    new_case = Case(case_name=case_name,
                    device_id=device_id,
                    data_path=new_case_path,
                    extractor=current_user)
    try:
        db.session.add(new_case)
        db.session.commit()
    except Exception:
        response = {
            "success": False,
            "message": "Something went wrong.",
        }
        return make_response(jsonify(response)), status.INTERNAL_SERVER_ERROR

    response = {"success": True, "message": "Data Extraction Successfull."}
    return make_response(jsonify(response)), status.CREATED
示例#15
0
def roleupdate():
    """
    This handles role updation.
    """
    current_user = get_current_user(roleupdate.role, roleupdate.public_id)
    try:
        req = request.get_json()
        email = str(req['email'])
        password = str(req['password'])
        new_role = str(req['new_role'])
    except:
        response = {
            "success": False,
            "message": "Please provide all parameters"
        }
        return make_response(jsonify(response)), 409

    if new_role == "extractor":
        user = Management.query.filter_by(admin=current_user).filter_by(email=email).first()
        if not user:
            response = {
                "success": False,
                "message": f"{email} is not a management member."
            }
            return make_response(jsonify(response))

        if not user.check_password(password):
            response = {
                "success": False,
                "message": "wrong password."
            }
            return make_response(jsonify(response)), 409

        new_extractor = Extractor(name=user.name, email=user.email, password=password, admin=user.admin)
        db.session.add(new_extractor)
        db.session.delete(user)
        db.session.commit()
        response = {
            "success": True,
            "message": f"User {user.email} has changed to {new_role}."
        }
        return make_response(jsonify(response)), 200

    elif new_role == "management":
        user = Extractor.query.filter_by(admin=current_user).filter_by(email=email).first()
        if not user:
            response = {
                "success": False,
                "message": f"{email} is not a extractor member."
            }
            return make_response(jsonify(response))

        if not user.check_password(password):
            response = {
                "success": False,
                "message": "wrong password."
            }
            return make_response(jsonify(response)), 409

        new_management = Management(name=user.name, email=user.email,password=password, admin=user.admin)
        db.session.add(new_management)
        db.session.delete(user)
        db.session.commit()
        response = {
            "success": True,
            "message": f"User {user.email} has changed to {new_role}."
        }
        return make_response(jsonify(response)), 200

    response = {
        "success": False,
        "message": "Please provide a valid role."
    }
    return make_response(jsonify(response)), 409
示例#16
0
def add_users():
    """
    This will be used by admin
    to create new/add new member.
    """
    current_user = get_current_user(add_users.role, add_users.public_id)
    try:
        req = request.get_json()
        email = str(req['email'])
        password = str(req['password'])
        name = str(req['name'])
        role = str(req['role'])
    except:
        response = {
            "success": False,
            "message": "Please provide all parameters"
        }
        return make_response(jsonify(response)), 409

    # For creating extractor member
    if role == "extractor":
        extractor = Extractor.query.filter_by(email=email).first()
        if extractor:
            response = {
                "success": False,
                "message": "Extractor member already exists."
            }
            return make_response(jsonify(response)), 409
        new_extractor = Extractor(name=name, email=email, password=password, admin=current_user)
        db.session.add(new_extractor)
        try:
            db.session.commit()
        except Exception as e:
            response = {
                "success": False,
                "message": e
            }
            return make_response(jsonify(response))
        response = {
            "success": True,
            "message": "Extractor member created."
        }
        return make_response(jsonify(response)), 200

    # For creating management member
    elif role == "management":
        management = Management.query.filter_by(email=email).first()
        if management:
            response = {
                "success": False,
                "message": "Extractor member already exists."
            }
            return make_response(jsonify(response)), 409
        new_management = Management(name=name, email=email, password=password, admin=current_user)
        db.session.add(new_management)
        try:
            db.session.commit()
        except Exception as e:
            response = {
                "success": False,
                "message": e
            }
            return make_response(jsonify(response))
        response = {
            "success": True,
            "message": "Management member created."
        }
        return make_response(jsonify(response)), 200

    # For non-valid role
    else:
        response = {
            "success": False,
            "message": "Please provide a valid role."
        }
        return make_response(jsonify(response)), 409