make logfile configurable

This commit is contained in:
Christian Mehlmauer
2017-05-31 23:16:07 +02:00
parent d65567fc8f
commit 21f4de2ec1
7 changed files with 49 additions and 8 deletions

View File

@@ -8,14 +8,47 @@ $exit_code = 0
require File.join(__dir__, 'lib', 'wpscan', 'wpscan_helper')
def main
# delete old logfile, check if it is a symlink first.
File.delete(LOG_FILE) if File.exist?(LOG_FILE) and !File.symlink?(LOG_FILE)
begin
wpscan_options = WpscanOptions.load_from_arguments
$log = wpscan_options.log
# some sanity checks
if $log
if $log.empty?
$log = DEFAULT_LOG_FILE
end
# translate to full path if no starting / detected
if $log !~ /^#{File::SEPARATOR}/
$log = File.join(ROOT_DIR, $log)
end
# check if file exists and has a size greater zero
if File.exist?($log) && File.size?($log)
puts notice("The supplied log file #{$log} already exists. If you continue the new output will be appended.")
print '[?] Do you want to continue? [Y]es [N]o, default: [N]'
if Readline.readline !~ /^y/i
# unset logging so puts will try to log to the file
$log = nil
puts notice('Scan aborted')
exit(1)
end
end
# check if we can write the file
begin
File.open($log, 'a')
rescue SystemCallError => e
# unset logging so puts will try to log to the file
temp = $log
$log = nil
puts critical("Error with logfile #{temp}:")
puts critical(e)
exit(1)
end
end
banner() unless wpscan_options.no_banner # called after $log set
unless wpscan_options.has_options?