2013-12-05 06:28:53 +00:00
|
|
|
# https://en.wikipedia.org/wiki/Printer_Job_Language
|
|
|
|
# See external links for PJL spec
|
2013-12-05 03:46:45 +00:00
|
|
|
|
2013-12-05 16:25:04 +00:00
|
|
|
module Rex::Proto::PJL
|
2013-12-05 03:46:45 +00:00
|
|
|
class Client
|
|
|
|
|
|
|
|
def initialize(sock)
|
|
|
|
@sock = sock
|
|
|
|
end
|
|
|
|
|
2013-12-05 06:28:53 +00:00
|
|
|
# Begin PJL job
|
|
|
|
#
|
2013-12-05 16:25:04 +00:00
|
|
|
# @return [void]
|
|
|
|
def begin_job
|
|
|
|
command = "#{UEL}#{PREFIX}\n"
|
2013-12-05 03:46:45 +00:00
|
|
|
@sock.put(command)
|
|
|
|
end
|
|
|
|
|
2013-12-05 06:28:53 +00:00
|
|
|
# End PJL job
|
|
|
|
#
|
2013-12-05 16:25:04 +00:00
|
|
|
# @return [void]
|
|
|
|
def end_job
|
|
|
|
command = "#{UEL}\n"
|
2013-12-05 03:46:45 +00:00
|
|
|
@sock.put(command)
|
|
|
|
end
|
|
|
|
|
2013-12-05 16:56:28 +00:00
|
|
|
# Send INFO request and read response
|
2013-12-05 06:28:53 +00:00
|
|
|
#
|
|
|
|
# @param category [String] INFO category
|
|
|
|
# @return [String] INFO response
|
2013-12-05 16:56:28 +00:00
|
|
|
def info(category)
|
|
|
|
categories = {
|
|
|
|
:id => INFO_ID,
|
|
|
|
:status => INFO_STATUS,
|
|
|
|
:filesys => INFO_FILESYS
|
|
|
|
}
|
|
|
|
unless categories.has_key?(category)
|
|
|
|
raise ArgumentError, "Unknown INFO category"
|
2013-12-05 03:46:45 +00:00
|
|
|
end
|
2013-12-05 16:56:28 +00:00
|
|
|
command = "#{categories[category]}\n"
|
2013-12-05 16:25:04 +00:00
|
|
|
begin_job
|
2013-12-05 03:46:45 +00:00
|
|
|
@sock.put(command)
|
2013-12-05 16:25:04 +00:00
|
|
|
end_job
|
2013-12-05 16:56:28 +00:00
|
|
|
@sock.get
|
2013-12-05 03:46:45 +00:00
|
|
|
end
|
|
|
|
|
2013-12-05 06:28:53 +00:00
|
|
|
# Get version information
|
|
|
|
#
|
|
|
|
# @return [String] Version information
|
2013-12-05 16:56:28 +00:00
|
|
|
def info_id
|
2013-12-05 03:46:45 +00:00
|
|
|
id = nil
|
2013-12-05 16:56:28 +00:00
|
|
|
response = info(:id)
|
|
|
|
if response =~ /"(.*?)"/m
|
2013-12-05 03:46:45 +00:00
|
|
|
id = $1
|
|
|
|
end
|
|
|
|
return id
|
|
|
|
end
|
|
|
|
|
2013-12-05 16:56:28 +00:00
|
|
|
# List volumes
|
|
|
|
#
|
|
|
|
# @return [String] Volume listing
|
|
|
|
def info_filesys
|
|
|
|
filesys = nil
|
|
|
|
response = info(:filesys)
|
|
|
|
if response =~ /\[\d+ TABLE\]\r?\n(.*?)\f/m
|
|
|
|
filesys = $1
|
|
|
|
end
|
|
|
|
return filesys
|
|
|
|
end
|
|
|
|
|
2013-12-05 06:28:53 +00:00
|
|
|
# Get ready message
|
|
|
|
#
|
|
|
|
# @return [String] Ready message
|
2013-12-05 16:25:04 +00:00
|
|
|
def get_rdymsg
|
2013-12-05 03:46:45 +00:00
|
|
|
rdymsg = nil
|
2013-12-05 16:56:28 +00:00
|
|
|
response = info(:status)
|
|
|
|
if response =~ /DISPLAY="(.*?)"/m
|
2013-12-05 03:46:45 +00:00
|
|
|
rdymsg = $1
|
|
|
|
end
|
|
|
|
return rdymsg
|
|
|
|
end
|
|
|
|
|
2013-12-05 06:28:53 +00:00
|
|
|
# Set ready message
|
|
|
|
#
|
|
|
|
# @param message [String] Ready message
|
2013-12-05 16:25:04 +00:00
|
|
|
# @return [void]
|
|
|
|
def set_rdymsg(message)
|
|
|
|
command = %Q{#{RDYMSG_DISPLAY} = "#{message}"\n}
|
|
|
|
begin_job
|
2013-12-05 03:46:45 +00:00
|
|
|
@sock.put(command)
|
2013-12-05 16:25:04 +00:00
|
|
|
end_job
|
2013-12-05 03:46:45 +00:00
|
|
|
end
|
|
|
|
|
2013-12-05 16:56:28 +00:00
|
|
|
# Initialize volume
|
|
|
|
#
|
|
|
|
# @param volume [String] Volume
|
|
|
|
# @return [void]
|
|
|
|
def fsinit(volume)
|
|
|
|
if volume !~ /^[0-2]:$/
|
|
|
|
raise ArgumentError, "Volume must be 0:, 1:, or 2:"
|
|
|
|
end
|
|
|
|
command = %Q{#{FSINIT_VOLUME} = "#{volume}"\n}
|
|
|
|
begin_job
|
|
|
|
@sock.put(command)
|
|
|
|
end_job
|
|
|
|
end
|
|
|
|
|
|
|
|
# List directory
|
|
|
|
#
|
|
|
|
# @param pathname [String] Pathname
|
|
|
|
# @param count [Fixnum] Number of entries to list
|
|
|
|
# @return [String] Directory listing
|
|
|
|
def fsdirlist(pathname, count = 2147483647)
|
|
|
|
if pathname !~ /^[0-2]:/
|
|
|
|
raise ArgumentError, "Pathname must begin with 0:, 1:, or 2:"
|
|
|
|
end
|
|
|
|
listing = nil
|
|
|
|
command = %Q{#{FSDIRLIST_NAME} = "#{pathname}" ENTRY=1 COUNT=#{count}\n}
|
|
|
|
begin_job
|
|
|
|
@sock.put(command)
|
|
|
|
end_job
|
|
|
|
response = @sock.get
|
|
|
|
if response =~ /ENTRY=1\r?\n(.*?)\f/m
|
|
|
|
listing = $1
|
|
|
|
end
|
|
|
|
return listing
|
|
|
|
end
|
|
|
|
|
|
|
|
# Download file
|
|
|
|
#
|
|
|
|
# @param pathname [String] Pathname
|
|
|
|
# @param size [Fixnum] Size of file
|
|
|
|
# @return [String] File as a string
|
|
|
|
def fsupload(pathname, size = 2147483647)
|
|
|
|
if pathname !~ /^[0-2]:/
|
|
|
|
raise ArgumentError, "Pathname must begin with 0:, 1:, or 2:"
|
|
|
|
end
|
|
|
|
file = nil
|
|
|
|
command = %Q{#{FSUPLOAD_NAME} = "#{pathname}" OFFSET=0 SIZE=#{size}\n}
|
|
|
|
begin_job
|
|
|
|
@sock.put(command)
|
|
|
|
end_job
|
|
|
|
response = @sock.get
|
|
|
|
if response =~ /SIZE=\d+\r?\n(.*?)\f/m
|
|
|
|
file = $1
|
|
|
|
end
|
|
|
|
return file
|
|
|
|
end
|
|
|
|
|
2013-12-05 03:46:45 +00:00
|
|
|
end
|
|
|
|
end
|