From 205921b1a29ac132f1765de5243e83f4e6da96dd Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Mon, 25 Feb 2019 10:29:39 +0000 Subject: [PATCH] rubocop extensions/demos --- extensions/demos/api.rb | 38 +++++++-------- extensions/demos/extension.rb | 22 ++++----- extensions/demos/handler.rb | 89 +++++++++++++++++------------------ 3 files changed, 69 insertions(+), 80 deletions(-) diff --git a/extensions/demos/api.rb b/extensions/demos/api.rb index d1845d808..32fd91825 100644 --- a/extensions/demos/api.rb +++ b/extensions/demos/api.rb @@ -4,31 +4,29 @@ # See the file 'doc/COPYING' for copying permission # module BeEF -module Extension -module Demos + module Extension + module Demos + module RegisterHttpHandlers + BeEF::API::Registrar.instance.register(BeEF::Extension::Demos::RegisterHttpHandlers, BeEF::API::Server, 'mount_handler') - module RegisterHttpHandlers + def self.mount_handler(beef_server) + # mount everything in html directory to /demos/ + path = File.dirname(__FILE__) + '/html/' + files = Dir[path + '**/*'] - BeEF::API::Registrar.instance.register(BeEF::Extension::Demos::RegisterHttpHandlers, BeEF::API::Server, 'mount_handler') + beef_server.mount('/demos', Rack::File.new(path)) - def self.mount_handler(beef_server) - # mount everything in html directory to /demos/ - path = File.dirname(__FILE__)+'/html/' - files = Dir[path+'**/*'] - - beef_server.mount('/demos', Rack::File.new(path)) - - files.each do |f| - # don't follow symlinks - next if File.symlink?(f) - mount_path = '/demos/'+f.sub(path,'') - if File.extname(f) == '.html' - # use handler to mount HTML templates - beef_server.mount(mount_path, BeEF::Extension::Demos::Handler.new(f)) + files.each do |f| + # don't follow symlinks + next if File.symlink?(f) + mount_path = '/demos/' + f.sub(path, '') + if File.extname(f) == '.html' + # use handler to mount HTML templates + beef_server.mount(mount_path, BeEF::Extension::Demos::Handler.new(f)) + end + end end end end end end -end -end diff --git a/extensions/demos/extension.rb b/extensions/demos/extension.rb index f27eda0f5..8d410cdbd 100644 --- a/extensions/demos/extension.rb +++ b/extensions/demos/extension.rb @@ -4,19 +4,15 @@ # See the file 'doc/COPYING' for copying permission # module BeEF -module Extension -module Demos - - extend BeEF::API::Extension - - @short_name = 'demos' - - @full_name = 'demonstrations' - - @description = 'Demonstration pages for BeEF' - -end -end + module Extension + module Demos + extend BeEF::API::Extension + + @short_name = 'demos' + @full_name = 'demonstrations' + @description = 'Demonstration pages for BeEF' + end + end end require 'extensions/demos/api' diff --git a/extensions/demos/handler.rb b/extensions/demos/handler.rb index 90049e0d6..bc6d65abc 100644 --- a/extensions/demos/handler.rb +++ b/extensions/demos/handler.rb @@ -4,56 +4,51 @@ # See the file 'doc/COPYING' for copying permission # module BeEF -module Extension -module Demos + module Extension + module Demos + class Handler + def initialize(file_path) + if File.exist?(file_path) + @file_path = file_path + else + print_error "[Demos] File does not exist: #{file_path}" + end + end - class Handler + def call(env) + @body = '' + @request = Rack::Request.new(env) + @params = @request.query_string + @response = Rack::Response.new(body = [], 200, header = {}) + config = BeEF::Core::Configuration.instance + eruby = Erubis::FastEruby.new(File.read(@file_path)) + @body << eruby.evaluate( + 'hook_uri' => config.get('beef.http.hook_file') + ) - def initialize(file_path) - if File.exists?(file_path) - @file_path = file_path - else - print_error "[Demos] File does not exist: #{file_path}" + @response = Rack::Response.new( + body = [@body], + status = 200, + header = { + 'Pragma' => 'no-cache', + 'Cache-Control' => 'no-cache', + 'Expires' => '0', + 'Content-Type' => 'text/html' + } + ) + end + + private + + # @note String representing the absolute path to the .html file + @file_path + + # @note Object representing the HTTP request + @request + + # @note Object representing the HTTP response + @response end end - - def call(env) - @body = '' - @request = Rack::Request.new(env) - @params = @request.query_string - @response = Rack::Response.new(body=[], 200, header={}) - config = BeEF::Core::Configuration.instance - eruby = Erubis::FastEruby.new(File.read(@file_path)) - @body << eruby.evaluate({ - 'hook_uri' => config.get("beef.http.hook_file") - }) - - @response = Rack::Response.new( - body = [@body], - status = 200, - header = { - 'Pragma' => 'no-cache', - 'Cache-Control' => 'no-cache', - 'Expires' => '0', - 'Content-Type' => 'text/html' - } - ) - - end - - private - - # @note String representing the absolute path to the .html file - @file_path - - # @note Object representing the HTTP request - @request - - # @note Object representing the HTTP response - @response - end - -end -end end