mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 23:13:48 +01:00
Allow to define ssl and certification for mysql
This commit is contained in:
parent
2f40bd4704
commit
8a3a9d9aa3
@ -63,6 +63,8 @@ public class JobsManager {
|
|||||||
c.get("mysql-hostname", "localhost:3306");
|
c.get("mysql-hostname", "localhost:3306");
|
||||||
c.get("mysql-database", "minecraft");
|
c.get("mysql-database", "minecraft");
|
||||||
c.get("mysql-table-prefix", "jobs_");
|
c.get("mysql-table-prefix", "jobs_");
|
||||||
|
c.get("verify-server-certificate", "false");
|
||||||
|
c.get("use-ssl", "false");
|
||||||
|
|
||||||
if (storageMethod.equalsIgnoreCase("mysql")) {
|
if (storageMethod.equalsIgnoreCase("mysql")) {
|
||||||
DbType = DataBaseType.MySQL;
|
DbType = DataBaseType.MySQL;
|
||||||
@ -102,8 +104,11 @@ public class JobsManager {
|
|||||||
String hostname = config.getString("mysql-hostname");
|
String hostname = config.getString("mysql-hostname");
|
||||||
String database = config.getString("mysql-database");
|
String database = config.getString("mysql-database");
|
||||||
String prefix = config.getString("mysql-table-prefix");
|
String prefix = config.getString("mysql-table-prefix");
|
||||||
|
|
||||||
|
boolean certificate = config.getBoolean("verify-server-certificate", false);
|
||||||
|
boolean ssl = config.getBoolean("use-ssl", false);
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix);
|
JobsMySQL data = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl);
|
||||||
data.initialize();
|
data.initialize();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
private String database;
|
private String database;
|
||||||
private Jobs plugin;
|
private Jobs plugin;
|
||||||
|
|
||||||
JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix) {
|
JobsMySQL(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl) {
|
||||||
super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database + "?autoReconnect=true&useSSL=false", username, password, prefix);
|
super(plugin, "com.mysql.jdbc.Driver", "jdbc:mysql://" + hostname + "/" + database + "?autoReconnect=true&useSSL=" + ssl + "&verifyServerCertificate=" + certificate, username, password, prefix);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.setDbType(DataBaseType.MySQL);
|
this.setDbType(DataBaseType.MySQL);
|
||||||
@ -27,9 +27,9 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JobsMySQL initialize(Jobs plugin, String hostname, String database, String username, String password, String prefix) {
|
public JobsMySQL initialize(Jobs plugin, String hostname, String database, String username, String password, String prefix, boolean certificate, boolean ssl) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
JobsMySQL dao = new JobsMySQL(plugin, hostname, database, username, password, prefix);
|
JobsMySQL dao = new JobsMySQL(plugin, hostname, database, username, password, prefix, certificate, ssl);
|
||||||
try {
|
try {
|
||||||
dao.setUp();
|
dao.setUp();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@ -115,7 +115,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
@Override
|
@Override
|
||||||
public boolean createTable(String query) {
|
public boolean createTable(String query) {
|
||||||
Jobs.consoleMsg(query);
|
Jobs.consoleMsg(query);
|
||||||
Statement statement = null;
|
Statement statement = null;
|
||||||
if (query == null || query.equals("")) {
|
if (query == null || query.equals("")) {
|
||||||
Jobs.consoleMsg("&cCould not create table: query is empty or null.");
|
Jobs.consoleMsg("&cCould not create table: query is empty or null.");
|
||||||
@ -127,7 +127,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
statement.execute(query);
|
statement.execute(query);
|
||||||
statement.close();
|
statement.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not create table, SQLException: " + e.getMessage());
|
||||||
close(statement);
|
close(statement);
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -143,7 +143,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
try {
|
try {
|
||||||
statement = getConnection().createStatement();
|
statement = getConnection().createStatement();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not check if its table, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not check if its table, SQLException: " + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -151,7 +151,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
statement.close();
|
statement.close();
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("Not a table |" + "SELECT * FROM " + table + "|");
|
Jobs.consoleMsg("Not a table |" + "SELECT * FROM " + table + "|");
|
||||||
close(statement);
|
close(statement);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
try {
|
try {
|
||||||
statement = getConnection().createStatement();
|
statement = getConnection().createStatement();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not check if its collumn, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not check if its collumn, SQLException: " + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -172,7 +172,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
statement.close();
|
statement.close();
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("Not a culumn |" + "SELECT " + collumn + " FROM " + table + "|");
|
Jobs.consoleMsg("Not a culumn |" + "SELECT " + collumn + " FROM " + table + "|");
|
||||||
close(statement);
|
close(statement);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -185,11 +185,11 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
try {
|
try {
|
||||||
statement = getConnection().createStatement();
|
statement = getConnection().createStatement();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not add new collumn, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not add new collumn, SQLException: " + e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Jobs.consoleMsg("Creating culumn |" + "ALTER TABLE `" + table + "` ADD COLUMN `" + collumn + "` " + type + ";" + "|");
|
Jobs.consoleMsg("Creating culumn |" + "ALTER TABLE `" + table + "` ADD COLUMN `" + collumn + "` " + type + ";" + "|");
|
||||||
statement.executeUpdate("ALTER TABLE `" + table + "` ADD COLUMN `" + collumn + "` " + type + ";");
|
statement.executeUpdate("ALTER TABLE `" + table + "` ADD COLUMN `" + collumn + "` " + type + ";");
|
||||||
statement.close();
|
statement.close();
|
||||||
return true;
|
return true;
|
||||||
@ -207,7 +207,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
String query = null;
|
String query = null;
|
||||||
try {
|
try {
|
||||||
if (!this.isTable(table)) {
|
if (!this.isTable(table)) {
|
||||||
Jobs.consoleMsg("&cTable \"" + table + "\" does not exist.");
|
Jobs.consoleMsg("&cTable \"" + table + "\" does not exist.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
statement = getConnection().createStatement();
|
statement = getConnection().createStatement();
|
||||||
@ -217,7 +217,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
||||||
close(statement);
|
close(statement);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
@ -231,7 +231,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
String query = null;
|
String query = null;
|
||||||
try {
|
try {
|
||||||
if (!this.isTable(table)) {
|
if (!this.isTable(table)) {
|
||||||
Jobs.consoleMsg("&cTable \"" + table + "\" does not exist.");
|
Jobs.consoleMsg("&cTable \"" + table + "\" does not exist.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
statement = getConnection().createStatement();
|
statement = getConnection().createStatement();
|
||||||
@ -241,7 +241,7 @@ public class JobsMySQL extends JobsDAO {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
Jobs.consoleMsg("&cCould not wipe table, SQLException: " + e.getMessage());
|
||||||
close(statement);
|
close(statement);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user