vmpooler/lib/vmpooler/logger.rb
Brandon High a839af2710
Use URI.parse.open/File.open instead of open
This commit updates the dashboard to use `URI.parse` instead of `Kernel#open`
because open can potentially open files on the server and has other
possible security issues.

Also updated the logger to use `File.open` as it is more explicit and
doesn't have the extra potential for abuse like `Kernel#open`

https://rubocop.readthedocs.io/en/latest/cops_security/#securityopen
2020-03-05 16:56:06 -08:00

24 lines
449 B
Ruby

# frozen_string_literal: true
require 'rubygems' unless defined?(Gem)
module Vmpooler
class Logger
def initialize(
f = '/var/log/vmpooler.log'
)
@file = f
end
def log(_level, string)
time = Time.new
stamp = time.strftime('%Y-%m-%d %H:%M:%S')
puts "[#{stamp}] #{string}" if ENV['VMPOOLER_DEBUG']
File.open(@file, 'a') do |f|
f.puts "[#{stamp}] #{string}"
end
end
end
end