Exemple #1
0
def search_file(request):
    key = request.POST['key']
    value = request.POST['term'].lower()
    curr_project = request.POST['curr_project']
    if 'project' in request.POST:
        project_search = request.POST['project']
    else:
        project_search = False

    # Set some data holders
    results = []
    projects = []

    # Search All Projects
    if project_search:
        # Get list of project paths
        project_list = __project__.list()
        for p in project_list:
            projects.append(p['name'])
    else:
        # If not searching all projects what are we searching
        projects.append(curr_project)

    # Search each Project in the list
    for project in projects:
        db = open_db(project)
        # get results
        proj_results = []
        rows = db.find(key=key, value=value)
        for row in rows:
            proj_results.append([row.name, row.sha256])
        results.append({'name': project, 'res': proj_results})
    # Return some things
    return render(request, 'search.html', {'results': results})
Exemple #2
0
def main_page(request, project='default', error=None, success=None):
    db = open_db(project)

    # set pagination details
    page = request.GET.get('page')
    if not page:
        page = 1
    page_count = request.GET.get('count')
    if not page_count:
        page_count = 25

    # Get all Samples
    sample_list = db.find('all')

    sample_count = len(sample_list)
    first_sample = int(page) * int(page_count) - int(page_count) + 1
    last_sample = int(page) * int(page_count)
    paginator = Paginator(sample_list, page_count)
    try:
        samples = paginator.page(page)
    except PageNotAnInteger:
        samples = paginator.page(1)
    except EmptyPage:
        samples = paginator.page(paginator.num_pages)
    return render(request, 'index.html', {'sample_list': samples,
                                          'sample_count': sample_count,
                                          'samples': [first_sample, last_sample],
                                          'error_line': False,
                                          'project': project,
                                          'projects': __project__.list(),
                                          'error': error,
                                          'success':success
                                          })
Exemple #3
0
def open_db(project):
    # Check for valid project
    project_list = __project__.list()
    if any(d.get('name', None) == project for d in project_list):
        # Open Project
        __project__.open(project)
        # Init DB
        return Database()
Exemple #4
0
def open_db(project):
    project_list = __project__.list()
    # Check for valid project
    if project == 'default':
        __project__.open(project)
    elif any(d.get('name', None) == project for d in project_list):
        # Open Project
        __project__.open(project)
    else:
        return False
    return Database()
Exemple #5
0
def project_list(request):
    project_list = __project__.list()
    return JsonResponse({'response': '200', 'data': project_list}, safe=False)