2020-02-06 21:08:07 +00:00
|
|
|
use std::fmt::Write;
|
|
|
|
use std::fs;
|
|
|
|
use std::net::ToSocketAddrs;
|
|
|
|
|
|
|
|
use proxmox::tools;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let nodename = tools::nodename();
|
|
|
|
let addr = format!("{}:8007", nodename);
|
|
|
|
|
2020-02-10 13:43:26 +00:00
|
|
|
let mut banner = format!(
|
|
|
|
"
|
2020-02-06 21:08:07 +00:00
|
|
|
{:-<78}
|
|
|
|
|
|
|
|
Welcome to the Proxmox Backup Server. Please use your web browser to
|
|
|
|
configure this server - connect to:
|
|
|
|
|
|
|
|
",
|
|
|
|
""
|
|
|
|
);
|
|
|
|
|
2020-02-07 17:30:41 +00:00
|
|
|
let msg = match addr.to_socket_addrs() {
|
|
|
|
Ok(saddrs) => {
|
|
|
|
let saddrs: Vec<_> = saddrs
|
2020-02-10 13:43:26 +00:00
|
|
|
.filter_map(|s| match !s.ip().is_loopback() {
|
|
|
|
true => Some(format!(" https://{}/", s)),
|
|
|
|
false => None,
|
|
|
|
})
|
|
|
|
.collect();
|
2020-02-06 21:08:07 +00:00
|
|
|
|
2020-02-07 17:30:41 +00:00
|
|
|
if !saddrs.is_empty() {
|
|
|
|
saddrs.join("\n")
|
|
|
|
} else {
|
2020-02-10 13:43:26 +00:00
|
|
|
format!(
|
|
|
|
"hostname '{}' does not resolves to any non-loopback address",
|
|
|
|
nodename
|
|
|
|
)
|
2020-02-07 17:30:41 +00:00
|
|
|
}
|
2020-02-10 13:43:26 +00:00
|
|
|
}
|
2020-02-07 17:30:41 +00:00
|
|
|
Err(e) => format!("could not resolve hostname '{}': {}", nodename, e),
|
|
|
|
};
|
|
|
|
banner += &msg;
|
2020-02-06 21:08:07 +00:00
|
|
|
|
|
|
|
// unwrap will never fail for write!:
|
|
|
|
// https://github.com/rust-lang/rust/blob/1.39.0/src/liballoc/string.rs#L2318-L2331
|
2020-02-07 17:30:41 +00:00
|
|
|
write!(&mut banner, "\n\n{:-<78}\n\n", "").unwrap();
|
2020-02-06 21:08:07 +00:00
|
|
|
|
|
|
|
fs::write("/etc/issue", banner.as_bytes()).expect("Unable to write banner to issue file");
|
|
|
|
}
|