Sha256: b91cbb9cd84689d5ce72b48a9f80a20231babd8791da2a10a55369312460b85b

Contents?: true

Size: 1.81 KB

Versions: 65

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

require 'barby'
require 'rqrcode'
require 'chunky_png'

module PWN
  module Plugins
    # This plugin is used to Create Scannable BarCodes and QR Codes
    module ScannableCodes
      # Supported Method Parameters::
      # response = PWN::Plugins::ScannableCodes.generate(
      #   data: 'required - data to encode',
      #   type: 'optional - :barcode || :qrcode (defaults to :qrcode)',
      #   path: 'optional - path to save image (defaults to "./#{data}.png")'
      # )

      public_class_method def self.generate(opts = {})
        data = opts[:data]
        raise 'ERROR: option data is required.' unless data

        type = opts[:type]
        type ||= :qrcode

        path = opts[:path]
        path ||= "./#{data}.png"

        case type
        when :barcode
          barcode = Barby::Code128B.new(data)
          barcode.to_png.save(path)
        when :qrcode
          qrcode = RQRCode::QRCode.new(data)
          png = qrcode.as_png
          png.resize(200, 200).save(path)
        else
          raise 'ERROR: type must be :barcode or :qrcode.'
        end

        puts "Saved #{type} to #{path}"
      rescue Interrupt
        puts "\nGoodbye."
      rescue StandardError => e
        raise e
      end

      # Author(s):: 0day Inc. <support@0dayinc.com>

      public_class_method def self.authors
        "AUTHOR(S):
          0day Inc. <support@0dayinc.com>
        "
      end

      # Display Usage for this Module

      public_class_method def self.help
        puts "USAGE:
          #{self}.generate(
            data: 'required - data to encode',
            type: 'optional - :barcode || :qrcode (defaults to :qrcode)',
            path: 'optional - path to save image (defaults to \"./\#{data}.png\")'
          )

          #{self}.authors
        "
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
pwn-0.5.152 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.151 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.150 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.106 lib/pwn/plugins/scannable_codes.rb
pwn-0.5.105 lib/pwn/plugins/scannable_codes.rb