Skip to content

Commit

Permalink
Added delete and watching filterlists.csv
Browse files Browse the repository at this point in the history
  • Loading branch information
mkb2091 committed Mar 5, 2024
1 parent 6bfc3de commit d30f32e
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 135 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ sct = { version = "0.7.1", optional = true }
ct-logs = { version = "0.9.0", optional = true }
rand = { version = "0.8.5", optional = true }
hickory-proto = { version = "0.24.0", default-features = false }
humantime = "2.1.0"
notify = {version = "6.1.1", optional = true}


[features]
Expand Down Expand Up @@ -81,6 +83,7 @@ ssr = [
"dep:sct",
"dep:ct-logs",
"dep:rand",
"dep:notify",
]
default = ["ssr"]

Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
}
}
42 changes: 36 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ fn FilterListSummary(url: crate::FilterListUrl, record: crate::FilterListRecord)

</td>
<td class="max-w-20 break-normal break-words">{record.author.to_string()}</td>
<td>{record.license.to_string()}</td>
<td>{format!("{:?}", record.expires)}</td>
<td class="max-w-xl break-normal break-words">{record.license.to_string()}</td>
<td>{humantime::format_duration(record.expires).to_string()}</td>
<td>{format!("{:?}", record.list_format)}</td>
<td>
<LastUpdated last_updated=last_updated/>
Expand Down Expand Up @@ -320,10 +320,32 @@ fn HomePage() -> impl IntoView {

view! {
<h1>"Welcome to Leptos!"</h1>
<p>"Total Rules: " <TotalRuleCount/></p>
<p>"Total Domains: " <DomainCount/></p>
<p>"Total Subdomains: " <SubdomainCount/></p>
<p>"Total DNS Lookups: " <DnsLookupCount/></p>
<table class="table max-w-fit">
<tr>
<td>"Total Rules"</td>
<td>
<TotalRuleCount/>
</td>
</tr>
<tr>
<td>"Total Domains"</td>
<td>
<DomainCount/>
</td>
</tr>
<tr>
<td>"Total Subdomains"</td>
<td>
<SubdomainCount/>
</td>
</tr>
<tr>
<td>"Total DNS Lookups"</td>
<td>
<DnsLookupCount/>
</td>
</tr>
</table>
<UpdateAll/>
<ReparseAll/>
<Transition fallback=move || {
Expand All @@ -338,6 +360,14 @@ fn HomePage() -> impl IntoView {
log::info!("Displaying list");
view! {
<table class="table table-zebra">
<thead>
<td>"Name"</td>
<td>"Author"</td>
<td>"License"</td>
<td>"Update frequency"</td>
<td>"Format"</td>
<td>"Last Updated"</td>
</thead>
<tbody>
<For
each=move || { data.0.clone() }
Expand Down
26 changes: 13 additions & 13 deletions src/domain_view.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
app::Loading,
list_view::FilterListLink,
rule_view::{DisplayRule, RuleData},
DomainId, RuleId, SourceId,
DomainId, FilterListUrl, RuleId, SourceId,
};
use leptos::*;
use leptos_router::*;
Expand Down Expand Up @@ -104,7 +105,15 @@ fn DnsResultView(get_domain: Box<dyn Fn() -> Result<String, ParamsError>>) -> im
#[server]
async fn get_blocked_by(
domain: String,
) -> Result<Vec<(String, RuleId, SourceId, crate::list_parser::RulePair)>, ServerFnError> {
) -> Result<
Vec<(
FilterListUrl,
RuleId,
SourceId,
crate::list_parser::RulePair,
)>,
ServerFnError,
> {
let records = sqlx::query!(
r#"
WITH matching_domain_rules AS (
Expand Down Expand Up @@ -158,7 +167,7 @@ async fn get_blocked_by(
let pair = crate::list_parser::RulePair::new(source.into(), rule);
let url = record.url.clone();
Ok((
url,
url.parse()?,
RuleId(record.rule_id),
SourceId(record.source_id),
pair,
Expand Down Expand Up @@ -191,19 +200,10 @@ fn BlockedBy(get_domain: Box<dyn Fn() -> Result<String, ParamsError>>) -> impl I
let rule = pair.get_rule().clone();
let rule_href = format!("/rule/{}", rule_id.0);
let source_href = format!("/rule_source/{}", source_id.0);
let url_href = format!(
"/list{}",
params_map! {
"url" => url.as_str(),
}
.to_query_string(),
);
view! {
<tr>
<td>
<A href=url_href class="link link-neutral">
{url}
</A>
<FilterListLink url=url/>
</td>
<td>
<A href=source_href class="link link-neutral">
Expand Down
19 changes: 10 additions & 9 deletions src/fileserv.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use crate::app::App;
use axum::response::Response as AxumResponse;
use axum::{
body::Body,
extract::State,
response::IntoResponse,
http::{Request, Response, StatusCode, Uri},
response::IntoResponse,
};
use axum::response::Response as AxumResponse;
use leptos::*;
use tower::ServiceExt;
use tower_http::services::ServeDir;
use leptos::*;
use crate::app::App;

pub async fn file_and_error_handler(uri: Uri, State(options): State<LeptosOptions>, req: Request<Body>) -> AxumResponse {
pub async fn file_and_error_handler(
uri: Uri,
State(options): State<LeptosOptions>,
req: Request<Body>,
) -> AxumResponse {
let root = options.site_root.clone();
let res = get_static_file(uri.clone(), &root).await.unwrap();

Expand All @@ -22,10 +26,7 @@ pub async fn file_and_error_handler(uri: Uri, State(options): State<LeptosOption
}
}

async fn get_static_file(
uri: Uri,
root: &str,
) -> Result<Response<Body>, (StatusCode, String)> {
async fn get_static_file(uri: Uri, root: &str) -> Result<Response<Body>, (StatusCode, String)> {
let req = Request::builder()
.uri(uri.clone())
.body(Body::empty())
Expand Down
2 changes: 1 addition & 1 deletion src/ip_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn IpView() -> impl IntoView {
<h1 class="text-2xl">
"IP Address:"
{

get_ip
}

Expand Down
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod source_view;
use mimalloc::MiMalloc;
use serde::*;
use std::convert::From;
use std::str::FromStr;
use std::sync::Arc;

#[cfg(feature = "ssr")]
Expand Down Expand Up @@ -55,9 +56,16 @@ impl std::ops::Deref for FilterListUrl {
}
}

impl FilterListUrl {
pub fn new(url: url::Url) -> Self {
Self { url: Arc::new(url) }
impl From<url::Url> for FilterListUrl {
fn from(url: url::Url) -> Self {
Self { url: url.into() }
}
}

impl FromStr for FilterListUrl {
type Err = url::ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(url::Url::parse(s)?.into())
}
}

Expand Down
Loading

0 comments on commit d30f32e

Please sign in to comment.