Class: Mdm::Workspace
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mdm::Workspace
- Defined in:
- app/models/mdm/workspace.rb
Constant Summary collapse
- DEFAULT =
CONSTANTS
'default'
Class Method Summary collapse
Instance Method Summary collapse
-
#allow_actions_on?(ips) ⇒ Boolean
If limit_to_network is disabled, this will always return true.
- #boundary_must_be_ip_range ⇒ Object
- #creds ⇒ Object
- #default? ⇒ Boolean
-
#each_cred(&block) ⇒ Object
This method iterates the creds table calling the supplied block with the cred instance of each entry.
- #each_host_tag(&block) ⇒ Object
- #host_tags ⇒ Object
- #unique_web_forms ⇒ Object
- #web_forms ⇒ Object
- #web_pages ⇒ Object
- #web_sites ⇒ Object
- #web_unique_forms(addrs = nil) ⇒ Object
- #web_vulns ⇒ Object
Class Method Details
.default ⇒ Object
81 82 83 |
# File 'app/models/mdm/workspace.rb', line 81 def self.default find_or_create_by_name(DEFAULT) end |
Instance Method Details
#allow_actions_on?(ips) ⇒ Boolean
If limit_to_network is disabled, this will always return true. Otherwise, return true only if all of the given IPs are within the project boundaries.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/mdm/workspace.rb', line 53 def allow_actions_on?(ips) return true unless limit_to_network return true unless boundary return true if boundary.empty? boundaries = Shellwords.split(boundary) return true if boundaries.empty? # It's okay if there is no boundary range after all given_range = Rex::Socket::RangeWalker.new(ips) return false unless given_range # Can't do things to nonexistant IPs allowed = false boundaries.each do |boundary_range| ok_range = Rex::Socket::RangeWalker.new(boundary) allowed = true if ok_range.include_range? given_range end return allowed end |
#boundary_must_be_ip_range ⇒ Object
69 70 71 |
# File 'app/models/mdm/workspace.rb', line 69 def boundary_must_be_ip_range errors.add(:boundary, "must be a valid IP range") unless valid_ip_or_range?(boundary) end |
#creds ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/models/mdm/workspace.rb', line 73 def creds Mdm::Cred.find( :all, :include => {:service => :host}, :conditions => ["hosts.workspace_id = ?", self.id] ) end |
#default? ⇒ Boolean
85 86 87 |
# File 'app/models/mdm/workspace.rb', line 85 def default? name == DEFAULT end |
#each_cred(&block) ⇒ Object
This method iterates the creds table calling the supplied block with the cred instance of each entry.
93 94 95 96 97 |
# File 'app/models/mdm/workspace.rb', line 93 def each_cred(&block) creds.each do |cred| block.call(cred) end end |
#each_host_tag(&block) ⇒ Object
99 100 101 102 103 |
# File 'app/models/mdm/workspace.rb', line 99 def each_host_tag(&block) .each do |host_tag| block.call(host_tag) end end |
#host_tags ⇒ Object
105 106 107 108 109 110 111 |
# File 'app/models/mdm/workspace.rb', line 105 def Mdm::Tag.find( :all, :include => :hosts, :conditions => ["hosts.workspace_id = ?", self.id] ) end |
#unique_web_forms ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/models/mdm/workspace.rb', line 160 def unique_web_forms query = <<-EOQ SELECT DISTINCT web_forms.web_site_id, web_forms.path, web_forms.method, web_forms.query FROM hosts, services, web_sites, web_forms WHERE hosts.workspace_id = #{id} AND services.host_id = hosts.id AND web_sites.service_id = services.id AND web_forms.web_site_id = web_sites.id EOQ Mdm::WebForm.find_by_sql(query) end |
#web_forms ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/mdm/workspace.rb', line 113 def web_forms query = <<-EOQ SELECT DISTINCT web_forms.* FROM hosts, services, web_sites, web_forms WHERE hosts.workspace_id = #{id} AND services.host_id = hosts.id AND web_sites.service_id = services.id AND web_forms.web_site_id = web_sites.id EOQ Mdm::WebForm.find_by_sql(query) end |
#web_pages ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/models/mdm/workspace.rb', line 125 def web_pages query = <<-EOQ SELECT DISTINCT web_pages.* FROM hosts, services, web_sites, web_pages WHERE hosts.workspace_id = #{id} AND services.host_id = hosts.id AND web_sites.service_id = services.id AND web_pages.web_site_id = web_sites.id EOQ Mdm::WebPage.find_by_sql(query) end |
#web_sites ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'app/models/mdm/workspace.rb', line 137 def web_sites query = <<-EOQ SELECT DISTINCT web_sites.* FROM hosts, services, web_sites WHERE hosts.workspace_id = #{id} AND services.host_id = hosts.id AND web_sites.service_id = services.id EOQ Mdm::WebSite.find_by_sql(query) end |
#web_unique_forms(addrs = nil) ⇒ Object
172 173 174 175 176 177 178 |
# File 'app/models/mdm/workspace.rb', line 172 def web_unique_forms(addrs=nil) forms = unique_web_forms if addrs forms.reject!{|f| not addrs.include?( f.web_site.service.host.address ) } end forms end |
#web_vulns ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/models/mdm/workspace.rb', line 148 def web_vulns query = <<-EOQ SELECT DISTINCT web_vulns.* FROM hosts, services, web_sites, web_vulns WHERE hosts.workspace_id = #{id} AND services.host_id = hosts.id AND web_sites.service_id = services.id AND web_vulns.web_site_id = web_sites.id EOQ Mdm::WebVuln.find_by_sql(query) end |