Class: Webconsole::ConsoleController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Webconsole::ConsoleController
- Defined in:
- app/controllers/webconsole/console_controller.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #index ⇒ Object
- #remote_connect ⇒ Object
- #run_command ⇒ Object
- #send_command ⇒ Object
Instance Method Details
#connect ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/webconsole/console_controller.rb', line 27 def connect if not allowed_ips.any? { |block| block.include?(request.remote_ip) } render json: { connected: false, message: "You are not allowed to connect to the console.", ip: request.remote_ip } else render json: { connected: true, ip: request.remote_ip } end end |
#index ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/webconsole/console_controller.rb', line 12 def index if params[:ip] @details = { name: "Webconsole", ip: params[:ip], connect: true } else @details = { name: "Webconsole", connect: false } end end |
#remote_connect ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/webconsole/console_controller.rb', line 102 def remote_connect begin response = HTTParty.put("http://" + params[:ip] + "/webconsole/console/connect") if response.code == 200 render json: JSON.parse(response.body) else render json: { connected: false } end rescue Exception => e render json: { connected: false } end end |
#run_command ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/webconsole/console_controller.rb', line 42 def run_command command = params[:command].strip if command.nil? || command.empty? send_response("No command specified", "error", "string") return end if command[0, 6] == "shell " begin eval_result = system(command[6..-1]) status = "success" rescue Exception => e eval_result = e. status = "error" end else begin eval_result = eval(command) status = "success" rescue Exception => e eval_result = e..to_s status = "error" end end puts "Result of command: #{eval_result}" result = parse_command_response(eval_result) send_response( result[:result], status ) end |
#send_command ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/webconsole/console_controller.rb', line 78 def send_command begin response = HTTParty.put("http://" + params[:ip] + "/webconsole/console", body: { command: params[:command] } ) if response.code == 200 render json: JSON.parse(response.body) else render json: { status: "error", message: "Error while sending command" } end rescue Exception => e render json: { status: "error", message: "Error while sending command" } end end |