allow more stuff for "everything else" section, only link to /info/ if a index.html exists
This commit is contained in:
parent
92141190aa
commit
80a86e9f8a
@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
<h4>links</h4>
|
<h4>links</h4>
|
||||||
In the "running" section on the website, the ids may or may not be links.
|
In the "running" section on the website, the ids may or may not be links.
|
||||||
If a <code>/srv/tomatenmhark-slashinfo/*</code> entry exists, the link will point to that info site,
|
If a <code>/srv/tomatenmhark-slashinfo/*/index.html</code> entry exists, the link will point to that info site,
|
||||||
If only a <code>/srv/tomatenmhark-redirect/*</code> entry exists, the link will follow that redirect,
|
If only a <code>/srv/tomatenmhark-redirect/*</code> entry exists, the link will follow that redirect,
|
||||||
and if neither exist, there will be no link.<br>
|
and if neither exist, there will be no link.<br>
|
||||||
In the "everything else" section, every entry links to its info page.
|
In the "everything else" section, every entry links to its info page, if there is one.
|
||||||
|
|
||||||
<h4>/tmp/tomatenmhark-status-*</h4>
|
<h4>/tmp/tomatenmhark-status-*</h4>
|
||||||
For each file <code>/tmp/tomatenmhark-status-*</code>, an entry will be created on <a href="/">tomatenmhark.org</a>.
|
For each file <code>/tmp/tomatenmhark-status-*</code>, an entry will be created on <a href="/">tomatenmhark.org</a>.
|
||||||
|
58
src/main.rs
58
src/main.rs
@ -64,16 +64,22 @@ span {
|
|||||||
o.push_str("<h2>:) tomatenmhark :)</h2>");
|
o.push_str("<h2>:) tomatenmhark :)</h2>");
|
||||||
let status = data.status_async(dbg).await;
|
let status = data.status_async(dbg).await;
|
||||||
let time_queried = Instant::now();
|
let time_queried = Instant::now();
|
||||||
if !status.0.is_empty() {
|
fn push_elem_to_html(
|
||||||
o.push_str("<h3>things running on the server</h3>");
|
id: &str,
|
||||||
o.push_str("<ul>");
|
info: bool,
|
||||||
for (id, (info, redirect, status, additional, dur)) in status.0.iter() {
|
redirect: bool,
|
||||||
|
status: &str,
|
||||||
|
additional: Option<&str>,
|
||||||
|
dur: Option<Duration>,
|
||||||
|
o: &mut String,
|
||||||
|
dbg: bool,
|
||||||
|
) {
|
||||||
o.push_str("<li>");
|
o.push_str("<li>");
|
||||||
if *info {
|
if info {
|
||||||
o.push_str(r#"<a href="/info/"#);
|
o.push_str(r#"<a href="/info/"#);
|
||||||
o.push_str(&html_escape::encode_double_quoted_attribute(&id));
|
o.push_str(&html_escape::encode_double_quoted_attribute(&id));
|
||||||
o.push_str(r#"">"#);
|
o.push_str(r#"">"#);
|
||||||
} else if *redirect {
|
} else if redirect {
|
||||||
o.push_str(r#"<a href="/"#);
|
o.push_str(r#"<a href="/"#);
|
||||||
o.push_str(&html_escape::encode_double_quoted_attribute(&id));
|
o.push_str(&html_escape::encode_double_quoted_attribute(&id));
|
||||||
o.push_str(r#"">"#);
|
o.push_str(r#"">"#);
|
||||||
@ -81,7 +87,7 @@ span {
|
|||||||
o.push_str("<span>");
|
o.push_str("<span>");
|
||||||
}
|
}
|
||||||
o.push_str(&html_escape::encode_text(&id));
|
o.push_str(&html_escape::encode_text(&id));
|
||||||
if *info || *redirect {
|
if info || redirect {
|
||||||
o.push_str("</a>");
|
o.push_str("</a>");
|
||||||
} else {
|
} else {
|
||||||
o.push_str("</span>");
|
o.push_str("</span>");
|
||||||
@ -101,27 +107,43 @@ span {
|
|||||||
o.push_str("</div>");
|
o.push_str("</div>");
|
||||||
}
|
}
|
||||||
if dbg {
|
if dbg {
|
||||||
if let Some(dur) = *dur {
|
if let Some(dur) = dur {
|
||||||
o.push_str(&format!(" | {}ms", dur.as_millis()));
|
o.push_str(&format!(" | {}ms", dur.as_millis()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
o.push_str("</li>");
|
o.push_str("</li>");
|
||||||
}
|
}
|
||||||
|
if !status.0.is_empty() {
|
||||||
|
o.push_str("<h3>things running on the server</h3>");
|
||||||
|
o.push_str("<ul>");
|
||||||
|
for (id, (info, redirect, status, additional, dur)) in status.0.iter() {
|
||||||
|
push_elem_to_html(
|
||||||
|
id,
|
||||||
|
*info,
|
||||||
|
*redirect,
|
||||||
|
status,
|
||||||
|
additional.as_ref().map(|v| v.as_str()),
|
||||||
|
*dur,
|
||||||
|
&mut o,
|
||||||
|
dbg,
|
||||||
|
);
|
||||||
|
}
|
||||||
o.push_str("</ul>");
|
o.push_str("</ul>");
|
||||||
}
|
}
|
||||||
if !status.1.is_empty() {
|
if !status.1.is_empty() {
|
||||||
o.push_str("<h3>everything else</h3>");
|
o.push_str("<h3>everything else</h3>");
|
||||||
o.push_str("<ul>");
|
o.push_str("<ul>");
|
||||||
for (id, text) in status.1.iter() {
|
for (id, (info, redirect, status, additional)) in status.1.iter() {
|
||||||
o.push_str("<li>");
|
push_elem_to_html(
|
||||||
o.push_str(r#"<a href="/info/"#);
|
id,
|
||||||
o.push_str(&html_escape::encode_double_quoted_attribute(&id));
|
*info,
|
||||||
o.push_str(r#"">"#);
|
*redirect,
|
||||||
o.push_str(&html_escape::encode_text(&id));
|
status,
|
||||||
o.push_str("</a>");
|
additional.as_ref().map(|v| v.as_str()),
|
||||||
o.push_str(": ");
|
None,
|
||||||
o.push_str(&html_escape::encode_text(&text));
|
&mut o,
|
||||||
o.push_str("</li>");
|
dbg,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
o.push_str("</ul>");
|
o.push_str("</ul>");
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ const REDIRECT: &'static str = "/srv/tomatenmhark-redirect/";
|
|||||||
|
|
||||||
pub struct Status(
|
pub struct Status(
|
||||||
pub BTreeMap<String, (bool, bool, String, Option<String>, Option<Duration>)>,
|
pub BTreeMap<String, (bool, bool, String, Option<String>, Option<Duration>)>,
|
||||||
pub BTreeMap<String, String>,
|
pub BTreeMap<String, (bool, bool, String, Option<String>)>,
|
||||||
pub Duration,
|
pub Duration,
|
||||||
);
|
);
|
||||||
impl Status {
|
impl Status {
|
||||||
@ -46,7 +46,29 @@ impl Status {
|
|||||||
let mut p = f.path();
|
let mut p = f.path();
|
||||||
p.push("desc");
|
p.push("desc");
|
||||||
if let Ok(desc) = std::fs::read_to_string(&p) {
|
if let Ok(desc) = std::fs::read_to_string(&p) {
|
||||||
rest.insert(id.to_owned(), desc);
|
let info = Path::new(SLASHINFO).join(id).join("index.html");
|
||||||
|
let info = info.starts_with(SLASHINFO)
|
||||||
|
&& info.try_exists().ok() == Some(true);
|
||||||
|
let redirect = Path::new(REDIRECT).join(id);
|
||||||
|
let redirect = redirect.starts_with(REDIRECT)
|
||||||
|
&& redirect.try_exists().ok() == Some(true);
|
||||||
|
let desc = desc.trim();
|
||||||
|
if let Some(i) = desc.find('\n') {
|
||||||
|
rest.insert(
|
||||||
|
id.to_owned(),
|
||||||
|
(
|
||||||
|
info,
|
||||||
|
redirect,
|
||||||
|
desc[0..i].trim().to_owned(),
|
||||||
|
Some(desc[i + 1..].trim().to_owned()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
rest.insert(
|
||||||
|
id.to_owned(),
|
||||||
|
(info, redirect, desc.to_owned(), None),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +112,26 @@ impl Status {
|
|||||||
let mut p = f.path();
|
let mut p = f.path();
|
||||||
p.push("desc");
|
p.push("desc");
|
||||||
if let Ok(desc) = tokio::fs::read_to_string(&p).await {
|
if let Ok(desc) = tokio::fs::read_to_string(&p).await {
|
||||||
rest.insert(id.to_owned(), desc);
|
let info = Path::new(SLASHINFO).join(id).join("index.html");
|
||||||
|
let info = info.starts_with(SLASHINFO)
|
||||||
|
&& tokio::fs::try_exists(info).await.ok() == Some(true);
|
||||||
|
let redirect = Path::new(REDIRECT).join(id);
|
||||||
|
let redirect = redirect.starts_with(REDIRECT)
|
||||||
|
&& tokio::fs::try_exists(redirect).await.ok() == Some(true);
|
||||||
|
let desc = desc.trim();
|
||||||
|
if let Some(i) = desc.find('\n') {
|
||||||
|
rest.insert(
|
||||||
|
id.to_owned(),
|
||||||
|
(
|
||||||
|
info,
|
||||||
|
redirect,
|
||||||
|
desc[0..i].trim().to_owned(),
|
||||||
|
Some(desc[i + 1..].trim().to_owned()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
rest.insert(id.to_owned(), (info, redirect, desc.to_owned(), None));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +154,7 @@ fn query_status_sync(mut func: impl FnMut(&str, bool, bool, &str, Option<Duratio
|
|||||||
.map(|v| v.trim_end())
|
.map(|v| v.trim_end())
|
||||||
{
|
{
|
||||||
if !status.is_empty() {
|
if !status.is_empty() {
|
||||||
let info = Path::new(SLASHINFO).join(id);
|
let info = Path::new(SLASHINFO).join(id).join("index.html");
|
||||||
let info = info.starts_with(SLASHINFO)
|
let info = info.starts_with(SLASHINFO)
|
||||||
&& info.try_exists().ok() == Some(true);
|
&& info.try_exists().ok() == Some(true);
|
||||||
let redirect = Path::new(REDIRECT).join(id);
|
let redirect = Path::new(REDIRECT).join(id);
|
||||||
@ -143,7 +184,7 @@ fn query_status_sync(mut func: impl FnMut(&str, bool, bool, &str, Option<Duratio
|
|||||||
let out = String::from_utf8_lossy(&output.stdout);
|
let out = String::from_utf8_lossy(&output.stdout);
|
||||||
let out = out.trim_end();
|
let out = out.trim_end();
|
||||||
if dbg || !out.is_empty() {
|
if dbg || !out.is_empty() {
|
||||||
let info = Path::new(SLASHINFO).join(id);
|
let info = Path::new(SLASHINFO).join(id).join("index.html");
|
||||||
let info = info.starts_with(SLASHINFO)
|
let info = info.starts_with(SLASHINFO)
|
||||||
&& info.try_exists().ok() == Some(true);
|
&& info.try_exists().ok() == Some(true);
|
||||||
let redirect = Path::new(REDIRECT).join(id);
|
let redirect = Path::new(REDIRECT).join(id);
|
||||||
@ -175,7 +216,7 @@ async fn query_status_async(
|
|||||||
.map(|v| v.trim_end())
|
.map(|v| v.trim_end())
|
||||||
{
|
{
|
||||||
if !status.is_empty() {
|
if !status.is_empty() {
|
||||||
let info = Path::new(SLASHINFO).join(id);
|
let info = Path::new(SLASHINFO).join(id).join("index.html");
|
||||||
let info = info.starts_with(SLASHINFO)
|
let info = info.starts_with(SLASHINFO)
|
||||||
&& tokio::fs::try_exists(info).await.ok() == Some(true);
|
&& tokio::fs::try_exists(info).await.ok() == Some(true);
|
||||||
let redirect = Path::new(REDIRECT).join(id);
|
let redirect = Path::new(REDIRECT).join(id);
|
||||||
@ -204,7 +245,7 @@ async fn query_status_async(
|
|||||||
let out = String::from_utf8_lossy(&output.stdout);
|
let out = String::from_utf8_lossy(&output.stdout);
|
||||||
let out = out.trim_end();
|
let out = out.trim_end();
|
||||||
if dbg || !out.is_empty() {
|
if dbg || !out.is_empty() {
|
||||||
let info = Path::new(SLASHINFO).join(id);
|
let info = Path::new(SLASHINFO).join(id).join("index.html");
|
||||||
let info = info.starts_with(SLASHINFO)
|
let info = info.starts_with(SLASHINFO)
|
||||||
&& tokio::fs::try_exists(info).await.ok() == Some(true);
|
&& tokio::fs::try_exists(info).await.ok() == Some(true);
|
||||||
let redirect = Path::new(REDIRECT).join(id);
|
let redirect = Path::new(REDIRECT).join(id);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user