Compare commits
No commits in common. "1180849b44783e0706431e6082a988d17e8d9e6b" and "46a18879827ebeda8e73f48aaf5716f8a0823ab6" have entirely different histories.
1180849b44
...
46a1887982
@ -164,13 +164,9 @@
|
||||
fetch("?content", { credentials: "same-origin" })
|
||||
.then(function(response) {
|
||||
if (response.ok) return response.text();
|
||||
throw new Error();
|
||||
})
|
||||
.then(function(html) {
|
||||
document.getElementById("content").innerHTML = html;
|
||||
})
|
||||
.catch(function() {
|
||||
document.getElementById("content").innerHTML = "Error";
|
||||
if (html) document.getElementById("content").innerHTML = html;
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
|
||||
14
bin/malpd
14
bin/malpd
@ -62,16 +62,12 @@ if Process.uid != 0
|
||||
exit(1)
|
||||
end
|
||||
|
||||
if ENV["LISTEN_FDS"]
|
||||
server = UNIXServer.for_fd(3)
|
||||
else
|
||||
FileUtils.mkdir_p(File.dirname(SOCKET_PATH))
|
||||
FileUtils.rm_f(SOCKET_PATH)
|
||||
FileUtils.mkdir_p(File.dirname(SOCKET_PATH))
|
||||
FileUtils.rm_f(SOCKET_PATH)
|
||||
|
||||
server = UNIXServer.new(SOCKET_PATH)
|
||||
File.chmod(0660, SOCKET_PATH)
|
||||
FileUtils.chown(nil, "apache", SOCKET_PATH)
|
||||
end
|
||||
server = UNIXServer.new(SOCKET_PATH)
|
||||
File.chmod(0660, SOCKET_PATH)
|
||||
FileUtils.chown(nil, "apache", SOCKET_PATH)
|
||||
|
||||
Signal.trap("TERM") { server.close }
|
||||
Signal.trap("INT") { server.close }
|
||||
|
||||
@ -3,9 +3,7 @@
|
||||
require "cgi"
|
||||
require "erb"
|
||||
require "digest"
|
||||
require "json"
|
||||
require "securerandom"
|
||||
require "socket"
|
||||
|
||||
ASSETS_DIR = File.join(__dir__, "../assets")
|
||||
DATA_DIR = File.join(__dir__, "../data")
|
||||
@ -83,39 +81,9 @@ end
|
||||
|
||||
if cgi.params.key?("content")
|
||||
if authenticated
|
||||
html = ""
|
||||
|
||||
begin
|
||||
sock = UNIXSocket.new("/run/malpd/malpd.sock")
|
||||
sock.puts "info"
|
||||
info = JSON.parse(sock.gets)
|
||||
sock.close
|
||||
rescue
|
||||
sleep 5
|
||||
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
|
||||
html
|
||||
"<p>Content placeholder</p>"
|
||||
end
|
||||
else
|
||||
cgi.out("Status" => "403 Forbidden", "type" => "text/plain", "charset" => "UTF-8") do
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
[Unit]
|
||||
Description=MALP monitoring daemon
|
||||
Requires=malpd.socket
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/var/www/malp/bin/malpd
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@ -1,10 +0,0 @@
|
||||
[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