Skip to content

Commit

Permalink
Merge pull request #3 from Lissy93/FEAT/show-upstream-dns
Browse files Browse the repository at this point in the history
[Feature] Show upstream DNS in query log
Fixes #2
  • Loading branch information
Lissy93 authored May 29, 2023
2 parents d7f5997 + a203de6 commit fccbfb7
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 35 deletions.
5 changes: 2 additions & 3 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
- Improved deployment: 12Mb Docker image, 1-line install script, and publish to crates.io
- Adds documentation
- Faster start-up time
Adds new coloumn to query log, showing the upstream DNS server used for the query (#2)
Also updates the query log table to be responsive, so on smaller screens the upstream DNS and client IP won't be visible.
3 changes: 3 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Features:
- **Easy and Lightweight**: _AdGuardian can be run either with a super tiny Docker image, or directly with the zero-dependency executable_
- **Good and Safe**: _Written in Rust and unit tested, the app runs locally with no external requests, and (of course) it's fully open source_

About AdGuard:

[AdGuard Home](https://github.com/AdguardTeam/AdGuardHome) is a free and open source self-hosted (or managed) network-wide ad + tracker blocker. It operates as a DNS server that re-routes tracking domains to a "black hole", thus preventing your devices from connecting to those servers. It makes your internet, faster, safer and gives you a bunch of useful features, like encrypted DNS (DoH, DoT, DNSCrypt), parental controls, blocking of malware / phishing, per-device configs, custom DNS rules, etc.

<details>
<summary><b>Contents</b></summary>
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "adguardian"
version = "1.0.0"
version = "1.1.0"
edition = "2021"
authors = ["Alicia Sykes"]
description = "Terminal-based, real-time traffic monitoring and statistics for your AdGuard Home instance "
Expand Down
1 change: 1 addition & 0 deletions src/fetch/fetch_query_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct QueryResponse {
pub struct Query {
pub cached: bool,
pub client: String,
pub upstream: String,
#[serde(rename = "elapsedMs")]
pub elapsed_ms: String,
pub question: Question,
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub async fn draw_ui(

// Make the charts
let gauge = make_gauge(&stats);
let table = make_query_table(&data);
let table = make_query_table(&data, size.width);
let graph = make_history_chart(&stats);
let paragraph = render_status_paragraph(&status, &stats);
let filters = make_filters_list(filters.filters.as_slice(), size.width);
Expand Down
84 changes: 55 additions & 29 deletions src/widgets/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use tui::{
use chrono::{DateTime, Utc};

use crate::fetch::fetch_query_log::{Query, Question};

pub fn make_query_table(data: &[Query]) -> Table<'_> {
pub fn make_query_table(data: &[Query], width: u16) -> Table<'_> {
let rows = data.iter().map(|query| {
let time = Cell::from(
time_ago(query.time.as_str()).unwrap_or("unknown".to_string())
).style(Style::default().fg(Color::Gray));

let question = Cell::from(make_request_cell(&query.question).unwrap())
.style(Style::default().add_modifier(Modifier::BOLD));

Expand All @@ -27,35 +26,62 @@ pub fn make_query_table(data: &[Query]) -> Table<'_> {
let (status_txt, status_color) = block_status_text(&query.reason, query.cached);
let status = Cell::from(status_txt).style(Style::default().fg(status_color));

let upstream = Cell::from(query.upstream.as_str()).style(Style::default().fg(Color::Blue));

let color = make_row_color(&query.reason);
Row::new(vec![time, question, status, client, elapsed_ms])
Row::new(vec![time, question, status, elapsed_ms, client, upstream])
.style(Style::default().fg(color))
}).collect::<Vec<Row>>(); // Clone the data here

let table = Table::new(rows) // Table now owns its data
.header(Row::new(vec![
Cell::from(Span::raw("Time")),
Cell::from(Span::raw("Request")),
Cell::from(Span::raw("Status")),
Cell::from(Span::raw("Client")),
Cell::from(Span::raw("Time Taken")),
]))
.block(
Block::default()
.title(Span::styled(
"Query Log",
Style::default().add_modifier(Modifier::BOLD),
))
.borders(Borders::ALL))
.widths(&[
Constraint::Percentage(15),
Constraint::Percentage(35),
Constraint::Percentage(15),
Constraint::Percentage(20),
Constraint::Percentage(15),
}).collect::<Vec<Row>>();


let title = Span::styled(
"Query Log",
Style::default().add_modifier(Modifier::BOLD),
);

let block = Block::default()
.title(title)
.borders(Borders::ALL);

let mut headers = vec![
Cell::from(Span::raw("Time")),
Cell::from(Span::raw("Request")),
Cell::from(Span::raw("Status")),
Cell::from(Span::raw("Time Taken")),
];

if width > 120 {
headers.extend(vec![
Cell::from(Span::raw("Client")),
Cell::from(Span::raw("Upstream DNS")),
]);

table

let widths = &[
Constraint::Percentage(15),
Constraint::Percentage(35),
Constraint::Percentage(10),
Constraint::Percentage(10),
Constraint::Percentage(15),
Constraint::Percentage(15),
];

Table::new(rows)
.header(Row::new(headers))
.widths(widths)
.block(block)
} else {
let widths = &[
Constraint::Percentage(20),
Constraint::Percentage(40),
Constraint::Percentage(20),
Constraint::Percentage(20),
];

Table::new(rows)
.header(Row::new(headers))
.widths(widths)
.block(block)
}
}

// Given a timestamp, return a string representing how long ago that was
Expand Down

0 comments on commit fccbfb7

Please sign in to comment.