diff --git a/app/controllers/admin/plow_controller.rb b/app/controllers/admin/plow_controller.rb
index dbbb6ae..2ea2c39 100644
--- a/app/controllers/admin/plow_controller.rb
+++ b/app/controllers/admin/plow_controller.rb
@@ -1,29 +1,64 @@
-class Admin::PlowController < ApplicationController
+class Admin::PlowController < OrbitAdminController
include ReverseProxy::Controller
+ SocketFile = "#{Rails.root}/tmp/plow.sock"
+ Binary = File.expand_path("../../../../bin/plow", __FILE__)
+ LogFile = "#{Rails.root}/tmp/plow_summary.log"
+ before_action :setup_setting, only: [:setting, :save_setting]
def index
- # Assuming the WordPress server is being hosted on port 8080
reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: '/' do |config|
- # We got a 404!
- # config.on_missing do |code, response|
- # redirect_to root_url and return
- # end
-
- # There's also other callbacks:
- # - on_set_cookies
- # - on_connect
- # - on_response
- # - on_set_cookies
- # - on_success
- # - on_redirect
- # - on_missing
- # - on_error
- # - on_complete
end
end
def show
- path = request.env['ORIGINAL_FULLPATH']
- reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: '/' do |config|
+ path = request.env['ORIGINAL_FULLPATH']#.gsub("/admin/plow", "")
+ reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: path do |config|
end
end
+ def setting
+ if File.exist?(LogFile)
+ @logContent = File.read(LogFile).gsub("\n", "
").html_safe
+ end
+ end
+
+ def save_setting
+ @setting.update_attributes(params[:plow_setting].permit!)
+ if File.exist?(SocketFile)
+ if @plow_pid
+ Process.kill(:INT, @plow_pid)
+ end
+ `rm #{SocketFile}`
+ end
+ if params['act'] == 'Start Test'
+ uri = URI.parse(@setting.url)
+ host = uri.host
+ ip = @setting.ip
+ concurrent = @setting.concurrent
+ scheme = uri.scheme
+ Thread.new do
+ if !ip.blank?
+ `#{Binary} #{scheme}://#{ip}#{uri.request_uri} --host=#{host} --listen=#{SocketFile} -c#{concurrent} --summary > #{LogFile}`
+ else
+ `#{Binary} #{@setting.url} --listen=#{SocketFile} -c#{concurrent} --summary > #{LogFile}`
+ end
+ end
+ max_wait = 10
+ while 1
+ sleep(1)
+ setup_setting
+ max_wait -= 1
+ if @enable_plow
+ break
+ end
+ end
+ end
+ redirect_to action: :setting
+ end
+
+private
+ def setup_setting
+ @setting = PlowSetting.first
+ @plow_pid = `fuser #{SocketFile}`.gsub(/\n/, '').to_i
+ @enable_plow = @plow_pid > 0
+
+ end
end
\ No newline at end of file
diff --git a/app/models/plow_setting.rb b/app/models/plow_setting.rb
new file mode 100644
index 0000000..26eac36
--- /dev/null
+++ b/app/models/plow_setting.rb
@@ -0,0 +1,8 @@
+class PlowSetting
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :concurrent, type: Integer, :default => 1
+ field :ip, type: String
+ field :url, type: String
+end
\ No newline at end of file
diff --git a/app/views/admin/plow/setting.html.erb b/app/views/admin/plow/setting.html.erb
new file mode 100644
index 0000000..3b8b97c
--- /dev/null
+++ b/app/views/admin/plow/setting.html.erb
@@ -0,0 +1,45 @@
+<% content_for :page_specific_css do %>
+ <%= stylesheet_link_tag "lib/main-forms" %>
+<% end %>
+