コード例 #1
0
def generic_procbridge_request(api_identifier,
                               body=None,
                               port=PROC_PORT_POLICY):
    """
    Generic request function to the procbridge server
    """
    try:
        client = procbridge.Client(PROC_HOST, port)
        if body is None:
            response = client.request(api_identifier)
        else:
            response = client.request(api_identifier, json.loads(body))
    except:
        raise LookupError('Error')
    return Response(response, status=status.HTTP_200_OK)
コード例 #2
0
ファイル: adatgyujtes.py プロジェクト: vitarex/DNS_Browser
def delete_databases():
    client = procbridge.Client('127.0.0.1', CONFIG.proc_port)
    response = client.request('db_shutdown', {'id': '1234'})
    print("RESPONSE IS: ", response)
    directory = os.path.dirname(CONFIG.database_path)
    random_key_file_name = "random.json"
    random_key_file_path = os.path.join(directory, random_key_file_name)
    config = "config.ini"
    CONFIG.completed = True
    for item in [config, CONFIG.copied_database_path, random_key_file_path]:
        try:
            delete_file(item)
        except Exception as e:
            result = "Hiba a fájl törlése közben. \nA file: " + item + " \nA hiba: " + str(e)
            print(result)
            return result
    return redirect(url_for('thanks'), code=302)
コード例 #3
0
 def setUp(self):
     self.client = pb.Client('127.0.0.1', PORT)
コード例 #4
0
ファイル: adatgyujtes.py プロジェクト: vitarex/DNS_Browser
def table_full():
    live_dataset.connect()
    dataset = live_dataset # Doesnt override global instance, variable is local.
    table = "queries"

    page_number = request.args.get('page') or ''
    page_number = int(page_number) if page_number.isdigit() else 1

    dataset.update_cache(table)
    ds_table = dataset[table]

    raw_data = request.args.get('raw_data') == "True"

    rows_per_page = app.config['ROWS_PER_PAGE']

    search = request.args.get('search')
    if search:
        query = ds_table.model_class.select().where(ds_table.model_class._meta.fields['domain'].contains(search))
    else:
        query = ds_table.all()

    total_rows = query.count()
    total_pages = int(math.ceil(total_rows / float(rows_per_page)))
    # Restrict bounds.
    page_number = min(page_number, total_pages)
    page_number = max(page_number, 1)

    previous_page = page_number - 1 if page_number > 1 else None
    next_page = page_number + 1 if page_number < total_pages else None

    delete_index = request.args.get('delete')
    if delete_index:
        #ds_table.delete(id=delete_index)
        client = procbridge.Client('127.0.0.1', CONFIG.proc_port)
        response = client.request('delete_id', {'id': int(delete_index)})
        if response != 'OK':
            flash('Nem sikerült végrehajtani a törlés utasítást. Kérjük próbálja meg újra! \nA hiba: ' + str(response))

    query = query.paginate(page_number, rows_per_page)

    ordering = request.args.get('ordering')
    if ordering:
        field = ds_table.model_class._meta.columns[ordering.lstrip('-')]
        if ordering.startswith('-'):
            field = field.desc()
        query = query.order_by(field)

    field_names = ds_table.columns
    columns = [f.column_name for f in ds_table.model_class._meta.sorted_fields]

    table_sql = dataset.query(
        'SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?',
        [table, 'table']).fetchone()[0]

    return render_template(
        'table_queries_full.html',
        columns=columns,
        ds_table=ds_table,
        field_names=field_names,
        next_page=next_page,
        ordering=ordering,
        page=page_number,
        previous_page=previous_page,
        query=query,
        total_pages=total_pages,
        total_rows=total_rows,
        search=search,
        true_content=True,
        raw_data=raw_data)
コード例 #5
0
ファイル: adatgyujtes.py プロジェクト: vitarex/DNS_Browser
def table_domains():
    table = "queries"

    page_number = request.args.get('page') or ''
    page_number = int(page_number) if page_number.isdigit() else 1

    dataset.update_cache(table)
    ds_table = dataset[table]

    rows_per_page = app.config['ROWS_PER_PAGE']

    dom_field = None
    if ('domain' in ds_table.model_class._meta.fields):
        dom_field = ds_table.model_class._meta.fields['domain']

    delete_domain = request.args.get('delete')
    if delete_domain:
        ds_table.delete(domain=delete_domain)
        #open_live_dataset_table(table).delete(domain=delete_domain)
        client = procbridge.Client('127.0.0.1', CONFIG.proc_port)
        response = client.request('delete_domain', {'domain': delete_domain})
        if response != 'OK':
            flash('Nem sikerült végrehajtani a törlés utasítást. Kérjük próbálja meg újra!')


    search = request.args.get('search')
    if search:
        query = ds_table.model_class.select(dom_field, fn.COUNT(dom_field).alias('ct')).group_by(dom_field).where(dom_field.contains(search)).order_by(fn.COUNT(dom_field).desc())
    else:
        query = ds_table.model_class.select(dom_field, fn.COUNT(dom_field).alias('ct')).group_by(dom_field).order_by(fn.COUNT(dom_field).desc())

    #pdb.set_trace()

    total_rows = query.count()
    total_pages = int(math.ceil(total_rows / float(rows_per_page)))
    # Restrict bounds.
    page_number = min(page_number, total_pages)
    page_number = max(page_number, 1)

    previous_page = page_number - 1 if page_number > 1 else None
    next_page = page_number + 1 if page_number < total_pages else None



    query = query.paginate(page_number, rows_per_page)

    ordering = request.args.get('ordering')
    if ordering:
        field = ds_table.model_class._meta.columns[ordering.lstrip('-')]
        if ordering.startswith('-'):
            field = field.desc()
        query = query.order_by(field)

    field_names = ds_table.columns
    columns = [f.column_name for f in ds_table.model_class._meta.sorted_fields]

    table_sql = dataset.query(
        'SELECT sql FROM sqlite_master WHERE tbl_name = ? AND type = ?',
        [table, 'table']).fetchone()[0]

    return render_template(
        'table_domains.html',
        columns=columns,
        ds_table=ds_table,
        field_names=field_names,
        next_page=next_page,
        ordering=ordering,
        page=page_number,
        previous_page=previous_page,
        query=query,
        total_pages=total_pages,
        total_rows=total_rows,
        search=search,
        true_content=None)