2015-10-07 11:04:40 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
|
|
|
# license: All rights reserved
|
|
|
|
|
|
|
|
class Script < Cmd
|
|
|
|
name 'script'
|
2015-10-07 11:13:37 +00:00
|
|
|
attr_accessor :command
|
|
|
|
|
2015-10-07 11:04:40 +00:00
|
|
|
def initialize(script)
|
2015-10-26 03:04:18 +00:00
|
|
|
case inspec.os[:family]
|
2015-10-07 11:04:40 +00:00
|
|
|
when 'windows'
|
|
|
|
# encodes a script as base64 to run as powershell encodedCommand
|
|
|
|
# this comes with performance issues: @see https://gist.github.com/fnichol/7b20596b950e65fb96f9
|
|
|
|
require 'winrm'
|
|
|
|
script = WinRM::PowershellScript.new(script)
|
|
|
|
cmd = "powershell -encodedCommand #{script.encoded}"
|
|
|
|
else
|
|
|
|
return skip_resource 'The `script` resource is not supported on your OS yet.'
|
|
|
|
end
|
|
|
|
|
|
|
|
@command = cmd
|
|
|
|
end
|
|
|
|
|
2015-10-07 11:15:04 +00:00
|
|
|
# we cannot determine if a command exists, because that does not work for scripts
|
|
|
|
def exist?
|
|
|
|
nil
|
2015-10-07 11:04:40 +00:00
|
|
|
end
|
2015-10-12 11:01:58 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
'Script'
|
|
|
|
end
|
2015-10-07 11:04:40 +00:00
|
|
|
end
|