Skip to content

Commit

Permalink
Add ZoneFile
Browse files Browse the repository at this point in the history
  • Loading branch information
docjyJ committed Sep 11, 2024
1 parent e042f8a commit 7e5d64e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/pages/directory/domains/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,37 @@ struct DnsRecord {
content: String,
}

fn format_zonefile(records: &Vec<DnsRecord>, domain: &str) -> String {
let formatted_records: Vec<[&str; 3]> = records
.iter()
.filter_map(|record| {
record.name.strip_suffix(domain).map(|name| {
if name.is_empty() {
["@", &record.typ, &record.content]
} else {
[name, &record.typ, &record.content]
}
})
})
.collect();

let max_len = formatted_records.iter().fold([0, 0], |acc, x| {
[acc[0].max(x[0].len()), acc[1].max(x[1].len())]
});

formatted_records.iter().fold(String::new(), |acc, x| {
format!(
"{}{: <width1$} IN {: <width2$} {}\n",
acc,
x[0],
x[1],
x[2],
width1 = max_len[0],
width2 = max_len[1]
)
})
}

#[component]
pub fn DomainDisplay() -> impl IntoView {
let auth = use_authorization();
Expand Down Expand Up @@ -87,6 +118,7 @@ pub fn DomainDisplay() -> impl IntoView {
.filter(|r| r.typ == "TXT" && r.content.contains("DKIM"))
.count()
.to_string();
let zonefile = format_zonefile(&records, &params.get().get("id").cloned().unwrap_or_default());
Some(
view! {
<Card>
Expand Down Expand Up @@ -135,6 +167,17 @@ pub fn DomainDisplay() -> impl IntoView {
.collect_view()}

</Table>
<div class="sm:col-span-12 pb-4">
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-200">
Zonefile
</h2>
</div>
<textarea
class="py-3 px-4 block w-full border-gray-200 rounded-lg text-sm focus:border-blue-500 focus:ring-blue-500 disabled:opacity-50 disabled:pointer-events-none dark:bg-slate-900 dark:border-gray-700 dark:text-gray-400 dark:focus:ring-gray-600"
readonly=true
>
{zonefile}
</textarea>

</div>

Expand Down

0 comments on commit 7e5d64e

Please sign in to comment.