]> git.proxmox.com Git - proxmox-backup.git/blame - src/bin/proxmox-backup-banner.rs
Cargo.toml: pathpatterns, pxar, proxmox-fuse
[proxmox-backup.git] / src / bin / proxmox-backup-banner.rs
CommitLineData
274b0c7b
TL
1use std::fmt::Write;
2use std::fs;
3use std::net::ToSocketAddrs;
4
5use proxmox::tools;
6
7fn main() {
8 let nodename = tools::nodename();
9 let addr = format!("{}:8007", nodename);
10
b69b8af2
TL
11 let mut banner = format!(
12 "
274b0c7b
TL
13{:-<78}
14
15Welcome to the Proxmox Backup Server. Please use your web browser to
16configure this server - connect to:
17
18",
19 ""
20 );
21
e2b5e75a
TL
22 let msg = match addr.to_socket_addrs() {
23 Ok(saddrs) => {
24 let saddrs: Vec<_> = saddrs
b69b8af2
TL
25 .filter_map(|s| match !s.ip().is_loopback() {
26 true => Some(format!(" https://{}/", s)),
27 false => None,
28 })
29 .collect();
274b0c7b 30
e2b5e75a
TL
31 if !saddrs.is_empty() {
32 saddrs.join("\n")
33 } else {
b69b8af2
TL
34 format!(
35 "hostname '{}' does not resolves to any non-loopback address",
36 nodename
37 )
e2b5e75a 38 }
b69b8af2 39 }
e2b5e75a
TL
40 Err(e) => format!("could not resolve hostname '{}': {}", nodename, e),
41 };
42 banner += &msg;
274b0c7b
TL
43
44 // unwrap will never fail for write!:
45 // https://github.com/rust-lang/rust/blob/1.39.0/src/liballoc/string.rs#L2318-L2331
e2b5e75a 46 write!(&mut banner, "\n\n{:-<78}\n\n", "").unwrap();
274b0c7b
TL
47
48 fs::write("/etc/issue", banner.as_bytes()).expect("Unable to write banner to issue file");
49}