ronin-db-activerecord 0.1.6 → 0.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog.md +91 -0
  3. data/README.md +49 -1
  4. data/db/migrate/0037_add_created_at_column_to_ronin_ports_table.rb +40 -0
  5. data/db/migrate/0038_add_created_at_column_to_ronin_services_table.rb +40 -0
  6. data/db/migrate/0039_create_ronin_cert_names_table.rb +37 -0
  7. data/db/migrate/0040_create_ronin_cert_issuers_table.rb +52 -0
  8. data/db/migrate/0041_create_ronin_cert_subjects_table.rb +54 -0
  9. data/db/migrate/0042_create_ronin_cert_subject_alt_names_table.rb +42 -0
  10. data/db/migrate/0043_create_ronin_certs_table.rb +61 -0
  11. data/db/migrate/0044_add_cert_id_column_to_ronin_open_ports_table.rb +35 -0
  12. data/db/migrate/0045_create_ronin_notes_table.rb +120 -0
  13. data/db/migrate/0046_create_ronin_web_vulns_table.rb +61 -0
  14. data/db/migrate/0047_create_ronin_phone_numbers_table.rb +47 -0
  15. data/db/migrate/0048_create_ronin_street_addresses_table.rb +46 -0
  16. data/db/migrate/0049_create_ronin_people_table.rb +48 -0
  17. data/db/migrate/0050_create_ronin_personal_connections_table.rb +48 -0
  18. data/db/migrate/0051_create_ronin_personal_phone_numbers_table.rb +48 -0
  19. data/db/migrate/0052_create_ronin_personal_email_addresses_table.rb +45 -0
  20. data/db/migrate/0053_create_ronin_personal_street_addresses_table.rb +47 -0
  21. data/db/migrate/0054_add_type_column_to_ronin_organizations_table.rb +33 -0
  22. data/db/migrate/0055_add_parent_id_column_to_ronin_organizations_table.rb +43 -0
  23. data/db/migrate/0056_create_ronin_organization_departments_table.rb +59 -0
  24. data/db/migrate/0057_create_ronin_organization_members_table.rb +62 -0
  25. data/db/migrate/0058_create_ronin_organization_customers_table.rb +52 -0
  26. data/db/migrate/0059_create_ronin_organization_phone_numbers_table.rb +47 -0
  27. data/db/migrate/0060_create_ronin_organization_email_addresses_table.rb +45 -0
  28. data/db/migrate/0061_create_ronin_organization_street_addresses_table.rb +47 -0
  29. data/db/migrate/0062_add_source_ip_column_to_http_requests_table.rb +30 -0
  30. data/db/migrate/0063_create_ronin_dns_queries_table.rb +41 -0
  31. data/db/migrate/0064_create_ronin_dns_records_table.rb +42 -0
  32. data/db/migrate/0065_create_ronin_organization_host_names_table.rb +43 -0
  33. data/db/migrate/0066_create_ronin_organization_ip_addresses_table.rb +43 -0
  34. data/gemspec.yml +1 -1
  35. data/lib/ronin/db/address.rb +1 -1
  36. data/lib/ronin/db/advisory.rb +66 -1
  37. data/lib/ronin/db/arch.rb +1 -1
  38. data/lib/ronin/db/asn.rb +15 -1
  39. data/lib/ronin/db/cert.rb +501 -0
  40. data/lib/ronin/db/cert_issuer.rb +78 -0
  41. data/lib/ronin/db/cert_name.rb +107 -0
  42. data/lib/ronin/db/cert_organization.rb +127 -0
  43. data/lib/ronin/db/cert_subject.rb +81 -0
  44. data/lib/ronin/db/cert_subject_alt_name.rb +88 -0
  45. data/lib/ronin/db/credential.rb +10 -1
  46. data/lib/ronin/db/dns_query.rb +98 -0
  47. data/lib/ronin/db/dns_record.rb +76 -0
  48. data/lib/ronin/db/email_address.rb +139 -1
  49. data/lib/ronin/db/host_name.rb +45 -1
  50. data/lib/ronin/db/host_name_ip_address.rb +1 -1
  51. data/lib/ronin/db/http_header_name.rb +1 -1
  52. data/lib/ronin/db/http_query_param.rb +1 -1
  53. data/lib/ronin/db/http_query_param_name.rb +1 -1
  54. data/lib/ronin/db/http_request.rb +13 -1
  55. data/lib/ronin/db/http_request_header.rb +1 -1
  56. data/lib/ronin/db/http_response.rb +1 -1
  57. data/lib/ronin/db/http_response_header.rb +1 -1
  58. data/lib/ronin/db/ip_address.rb +46 -1
  59. data/lib/ronin/db/ip_address_mac_address.rb +1 -1
  60. data/lib/ronin/db/mac_address.rb +28 -1
  61. data/lib/ronin/db/migrations.rb +1 -1
  62. data/lib/ronin/db/model/has_name.rb +18 -1
  63. data/lib/ronin/db/model/has_unique_name.rb +1 -1
  64. data/lib/ronin/db/model/importable.rb +1 -1
  65. data/lib/ronin/db/model/last_scanned_at.rb +1 -1
  66. data/lib/ronin/db/model.rb +1 -1
  67. data/lib/ronin/db/models.rb +44 -2
  68. data/lib/ronin/db/note.rb +199 -0
  69. data/lib/ronin/db/open_port.rb +104 -3
  70. data/lib/ronin/db/organization.rb +237 -3
  71. data/lib/ronin/db/organization_customer.rb +73 -0
  72. data/lib/ronin/db/organization_department.rb +97 -0
  73. data/lib/ronin/db/organization_email_address.rb +66 -0
  74. data/lib/ronin/db/organization_host_name.rb +65 -0
  75. data/lib/ronin/db/organization_ip_address.rb +65 -0
  76. data/lib/ronin/db/organization_member.rb +158 -0
  77. data/lib/ronin/db/organization_phone_number.rb +66 -0
  78. data/lib/ronin/db/organization_street_address.rb +66 -0
  79. data/lib/ronin/db/os.rb +35 -1
  80. data/lib/ronin/db/os_guess.rb +1 -1
  81. data/lib/ronin/db/password.rb +84 -1
  82. data/lib/ronin/db/person.rb +455 -0
  83. data/lib/ronin/db/personal_connection.rb +110 -0
  84. data/lib/ronin/db/personal_email_address.rb +66 -0
  85. data/lib/ronin/db/personal_phone_number.rb +76 -0
  86. data/lib/ronin/db/personal_street_address.rb +66 -0
  87. data/lib/ronin/db/phone_number.rb +330 -0
  88. data/lib/ronin/db/port.rb +110 -1
  89. data/lib/ronin/db/service.rb +130 -1
  90. data/lib/ronin/db/service_credential.rb +1 -1
  91. data/lib/ronin/db/software.rb +37 -1
  92. data/lib/ronin/db/software_vendor.rb +1 -1
  93. data/lib/ronin/db/street_address.rb +340 -0
  94. data/lib/ronin/db/url.rb +37 -1
  95. data/lib/ronin/db/url_query_param.rb +1 -1
  96. data/lib/ronin/db/url_query_param_name.rb +9 -1
  97. data/lib/ronin/db/url_scheme.rb +1 -1
  98. data/lib/ronin/db/user_name.rb +58 -1
  99. data/lib/ronin/db/vulnerability.rb +1 -1
  100. data/lib/ronin/db/web_credential.rb +1 -1
  101. data/lib/ronin/db/web_vuln.rb +348 -0
  102. metadata +57 -2
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -70,6 +70,12 @@ module Ronin
70
70
  # @return [Boolean]
