RemoteWebConsole 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/controllers/webconsole/webconsole_controller.rb +111 -0
- data/app/helpers/console_helper.rb +46 -0
- data/config/locales/en.yml +9 -0
- data/lib/webconsole.rb +8 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 92719f9c99ff4bb17f4e9edcbfc91645f5ed308c7b715f3663b5be1edc23959d
|
4
|
+
data.tar.gz: 7358878a5a291bb99d9d8b5c8e6ca3b2bc7c5d5d8b51a670f8c1e4ac3a95102c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb89d3c0e94b88b96d8fc39b28bce3840a4e7dafc24890948a7e65ceb8563d4c39aa34c16454a7de23ef30cf6b465e5c3a9a745a207e6a3fc809a3fe864cf8ef
|
7
|
+
data.tar.gz: fd2d3290da72b7389e809cdcd7ed096c2516660c16c15e9e3dcebfaeb16fa001bc83858ab91ea3bc612aeae59d652da781f0e592288a1461a8baeff6f3e71432
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module WebConsole
|
2
|
+
class WebConsoleController < ApplicationController
|
3
|
+
include WebConsoleHelper
|
4
|
+
|
5
|
+
skip_before_action :verify_authenticity_token
|
6
|
+
before_action :check_admin_access, only: [:run_command]
|
7
|
+
|
8
|
+
def connect
|
9
|
+
# Recieve a connection request from the client
|
10
|
+
# and send back the connection ip and port
|
11
|
+
# if the request is from a valid ip address
|
12
|
+
|
13
|
+
if !allowed_ips.include?(current_ip_address)
|
14
|
+
render json: {
|
15
|
+
connected: true,
|
16
|
+
ip: request.remote_ip
|
17
|
+
}
|
18
|
+
else
|
19
|
+
render json: {
|
20
|
+
connected: false,
|
21
|
+
ip: request.remote_ip
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_command
|
27
|
+
command = params[:command].strip
|
28
|
+
if command.nil? || command.empty?
|
29
|
+
send_response("No command specified", "error", "string")
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
eval_result = eval(command)
|
35
|
+
status = "success"
|
36
|
+
rescue Exception => e
|
37
|
+
eval_result = e.message
|
38
|
+
status = "error"
|
39
|
+
end
|
40
|
+
|
41
|
+
result = parse_command_response(response)
|
42
|
+
|
43
|
+
send_response(
|
44
|
+
result[:result],
|
45
|
+
status,
|
46
|
+
result[:type]
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_command
|
51
|
+
# Find the server with the specified id
|
52
|
+
# and send the command to it
|
53
|
+
server = Server.find(params[:id])
|
54
|
+
render json: send_command(params[:command], server.ip)
|
55
|
+
end
|
56
|
+
|
57
|
+
def connect_remote
|
58
|
+
server = Server.find(params[:id])
|
59
|
+
render json: connect(server.ip)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def send_response(result, status, type)
|
65
|
+
render json: {
|
66
|
+
result: result,
|
67
|
+
status: status,
|
68
|
+
type: type
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_command_response(response)
|
73
|
+
if response.is_a?(String)
|
74
|
+
return {
|
75
|
+
result: response,
|
76
|
+
type: "string"
|
77
|
+
}
|
78
|
+
elsif response.is_a?(Array)
|
79
|
+
return {
|
80
|
+
result: response.join("\n"),
|
81
|
+
type: "array"
|
82
|
+
}
|
83
|
+
else
|
84
|
+
return {
|
85
|
+
result: response.to_json,
|
86
|
+
type: "json"
|
87
|
+
}
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def check_admin_access
|
92
|
+
if !allowed_ips.include?(current_ip_address)
|
93
|
+
render json: {
|
94
|
+
connected: false,
|
95
|
+
ip: request.remote_ip
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def allowed_ips
|
101
|
+
ips_blocks = [
|
102
|
+
"::1",
|
103
|
+
"85.24.169.213"
|
104
|
+
]
|
105
|
+
end
|
106
|
+
|
107
|
+
def current_ip_address
|
108
|
+
request.env['HTTP_X_REAL_IP'] || request.env['REMOTE_ADDR']
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module WebConsole
|
2
|
+
class WebConsoleHelper < ApplicationHelper
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
def send_command(command, ip)
|
6
|
+
begin
|
7
|
+
response = HTTParty.put("http://" + ip + "/console",
|
8
|
+
body: {
|
9
|
+
command: command
|
10
|
+
}
|
11
|
+
)
|
12
|
+
|
13
|
+
if response.code == 200
|
14
|
+
return JSON.parse(response.body)
|
15
|
+
else
|
16
|
+
return {
|
17
|
+
status: "error",
|
18
|
+
message: "Error while sending command"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
rescue Exception => e
|
22
|
+
return {
|
23
|
+
status: "error",
|
24
|
+
message: "Error while sending command"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def connect(ip)
|
30
|
+
begin
|
31
|
+
response = HTTParty.put("http://" + ip + "/console/connect")
|
32
|
+
if response.code == 200
|
33
|
+
return JSON.parse(response.body)
|
34
|
+
else
|
35
|
+
return {
|
36
|
+
connected: false
|
37
|
+
}
|
38
|
+
end
|
39
|
+
rescue Exception => e
|
40
|
+
return {
|
41
|
+
connected: false
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
en:
|
2
|
+
webconsole:
|
3
|
+
connect:
|
4
|
+
refused: "The server has refused your connection attempt"
|
5
|
+
success: "The server has accepted your connection and you are now connected"
|
6
|
+
error: "Something went wrong when connection to server"
|
7
|
+
error_paranoid: "Something went wrong when connection to server. Server might be down"
|
8
|
+
commands:
|
9
|
+
invalid: "Invalid command. Write 'help' for instructions"
|
data/lib/webconsole.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
class WebConsole
|
2
|
+
WebConsole::Engine.routes.draw do
|
3
|
+
put '/console', to: 'console#run_command', as: :console_run_command
|
4
|
+
put '/console/connect', to: 'console#connect', as: :console_connect
|
5
|
+
put '/console/connect_remote/:id', to: 'console#connect_remote', as: :console_connect_remote
|
6
|
+
put '/console/send_command', to: 'console#send_command', as: :console_send_command
|
7
|
+
end
|
8
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: RemoteWebConsole
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Eriksson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A webconsole that can be used accross multiple applications.
|
14
|
+
email: sebastian98@live.se
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- app/controllers/webconsole/webconsole_controller.rb
|
20
|
+
- app/helpers/console_helper.rb
|
21
|
+
- config/locales/en.yml
|
22
|
+
- lib/webconsole.rb
|
23
|
+
homepage: https://rubygems.org/gems/webconsole
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.1.4
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Webconsole for Ruby
|
46
|
+
test_files: []
|