CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/http/handler/proc.rb
Views: 11766
1
# -*- coding: binary -*-
2
require 'erb'
3
4
module Rex
5
module Proto
6
module Http
7
8
###
9
#
10
# This class is used to wrapper the calling of a procedure when a request
11
# arrives.
12
#
13
###
14
class Handler::Proc < Handler
15
16
#
17
# Initializes the proc handler with the supplied procedure
18
#
19
def initialize(server, procedure, virt_dir = false)
20
super(server)
21
22
self.procedure = procedure
23
self.virt_dir = virt_dir || false
24
end
25
26
#
27
# Returns true if the procedure is representing a virtual directory.
28
#
29
def relative_resource_required?
30
virt_dir
31
end
32
33
#
34
# Called when a request arrives.
35
#
36
def on_request(cli, req)
37
begin
38
procedure.call(cli, req)
39
rescue Errno::EPIPE, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED => e
40
elog('Proc::on_request: Client closed connection prematurely', LogSource, error: e)
41
rescue => e
42
elog('Proc::on_request', LogSource, error: e)
43
if self.server and self.server.context
44
exploit = self.server.context['MsfExploit']
45
if exploit
46
exploit.print_error("Exception handling request: #{$!}")
47
end
48
end
49
end
50
end
51
52
protected
53
54
attr_accessor :procedure # :nodoc:
55
attr_accessor :virt_dir # :nodoc:
56
57
end
58
59
end
60
end
61
end
62
63