71
71
  attribute :ssl, :boolean
72
72
 
73
+ # @!attribute [rw] cert
74
+ # The SSL/TLS certificate used by the open port.
75
+ #
76
+ # @return [Cert, nil]
77
+ belongs_to :cert, optional: true
78
+
73
79
  # @!attribute [r] created_at
74
80
  # Define the created_at timestamp
75
81
  #
@@ -88,6 +94,98 @@ module Ronin
88
94
  # @return [Array<Credential>]
89
95
  has_many :credentials, through: :service_credentials
90
96
 
97
+ # @!attribute [rw] vulnerabilities
98
+ # The vulnerabilities which reference the open port.
99
+ #
100
+ # @return [Array<Vulnerability>]
101
+ #
102
+ # @since 0.2.0
103
+ has_many :vulnerabilities, dependent: :destroy
104
+
105
+ # @!attribute [rw] advisories
106
+ # The advisories that the open port is vulnerable to.
107
+ #
108
+ # @return [Array<Advisory>]
109
+ #
110
+ # @since 0.2.0
111
+ has_many :advisories, through: :vulnerabilities
112
+
113
+ # @!attribute [rw] notes
114
+ # The associated notes.
115
+ #
116
+ # @return [Array<Note>]
117
+ #
118
+ # @since 0.2.0
119
+ has_many :notes, dependent: :destroy
120
+
121
+ #
122
+ # Queries all open ports with the port number.
123
+ #
124
+ # @param [Integer] number
125
+ # The port number to search for.
126
+ #
127
+ # @return [Array<OpenPort>]
128
+ # The open ports that use the port number.
129
+ #
130
+ # @api public
131
+ #
132
+ # @since 0.2.0
133
+ #
134
+ def self.with_port_number(number)
135
+ joins(:port).where(port: {number: number})
136
+ end
137
+
138
+ #
139
+ # Queries all open ports with the protocol.
140
+ #
141
+ # @param [:tcp, ;udp] protocol
142
+ # The protocol to search for.
143
+ #
144
+ # @return [Array<OpenPort>]
145
+ # The open ports that use the protocol.
146
+ #
147
+ # @api public
148
+ #
149
+ # @since 0.2.0
150
+ #
151
+ def self.with_protocol(protocol)
152
+ joins(:port).where(port: {protocol: protocol})
153
+ end
154
+
155
+ #
156
+ # Queries all open ports associated with the service name.
157
+ #
158
+ # @param [String] name
159
+ # The service name to search for.
160
+ #
161
+ # @return [Array<OpenPort>]
162
+ # The open ports associated with the service name.
163
+ #
164
+ # @api public
165
+ #
166
+ # @since 0.2.0
167
+ #
168
+ def self.with_service_name(name)
169
+ joins(:service).where(service: {name: name})
170
+ end
171
+
172
+ #
173
+ # Queries all open ports associated with the IP address.
174
+ #
175
+ # @param [String] address
176
+ # The IP address to search by.
177
+ #
178
+ # @return [Array<OpenPort>]
179
+ # The open ports associated with the IP address.
180
+ #
181
+ # @api public
182
+ #
183
+ # @since 0.2.0
184
+ #
185
+ def self.with_ip_address(address)
186
+ joins(:ip_address).where(ip_address: {address: address})
187
+ end
188
+
91
189
  #
