don't create a new socket every time the command prompt is displayed
parent
395346a720
commit
8083853cb9
|
@ -381,33 +381,46 @@ protected
|
||||||
#
|
#
|
||||||
def format_prompt(str)
|
def format_prompt(str)
|
||||||
if framework
|
if framework
|
||||||
if str.include?("%T")
|
if str.include?('%T')
|
||||||
t = Time.now
|
t = Time.now
|
||||||
# This %T is the strftime shorthand for %H:%M:%S
|
# This %T is the strftime shorthand for %H:%M:%S
|
||||||
format = framework.datastore['PromptTimeFormat'] || "%T"
|
format = framework.datastore['PromptTimeFormat'] || '%T'
|
||||||
t = t.strftime(format)
|
t = t.strftime(format)
|
||||||
# This %T is the marker in the prompt where we need to place the time
|
# This %T is the marker in the prompt where we need to place the time
|
||||||
str.gsub!(/%T/, t.to_s)
|
str.gsub!('%T', t.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
if str.include?("%H")
|
if str.include?('%H')
|
||||||
hostname = ENV['HOSTNAME'] || `hostname`.split('.')[0] ||
|
hostname = ENV['HOSTNAME'] || `hostname`.split('.')[0] ||
|
||||||
ENV['COMPUTERNAME'] || 'unknown'
|
ENV['COMPUTERNAME'] || 'unknown'
|
||||||
|
|
||||||
str.gsub!(/%H/, hostname.chomp)
|
str.gsub!('%H', hostname.chomp)
|
||||||
end
|
end
|
||||||
|
|
||||||
if str.include?("%U")
|
if str.include?('%U')
|
||||||
user = ENV['USER'] || `whoami` || ENV['USERNAME'] || 'unknown'
|
user = ENV['USER'] || `whoami` || ENV['USERNAME'] || 'unknown'
|
||||||
str.gsub!(/%U/, user.chomp)
|
str.gsub!('%U', user.chomp)
|
||||||
end
|
end
|
||||||
|
|
||||||
str.gsub!(/%S/, framework.sessions.length.to_s)
|
if str.include?('%S')
|
||||||
str.gsub!(/%J/, framework.jobs.length.to_s)
|
str.gsub!('%S', framework.sessions.length.to_s)
|
||||||
str.gsub!(/%L/, Rex::Socket.source_address("50.50.50.50"))
|
end
|
||||||
str.gsub!(/%D/, ::Dir.getwd)
|
|
||||||
if framework.db.active
|
if str.include?('%J')
|
||||||
str.gsub!(/%W/, framework.db.workspace.name)
|
str.gsub!('%J', framework.jobs.length.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
if str.include?('%L')
|
||||||
|
ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
|
||||||
|
str.gsub!('%L', ip.ip_address)
|
||||||
|
end
|
||||||
|
|
||||||
|
if str.include?('%D')
|
||||||
|
str.gsub!('%D', ::Dir.getwd)
|
||||||
|
end
|
||||||
|
|
||||||
|
if str.include?('%W') && framework.db.active
|
||||||
|
str.gsub!('%W', framework.db.workspace.name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue