/** Creates new form DbConnectDialog */
 public DbConnectDialog(Frame parent, RpcConnection rpcConn, boolean modal) {
   super(parent, "Database Connection Options", modal);
   initComponents();
   this.rpcConn = rpcConn;
   myParent = parent;
   success = false;
   props = MsfguiApp.getPropertiesNode();
   try {
     // If we don't have saved creds, look for them
     if (!props.containsKey("dbusername")) reloadDefaults();
     showDefaults();
   } catch (NullPointerException nex) {
   } catch (MsfException mex) { // No msf root?
     mex.printStackTrace();
   }
   Object driver = props.get("dbdriver");
   List l = ((javax.swing.SpinnerListModel) typeSpinner.getModel()).getList();
   for (Object o : l) if (o.equals(driver)) typeSpinner.setValue(driver);
 }
Example #2
0
 /** Setup sets up a connection and authenticates. */
 public void setup(String username, char[] password, String host, int port, boolean ssl)
     throws MsfException {
   boolean haveRpcd = false;
   this.username = username;
   this.password = new String(password);
   this.host = host;
   this.port = port;
   this.ssl = ssl;
   String message = "";
   try {
     connect();
     if (username == null || username.equals("")) {
       rpcToken = this.password;
       execute("core.version"); // throws error if unsuccessful
       haveRpcd = true;
     } else {
       Map results = (Map) exec("auth.login", new Object[] {username, this.password});
       rpcToken = results.get("token").toString();
       haveRpcd = results.get("result").equals("success");
     }
   } catch (MsfException xre) {
     message = xre.getLocalizedMessage();
   } catch (IOException io) {
     message = io.getLocalizedMessage();
   } catch (NullPointerException nex) {
   } catch (NoSuchAlgorithmException nsax) {
   } catch (KeyManagementException kmx) {
   }
   if (!haveRpcd) throw new MsfException("Error connecting. " + message);
   Map root = MsfguiApp.getPropertiesNode();
   root.put("username", username);
   root.put("password", this.password);
   root.put("host", host);
   root.put("port", port);
   root.put("ssl", ssl);
   root.put("disableDb", disableDb);
   MsfguiApp.savePreferences();
 }