Class: OpenC3::HostInterface

Inherits:
Interface
  • Object
show all
Defined in:
lib/host_interface.rb

Overview

Allows ANY command to be executed on the host OS and returns the result. This is fundamentally insecure and dangerous! Only install on trusted hosts!

Instance Method Summary collapse

Constructor Details

#initializeHostInterface

Returns a new instance of HostInterface.



8
9
10
11
# File 'lib/host_interface.rb', line 8

def initialize
  super
  @results = []
end

Instance Method Details

#connectObject



13
14
15
16
# File 'lib/host_interface.rb', line 13

def connect
  super
  @results = []
end

#connected?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/host_interface.rb', line 18

def connected?
  true
end

#read_interfaceObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/host_interface.rb', line 22

def read_interface
  begin
    data = @results.shift
    if data.nil? or data.length <= 0
      raise
    end
  rescue
    sleep 0.5
    retry
  end
  read_interface_base(data)
  data
end

#write_interface(data) ⇒ Object



36
37
38
39
40
41
# File 'lib/host_interface.rb', line 36

def write_interface(data)
  write_interface_base(data)
  hash = JSON.parse(data)
  output, status = Open3.capture2e(hash['command'])
  @results << { id: 1, status: status, output: output.strip }.to_json
end