@@ -176,50 +176,60 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
176
176
end
177
177
end
178
178
179
- # Look for our database configuration in the following places, in order:
180
- # command line arguments
181
- # environment variable
182
- # configuration directory (usually ~/.msf3)
183
- dbfile = opts [ 'DatabaseYAML' ]
184
- dbfile ||= ENV [ "MSF_DATABASE_CONFIG" ]
185
- dbfile ||= File . join ( Msf ::Config . get_config_root , "database.yml" )
186
- if ( dbfile and File . exists? dbfile )
187
- if File . readable? ( dbfile )
188
- dbinfo = YAML . load ( File . read ( dbfile ) )
189
- dbenv = opts [ 'DatabaseEnv' ] || Rails . env
190
- db = dbinfo [ dbenv ]
191
- else
192
- print_error ( "Warning, #{ dbfile } is not readable. Try running as root or chmod." )
193
- end
194
- if not db
195
- print_error ( "No database definition for environment #{ dbenv } " )
196
- else
197
- if not framework . db . connect ( db )
198
- if framework . db . error . to_s =~ /RubyGem version.*pg.*0\. 11/i
199
- print_error ( "***" )
200
- print_error ( "*" )
201
- print_error ( "* Metasploit now requires version 0.11 or higher of the 'pg' gem for database support" )
202
- print_error ( "* There a three ways to accomplish this upgrade:" )
203
- print_error ( "* 1. If you run Metasploit with your system ruby, simply upgrade the gem:" )
204
- print_error ( "* $ rvmsudo gem install pg " )
205
- print_error ( "* 2. Use the Community Edition web interface to apply a Software Update" )
206
- print_error ( "* 3. Uninstall, download the latest version, and reinstall Metasploit" )
207
- print_error ( "*" )
208
- print_error ( "***" )
209
- print_error ( "" )
210
- print_error ( "" )
211
- end
212
-
213
- print_error ( "Failed to connect to the database: #{ framework . db . error } " )
179
+ if framework . db . connection_established?
180
+ framework . db . after_establish_connection
181
+ else
182
+ # Look for our database configuration in the following places, in order:
183
+ # command line arguments
184
+ # environment variable
185
+ # configuration directory (usually ~/.msf3)
186
+ dbfile = opts [ 'DatabaseYAML' ]
187
+ dbfile ||= ENV [ "MSF_DATABASE_CONFIG" ]
188
+ dbfile ||= File . join ( Msf ::Config . get_config_root , "database.yml" )
189
+
190
+ if ( dbfile and File . exists? dbfile )
191
+ if File . readable? ( dbfile )
192
+ dbinfo = YAML . load ( File . read ( dbfile ) )
193
+ dbenv = opts [ 'DatabaseEnv' ] || Rails . env
194
+ db = dbinfo [ dbenv ]
214
195
else
215
- self . framework . modules . refresh_cache_from_database
196
+ print_error ( "Warning, #{ dbfile } is not readable. Try running as root or chmod." )
197
+ end
216
198
217
- if self . framework . modules . cache_empty?
218
- print_status ( "The initial module cache will be built in the background, this can take 2-5 minutes..." )
219
- end
199
+ if not db
200
+ print_error ( "No database definition for environment #{ dbenv } " )
201
+ else
202
+ framework . db . connect ( db )
220
203
end
221
204
end
222
205
end
206
+
207
+ # framework.db.active will be true if after_establish_connection ran directly when connection_established? was
208
+ # already true or if framework.db.connect called after_establish_connection.
209
+ if framework . db . active
210
+ self . framework . modules . refresh_cache_from_database
211
+
212
+ if self . framework . modules . cache_empty?
213
+ print_status ( "The initial module cache will be built in the background, this can take 2-5 minutes..." )
214
+ end
215
+ elsif !framework . db . error . nil?
216
+ if framework . db . error . to_s =~ /RubyGem version.*pg.*0\. 11/i
217
+ print_error ( "***" )
218
+ print_error ( "*" )
219
+ print_error ( "* Metasploit now requires version 0.11 or higher of the 'pg' gem for database support" )
220
+ print_error ( "* There a three ways to accomplish this upgrade:" )
221
+ print_error ( "* 1. If you run Metasploit with your system ruby, simply upgrade the gem:" )
222
+ print_error ( "* $ rvmsudo gem install pg " )
223
+ print_error ( "* 2. Use the Community Edition web interface to apply a Software Update" )
224
+ print_error ( "* 3. Uninstall, download the latest version, and reinstall Metasploit" )
225
+ print_error ( "*" )
226
+ print_error ( "***" )
227
+ print_error ( "" )
228
+ print_error ( "" )
229
+ end
230
+
231
+ print_error ( "Failed to connect to the database: #{ framework . db . error } " )
232
+ end
223
233
end
224
234
225
235
# Initialize the module paths only if we didn't get passed a Framework instance
0 commit comments