class Rex::Proto::PJL::Client

Public Class Methods

new(sock) click to toggle source
# File lib/rex/proto/pjl/client.rb, line 8
def initialize(sock)
  @sock = sock
end

Public Instance Methods

begin_job() click to toggle source

Begin a PJL job

@return [void]

# File lib/rex/proto/pjl/client.rb, line 15
def begin_job
  @sock.put("#{UEL}#{PREFIX}\n")
end
end_job() click to toggle source

End a PJL job

@return [void]

# File lib/rex/proto/pjl/client.rb, line 22
def end_job
  @sock.put(UEL)
end
fsdelete(path) click to toggle source

Delete a file

@param path [String] Remote path @return [Boolean] True if the file was deleted

# File lib/rex/proto/pjl/client.rb, line 205
def fsdelete(path)
  if path !~ /^[0-2]:/
    raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
  end

  @sock.put(%Q{#{FSDELETE} NAME = "#{path}"\n})

  !fsquery(path)
end
fsdirlist(path, count = COUNT_MAX) click to toggle source

List a directory

@param path [String] Remote path @param count [Fixnum] Number of entries to list @return [String] Directory listing

# File lib/rex/proto/pjl/client.rb, line 143
def fsdirlist(path, count = COUNT_MAX)
  if path !~ /^[0-2]:/
    raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
  end

  listing = nil

  @sock.put(%Q{#{FSDIRLIST} NAME = "#{path}" ENTRY=1 COUNT=#{count}\n})

  if @sock.get(DEFAULT_TIMEOUT) =~ /ENTRY=1\r?\n(.*?)\f/m
    listing = $1
  end

  listing
end
fsdownload(lpath, rpath) click to toggle source

Upload a file

@param lpath [String] Local path @param rpath [String] Remote path @return [Boolean] True if the file was uploaded

# File lib/rex/proto/pjl/client.rb, line 184
def fsdownload(lpath, rpath)
  if rpath !~ /^[0-2]:/
    raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
  end

  file = File.read(lpath)

  @sock.put(
    %Q{#{FSDOWNLOAD} FORMAT:BINARY SIZE=#{file.length} NAME = "#{rpath}"\n}
  )

  @sock.put(file)
  @sock.put(UEL)

  fsquery(rpath)
end
fsinit(volume) click to toggle source

Initialize a volume

@param volume [String] Volume @return [void]

# File lib/rex/proto/pjl/client.rb, line 110
def fsinit(volume)
  if volume !~ /^[0-2]:$/
    raise ArgumentError, "Volume must be 0:, 1:, or 2:"
  end

  @sock.put(%Q{#{FSINIT} VOLUME = "#{volume}"\n})
end
fsquery(path) click to toggle source

Query a file

@param path [String] Remote path @return [Boolean] True if file exists

# File lib/rex/proto/pjl/client.rb, line 122
def fsquery(path)
  if path !~ /^[0-2]:/
    raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
  end

  file = false

  @sock.put(%Q{#{FSQUERY} NAME = "#{path}"\n})

  if @sock.get(DEFAULT_TIMEOUT) =~ /TYPE=(FILE|DIR)/m
    file = true
  end

  file
end
fsupload(path) click to toggle source

Download a file

@param path [String] Remote path @return [String] File as a string

# File lib/rex/proto/pjl/client.rb, line 163
def fsupload(path)
  if path !~ /^[0-2]:/
    raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
  end

  file = nil

  @sock.put(%Q{#{FSUPLOAD} NAME = "#{path}" OFFSET=0 SIZE=#{SIZE_MAX}\n})

  if @sock.get(DEFAULT_TIMEOUT) =~ /SIZE=\d+\r?\n(.*)\f/m
    file = $1
  end

  file
end
get_rdymsg() click to toggle source

Get the ready message

@return [String] Ready message

# File lib/rex/proto/pjl/client.rb, line 88
def get_rdymsg
  rdymsg = nil

  if info(:status) =~ /DISPLAY="(.*?)"/m
    rdymsg = $1
  end

  rdymsg
end
info(category) click to toggle source

Send an INFO request and read the response

@param category [String] INFO category @return [String] INFO response

# File lib/rex/proto/pjl/client.rb, line 30
def info(category)
  categories = {
    :id => Info::ID,
    :status => Info::STATUS,
    :variables => Info::VARIABLES,
    :filesys => Info::FILESYS
  }

  unless categories.has_key?(category)
    raise ArgumentError, "Unknown INFO category"
  end

  @sock.put("#{categories[category]}\n")
  @sock.get(DEFAULT_TIMEOUT)
end
info_filesys() click to toggle source

List volumes

@return [String] Volume listing

# File lib/rex/proto/pjl/client.rb, line 75
def info_filesys
  filesys = nil

  if info(:filesys) =~ /\[\d+ TABLE\]\r?\n(.*?)\f/m
    filesys = $1
  end

  filesys
end
info_id() click to toggle source

Get version information

@return [String] Version information

# File lib/rex/proto/pjl/client.rb, line 49
def info_id
  id = nil

  if info(:id) =~ /"(.*?)"/m
    id = $1
  end

  id
end
info_variables() click to toggle source

Get environment variables

@return [String] Environment variables

# File lib/rex/proto/pjl/client.rb, line 62
def info_variables
  env_vars = nil

  if info(:variables) =~ /#{Info::VARIABLES}\r?\n(.*?)\f/m
    env_vars = $1
  end

  env_vars
end
set_rdymsg(message) click to toggle source

Set the ready message

@param message [String] Ready message @return [void]

# File lib/rex/proto/pjl/client.rb, line 102
def set_rdymsg(message)
  @sock.put(%Q{#{RDYMSG} DISPLAY = "#{message}"\n})
end