Remove all files

This commit is contained in:
HaHaWTH
2023-09-20 02:10:19 +08:00
parent 62f27f8231
commit ed320196fe
478 changed files with 0 additions and 94591 deletions
@@ -1,55 +0,0 @@
package fr.xephi.authme.datasource.mysqlextensions;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
* Extension for IPB4.
*/
class Ipb4Extension extends MySqlExtension {
private final String ipbPrefix;
private final int ipbGroup;
Ipb4Extension(Settings settings, Columns col) {
super(settings, col);
this.ipbPrefix = settings.getProperty(HooksSettings.IPB_TABLE_PREFIX);
this.ipbGroup = settings.getProperty(HooksSettings.IPB_ACTIVATED_GROUP_ID);
}
@Override
public void saveAuth(PlayerAuth auth, Connection con) throws SQLException {
// Update player group in core_members
String sql = "UPDATE " + ipbPrefix + tableName
+ " SET " + tableName + ".member_group_id=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst2 = con.prepareStatement(sql)) {
pst2.setInt(1, ipbGroup);
pst2.setString(2, auth.getNickname());
pst2.executeUpdate();
}
// Get current time without ms
long time = System.currentTimeMillis() / 1000;
// update joined date
sql = "UPDATE " + ipbPrefix + tableName
+ " SET " + tableName + ".joined=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst2 = con.prepareStatement(sql)) {
pst2.setLong(1, time);
pst2.setString(2, auth.getNickname());
pst2.executeUpdate();
}
// Update last_visit
sql = "UPDATE " + ipbPrefix + tableName
+ " SET " + tableName + ".last_visit=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst2 = con.prepareStatement(sql)) {
pst2.setLong(1, time);
pst2.setString(2, auth.getNickname());
pst2.executeUpdate();
}
}
}
@@ -1,96 +0,0 @@
package fr.xephi.authme.datasource.mysqlextensions;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.DatabaseSettings;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.OptionalInt;
/**
* Extension for the MySQL data source for forums. For certain password hashes (e.g. phpBB), we want
* to hook into the forum board and execute some actions specific to the forum software.
*/
public abstract class MySqlExtension {
protected final Columns col;
protected final String tableName;
MySqlExtension(Settings settings, Columns col) {
this.col = col;
this.tableName = settings.getProperty(DatabaseSettings.MYSQL_TABLE);
}
/**
* Performs additional actions when a new player is saved.
*
* @param auth the player auth that has been saved
* @param con connection to the sql table
* @throws SQLException .
*/
public void saveAuth(PlayerAuth auth, Connection con) throws SQLException {
// extend for custom behavior
}
/**
* Writes properties to the given PlayerAuth object that need to be retrieved in a specific manner
* when a PlayerAuth object is read from the table.
*
* @param auth the player auth object to extend
* @param id the database id of the player auth entry
* @param con connection to the sql table
* @throws SQLException .
*/
public void extendAuth(PlayerAuth auth, int id, Connection con) throws SQLException {
// extend for custom behavior
}
/**
* Performs additional actions when a user's password is changed.
*
* @param user the name of the player (lowercase)
* @param password the new password to set
* @param con connection to the sql table
* @throws SQLException .
*/
public void changePassword(String user, HashedPassword password, Connection con) throws SQLException {
// extend for custom behavior
}
/**
* Performs additional actions when a player is removed from the database.
*
* @param user the user to remove
* @param con connection to the sql table
* @throws SQLException .
*/
public void removeAuth(String user, Connection con) throws SQLException {
// extend for custom behavior
}
/**
* Fetches the database ID of the given name from the database.
*
* @param name the name to get the ID for
* @param con connection to the sql table
* @return id of the playerAuth, or empty OptionalInt if the name is not registered
* @throws SQLException .
*/
protected OptionalInt retrieveIdFromTable(String name, Connection con) throws SQLException {
String sql = "SELECT " + col.ID + " FROM " + tableName + " WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setString(1, name);
try (ResultSet rs = pst.executeQuery()) {
if (rs.next()) {
return OptionalInt.of(rs.getInt(col.ID));
}
}
}
return OptionalInt.empty();
}
}
@@ -1,39 +0,0 @@
package fr.xephi.authme.datasource.mysqlextensions;
import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import javax.inject.Inject;
/**
* Creates the appropriate {@link MySqlExtension}, depending on the configured password hashing algorithm.
*/
public class MySqlExtensionsFactory {
@Inject
private Settings settings;
/**
* Creates a new {@link MySqlExtension} object according to the configured hash algorithm.
*
* @param columnsConfig the columns configuration
* @return the extension the MySQL data source should use
*/
public MySqlExtension buildExtension(Columns columnsConfig) {
HashAlgorithm hash = settings.getProperty(SecuritySettings.PASSWORD_HASH);
switch (hash) {
case IPB4:
return new Ipb4Extension(settings, columnsConfig);
case PHPBB:
return new PhpBbExtension(settings, columnsConfig);
case WORDPRESS:
return new WordpressExtension(settings, columnsConfig);
case XFBCRYPT:
return new XfBcryptExtension(settings, columnsConfig);
default:
return new NoOpExtension(settings, columnsConfig);
}
}
}
@@ -1,14 +0,0 @@
package fr.xephi.authme.datasource.mysqlextensions;
import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.settings.Settings;
/**
* Extension implementation that does not do anything.
*/
class NoOpExtension extends MySqlExtension {
NoOpExtension(Settings settings, Columns col) {
super(settings, col);
}
}
@@ -1,83 +0,0 @@
package fr.xephi.authme.datasource.mysqlextensions;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.OptionalInt;
/**
* Extensions for phpBB when MySQL is used as data source.
*/
class PhpBbExtension extends MySqlExtension {
private final String phpBbPrefix;
private final int phpBbGroup;
PhpBbExtension(Settings settings, Columns col) {
super(settings, col);
this.phpBbPrefix = settings.getProperty(HooksSettings.PHPBB_TABLE_PREFIX);
this.phpBbGroup = settings.getProperty(HooksSettings.PHPBB_ACTIVATED_GROUP_ID);
}
@Override
public void saveAuth(PlayerAuth auth, Connection con) throws SQLException {
OptionalInt authId = retrieveIdFromTable(auth.getNickname(), con);
if (authId.isPresent()) {
updateSpecificsOnSave(authId.getAsInt(), auth.getNickname(), con);
}
}
private void updateSpecificsOnSave(int id, String name, Connection con) throws SQLException {
// Insert player in phpbb_user_group
String sql = "INSERT INTO " + phpBbPrefix
+ "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, phpBbGroup);
pst.setInt(2, id);
pst.setInt(3, 0);
pst.setInt(4, 0);
pst.executeUpdate();
}
// Update username_clean in phpbb_users
sql = "UPDATE " + tableName + " SET " + tableName + ".username_clean=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setString(1, name);
pst.setString(2, name);
pst.executeUpdate();
}
// Update player group in phpbb_users
sql = "UPDATE " + tableName + " SET " + tableName + ".group_id=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, phpBbGroup);
pst.setString(2, name);
pst.executeUpdate();
}
// Get current time without ms
long time = System.currentTimeMillis() / 1000;
// Update user_regdate
sql = "UPDATE " + tableName + " SET " + tableName + ".user_regdate=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setLong(1, time);
pst.setString(2, name);
pst.executeUpdate();
}
// Update user_lastvisit
sql = "UPDATE " + tableName + " SET " + tableName + ".user_lastvisit=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setLong(1, time);
pst.setString(2, name);
pst.executeUpdate();
}
// Increment num_users
sql = "UPDATE " + phpBbPrefix
+ "config SET config_value = config_value + 1 WHERE config_name = 'num_users';";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.executeUpdate();
}
}
}
@@ -1,84 +0,0 @@
package fr.xephi.authme.datasource.mysqlextensions;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.OptionalInt;
/**
* MySQL extensions for Wordpress.
*/
class WordpressExtension extends MySqlExtension {
private final String wordpressPrefix;
WordpressExtension(Settings settings, Columns col) {
super(settings, col);
this.wordpressPrefix = settings.getProperty(HooksSettings.WORDPRESS_TABLE_PREFIX);
}
@Override
public void saveAuth(PlayerAuth auth, Connection con) throws SQLException {
OptionalInt authId = retrieveIdFromTable(auth.getNickname(), con);
if (authId.isPresent()) {
saveSpecifics(auth, authId.getAsInt(), con);
}
}
/**
* Saves the required data to Wordpress tables.
*
* @param auth the player data
* @param id the player id
* @param con the sql connection
* @throws SQLException .
*/
private void saveSpecifics(PlayerAuth auth, int id, Connection con) throws SQLException {
String sql = "INSERT INTO " + wordpressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?)";
try (PreparedStatement pst = con.prepareStatement(sql)) {
new UserMetaBatchAdder(pst, id)
.addMetaRow("first_name", "")
.addMetaRow("last_name", "")
.addMetaRow("nickname", auth.getNickname())
.addMetaRow("description", "")
.addMetaRow("rich_editing", "true")
.addMetaRow("comment_shortcuts", "false")
.addMetaRow("admin_color", "fresh")
.addMetaRow("use_ssl", "0")
.addMetaRow("show_admin_bar_front", "true")
.addMetaRow(wordpressPrefix + "capabilities", "a:1:{s:10:\"subscriber\";b:1;}")
.addMetaRow(wordpressPrefix + "user_level", "0")
.addMetaRow("default_password_nag", "");
// Execute queries
pst.executeBatch();
pst.clearBatch();
}
}
/** Helper to add batch entries to the wrapped prepared statement. */
private static final class UserMetaBatchAdder {
private final PreparedStatement pst;
private final int userId;
UserMetaBatchAdder(PreparedStatement pst, int userId) {
this.pst = pst;
this.userId = userId;
}
UserMetaBatchAdder addMetaRow(String metaKey, String metaValue) throws SQLException {
pst.setInt(1, userId);
pst.setString(2, metaKey);
pst.setString(3, metaValue);
pst.addBatch();
return this;
}
}
}
@@ -1,148 +0,0 @@
package fr.xephi.authme.datasource.mysqlextensions;
import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.datasource.Columns;
import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.security.crypts.XfBCrypt;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.OptionalInt;
/**
* Extension for XFBCRYPT.
*/
class XfBcryptExtension extends MySqlExtension {
private final String xfPrefix;
private final int xfGroup;
XfBcryptExtension(Settings settings, Columns col) {
super(settings, col);
this.xfPrefix = settings.getProperty(HooksSettings.XF_TABLE_PREFIX);
this.xfGroup = settings.getProperty(HooksSettings.XF_ACTIVATED_GROUP_ID);
}
@Override
public void saveAuth(PlayerAuth auth, Connection con) throws SQLException {
OptionalInt authId = retrieveIdFromTable(auth.getNickname(), con);
if (authId.isPresent()) {
updateXenforoTablesOnSave(auth, authId.getAsInt(), con);
}
}
/**
* Updates the xenforo tables after a player auth has been saved.
*
* @param auth the player auth which was saved
* @param id the account id
* @param con connection to the database
*/
private void updateXenforoTablesOnSave(PlayerAuth auth, int id, Connection con) throws SQLException {
// Insert player password, salt in xf_user_authenticate
String sql = "INSERT INTO " + xfPrefix + "user_authenticate (user_id, scheme_class, data) VALUES (?,?,?)";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, id);
pst.setString(2, XfBCrypt.SCHEME_CLASS);
String serializedHash = XfBCrypt.serializeHash(auth.getPassword().getHash());
byte[] bytes = serializedHash.getBytes();
Blob blob = con.createBlob();
blob.setBytes(1, bytes);
pst.setBlob(3, blob);
pst.executeUpdate();
}
// Update player group in xf_users
sql = "UPDATE " + tableName + " SET " + tableName + ".user_group_id=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, xfGroup);
pst.setString(2, auth.getNickname());
pst.executeUpdate();
}
// Update player permission combination in xf_users
sql = "UPDATE " + tableName + " SET " + tableName + ".permission_combination_id=? WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, xfGroup);
pst.setString(2, auth.getNickname());
pst.executeUpdate();
}
// Insert player privacy combination in xf_user_privacy
sql = "INSERT INTO " + xfPrefix + "user_privacy (user_id, allow_view_profile, allow_post_profile, "
+ "allow_send_personal_conversation, allow_view_identities, allow_receive_news_feed) VALUES (?,?,?,?,?,?)";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, id);
pst.setString(2, "everyone");
pst.setString(3, "members");
pst.setString(4, "members");
pst.setString(5, "everyone");
pst.setString(6, "everyone");
pst.executeUpdate();
}
// Insert player group relation in xf_user_group_relation
sql = "INSERT INTO " + xfPrefix + "user_group_relation (user_id, user_group_id, is_primary) VALUES (?,?,?)";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setInt(1, id);
pst.setInt(2, xfGroup);
pst.setString(3, "1");
pst.executeUpdate();
}
}
@Override
public void extendAuth(PlayerAuth auth, int id, Connection con) throws SQLException {
try (PreparedStatement pst = con.prepareStatement(
"SELECT data FROM " + xfPrefix + "user_authenticate WHERE " + col.ID + "=?;")) {
pst.setInt(1, id);
try (ResultSet rs = pst.executeQuery()) {
if (rs.next()) {
Blob blob = rs.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length());
auth.setPassword(new HashedPassword(XfBCrypt.getHashFromBlob(bytes)));
}
}
}
}
@Override
public void changePassword(String user, HashedPassword password, Connection con) throws SQLException {
OptionalInt authId = retrieveIdFromTable(user, con);
if (authId.isPresent()) {
final int id = authId.getAsInt();
// Insert password in the correct table
String sql = "UPDATE " + xfPrefix + "user_authenticate SET data=? WHERE " + col.ID + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
String serializedHash = XfBCrypt.serializeHash(password.getHash());
byte[] bytes = serializedHash.getBytes();
Blob blob = con.createBlob();
blob.setBytes(1, bytes);
pst.setBlob(1, blob);
pst.setInt(2, id);
pst.executeUpdate();
}
// ...
sql = "UPDATE " + xfPrefix + "user_authenticate SET scheme_class=? WHERE " + col.ID + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
pst.setString(1, XfBCrypt.SCHEME_CLASS);
pst.setInt(2, id);
pst.executeUpdate();
}
}
}
@Override
public void removeAuth(String user, Connection con) throws SQLException {
OptionalInt authId = retrieveIdFromTable(user, con);
if (authId.isPresent()) {
String sql = "DELETE FROM " + xfPrefix + "user_authenticate WHERE " + col.ID + "=?;";
try (PreparedStatement xfDelete = con.prepareStatement(sql)) {
xfDelete.setInt(1, authId.getAsInt());
xfDelete.executeUpdate();
}
}
}
}