23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/rbitter/xmlrpcd/xmlrpc_auth_server.rb', line 23
def service(request, response)
if @valid_ip
raise WEBrick::HTTPStatus::Forbidden unless @valid_ip.any? { |ip| request.peeraddr[3] =~ ip }
end
if request.request_method != "POST"
raise WEBrick::HTTPStatus::MethodNotAllowed,
"unsupported method `#{request.request_method}'."
end
if parse_content_type(request['Content-type']).first != "text/xml"
raise WEBrick::HTTPStatus::BadRequest
end
length = (request['Content-length'] || 0).to_i
raise WEBrick::HTTPStatus::LengthRequired unless length > 0
data = request.body
if data.nil? or data.bytesize != length
raise WEBrick::HTTPStatus::BadRequest
end
rpc_method_name, rpc_params = parser().parseMethodCall(data)
rpc_method = (rpc_method_name)
if RPCHandles.auth.nil?
resp = handle(rpc_method_name, *rpc_params)
else
if rpc_method.owner.ancestors.include?(RPCHandles::BaseHandle::Auth)
if request.cookies.size == 1 \
and request.cookies[0].name == "auth_key" \
and RPCHandles.auth.include?(request.cookies[0].value)
resp = handle(rpc_method_name, *rpc_params)
else
raise WEBrick::HTTPStatus::Forbidden
end
elsif rpc_method.owner.ancestors.include?(RPCHandles::BaseHandle::NoAuth)
resp = handle(rpc_method_name, *rpc_params)
else
raise WEBrick::HTTPStatus::Forbidden
end
end
if resp.nil? or resp.bytesize <= 0
raise WEBrick::HTTPStatus::InternalServerError
end
response.status = 200
response['Content-Length'] = resp.bytesize
response['Content-Type'] = "text/xml; charset=utf-8"
response.body = resp
end
|