Compare commits
No commits in common. "1180849b44783e0706431e6082a988d17e8d9e6b" and "46a18879827ebeda8e73f48aaf5716f8a0823ab6" have entirely different histories.
1180849b44
...
46a1887982
@ -164,13 +164,9 @@
|
|||||||
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) {
|
||||||
document.getElementById("content").innerHTML = html;
|
if (html) document.getElementById("content").innerHTML = html;
|
||||||
})
|
|
||||||
.catch(function() {
|
|
||||||
document.getElementById("content").innerHTML = "Error";
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
14
bin/malpd
14
bin/malpd
@ -62,16 +62,12 @@ if Process.uid != 0
|
|||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV["LISTEN_FDS"]
|
FileUtils.mkdir_p(File.dirname(SOCKET_PATH))
|
||||||
server = UNIXServer.for_fd(3)
|
FileUtils.rm_f(SOCKET_PATH)
|
||||||
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,9 +3,7 @@
|
|||||||
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")
|
||||||
@ -83,39 +81,9 @@ end
|
|||||||
|
|
||||||
if cgi.params.key?("content")
|
if cgi.params.key?("content")
|
||||||
if authenticated
|
if authenticated
|
||||||
html = ""
|
sleep 5
|
||||||
|
|
||||||
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
|
cgi.out("type" => "text/html", "charset" => "UTF-8") do
|
||||||
"Could not connect to malpd socket"
|
"<p>Content placeholder</p>"
|
||||||
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
|
|
||||||
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
|
||||||
|
|||||||
@ -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