92
190
  # The IP Address of the open port.
93
191
  #
@@ -133,8 +231,8 @@ module Ronin
133
231
  # @api public
134
232
  #
135
233
  def to_s
136
- if self.service then "#{self.port} (#{self.service})"
137
- else "#{self.port}"
234
+ if self.service then "#{self.ip_address} #{self.port} (#{self.service})"
235
+ else "#{self.ip_address} #{self.port}"
138
236
  end
139
237
  end
140
238
 
@@ -146,3 +244,6 @@ require 'ronin/db/ip_address'
146
244
  require 'ronin/db/port'
147
245
  require 'ronin/db/service'
148
246
  require 'ronin/db/service_credential'
247
+ require 'ronin/db/vulnerability'
248
+ require 'ronin/db/advisory'
249
+ require 'ronin/db/note'
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
4
  #
5
- # Copyright (c) 2022-2023 Hal Brodigan (postmodern.mod3 at gmail.com)
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
6
  #
7
7
  # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
8
  # it under the terms of the GNU Lesser General Public License as published
@@ -19,7 +19,8 @@
19
19
  #
20
20
 
21
21
  require 'ronin/db/model'
22
- require 'ronin/db/model/has_unique_name'
22
+ require 'ronin/db/model/has_name'
23
+ require 'ronin/db/model/importable'
23
24
 
