Sha256: 2d47b1d39433797469c5613de9b90151978d8a483a737b1f23a92746b7999485

Contents?: true

Size: 1.69 KB

Versions: 14

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

# Case->DSL#
# * send
# * tempfile
# * tempdir
# * remote_tempdir
# * remote_tempfile
module DSL
  def send(args = {})
    return if skip?

    return unless args[:copy_to]

    host = args[:copy_to].to_s
    return unless @conn_status[host].nil?

    ip = get((host + '_ip').to_sym)
    username = get((host + '_username').to_sym).to_s
    password = get((host + '_password').to_sym).to_s

    filename = @report.filename + '.' + @report.format.to_s
    localfilepath = File.join(@report.output_dir, filename)
    filename = args[:prefix].to_s + filename if args[:prefix]

    if args[:remote_dir]
      remotefilepath = File.join(args[:remote_dir], filename)
    else
      # remotefilepath = File.join(remote_tempdir, filename)
      remotefilepath = File.join('.', filename)
    end

    # Upload a file or directory to the remote host
    begin
      Net::SFTP.start(ip, username, password: password) do |sftp|
        sftp.upload!(localfilepath, remotefilepath)
      end
      verboseln("=> [ OK  ] #{(get(:tt_members)[0,15]).ljust(16)} : #{remotefilepath}")
    rescue
      verboseln("=> [ERROR] #{(get(:tt_members)[0,15]).ljust(16)} : scp #{localfilepath} => #{remotefilepath}")
    end
  end

  def tempfile(input = nil)
    return @action[:tempfile] if input.nil?

    name = input
    name = 'teuton.tmp' if input == :default

    @action[:tempfile] = File.join(@tmpdir, name)
    @action[:remote_tempfile] = File.join(@remote_tmpdir, name)

    @action[:tempfile]
  end

  def tempdir
    # puts '[WARN] Using DSL.tempdir'
    @tmpdir
  end

  def remote_tempfile
    # puts '[WARN] Using DSL.tempfile'
    @action[:remote_tempfile]
  end

  def remote_tempdir
    @remote_tmpdir
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
teuton-2.1.11 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.10 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.9 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.8 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.8dev1 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.7 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.6 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.5dev lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.4 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.3 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.2 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.1 lib/teuton/case_manager/case/dsl/send.rb
teuton-2.1.0 lib/teuton/case_manager/case/dsl/send.rb
teuton-0.0.1 lib/teuton/case_manager/case/dsl/send.rb