Skip to content

Commit

Permalink
QR - Create images directory if does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles committed May 15, 2015
1 parent ad87ea7 commit 87476c5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions extensions/qrcode/qrcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ def self.pre_http_start(http_hook_server)

# get URLs from QR config
configuration.get("beef.extension.qrcode.targets").each do |target|
# absolute URLs
if target.lines.grep(/^https?:\/\//i).size > 0
fullurls << target
# relative URLs
else
# network interfaces
BeEF::Core::Console::Banners.interfaces.each do |int|
Expand All @@ -41,10 +43,16 @@ def self.pre_http_start(http_hook_server)
end

unless fullurls.empty?
data = ""
img_dir = 'extensions/qrcode/images'
begin
Dir.mkdir(img_dir) unless File.directory?(img_dir)
rescue
print_error "[QR] Could not create directory '#{img_dir}'"
end
data = ''
fullurls.uniq.each do |target|
fname = ('a'..'z').to_a.shuffle[0,8].join
qr_path = "extensions/qrcode/images/#{fname}.png"
qr_path = "#{img_dir}/#{fname}.png"
begin
qr = Qr4r::encode(
target, qr_path, {
Expand All @@ -65,6 +73,11 @@ def self.pre_http_start(http_hook_server)
#w = configuration.get("beef.extension.qrcode.qrsize").to_i * 100
#h = configuration.get("beef.extension.qrcode.qrsize").to_i * 100
#data += "- Google API: https://chart.googleapis.com/chart?cht=qr&chs=#{w}x#{h}&chl=#{url}\n"
# QRServer.com
#url = URI.escape(target,Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
#w = configuration.get("beef.extension.qrcode.qrsize").to_i * 100
#h = configuration.get("beef.extension.qrcode.qrsize").to_i * 100
#data += "- QRServer API: https://api.qrserver.com/v1/create-qr-code/?size=#{w}x#{h}&data=#{url}\n"
end
print_info "QR code images available:"
print_more data
Expand Down

0 comments on commit 87476c5

Please sign in to comment.