Class: Rex::Proto::PJL::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/proto/pjl/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(sock) ⇒ Client

Returns a new instance of Client.


9
10
11
# File 'lib/rex/proto/pjl/client.rb', line 9

def initialize(sock)
  @sock = sock
end

Instance Method Details

#begin_jobvoid

This method returns an undefined value.

Begin a PJL job


16
17
18
# File 'lib/rex/proto/pjl/client.rb', line 16

def begin_job
  @sock.put("#{UEL}#{PREFIX}\n")
end

#end_jobvoid

This method returns an undefined value.

End a PJL job


23
24
25
# File 'lib/rex/proto/pjl/client.rb', line 23

def end_job
  @sock.put(UEL)
end

#fsdelete(path) ⇒ Boolean

Delete a file

Parameters:

  • path (String)

    Remote path

Returns:

  • (Boolean)

    True if the file was deleted


207
208
209
210
211
212
213
214
215
# File 'lib/rex/proto/pjl/client.rb', line 207

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) ⇒ String

List a directory

Parameters:

  • path (String)

    Remote path

  • count (Integer) (defaults to: COUNT_MAX)

    Number of entries to list

Returns:

  • (String)

    Directory listing


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/rex/proto/pjl/client.rb', line 144

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(data_or_lpath, rpath, is_file: true) ⇒ Boolean

Upload a file or write string data to remote path

Parameters:

  • data_or_lpath (String)

    data or local path

  • rpath (String)

    Remote path

  • is_file (Boolean) (defaults to: true)

    True if data_or_lpath is a local file path

Returns:

  • (Boolean)

    True if the file was uploaded


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/rex/proto/pjl/client.rb', line 186

def fsdownload(data_or_lpath, rpath, is_file: true)
  if rpath !~ /^[0-2]:/
    raise ArgumentError, "Path must begin with 0:, 1:, or 2:"
  end

  file = is_file ? File.read(data_or_lpath) : data_or_lpath

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

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

  fsquery(rpath)
end

#fsinit(volume) ⇒ void

This method returns an undefined value.

Initialize a volume

Parameters:

  • volume (String)

    Volume


111
112
113
114
115
116
117
# File 'lib/rex/proto/pjl/client.rb', line 111

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) ⇒ Boolean

Query a file

Parameters:

  • path (String)

    Remote path

Returns:

  • (Boolean)

    True if file exists


123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rex/proto/pjl/client.rb', line 123

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) ⇒ String

Download a file

Parameters:

  • path (String)

    Remote path

Returns:

  • (String)

    File as a string


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/rex/proto/pjl/client.rb', line 164

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_rdymsgString

Get the ready message

Returns:

  • (String)

    Ready message


89
90
91
92
93
94
95
96
97
# File 'lib/rex/proto/pjl/client.rb', line 89

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

Parameters:

  • category (String)

    INFO category

Returns:

  • (String)

    INFO response


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rex/proto/pjl/client.rb', line 31

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_filesysString

List volumes

Returns:

  • (String)

    Volume listing


76
77
78
79
80
81
82
83
84
# File 'lib/rex/proto/pjl/client.rb', line 76

def info_filesys
  filesys = nil

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

  filesys
end

#info_idString

Get version information

Returns:

  • (String)

    Version information


50
51
52
53
54
55
56
57
58
# File 'lib/rex/proto/pjl/client.rb', line 50

def info_id
  id = nil

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

  id
end

#info_variablesString

Get environment variables

Returns:

  • (String)

    Environment variables


63
64
65
66
67
68
69
70
71
# File 'lib/rex/proto/pjl/client.rb', line 63

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

Parameters:

  • message (String)

    Ready message


103
104
105
# File 'lib/rex/proto/pjl/client.rb', line 103

def set_rdymsg(message)
  @sock.put(%Q{#{RDYMSG} DISPLAY = "#{message}"\n})
end