24
25
  require 'active_record'
25
26
 
@@ -31,7 +32,11 @@ module Ronin
31
32
  class Organization < ActiveRecord::Base
32
33
 
33
34
  include Model
34
- include Model::HasUniqueName
35
+ include Model::HasName
36
+ include Model::Importable
37
+
38
+ # NOTE: disable STI so we can use the type column as an enum.
39
+ self.inheritance_column = nil
35
40
 
36
41
  # @!attribute [rw] id
37
42
  # Primary key of the organization
@@ -39,12 +44,241 @@ module Ronin
39
44
  # @return [Integer]
40
45
  attribute :id, :integer
41
46
 
47
+ # @!attribute [rw] type
48
+ # The type for the organization.
49
+ #
50
+ # @return ["company", "government", "military", nil]
51
+ #
52
+ # @since 0.2.0
53
+ enum :type, {
54
+ company: 'company',
55
+ government: 'government',
56
+ military: 'military'
57
+ }, prefix: 'is_'
58
+
42
59
  # @!attribute [r] created_at
43
60
  # Tracks when the organization was first created
44
61
  #
45
62
  # @return [Time]
46
63
  attribute :created_at, :datetime
47
64
 
65
+ # @!attribute [rw] parent
66
+ # The optional parent organization.
67
+ #
68
+ # @return [Organization, nil]
69
+ #
70
+ # @since 0.2.0
71
+ belongs_to :parent, optional: true,
72
+ class_name: 'Organization'
73
+
74
+ # NOTE: ensure the name is unique with respect to the parent organization
75
+ validates :name, uniqueness: {scope: [:parent_id]}
76
+
77
+ # @!attribute [rw] organization_street_addresses
78
+ # The association of street addresses associated with the organization.
79
+ #
80
+ # @return [Array<OrganizationStreetAddress>]
81
+ #
82
+ # @since 0.2.0
83
+ has_many :organization_street_addresses, dependent: :destroy
84
+
85
+ # @!attribute [rw] street_addresses
86
+ # The street addresses that are associated with the organization.
87
+ #
88
+ # @return [Array<StreetAddress>]
89
+ #
90
+ # @since 0.2.0
91
+ has_many :street_addresses, through: :organization_street_addresses
92
+
93
+ # @!attribute [rw] organization_phone_numbers
94
+ # The association of phone numbers associated with the organization.
95
+ #
96
+ # @return [Array<OrganizationPhoneNumber>]
97
+ #
98
+ # @since 0.2.0
99
+ has_many :organization_phone_numbers, dependent: :destroy
100
+
101
+ # @!attribute [rw] phone_numbers
102
+ # The phone numbers that are associated with the organization.
103
+ #
104
+ # @return [Array<PhoneNumber>]
105
+ #
106
+ # @since 0.2.0
107
+ has_many :phone_numbers, through: :organization_phone_numbers
108
+
109
+ # @!attribute [rw] organization_email_addresses
110
+ # The association of email addresses associated directly with the
111
+ # organization.
112
+ #
113
+ # @return [Array<OrganizationEmailAddress>]
114
+ #
115
+ # @since 0.2.0
116
+ has_many :organization_email_addresses, dependent: :destroy
117
+
118
+ # @!attribute [rw] organization_email_addresses
119
+ # The email addresses directly associated directly with the
120
+ # organization.
121
+ #
122
+ # @return [Array<EmailAddress>]
123
+ #
124
+ # @since 0.2.0
125
+ has_many :email_addresses, through: :organization_email_addresses
126
+
127
+ # @!attribute [rw] departments
128
+ # The associated departments of the organization.
129
+ #
130
+ # @return [Array<OrganizationDepartment>]
131
+ #
132
+ # @since 0.2.0
133
+ has_many :departments, class_name: 'OrganizationDepartment',
134
+ dependent: :destroy
135
+
136
+ # @!attribute [rw] members
137
+ # The members that belong to the organization.
138
+ #
139
+ # @return [Array<OrganizationMember>]
140
+ #
141
+ # @since 0.2.0
142
+ has_many :members, class_name: 'OrganizationMember'
143
+
144
+ # @!attribute [rw] member_email_addresses
145
+ # The email addresses used by members of the organization.
146
+ #
147
+ # @return [Array<EmailAddress>]
148
+ #
149
+ # @since 0.2.0
150
+ has_many :member_email_addresses, through: :members,
151
+ source: :email_address
152
+
153
+ # @!attribute [rw] organization_customers
154
+ # The organization's customer relationships.
155
+ #
156
+ # @return [Array<OrganizationCustomer>]
157
+ #
158
+ # @since 0.2.0
159
+ has_many :organization_customers, class_name: 'OrganizationCustomer',
160
+ foreign_key: :vendor_id,
161
+ dependent: :destroy
162
+
163
+ # @!attribute [rw] customers
164
+ # The individual customers (B2C) of the organization/
165
+ #
166
+ # @return [Array<Person>]
167
+ #
168
+ # @since 0.2.0
169
+ has_many :customers, through: :organization_customers
170
+
171
+ # @!attribute [rw] customer_organizations
172
+ # The other customer organizations (B2B) of the organization.
173
+ #
174
+ # @return [Array<Organization>]
175
+ #
176
+ # @since 0.2.0
177
+ has_many :customer_organizations, through: :organization_customers
178
+
179
+ # @!attribute [rw] vendor_relationships
180
+ # The organization's vendor relationships with other organizations.
181
+ #
182
+ # @return [Array<OrganizationCustomer>]
183
+ #
184
+ # @since 0.2.0
185
+ has_many :organization_vendors, class_name: 'OrganizationCustomer',
186
+ foreign_key: :customer_organization_id,
187
+ dependent: :destroy
188
+
189
+ # @!attribute [rw] vendors
190
+ # The vendor companies that the organization is a customer of.
191
+ #
192
+ # @return [Array<Organization>]
193
+ #
194
+ # @since 0.2.0
195
+ has_many :vendors, through: :organization_vendors
196
+
197
+ # @!attribute [rw] organization_host_names
198
+ # The association of organizations and host names.
199
+ #
200
+ # @return [Array<OrganizationHostName>]
201
+ #
202
+ # @since 0.2.0
203
+ has_many :organization_host_names, dependent: :destroy
204
+
205
+ # @!attribute [rw] host_names
206
+ # The host names that the organization owns.
207
+ #
208
+ # @return [Array<HostName>]
209
+ #
210
+ # @since 0.2.0
211
+ has_many :host_names, through: :organization_host_names
212
+
213
+ # @!attribute [rw] organization_ip_addresses
214
+ # The association of organizations and IP addresses.
215
+ #
216
+ # @return [Array<OrganizationIPAddress>]
217
+ #
218
+ # @since 0.2.0
219
+ has_many :organization_ip_addresses, class_name: 'OrganizationIPAddress',
220
+ dependent: :destroy
221
+
222
+ # @!attribute [rw] ip_addresses
223
+ # The IP addresses that the organization owns.
224
+ #
225
+ # @return [Array<IPAddress>]
226
+ #
227
+ # @since 0.2.0
228
+ has_many :ip_addresses, through: :organization_ip_addresses
229
+
230
+ # @!attribute [rw] notes
231
+ # The associated notes.
232
+ #
233
+ # @return [Array<Note>]
234
+ #
235
+ # @since 0.2.0
236
+ has_many :notes, dependent: :destroy
237
+
238
+ #
239
+ # Looks up the organization.
240
+ #
241
+ # @param [String] name
242
+ # The organization name to query.
243
+ #
244
+ # @return [Organization, nil]
245
+ # The found organization.
246
+ #
247
+ # @api public
248
+ #
249
+ # @since 0.2.0
250
+ #
251
+ def self.lookup(name)
252
+ find_by(name: name)
253
+ end
254
+
255
+ #
256
+ # Imports an organization.
257
+ #
258
+ # @param [String] name
259
+ # The organization name to import.
260
+ #
261
+ # @return [Organization]
262
+ # The imported organization.
263
+ #
264
+ # @api public
265
+ #
266
+ # @since 0.2.0
267
+ #
268
+ def self.import(name)
269
+ create(name: name)
270
+ end
271
+
48
272
  end
