]> git.proxmox.com Git - proxmox-backup.git/commitdiff
add login banner service
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 6 Feb 2020 21:08:07 +0000 (22:08 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 6 Feb 2020 21:19:22 +0000 (22:19 +0100)
Modeled after the one from PVE, but using rust instead of perl for
resolving the nodename and writing to /etc/issue

Behavior differs a bit. We write all non-loopback addresses to this
file, as the gui accepts connections from them all, so limiting it to
the first one is not really sensible.
Further an error to resolve, or only getting loopback addresses won't
write out an empty /etc/issue file, but a note about the error at the
place where the address would be displayed.

Named it "pbsbanner", not "proxmox-backup-banner" as it's rather an
internal tool anyway and mirrors pvebanner, pmgbanner

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Makefile
debian/proxmox-backup-server.install
etc/Makefile
etc/pbsbanner.service [new file with mode: 0644]
src/bin/pbsbanner.rs [new file with mode: 0644]

index 537d34f781cc887f2fa12fae1c2954b80f668d75..1d6a34f9542a2bb04b1aba399aa76cfccf537b99 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,8 @@ USR_BIN := \
        pxar
 
 # Binaries usable by admins
-USR_SBIN := proxmox-backup-manager
+USR_SBIN := proxmox-backup-manager \
+       pbsbanner
 
 # Binaries for services:
 SERVICE_BIN := \
index 1db15f42e368f91b7b7fd8b48e9a2742361ce0c9..f5a94f51258310a631aa314ea40a86809bc804f5 100644 (file)
@@ -1,8 +1,10 @@
 etc/proxmox-backup-proxy.service /lib/systemd/system/
 etc/proxmox-backup.service /lib/systemd/system/
+etc/pbsbanner.service /lib/systemd/system/
 usr/lib/x86_64-linux-gnu/proxmox-backup/proxmox-backup-api
 usr/lib/x86_64-linux-gnu/proxmox-backup/proxmox-backup-proxy
 usr/sbin/proxmox-backup-manager
+usr/sbin/pbsbanner
 usr/share/javascript/proxmox-backup/css/ext6-pbs.css
 usr/share/javascript/proxmox-backup/images/logo-128.png
 usr/share/javascript/proxmox-backup/images/proxmox_logo.png
index da1f083b01544989bda744247033f123a5bac3e9..93d0c731e61e120e5b62d8ee7329946035331642 100644 (file)
@@ -1,13 +1,16 @@
 include ../defines.mk
 
 UNITS := \
+       pbsbanner.service \
+
+DYNAMIC_UNITS := \
        proxmox-backup.service \
        proxmox-backup-proxy.service
 
-all: $(UNITS)
+all: $(UNITS) $(DYNAMIC_UNITS)
 
 clean:
-       rm -f $(UNITS)
+       rm -f $(DYNAMIC_UNITS)
 
 .SUFFIXES: .service.in .service
 .service.in.service:
diff --git a/etc/pbsbanner.service b/etc/pbsbanner.service
new file mode 100644 (file)
index 0000000..c284956
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=Proxmox Backup Server Login Banner
+ConditionPathExists=/usr/sbin/pbsbanner
+ConditionPathExists=!/usr/bin/pvebanner
+DefaultDependencies=no
+After=local-fs.target
+Before=console-getty.service
+
+[Service]
+ExecStart=/usr/sbin/pbsbanner
+Type=oneshot
+RemainAfterExit=yes
+
+[Install]
+WantedBy=getty.target
diff --git a/src/bin/pbsbanner.rs b/src/bin/pbsbanner.rs
new file mode 100644 (file)
index 0000000..927f68a
--- /dev/null
@@ -0,0 +1,48 @@
+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);
+
+    let mut banner = format!("
+{:-<78}
+
+Welcome to the Proxmox Backup Server. Please use your web browser to
+configure this server - connect to:
+
+",
+        ""
+    );
+
+    if let Ok(saddrs) = addr.to_socket_addrs() {
+        let saddrs: Vec<_> = saddrs
+            .filter_map(|s| match !s.ip().is_loopback() {
+                true => Some(format!(" https://{}/", s)),
+                false => None,
+            })
+            .collect();
+
+        if !saddrs.is_empty() {
+            writeln!(&mut banner, "{}", saddrs.join("\n")).unwrap();
+        } else {
+            writeln!(
+                &mut banner,
+                "hostname '{}' does not resolves to any non-loopback address",
+                nodename
+            )
+            .unwrap();
+        }
+    } else {
+        writeln!(&mut banner, "could not resolve hostname '{}'", nodename).unwrap();
+    }
+
+    // unwrap will never fail for write!:
+    // https://github.com/rust-lang/rust/blob/1.39.0/src/liballoc/string.rs#L2318-L2331
+    write!(&mut banner, "\n{:-<78}\n\n", "").unwrap();
+
+    fs::write("/etc/issue", banner.as_bytes()).expect("Unable to write banner to issue file");
+}