Compare commits
4 Commits
46a1887982
...
1180849b44
| Author | SHA1 | Date | |
|---|---|---|---|
| 1180849b44 | |||
| c717b5d589 | |||
| 7c907fe0ce | |||
| 51aa0c805e |
@ -164,9 +164,13 @@
|
|||||||
fetch("?content", { credentials: "same-origin" })
|
fetch("?content", { credentials: "same-origin" })
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
if (response.ok) return response.text();
|
if (response.ok) return response.text();
|
||||||
|
throw new Error();
|
||||||
})
|
})
|
||||||
.then(function(html) {
|
.then(function(html) {
|
||||||
if (html) document.getElementById("content").innerHTML = html;
|
document.getElementById("content").innerHTML = html;
|
||||||
|
})
|
||||||
|
.catch(function() {
|
||||||
|
document.getElementById("content").innerHTML = "Error";
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
14
bin/malpd
14
bin/malpd
@ -62,12 +62,16 @@ if Process.uid != 0
|
|||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
FileUtils.mkdir_p(File.dirname(SOCKET_PATH))
|
if ENV["LISTEN_FDS"]
|
||||||
FileUtils.rm_f(SOCKET_PATH)
|
server = UNIXServer.for_fd(3)
|
||||||
|
else
|
||||||
|
FileUtils.mkdir_p(File.dirname(SOCKET_PATH))
|
||||||
|
FileUtils.rm_f(SOCKET_PATH)
|
||||||
|
|
||||||
server = UNIXServer.new(SOCKET_PATH)
|
server = UNIXServer.new(SOCKET_PATH)
|
||||||
File.chmod(0660, SOCKET_PATH)
|
File.chmod(0660, SOCKET_PATH)
|
||||||
FileUtils.chown(nil, "apache", SOCKET_PATH)
|
FileUtils.chown(nil, "apache", SOCKET_PATH)
|
||||||
|
end
|
||||||
|
|
||||||
Signal.trap("TERM") { server.close }
|
Signal.trap("TERM") { server.close }
|
||||||
Signal.trap("INT") { server.close }
|
Signal.trap("INT") { server.close }
|
||||||
|
|||||||
@ -3,7 +3,9 @@
|
|||||||
require "cgi"
|
require "cgi"
|
||||||
require "erb"
|
require "erb"
|
||||||
require "digest"
|
require "digest"
|
||||||
|
require "json"
|
||||||
require "securerandom"
|
require "securerandom"
|
||||||
|
require "socket"
|
||||||
|
|
||||||
ASSETS_DIR = File.join(__dir__, "../assets")
|
ASSETS_DIR = File.join(__dir__, "../assets")
|
||||||
DATA_DIR = File.join(__dir__, "../data")
|
DATA_DIR = File.join(__dir__, "../data")
|
||||||
@ -81,9 +83,39 @@ end
|
|||||||
|
|
||||||
if cgi.params.key?("content")
|
if cgi.params.key?("content")
|
||||||
if authenticated
|
if authenticated
|
||||||
sleep 5
|
html = ""
|
||||||
|
|
||||||
|
begin
|
||||||
|
sock = UNIXSocket.new("/run/malpd/malpd.sock")
|
||||||
|
sock.puts "info"
|
||||||
|
info = JSON.parse(sock.gets)
|
||||||
|
sock.close
|
||||||
|
rescue
|
||||||
|
cgi.out("type" => "text/html", "charset" => "UTF-8") do
|
||||||
|
"Could not connect to malpd socket"
|
||||||
|
end
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
info.each do |entry|
|
||||||
|
case entry["type"]
|
||||||
|
when "drive"
|
||||||
|
dt = entry["drivetype"]
|
||||||
|
model = CGI.escapeHTML(entry["model"])
|
||||||
|
capacity = CGI.escapeHTML(entry["capacity"])
|
||||||
|
html << <<~HTML
|
||||||
|
<div class="card ok">
|
||||||
|
<div class="card-header">
|
||||||
|
<span class="card-title">#{model} <span class="drive-type #{dt}">#{dt.upcase}</span></span>
|
||||||
|
</div>
|
||||||
|
<div class="card-sub">#{capacity}</div>
|
||||||
|
</div>
|
||||||
|
HTML
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
cgi.out("type" => "text/html", "charset" => "UTF-8") do
|
cgi.out("type" => "text/html", "charset" => "UTF-8") do
|
||||||
"<p>Content placeholder</p>"
|
html
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
cgi.out("Status" => "403 Forbidden", "type" => "text/plain", "charset" => "UTF-8") do
|
cgi.out("Status" => "403 Forbidden", "type" => "text/plain", "charset" => "UTF-8") do
|
||||||
|
|||||||
10
systemd/malpd.service
Normal file
10
systemd/malpd.service
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=MALP monitoring daemon
|
||||||
|
Requires=malpd.socket
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/var/www/malp/bin/malpd
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
10
systemd/malpd.socket
Normal file
10
systemd/malpd.socket
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=malpd Unix socket
|
||||||
|
|
||||||
|
[Socket]
|
||||||
|
ListenStream=/run/malpd/malpd.sock
|
||||||
|
SocketGroup=apache
|
||||||
|
SocketMode=0660
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=sockets.target
|
||||||
Loading…
x
Reference in New Issue
Block a user