diff --git a/cgi-bin/malp.rb b/cgi-bin/malp.rb index 0d8e303..605bd09 100755 --- a/cgi-bin/malp.rb +++ b/cgi-bin/malp.rb @@ -3,7 +3,9 @@ require "cgi" require "erb" require "digest" +require "json" require "securerandom" +require "socket" ASSETS_DIR = File.join(__dir__, "../assets") DATA_DIR = File.join(__dir__, "../data") @@ -81,9 +83,32 @@ end if cgi.params.key?("content") if authenticated - sleep 5 + html = "" + + sock = UNIXSocket.new("/run/malpd/malpd.sock") + sock.puts "info" + info = JSON.parse(sock.gets) + sock.close + + info.each do |entry| + case entry["type"] + when "drive" + dt = entry["drivetype"] + model = CGI.escapeHTML(entry["model"]) + capacity = CGI.escapeHTML(entry["capacity"]) + html << <<~HTML +
+
+ #{model} #{dt.upcase} +
+
#{capacity}
+
+ HTML + end + end + cgi.out("type" => "text/html", "charset" => "UTF-8") do - "

Content placeholder

" + html end else cgi.out("Status" => "403 Forbidden", "type" => "text/plain", "charset" => "UTF-8") do