Module: Msf::WebServices::ServiceServlet

Defined in:
lib/msf/core/web_services/servlet/service_servlet.rb

Class Method Summary collapse

Class Method Details

.api_path ⇒ Object



3
4
5
# File 'lib/msf/core/web_services/servlet/service_servlet.rb', line 3

def self.api_path
  '/api/v1/services'
end

.api_path_with_id ⇒ Object



7
8
9
# File 'lib/msf/core/web_services/servlet/service_servlet.rb', line 7

def self.api_path_with_id
  "#{self.api_path}/?:id?"
end

.delete_service ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/msf/core/web_services/servlet/service_servlet.rb', line 62

def self.delete_service
  lambda {
    warden.authenticate!
    begin
      opts = parse_json_request(request, false)
      data = get_db.delete_service(opts)
      set_json_data_response(response: data)
    rescue => e
      print_error_and_create_response(error: e, message: 'There was an error deleting the service:', code: 500)
    end
  }
end

.get_services ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msf/core/web_services/servlet/service_servlet.rb', line 23

def self.get_services
  lambda {
    warden.authenticate!
    begin
      sanitized_params = sanitize_params(params, env['rack.request.query_hash'])
      data = get_db.services(sanitized_params)
      includes = [:host, :parents]
      data = data.first if is_single_object?(data, sanitized_params)
      set_json_data_response(response: data, includes: includes)
    rescue => e
      print_error_and_create_response(error: e, message: 'There was an error retrieving services:', code: 500)
    end
  }
end

.registered(app) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/msf/core/web_services/servlet/service_servlet.rb', line 11

def self.registered(app)
  app.get  self.api_path, &get_services
  app.get  self.api_path_with_id, &get_services
  app.post self.api_path, &report_service
  app.put self.api_path_with_id, &update_service
  app.delete self.api_path, &delete_service
end

.report_service ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/msf/core/web_services/servlet/service_servlet.rb', line 38

def self.report_service
  lambda {
    warden.authenticate!
    job = lambda { |opts| get_db.report_service(opts) }
    includes = [:host, :parents]
    exec_report_job(request, includes, &job)
  }
end

.update_service ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/msf/core/web_services/servlet/service_servlet.rb', line 47

def self.update_service
  lambda {
    warden.authenticate!
    begin
      opts = parse_json_request(request, false)
      tmp_params = sanitize_params(params)
      opts[:id] = tmp_params[:id] if tmp_params[:id]
      data = get_db.update_service(opts)
      set_json_data_response(response: data)
    rescue => e
      print_error_and_create_response(error: e, message: 'There was an error updating the service:', code: 500)
    end
  }
end