Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Revert "Security fix and code lookup changes (#141)"
Browse files Browse the repository at this point in the history
This reverts commit 2f34b98.
  • Loading branch information
larsenv authored Jul 31, 2023
1 parent 2f34b98 commit 15edb81
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 54 deletions.
47 changes: 2 additions & 45 deletions src/main/java/xyz/rc24/bot/commands/botadm/BashCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.rc24.bot.RiiConnect24Bot;
import xyz.rc24.bot.commands.Command;

import java.io.BufferedReader;
Expand All @@ -50,53 +49,11 @@ public class BashCommand implements Command {

@Override
public void onCommand(SlashCommandInteractionEvent event) {

// Allow usage only on config-defined root server
if (event.getGuild().getIdLong() != RiiConnect24Bot.getInstance().config.getRootServer()) {
event.reply("This command is private.").setEphemeral(true).queue();
return;
}

String bashCommand = event.getOption("command").getAsString();

if (bashCommand.isEmpty()) {
event.reply("Command cannot be empty!").setEphemeral(true).queue();
return;
}

StringBuilder output = new StringBuilder();
String finalOutput;

try {

ProcessBuilder builder = new ProcessBuilder(bashCommand.split(" "));
Process process = builder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String runningLineOutput;

while (!((runningLineOutput = reader.readLine()) == null)) {
output.append(runningLineOutput).append("\n");
}

if (output.toString().isEmpty()) {
event.reply("Executed command without output!").queue();
return;
}

// Remove linebreak
finalOutput = output.substring(0, output.length() - 1);
reader.close();

} catch (IOException e) {
event.reply("I wasn't able to find the command `" + bashCommand + "`!").setEphemeral(true).queue();
return;
} catch (Exception e) {
logger.error("An error occurred", e);
event.replyFormat("An error occurred: %s - Check the bot console.", e.getMessage()).setEphemeral(true).queue();
return;
}

event.replyFormat("Input:\n```%s```\nOutput:\n```%s```", bashCommand, finalOutput).queue();

return;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import xyz.rc24.bot.RiiConnect24Bot;
import xyz.rc24.bot.commands.Command;

public class ShutdownCommand implements Command {

@Override
public void onCommand(SlashCommandInteractionEvent event) {

// Allow usage only on config-defined root server
if (event.getGuild().getIdLong() != RiiConnect24Bot.getInstance().config.getRootServer()) {
event.reply("This command is private.").setEphemeral(true).queue();
return;
}

event.reply("Shutting down bot...").queue();
event.getJDA().shutdown();
System.exit(0);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xyz/rc24/bot/commands/wii/CodeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onCommand(SlashCommandInteractionEvent event) {
return;
}

event.replyEmbeds(embed.build()).queue();
event.replyEmbeds(embed.build()).setEphemeral(true).queue();

}
return;
Expand Down

0 comments on commit 15edb81

Please sign in to comment.