ronin-db 0.1.2-java → 0.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +3 -2
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/ChangeLog.md +35 -0
- data/Gemfile +6 -4
- data/README.md +17 -5
- data/Rakefile +13 -35
- data/data/completions/ronin-db +271 -0
- data/gemspec.yml +17 -2
- data/lib/ronin/db/cli/command.rb +1 -1
- data/lib/ronin/db/cli/commands/add.rb +1 -1
- data/lib/ronin/db/cli/commands/asn.rb +12 -2
- data/lib/ronin/db/cli/commands/certs.rb +322 -0
- data/lib/ronin/db/cli/commands/completion.rb +63 -0
- data/lib/ronin/db/cli/commands/creds.rb +2 -1
- data/lib/ronin/db/cli/commands/edit.rb +1 -1
- data/lib/ronin/db/cli/commands/emails.rb +22 -1
- data/lib/ronin/db/cli/commands/hosts.rb +2 -1
- data/lib/ronin/db/cli/commands/ips.rb +2 -1
- data/lib/ronin/db/cli/commands/irb.rb +8 -4
- data/lib/ronin/db/cli/commands/list.rb +1 -1
- data/lib/ronin/db/cli/commands/migrate.rb +12 -8
- data/lib/ronin/db/cli/commands/open_ports.rb +102 -0
- data/lib/ronin/db/cli/commands/oses.rb +95 -0
- data/lib/ronin/db/cli/commands/passwords.rb +83 -0
- data/lib/ronin/db/cli/commands/people.rb +185 -0
- data/lib/ronin/db/cli/commands/phone_numbers.rb +136 -0
- data/lib/ronin/db/cli/commands/ports.rb +103 -0
- data/lib/ronin/db/cli/commands/remove.rb +1 -1
- data/lib/ronin/db/cli/commands/services.rb +102 -0
- data/lib/ronin/db/cli/commands/software.rb +95 -0
- data/lib/ronin/db/cli/commands/street_addresses.rb +129 -0
- data/lib/ronin/db/cli/commands/urls.rb +2 -1
- data/lib/ronin/db/cli/commands/web_vulns.rb +235 -0
- data/lib/ronin/db/cli/database_options.rb +87 -0
- data/lib/ronin/db/cli/deletable.rb +85 -0
- data/lib/ronin/db/cli/importable.rb +108 -0
- data/lib/ronin/db/cli/model_command.rb +8 -6
- data/lib/ronin/db/cli/modifiable.rb +12 -104
- data/lib/ronin/db/cli/printing.rb +58 -0
- data/lib/ronin/db/cli/ruby_shell.rb +1 -1
- data/lib/ronin/db/cli/uri_methods.rb +1 -1
- data/lib/ronin/db/cli.rb +5 -1
- data/lib/ronin/db/config_file.rb +13 -8
- data/lib/ronin/db/exceptions.rb +10 -1
- data/lib/ronin/db/home.rb +1 -1
- data/lib/ronin/db/root.rb +1 -1
- data/lib/ronin/db/tasks.rb +87 -0
- data/lib/ronin/db/version.rb +2 -2
- data/lib/ronin/db.rb +24 -7
- data/man/ronin-db-add.1 +48 -70
- data/man/ronin-db-add.1.md +26 -22
- data/man/ronin-db-asn.1 +37 -55
- data/man/ronin-db-asn.1.md +29 -19
- data/man/ronin-db-certs.1 +108 -0
- data/man/ronin-db-certs.1.md +106 -0
- data/man/ronin-db-completion.1 +76 -0
- data/man/ronin-db-completion.1.md +78 -0
- data/man/ronin-db-creds.1 +29 -47
- data/man/ronin-db-creds.1.md +23 -16
- data/man/ronin-db-edit.1 +16 -27
- data/man/ronin-db-edit.1.md +11 -7
- data/man/ronin-db-emails.1 +37 -50
- data/man/ronin-db-emails.1.md +30 -17
- data/man/ronin-db-hosts.1 +32 -52
- data/man/ronin-db-hosts.1.md +25 -18
- data/man/ronin-db-ips.1 +32 -53
- data/man/ronin-db-ips.1.md +26 -19
- data/man/ronin-db-irb.1 +23 -36
- data/man/ronin-db-irb.1.md +17 -10
- data/man/ronin-db-list.1 +17 -31
- data/man/ronin-db-list.1.md +13 -9
- data/man/ronin-db-migrate.1 +23 -36
- data/man/ronin-db-migrate.1.md +17 -10
- data/man/ronin-db-open-ports.1 +72 -0
- data/man/ronin-db-open-ports.1.md +70 -0
- data/man/ronin-db-oses.1 +72 -0
- data/man/ronin-db-oses.1.md +70 -0
- data/man/ronin-db-passwords.1 +75 -0
- data/man/ronin-db-passwords.1.md +73 -0
- data/man/ronin-db-people.1 +96 -0
- data/man/ronin-db-people.1.md +94 -0
- data/man/ronin-db-phone-numbers.1 +93 -0
- data/man/ronin-db-phone-numbers.1.md +91 -0
- data/man/ronin-db-ports.1 +87 -0
- data/man/ronin-db-ports.1.md +85 -0
- data/man/ronin-db-remove.1 +16 -29
- data/man/ronin-db-remove.1.md +12 -8
- data/man/ronin-db-services.1 +84 -0
- data/man/ronin-db-services.1.md +82 -0
- data/man/ronin-db-software.1 +72 -0
- data/man/ronin-db-software.1.md +70 -0
- data/man/ronin-db-street-addresses.1 +81 -0
- data/man/ronin-db-street-addresses.1.md +79 -0
- data/man/ronin-db-urls.1 +38 -61
- data/man/ronin-db-urls.1.md +28 -21
- data/man/ronin-db-web-vulns.1 +87 -0
- data/man/ronin-db-web-vulns.1.md +85 -0
- data/man/ronin-db.1 +118 -0
- data/man/ronin-db.1.md +99 -0
- data/scripts/setup +58 -0
- metadata +70 -13
- data/lib/ronin/db/cli/database_command.rb +0 -71
- data/lib/ronin/db/cli/resources_command.rb +0 -118
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
@@ -18,122 +18,30 @@
|
|
18
18
|
# along with ronin-db. If not, see <https://www.gnu.org/licenses/>.
|
19
19
|
#
|
20
20
|
|
21
|
+
require 'ronin/db/cli/deletable'
|
22
|
+
require 'ronin/db/cli/importable'
|
23
|
+
|
21
24
|
module Ronin
|
22
25
|
module DB
|
23
26
|
class CLI
|
24
27
|
#
|
25
|
-
# Allows a {ModelCommand} to add, import
|
28
|
+
# Allows a {ModelCommand} to add, import records from a file, delete
|
29
|
+
# individual records, or delete all records.
|
26
30
|
#
|
27
31
|
module Modifiable
|
28
32
|
#
|
29
|
-
# Adds the `--add`, `--import`, `--delete
|
33
|
+
# Adds the `--add`, `--import`, `--delete` and `--delete-all` options
|
30
34
|
# to the command.
|
31
35
|
#
|
32
36
|
# @param [Class<ModelCommand>] command
|
33
37
|
# The command class including {Modifiable}.
|
34
38
|
#
|
35
|
-
|
36
|
-
|
37
|
-
type: String,
|
38
|
-
usage: 'VALUE'
|
39
|
-
},
|
40
|
-
desc: 'Adds a value to the database'
|
41
|
-
|
42
|
-
command.option :import, value: {
|
43
|
-
type: String,
|
44
|
-
usage: 'FILE'
|
45
|
-
},
|
46
|
-
desc: 'Imports the values from the FILE into the database'
|
47
|
-
|
48
|
-
command.option :delete, value: {
|
49
|
-
type: String,
|
50
|
-
usage: 'VALUE'
|
51
|
-
},
|
52
|
-
desc: 'Deletes a value from the database'
|
53
|
-
|
54
|
-
command.option :delete_all, desc: 'Deletes all values from the database'
|
55
|
-
end
|
56
|
-
|
39
|
+
# @see Importable
|
40
|
+
# @see Deletable
|
57
41
|
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
connect
|
62
|
-
|
63
|
-
if options[:add]
|
64
|
-
add(options[:add])
|
65
|
-
elsif options[:import]
|
66
|
-
import_file(options[:import])
|
67
|
-
elsif options[:delete]
|
68
|
-
delete(options[:delete])
|
69
|
-
elsif options[:delete_all]
|
70
|
-
delete_all
|
71
|
-
else
|
72
|
-
list
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
# Adds a value to the database.
|
78
|
-
#
|
79
|
-
# @param [String] value
|
80
|
-
# The value to add.
|
81
|
-
#
|
82
|
-
def add(value)
|
83
|
-
record = model.import(value)
|
84
|
-
|
85
|
-
unless record.valid?
|
86
|
-
print_error "failed to import #{value}!"
|
87
|
-
|
88
|
-
record.errors.full_messages.each do |message|
|
89
|
-
print_error " - #{message}"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# Imports the values from the given file.
|
96
|
-
#
|
97
|
-
# @param [String] path
|
98
|
-
# The path to the file.
|
99
|
-
#
|
100
|
-
def import_file(path)
|
101
|
-
unless File.file?(path)
|
102
|
-
print_error "no such file or directory: #{path}"
|
103
|
-
exit(-1)
|
104
|
-
end
|
105
|
-
|
106
|
-
File.open(path) do |file|
|
107
|
-
model.transaction do
|
108
|
-
file.each_line(chomp: true) do |value|
|
109
|
-
log_info "Importing #{value} ..." if verbose?
|
110
|
-
|
111
|
-
add(value)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
#
|
118
|
-
# Deletes a value from the database.
|
119
|
-
#
|
120
|
-
# @param [String] value
|
121
|
-
# The value to lookup and delete.
|
122
|
-
#
|
123
|
-
def delete(value)
|
124
|
-
if (record = model.lookup(value))
|
125
|
-
record.destroy
|
126
|
-
else
|
127
|
-
print_error "value does not exist in the database: #{value}"
|
128
|
-
exit(-1)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
#
|
133
|
-
# Deletes all values from the database.
|
134
|
-
#
|
135
|
-
def delete_all
|
136
|
-
model.destroy_all
|
42
|
+
def self.included(command)
|
43
|
+
command.include Deletable
|
44
|
+
command.include Importable
|
137
45
|
end
|
138
46
|
end
|
139
47
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-db - A common database library for managing and querying security data.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-db 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 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. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Ronin
|
22
|
+
module DB
|
23
|
+
class CLI
|
24
|
+
#
|
25
|
+
# Helper methods for printing {Ronin::DB} records.
|
26
|
+
#
|
27
|
+
# @since 0.2.0
|
28
|
+
#
|
29
|
+
# @api semipublic
|
30
|
+
#
|
31
|
+
module Printing
|
32
|
+
#
|
33
|
+
# Maps a record to a human readable display name.
|
34
|
+
#
|
35
|
+
# @param [Ronin::DB::IPAddress,
|
36
|
+
# Ronin::DB::MACAddress,
|
37
|
+
# Ronin::DB::HostName,
|
38
|
+
# Ronin::DB::Port,
|
39
|
+
# Ronin::DB::Service,
|
40
|
+
# Ronin::DB::OpenPort] record
|
41
|
+
#
|
42
|
+
# @return [String, nil]
|
43
|
+
# The human readable type or `nil` if the record model is unknown.
|
44
|
+
#
|
45
|
+
def record_type(record)
|
46
|
+
case record
|
47
|
+
when HostName then 'host'
|
48
|
+
when IPAddress then 'IP'
|
49
|
+
when MACAddress then 'MAC'
|
50
|
+
when Port then 'port'
|
51
|
+
when Service then 'service'
|
52
|
+
when OpenPort then 'open port'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
data/lib/ronin/db/cli.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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,6 +19,7 @@
|
|
19
19
|
#
|
20
20
|
|
21
21
|
require 'ronin/db/version'
|
22
|
+
require 'ronin/core/cli/help/banner'
|
22
23
|
|
23
24
|
require 'command_kit/commands'
|
24
25
|
require 'command_kit/commands/auto_load'
|
@@ -39,10 +40,13 @@ module Ronin
|
|
39
40
|
namespace: "#{self}::Commands"
|
40
41
|
)
|
41
42
|
include CommandKit::Options::Version
|
43
|
+
include Core::CLI::Help::Banner
|
42
44
|
|
43
45
|
command_name 'ronin-db'
|
44
46
|
version Ronin::DB::VERSION
|
45
47
|
|
48
|
+
command_aliases['console'] = 'irb'
|
49
|
+
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
data/lib/ronin/db/config_file.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
@@ -21,6 +21,7 @@
|
|
21
21
|
require 'ronin/db/exceptions'
|
22
22
|
require 'ronin/db/home'
|
23
23
|
|
24
|
+
require 'fileutils'
|
24
25
|
require 'yaml'
|
25
26
|
require 'yaml/store'
|
26
27
|
|
@@ -65,21 +66,21 @@ module Ronin
|
|
65
66
|
#
|
66
67
|
def self.validate(path,data)
|
67
68
|
unless data.kind_of?(Hash)
|
68
|
-
raise(InvalidConfig)
|
69
|
+
raise(InvalidConfig,"config data must be a Hash: #{data.inspect}")
|
69
70
|
end
|
70
71
|
|
71
72
|
data.each do |key,value|
|
72
|
-
unless
|
73
|
-
raise(InvalidConfig)
|
73
|
+
unless key.kind_of?(Symbol)
|
74
|
+
raise(InvalidConfig,"all Hash keys must be a Symbol: #{key.inspect}")
|
74
75
|
end
|
75
76
|
|
76
77
|
unless value.kind_of?(Hash)
|
77
|
-
raise(InvalidConfig)
|
78
|
+
raise(InvalidConfig,"all Hash values must also be a Hash: #{value.inspect}")
|
78
79
|
end
|
79
80
|
|
80
81
|
value.each_key do |sub_key|
|
81
|
-
unless
|
82
|
-
raise(InvalidConfig)
|
82
|
+
unless sub_key.kind_of?(Symbol)
|
83
|
+
raise(InvalidConfig,"all sub-keys must be a Symbol: #{sub_key.inspect}")
|
83
84
|
end
|
84
85
|
end
|
85
86
|
end
|
@@ -124,8 +125,12 @@ module Ronin
|
|
124
125
|
# The loaded YAML configuration data.
|
125
126
|
#
|
126
127
|
def self.edit(path=PATH,&block)
|
127
|
-
|
128
|
+
unless File.file?(path)
|
129
|
+
# create the parent directory for YAML::Store
|
130
|
+
FileUtils.mkdir_p(File.dirname(path))
|
131
|
+
end
|
128
132
|
|
133
|
+
store = YAML::Store.new(path)
|
129
134
|
store.transaction(&block)
|
130
135
|
end
|
131
136
|
end
|
data/lib/ronin/db/exceptions.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
@@ -20,7 +20,16 @@
|
|
20
20
|
|
21
21
|
module Ronin
|
22
22
|
module DB
|
23
|
+
#
|
24
|
+
# Indicates that the given database name is not in the config file.
|
25
|
+
#
|
23
26
|
class UnknownDatabase < RuntimeError
|
24
27
|
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Indicates that the config file is corrupted.
|
31
|
+
#
|
32
|
+
class InvalidConfig < RuntimeError
|
33
|
+
end
|
25
34
|
end
|
26
35
|
end
|
data/lib/ronin/db/home.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
data/lib/ronin/db/root.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# ronin-db - A common database library for managing and querying security data.
|
4
|
+
#
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
|
+
#
|
7
|
+
# ronin-db 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 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. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'rake/tasklib'
|
22
|
+
|
23
|
+
module Ronin
|
24
|
+
module DB
|
25
|
+
#
|
26
|
+
# Defines `ronin:db` tasks in a `Rakefile`.
|
27
|
+
#
|
28
|
+
# ## Example
|
29
|
+
#
|
30
|
+
# require 'ronin/db/tasks'
|
31
|
+
# Ronin::DB::Tasks.new
|
32
|
+
#
|
33
|
+
class Tasks < Rake::TaskLib
|
34
|
+
|
35
|
+
# The database to connect to.
|
36
|
+
#
|
37
|
+
# @return [Symbol, Hash]
|
38
|
+
attr_reader :database
|
39
|
+
|
40
|
+
#
|
41
|
+
# Initializes the tasks.
|
42
|
+
#
|
43
|
+
# @param [Symbol, Hash] database
|
44
|
+
# The database name or Hash to connect to.
|
45
|
+
#
|
46
|
+
# @api public
|
47
|
+
#
|
48
|
+
def initialize(database: :default)
|
49
|
+
super()
|
50
|
+
|
51
|
+
@database = database
|
52
|
+
|
53
|
+
define
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Defines the `ronin:db` tasks.
|
58
|
+
#
|
59
|
+
# @api private
|
60
|
+
#
|
61
|
+
def define
|
62
|
+
namespace :db do
|
63
|
+
task :connect do
|
64
|
+
require 'ronin/db'
|
65
|
+
DB.connect(@database)
|
66
|
+
end
|
67
|
+
|
68
|
+
desc 'Migrates the development database'
|
69
|
+
task :migrate => :connect do
|
70
|
+
require 'ronin/db/migrations'
|
71
|
+
DB::Migrations.up
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'Starts an interactive database console'
|
75
|
+
task :console => :connect do
|
76
|
+
require 'logger'
|
77
|
+
DB.logger = Logger.new($stderr,:debug)
|
78
|
+
|
79
|
+
require 'ronin/db/cli/ruby_shell'
|
80
|
+
DB::CLI::RubyShell.start
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/ronin/db/version.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
@@ -21,6 +21,6 @@
|
|
21
21
|
module Ronin
|
22
22
|
module DB
|
23
23
|
# ronin-db version
|
24
|
-
VERSION = '0.
|
24
|
+
VERSION = '0.2.0'
|
25
25
|
end
|
26
26
|
end
|
data/lib/ronin/db.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# ronin-db - A common database library for managing and querying security data.
|
4
4
|
#
|
5
|
-
# Copyright (c) 2006-
|
5
|
+
# Copyright (c) 2006-2024 Hal Brodigan (postmodern.mod3 at gmail.com)
|
6
6
|
#
|
7
7
|
# ronin-db 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
|
@@ -76,8 +76,11 @@ module Ronin
|
|
76
76
|
#
|
77
77
|
# Connects to the Database.
|
78
78
|
#
|
79
|
-
# @param [Symbol, Hash] database
|
80
|
-
# The optional database name or Hash of database information.
|
79
|
+
# @param [Symbol, String, Hash] database
|
80
|
+
# The optional database name, String URL, or Hash of database information.
|
81
|
+
#
|
82
|
+
# @param [Integer, nil] pool
|
83
|
+
# Sets the connection pool for the database.
|
81
84
|
#
|
82
85
|
# @param [Boolean] migrate
|
83
86
|
# Specifies whether to hard or lazy migrate the database.
|
@@ -89,14 +92,25 @@ module Ronin
|
|
89
92
|
# The database name was not listed in the config file.
|
90
93
|
#
|
91
94
|
# @raise [ArgumentError]
|
92
|
-
# The given database was not a Symbol or a Hash.
|
95
|
+
# The given database was not a Symbol, String, or a Hash.
|
96
|
+
#
|
97
|
+
# @example Connect to the default database (`~/.local/share/ronin-db/default.sqlite3`):
|
98
|
+
# DB.connect
|
99
|
+
#
|
100
|
+
# @example Connect to a specific database from the configuration file (`~/.config/ronin-db/databases.yml`):
|
101
|
+
# DB.connect(:my_database)
|
102
|
+
#
|
103
|
+
# @example Connect to an arbitrary database:
|
104
|
+
# Db.connect({adapter: 'sqlite3', database: '/path/to/database.sqlite3'})
|
93
105
|
#
|
94
106
|
# @api semipublic
|
95
107
|
#
|
96
|
-
def self.connect(database=:default,
|
108
|
+
def self.connect(database=:default, pool: nil,
|
109
|
+
migrate: nil,
|
110
|
+
load_models: true)
|
97
111
|
config = case database
|
98
|
-
when Hash
|
99
|
-
|
112
|
+
when Hash then database
|
113
|
+
when String then {url: database}
|
100
114
|
when Symbol
|
101
115
|
self.config.fetch(database) do
|
102
116
|
raise(UnknownDatabase,"unknown database: #{database.inspect}")
|
@@ -105,6 +119,9 @@ module Ronin
|
|
105
119
|
raise(ArgumentError,"#{self}.#{__method__} only accepts a Symbol or a Hash")
|
106
120
|
end
|
107
121
|
|
122
|
+
# set/override the connection pool setting
|
123
|
+
config = config.merge(pool: pool) if pool
|
124
|
+
|
108
125
|
# load activerecord
|
109
126
|
require 'active_record'
|
110
127
|
|