Merge pull request #62 from cnaude/feature/sasl-password-file

new feature to load sasl password from file
This commit is contained in:
Chris 2024-05-12 14:33:21 -07:00 committed by GitHub
commit e8b7c2ec0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 4 deletions

16
pom.xml
View File

@ -6,7 +6,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Bukkit API Version, change if out dated --> <!-- Bukkit API Version, change if out dated -->
<bukkit.version>1.20-R0.1-SNAPSHOT</bukkit.version> <bukkit.version>1.20.6-R0.1-SNAPSHOT</bukkit.version>
<build.number>SNAPSHOT</build.number> <build.number>SNAPSHOT</build.number>
</properties> </properties>
@ -24,7 +24,6 @@
</pluginRepository> </pluginRepository>
</pluginRepositories> </pluginRepositories>
<repositories> <repositories>
<!-- For anything else without its own repo --> <!-- For anything else without its own repo -->
<repository> <repository>
@ -72,7 +71,18 @@
<repository> <repository>
<id>dynmap</id> <id>dynmap</id>
<url>https://repo.mikeprimm.com/</url> <url>https://repo.mikeprimm.com/</url>
</repository> </repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.sk89q.com/repo/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> </repositories>

View File

@ -39,6 +39,7 @@ import static com.cnaude.purpleirc.IRCMessage.Type.CTCP;
import static com.cnaude.purpleirc.IRCMessage.Type.MESSAGE; import static com.cnaude.purpleirc.IRCMessage.Type.MESSAGE;
import static com.cnaude.purpleirc.IRCMessage.Type.NOTICE; import static com.cnaude.purpleirc.IRCMessage.Type.NOTICE;
import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap; import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
import com.cnaude.purpleirc.Utilities.FileHelpers;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
@ -132,6 +133,7 @@ public final class PurpleBot {
public String botIdentPassword; public String botIdentPassword;
public String saslUsername; public String saslUsername;
public String saslPassword; public String saslPassword;
public String saslPasswordFile;
public List<String> rawMessages; public List<String> rawMessages;
public String channelCmdNotifyMode; public String channelCmdNotifyMode;
public String partInvalidChannelsMsg; public String partInvalidChannelsMsg;
@ -818,7 +820,14 @@ public final class PurpleBot {
botServerPass = config.getString("password", ""); botServerPass = config.getString("password", "");
botIdentPassword = config.getString("ident-password", ""); botIdentPassword = config.getString("ident-password", "");
saslUsername = config.getString("sasl-username", ""); saslUsername = config.getString("sasl-username", "");
saslPassword = config.getString("sasl-password", ""); saslPasswordFile = config.getString("sasl-password-file", "");
if (!saslPasswordFile.isEmpty()) {
plugin.logInfo("Loading sasl password from file: " + saslPasswordFile);
saslPassword = FileHelpers.loadFirstLineFromFile(saslPasswordFile);
} else {
saslPassword = config.getString("sasl-password", "");
}
// plugin.logDebug("saslPassword: " + saslPassword);
commandPrefix = config.getString("command-prefix", "."); commandPrefix = config.getString("command-prefix", ".");
chatDelay = config.getLong("message-delay", 1000); chatDelay = config.getLong("message-delay", 1000);
finger = config.getString("finger-reply", "PurpleIRC"); finger = config.getString("finger-reply", "PurpleIRC");

View File

@ -0,0 +1,23 @@
package com.cnaude.purpleirc.Utilities;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class FileHelpers {
public static String loadFirstLineFromFile(String filePath) throws IOException {
File file = new File(filePath);
if (!file.exists() || !file.canRead()) {
throw new IOException("File does not exist or is not readable.");
}
String firstLine;
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath))) {
firstLine = bufferedReader.readLine();
}
return firstLine;
}
}

View File

@ -47,6 +47,8 @@ ident-password: ''
sasl: false sasl: false
# SASL password # SASL password
sasl-password: '' sasl-password: ''
# Load SASL password from a file instead of this YAML file
sasl-password-file: ''
# SASL username # SASL username
sasl-username: '' sasl-username: ''
# command-prefix - The bot will listen for commands that start with this. # command-prefix - The bot will listen for commands that start with this.