client_management/app/controllers/admin/box_controller.rb

26 lines
925 B
Ruby

class Admin::BoxController < ApplicationController
include ReverseProxy::Controller
SocketFile = "#{Rails.root}/tmp/box.sock"
Binary = File.expand_path("../../../../bin/box", __FILE__)
CSSFile = File.expand_path("../../../../white-on-black.css", __FILE__)
skip_before_action :verify_authenticity_token
def index
is_not_open = `fuser #{SocketFile}`.gsub(/\n/, '').empty?
if !File.exists?(SocketFile) || `ss -elx | grep -w "$(stat -c 'ino:%i dev:0/%d' '#{SocketFile}')"`.blank?
Thread.new do
`#{Binary} --unixdomain-only #{SocketFile}:$USER:$USER:0666 --disable-ssl --debug --css #{CSSFile}`
end
sleep 3
end
reverse_proxy "unix://#{SocketFile}", path: '/' do |config|
end
end
def show
path = request.env['ORIGINAL_FULLPATH'].gsub(/.*\/admin\/box/, "")
puts ['path', path]
reverse_proxy "unix://#{SocketFile}", path: path do |config|
end
end
end