Class: Rex::Proto::PJL::Client
- Inherits:
-
Object
- Object
- Rex::Proto::PJL::Client
- Defined in:
- lib/rex/proto/pjl/client.rb
Instance Attribute Summary collapse
-
#sock ⇒ Object
readonly
Returns the value of attribute sock.
Instance Method Summary collapse
-
#begin_job ⇒ void
Begin a PJL job.
-
#end_job ⇒ void
End a PJL job.
-
#fsdirlist(pathname, count = COUNT_MAX) ⇒ String
List a directory.
-
#fsinit(volume) ⇒ void
Initialize a volume.
-
#fsupload(pathname, size = SIZE_MAX) ⇒ String
Download a file.
-
#get_rdymsg ⇒ String
Get the ready message.
-
#info(category) ⇒ String
Send an INFO request and read the response.
-
#info_filesys ⇒ String
List volumes.
-
#info_id ⇒ String
Get version information.
-
#info_variables ⇒ String
Get environment variables.
-
#initialize(sock) ⇒ Client
constructor
A new instance of Client.
-
#set_rdymsg(message) ⇒ void
Set the ready message.
Constructor Details
#initialize(sock) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/rex/proto/pjl/client.rb', line 10 def initialize(sock) @sock = sock end |
Instance Attribute Details
#sock ⇒ Object (readonly)
Returns the value of attribute sock.
8 9 10 |
# File 'lib/rex/proto/pjl/client.rb', line 8 def sock @sock end |
Instance Method Details
#begin_job ⇒ void
This method returns an undefined value.
Begin a PJL job
17 18 19 |
# File 'lib/rex/proto/pjl/client.rb', line 17 def begin_job @sock.put("#{UEL}#{PREFIX}\n") end |
#end_job ⇒ void
This method returns an undefined value.
End a PJL job
24 25 26 |
# File 'lib/rex/proto/pjl/client.rb', line 24 def end_job @sock.put(UEL) end |
#fsdirlist(pathname, count = COUNT_MAX) ⇒ String
List a directory
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rex/proto/pjl/client.rb', line 125 def fsdirlist(pathname, count = COUNT_MAX) if pathname !~ /^[0-2]:/ raise ArgumentError, "Pathname must begin with 0:, 1:, or 2:" end listing = nil @sock.put(%Q{#{FSDIRLIST} NAME = "#{pathname}" ENTRY=1 COUNT=#{count}\n}) if @sock.get(DEFAULT_TIMEOUT) =~ /ENTRY=1\r?\n(.*?)\f/m listing = $1 end listing end |
#fsinit(volume) ⇒ void
This method returns an undefined value.
Initialize a volume
112 113 114 115 116 117 118 |
# File 'lib/rex/proto/pjl/client.rb', line 112 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 |
#fsupload(pathname, size = SIZE_MAX) ⇒ String
Download a file
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/rex/proto/pjl/client.rb', line 146 def fsupload(pathname, size = SIZE_MAX) if pathname !~ /^[0-2]:/ raise ArgumentError, "Pathname must begin with 0:, 1:, or 2:" end file = nil @sock.put(%Q{#{FSUPLOAD} NAME = "#{pathname}" OFFSET=0 SIZE=#{size}\n}) if @sock.get(DEFAULT_TIMEOUT) =~ /SIZE=\d+\r?\n(.*)\f/m file = $1 end file end |
#get_rdymsg ⇒ String
Get the ready message
90 91 92 93 94 95 96 97 98 |
# File 'lib/rex/proto/pjl/client.rb', line 90 def get_rdymsg rdymsg = nil if info(:status) =~ /DISPLAY="(.*?)"/m rdymsg = $1 end rdymsg end |
#info(category) ⇒ String
Send an INFO request and read the response
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rex/proto/pjl/client.rb', line 32 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 ⇒ String
List volumes
77 78 79 80 81 82 83 84 85 |
# File 'lib/rex/proto/pjl/client.rb', line 77 def info_filesys filesys = nil if info(:filesys) =~ /\[\d+ TABLE\]\r?\n(.*?)\f/m filesys = $1 end filesys end |
#info_id ⇒ String
Get version information
51 52 53 54 55 56 57 58 59 |
# File 'lib/rex/proto/pjl/client.rb', line 51 def info_id id = nil if info(:id) =~ /"(.*?)"/m id = $1 end id end |
#info_variables ⇒ String
Get environment variables
64 65 66 67 68 69 70 71 72 |
# File 'lib/rex/proto/pjl/client.rb', line 64 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) ⇒ void
This method returns an undefined value.
Set the ready message
104 105 106 |
# File 'lib/rex/proto/pjl/client.rb', line 104 def set_rdymsg() @sock.put(%Q{#{RDYMSG} DISPLAY = "#{}"\n}) end |