rubocop extensions/demos
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user