diff --git a/bin/malpd b/bin/malpd index d0c66b3..aef874c 100755 --- a/bin/malpd +++ b/bin/malpd @@ -169,6 +169,49 @@ def read_virtual_machines end end +def read_os_id + return nil unless File.exist?("/etc/os-release") + File.readlines("/etc/os-release").each do |line| + if line =~ /^ID=(.+)$/ + return $1.strip.delete('"').downcase + end + end + nil +end + +def apt_updates + out = `apt-get -s -o Debug::NoLocking=true upgrade 2>/dev/null` + count = 0 + out.each_line do |line| + count += 1 if line.start_with?("Inst ") + end + count +end + +def apt_reboot_pending + File.exist?("/var/run/reboot-required") +end + +def dnf_updates + out = `dnf -q check-update 2>/dev/null` + status = $?.exitstatus + return 0 if status == 0 + return nil unless status == 100 + count = 0 + out.each_line do |line| + line = line.strip + next if line.empty? + next if line.start_with?("Obsoleting", "Last metadata") + count += 1 if line.split(/\s+/).size >= 3 + end + count +end + +def dnf_reboot_pending + `dnf needs-restarting -r >/dev/null 2>&1` + $?.exitstatus == 1 +end + def read_server_info info = { "type" => "server" } @@ -181,6 +224,15 @@ def read_server_info end end + case read_os_id + when "ubuntu", "debian" + info["updates"] = apt_updates + info["reboot_pending"] = apt_reboot_pending + when "almalinux", "rocky", "rhel", "centos", "fedora" + info["updates"] = dnf_updates + info["reboot_pending"] = dnf_reboot_pending + end + out = `stat -c %W / 2>/dev/null`.strip if out =~ /^\d+$/ && out.to_i > 0 info["install_date"] = Time.at(out.to_i).strftime("%Y-%m-%d") diff --git a/cgi-bin/malp.rb b/cgi-bin/malp.rb index c9a4cdc..0ee2064 100755 --- a/cgi-bin/malp.rb +++ b/cgi-bin/malp.rb @@ -125,8 +125,19 @@ if cgi.params.key?("content") html << %(