add easy box

This commit is contained in:
rulingcom 2023-07-01 10:28:18 +08:00
parent be60f987e4
commit f48d3dcfbc
4 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,25 @@
class Admin::BoxController < OrbitAdminController
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_filter :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: request.env['ORIGINAL_FULLPATH'] 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

BIN
bin/box Normal file

Binary file not shown.

View File

@ -5,7 +5,8 @@ Rails.application.routes.draw do
namespace :admin do
# get "client_managements/completed_requests", to: 'client_managements#completed_requests'
# get "client_managements/contracts", to: 'client_managements#contracts'
match 'box' => 'box#index', via: [:get, :post, :put, :patch, :delete]
match 'box/*path' => 'box#show', via: [:get, :post, :put, :patch, :delete]
match 'plow' => 'plow#index', via: [:get, :post, :put, :patch, :delete]
get 'plow/setting' => 'plow#setting'
patch 'plow/save_setting' => 'plow#save_setting'

53
white-on-black.css Normal file
View File

@ -0,0 +1,53 @@
#vt100 #cursor.bright {
background-color: white;
color: black;
}
#vt100 #cursor.dim {
background-color: black;
opacity: 0.2;
-moz-opacity: 0.2;
filter: alpha(opacity=20);
}
#vt100 #scrollable {
color: #ffffff;
background-color: #000000;
}
#vt100 #scrollable.inverted {
color: #000000;
background-color: #ffffff;
}
#vt100 .ansiDef {
color: #ffffff;
}
#vt100 .ansiDefR {
color: #000000;
}
#vt100 .bgAnsiDef {
background-color: #000000;
}
#vt100 .bgAnsiDefR {
background-color: #ffffff;
}
#vt100 #scrollable.inverted .ansiDef {
color: #000000;
}
#vt100 #scrollable.inverted .ansiDefR {
color: #ffffff;
}
#vt100 #scrollable.inverted .bgAnsiDef {
background-color: #ffffff;
}
#vt100 #scrollable.inverted .bgAnsiDefR {
background-color: #000000;
}