Skip to content

Commit

Permalink
Encrypt username and password when retrieving FTP url
Browse files Browse the repository at this point in the history
  • Loading branch information
LordTuxn committed Sep 15, 2021
1 parent dd4dd66 commit ac7af4a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/alpsbte/plotsystem/core/system/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.bukkit.Bukkit;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.*;
Expand Down Expand Up @@ -221,7 +222,7 @@ public static void undoReview(Review review) throws SQLException {
if (plotServer.getFTPConfiguration() != null) {
return FTPManager.deleteSchematics(FTPManager.getFTPUrl(plotServer, plot.getCity().getID()), plot.getID() + ".schematic", true);
}
} catch (SQLException | IOException ex) {
} catch (SQLException | IOException | URISyntaxException ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while undoing review!", ex);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.bukkit.World;

import java.io.File;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -90,7 +91,7 @@ public File getOutlinesSchematic() {
}
}
return file;
} catch (SQLException ex) {
} catch (SQLException | URISyntaxException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.SQLException;
Expand Down Expand Up @@ -156,7 +157,7 @@ public static void deletePlot(Plot plot) throws SQLException {
if (plotServer.getFTPConfiguration() != null) {
return FTPManager.deleteSchematics(FTPManager.getFTPUrl(plotServer, plot.getCity().getID()), plot.getID() + ".schematic", false);
}
} catch (IOException | SQLException ex) {
} catch (IOException | SQLException | URISyntaxException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.sql.ResultSet;
import java.sql.SQLException;
Expand Down Expand Up @@ -217,7 +218,7 @@ public static CompletableFuture<Void> savePlotAsSchematic(Plot plot) throws IOEx
CompletableFuture.supplyAsync(() -> {
try {
return FTPManager.uploadSchematic(FTPManager.getFTPUrl(plot.getCity().getCountry().getServer(), plot.getCity().getID()), finishedSchematicFile);
} catch (SQLException ex) {
} catch (SQLException | URISyntaxException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
return null;
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/com/alpsbte/plotsystem/utils/ftp/FTPManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.Bukkit;

import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
Expand All @@ -31,19 +33,15 @@ public class FTPManager {
}
}

public static String getFTPUrl(Server server, int cityID) throws SQLException {
public static String getFTPUrl(Server server, int cityID) throws SQLException, URISyntaxException {
String schematicsPath = server.getFTPConfiguration().getSchematicPath();

return String.format("%sftp://%s:%s@%s:%d/%s/%s/%s/",
server.getFTPConfiguration().isSFTP() ? "s" : "",
server.getFTPConfiguration().getUsername(),
server.getFTPConfiguration().getPassword(),
return new URI(server.getFTPConfiguration().isSFTP() ? "sftp" : "ftp",
server.getFTPConfiguration().getUsername() + ":" + server.getFTPConfiguration().getPassword(),
server.getFTPConfiguration().getAddress(),
server.getFTPConfiguration().getPort(),
schematicsPath == null ? DEFAULT_SCHEMATIC_PATH_LINUX : schematicsPath,
"finishedSchematics",
cityID
);
String.format("/%s/%s/%s/", schematicsPath == null ? DEFAULT_SCHEMATIC_PATH_LINUX : schematicsPath, "finishedSchematics", cityID),
null,
null).toString();
}

public static CompletableFuture<Void> uploadSchematic(String ftpURL, File schematic) {
Expand Down

0 comments on commit ac7af4a

Please sign in to comment.