49
273
  end
50
274
  end
275
+
276
+ require 'ronin/db/organization_street_address'
277
+ require 'ronin/db/organization_phone_number'
278
+ require 'ronin/db/organization_email_address'
279
+ require 'ronin/db/organization_department'
280
+ require 'ronin/db/organization_member'
281
+ require 'ronin/db/organization_customer'
282
+ require 'ronin/db/organization_host_name'
283
+ require 'ronin/db/organization_ip_address'
284
+ require 'ronin/db/note'
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+
23
+ require 'active_record'
24
+
25
+ module Ronin
26
+ module DB
27
+ #
28
+ # Represents a customer relationship of an {Organization}.
29
+ #
30
+ # @since 0.2.0
31
+ #
32
+ class OrganizationCustomer < ActiveRecord::Base
33
+
34
+ include Model
35
+
36
+ # @!attribute [rw] id
37
+ # Primary key of the customer relationship.
38
+ #
39
+ # @return [Integer]
40
+ attribute :id, :integer
41
+
42
+ # @!attribute [rw] vendor
43
+ # The vendor company.
44
+ #
45
+ # @return [Organization]
46
+ belongs_to :vendor, class_name: 'Organization'
47
+
48
+ # @!attribute [rw] organization
49
+ # The customer organization.
50
+ #
51
+ # @return [Organization, nil]
52
+ belongs_to :customer_organization, class_name: 'Organization'
53
+ validates :customer_organization, uniqueness: {scope: :vendor_id}
54
+
55
+ # @!attribute [rw] person
56
+ # The customer organization.
57
+ #
58
+ # @return [Person, nil]
59
+ belongs_to :customer, class_name: 'Person'
60
+ validates :customer, uniqueness: {scope: :vendor_id}
61
+
62
+ # @!attribute [r] created_at
63
+ # Tracks when the customer relationship was first created
64
+ #
65
+ # @return [Time]
66
+ attribute :created_at, :datetime
67
+
68
+ end
69
+ end
70
+ end
71
+
72
+ require 'ronin/db/organization'
73
+ require 'ronin/db/person'
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+ require 'ronin/db/model/has_name'
23
+
24
+ require 'active_record'
25
+
26
+ module Ronin
27
+ module DB
28
+ #
29
+ # Represents a department of an organization.
30
+ #
31
+ # @since 0.2.0
32
+ #
33
+ class OrganizationDepartment < ActiveRecord::Base
34
+
35
+ include Model
36
+ include Model::HasName
37
+
38
+ # @!attribute [rw] organization
39
+ # The organization that the department belongs to.
40
+ #
41
+ # @return [Organization]
42
+ belongs_to :organization
43
+ validates :name, uniqueness: {scope: :organization_id}
44
+
45
+ # @!attribute [rw] street_address
46
+ # The optional street address of the department.
47
+ #
48
+ # @return [StreetAddress, nil]
49
+ belongs_to :street_address, optional: true
50
+
51
+ # @!attribute [rw] phone_number
52
+ # The optional phone number of the department.
53
+ #
54
+ # @return [PhoneNumber, nil]
55
+ belongs_to :phone_number, optional: true
56
+
57
+ # @!attribute [rw] email_address
58
+ # The optional email address of the department.
59
+ #
60
+ # @return [EmailAddress, nil]
61
+ belongs_to :email_address, optional: true
62
+
63
+ # @!attribute [rw] parent_department
64
+ # The optional parent department of the subdepartment.
65
+ #
66
+ # @return [OrganizationDepartment, nil]
67
+ belongs_to :parent_department, optional: true,
68
+ class_name: 'OrganizationDepartment'
69
+
70
+ # @!attribute [r] created_at
71
+ # Tracks when the organization was first created
72
+ #
73
+ # @return [Time]
74
+ attribute :created_at, :datetime
75
+
76
+ # @!attribute [rw] subdepartments
77
+ # The associated subdepartments of the department.
78
+ #
79
+ # @return [Array<OrganizationDepartment>]
80
+ has_many :subdepartments, class_name: 'OrganizationDepartment',
81
+ foreign_key: :parent_department_id,
82
+ dependent: :destroy
83
+
84
+ # @!attribute [rw] members
85
+ # The members that belong to the department.
86
+ #
87
+ # @return [Array<OrganizationMember>]
88
+ has_many :members, class_name: 'OrganizationMember'
89
+
90
+ end
91
+ end
92
+ end
93
+
94
+ require 'ronin/db/organization'
95
+ require 'ronin/db/street_address'
96
+ require 'ronin/db/phone_number'
97
+ require 'ronin/db/email_address'
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+
23
+ require 'active_record'
24
+
25
+ module Ronin
26
+ module DB
27
+ #
28
+ # Represents an email address associated with an {Organization}.
29
+ #
30
+ # @since 0.2.0
31
+ #
32
+ class OrganizationEmailAddress < ActiveRecord::Base
33
+
34
+ include Model
35
+
36
+ # @!attribute [rw] id
37
+ # Primary key of the member.
38
+ #
39
+ # @return [Integer]
40
+ attribute :id, :integer
41
+
42
+ # @!attribute [rw] organization
43
+ # The organization.
44
+ #
45
+ # @return [Organization]
46
+ belongs_to :organization
47
+
48
+ # @!attribute [rw] email_address
49
+ # The email address associated with the organization.
50
+ #
51
+ # @return [EmailAddress]
52
+ belongs_to :email_address
53
+ validates :email_address, uniqueness: {scope: :organization_id}
54
+
55
+ # @!attribute [r] created_at
56
+ # Tracks when the organization email address was first created.
57
+ #
58
+ # @return [Time]
59
+ attribute :created_at, :datetime
60
+
61
+ end
62
+ end
63
+ end
64
+
65
+ require 'ronin/db/email_address'
66
+ require 'ronin/db/organization'
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # ronin-db-activerecord - ActiveRecord backend for the Ronin Database.
4
+ #
5
+ # Copyright (c) 2022-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
6
+ #
7
+ # ronin-db-activerecord is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # ronin-db-activerecord is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with ronin-db-activerecord. If not, see <https://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'ronin/db/model'
22
+
23
+ require 'active_record'
24
+
25
+ module Ronin
26
+ module DB
27
+ #
28
+ # Represents an association between an {Organization} and a {HostName}.
29
+ #
30
+ # @since 0.2.0
31
+ #
32
+ class OrganizationHostName < ActiveRecord::Base
33
+
34
+ include Model
35
+
36
+ # @!attribute [rw] id
37
+ # Primary key of the organization
38
+ #
39
+ # @return [Integer]
40
+ attribute :id, :integer
41
+
42
+ # @!attribute [rw] organization
43
+ # The organization that owns the host name.
44
+ #
45
+ # @return [Organization]
46
+ belongs_to :organization
47
+
48
+ # @!attribute [rw] host_name
49
+ # The host name that the organization owns.
50
+ #
51
+ # @return [HostName]
52
+ belongs_to :host_name
53
+
54
+ # @!attribute [r] created_at
55
+ # Tracks when the organization claimed ownership of the host name.
56
+ #
57
+ # @return [Time]
58
+ attribute :created_at, :datetime
59
+
60
+ end
61
+ end
62
+ end
63
+
64
+ require 'ronin/db/organization'
65
+ require 'ronin/db/host_name'