2023-07-01 03:17:17 +00:00
|
|
|
class Admin::BoxController < ApplicationController
|
2023-07-01 03:22:38 +00:00
|
|
|
include ActionController::Live
|
2023-07-01 02:28:18 +00:00
|
|
|
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 03:59:47 +00:00
|
|
|
before_action :check_login
|
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
|
2023-07-01 03:59:47 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
def check_login
|
|
|
|
user = current_user
|
2023-07-01 04:01:58 +00:00
|
|
|
if user.nil? || !user.is_admin?
|
2023-07-01 03:59:47 +00:00
|
|
|
return render :file => "#{Rails.root}/app/views/errors/404.html", :layout => false, :status => :not_found, :formats => [:html]
|
|
|
|
end
|
|
|
|
end
|
2023-07-01 02:28:18 +00:00
|
|
|
end
|