Module: WorkspaceDataProxy

Included in:
DataProxyAutoLoader
Defined in:
lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb

Instance Method Summary collapse

Instance Method Details

#add_workspace(workspace_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 14

def add_workspace(workspace_name)
  begin
    self.data_service_operation do |data_service|
      opts = { name: workspace_name }
      data_service.add_workspace(opts)
    end
  rescue => e
    self.log_error(e, "Problem adding workspace")
  end
end

#default_workspaceObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 25

def default_workspace
  begin
    ws = find_workspace(Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME)
    if ws.nil?
      ws = add_workspace(Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME)
    end
    ws
  rescue => e
    self.log_error(e, "Problem finding default workspace")
  end
end

#delete_workspaces(opts) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 70

def delete_workspaces(opts)
  begin
    self.data_service_operation do |data_service|
      data_service.delete_workspaces(opts)
    end
  rescue => e
    self.log_error(e, "Problem deleting workspaces")
  end
end

#find_workspace(workspace_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 3

def find_workspace(workspace_name)
  begin
    self.data_service_operation do |data_service|
      opts = { name: workspace_name }
      data_service.workspaces(opts).first
    end
  rescue => e
    self.log_error(e, "Problem finding workspace")
  end
end

#update_workspace(opts) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 80

def update_workspace(opts)
  begin
    self.data_service_operation do |data_service|
      data_service.update_workspace(opts)
    end
  rescue => e
    self.log_error(e, "Problem updating workspace")
  end
end

#workspaceObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 37

def workspace
  begin
    if @current_workspace
      @current_workspace
    else
      # This is mostly a failsafe to prevent bad things from happening. @current_workspace should always be set
      # outside of here, but this will save us from crashes/infinite loops if that happens
      @current_workspace = default_workspace
    end
  rescue => e
    self.log_error(e, "Problem retrieving workspace")
  end
end

#workspace=(workspace) ⇒ Object

TODO: Tracking of the current workspace should be moved out of the datastore. See MS-3095.



52
53
54
55
56
57
58
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 52

def workspace=(workspace)
  begin
    @current_workspace = workspace
  rescue => e
    self.log_error(e, "Problem setting workspace")
  end
end

#workspaces(opts = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb', line 60

def workspaces(opts = {})
  begin
    self.data_service_operation do |data_service|
      data_service.workspaces(opts)
    end
  rescue => e
    self.log_error(e, "Problem retrieving workspaces")
  end
end