diff --git a/app/controllers/admin/box_controller.rb b/app/controllers/admin/box_controller.rb new file mode 100644 index 0000000..99b4a30 --- /dev/null +++ b/app/controllers/admin/box_controller.rb @@ -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 diff --git a/bin/box b/bin/box new file mode 100644 index 0000000..a157acf Binary files /dev/null and b/bin/box differ diff --git a/config/routes.rb b/config/routes.rb index d69a6d1..b5efe58 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/white-on-black.css b/white-on-black.css new file mode 100644 index 0000000..92cdef8 --- /dev/null +++ b/white-on-black.css @@ -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; +}