client_management/app/controllers/admin/box_controller.rb

26 lines
924 B
Ruby
Raw Normal View History

2023-07-01 02:28:18 +00:00
class Admin::BoxController < OrbitAdminController
include ReverseProxy::Controller
SocketFile = "#{Rails.root}/tmp/box.sock"
Binary = File.expand_path("../../../../bin/box", __FILE__)
2023-07-01 02:42:16 +00:00
CSSFile = File.expand_path("../../../../white-on-black.css", __FILE__)
2023-07-01 03:08:18 +00:00
skip_before_action :verify_authenticity_token
2023-07-01 02:28:18 +00:00
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
2023-07-01 02:39:15 +00:00
`#{Binary} --unixdomain-only #{SocketFile}:$USER:$USER:0666 --disable-ssl --debug --css #{CSSFile}`
2023-07-01 02:28:18 +00:00
end
sleep 3
end
2023-07-01 03:10:36 +00:00
reverse_proxy "unix://#{SocketFile}", path: '/' do |config|
2023-07-01 02:28:18 +00:00
end
end
def show
2023-07-01 03:10:36 +00:00
path = request.env['ORIGINAL_FULLPATH'].gsub(/.*\/admin\/box/, "")
2023-07-01 02:28:18 +00:00
puts ['path', path]
reverse_proxy "unix://#{SocketFile}", path: path do |config|
end
end
end