Selaa lähdekoodia

Updated Vulnerable dependencies and CI script

Formatting changes.
Zoey76 2 vuotta sitten
vanhempi
sitoutus
3d41951fb5

+ 2 - 2
bitbucket-pipelines.yml

@@ -1,4 +1,4 @@
-image: openjdk:14-alpine
+image: openjdk:17-alpine
 
 pipelines:
    default:
@@ -12,7 +12,7 @@ pipelines:
       - step:
          deployment: Production
          script:
-          - pipe: atlassian/ftp-deploy:0.2.3
+          - pipe: atlassian/ftp-deploy:0.3.7
             variables:
               USER: $FTP_USER
               PASSWORD: $FTP_PASSWORD

+ 23 - 23
pom.xml

@@ -3,32 +3,32 @@
 	<modelVersion>4.0.0</modelVersion>
 	<groupId>com.l2jserver</groupId>
 	<artifactId>l2j-server-cli</artifactId>
-	<version>1.0.7</version>
+	<version>1.1.0</version>
 	<name>L2J Server Command Line</name>
 	<properties>
-		<maven.compiler.source>14</maven.compiler.source>
-		<maven.compiler.target>14</maven.compiler.target>
+		<maven.compiler.source>17</maven.compiler.source>
+		<maven.compiler.target>17</maven.compiler.target>
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<!-- Dependencies -->
-		<picocli.version>4.5.0</picocli.version>
-		<jgit.version>5.8.1.202007141445-r</jgit.version>
+		<picocli.version>4.7.0</picocli.version>
+		<jgit.version>6.4.0.202211300538-r</jgit.version>
 		<slf4j.version>1.7.30</slf4j.version>
-		<log4j.version>2.13.3</log4j.version>
-		<mysql-connector-java.version>8.0.21</mysql-connector-java.version>
-		<mariadb-java-client.version>2.6.2</mariadb-java-client.version>
-		<mssql-jdbc.version>8.4.0.jre14</mssql-jdbc.version>
-		<postgresql.version>42.2.15</postgresql.version>
-		<hsqldb.version>2.5.1</hsqldb.version>
+		<log4j.version>2.19.0</log4j.version>
+		<mysql-connector-j.version>8.0.32</mysql-connector-j.version>
+		<mariadb-java-client.version>3.1.1</mariadb-java-client.version>
+		<mssql-jdbc.version>11.2.3.jre17</mssql-jdbc.version>
+		<postgresql.version>42.5.1</postgresql.version>
+		<hsqldb.version>2.7.1</hsqldb.version>
 		<h2.version>1.4.200</h2.version>
-		<derbyclient.version>10.15.2.0</derbyclient.version>
+		<derbyclient.version>10.16.1.1</derbyclient.version>
 		<asciitable.version>0.3.2</asciitable.version>
 		<owner.version>1.0.12</owner.version>
 		<l2j-server-commons.version>2.6.3.0</l2j-server-commons.version>
 		<maven-invoker.version>3.2.0</maven-invoker.version>
 		<!-- Plugins -->
-		<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
-		<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
-		<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
+		<maven-dependency-plugin.version>3.5.0</maven-dependency-plugin.version>
+		<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
+		<maven-assembly-plugin.version>3.4.2</maven-assembly-plugin.version>
 	</properties>
 	<repositories>
 		<repository>
@@ -64,9 +64,9 @@
 		</dependency>
 		<!-- Database -->
 		<dependency>
-			<groupId>mysql</groupId>
-			<artifactId>mysql-connector-java</artifactId>
-			<version>${mysql-connector-java.version}</version>
+			<groupId>com.mysql</groupId>
+			<artifactId>mysql-connector-j</artifactId>
+			<version>${mysql-connector-j.version}</version>
 		</dependency>
 		<dependency>
 			<groupId>org.mariadb.jdbc</groupId>
@@ -110,10 +110,10 @@
 			<version>${owner.version}</version>
 		</dependency>
 		<dependency>
-            <groupId>org.apache.maven.shared</groupId>
-            <artifactId>maven-invoker</artifactId>
-            <version>${maven-invoker.version}</version>
-        </dependency>
+			<groupId>org.apache.maven.shared</groupId>
+			<artifactId>maven-invoker</artifactId>
+			<version>${maven-invoker.version}</version>
+		</dependency>
 	</dependencies>
 	<build>
 		<plugins>
@@ -135,7 +135,7 @@
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-assembly-plugin</artifactId>
-				<version>${maven-assembly-plugin.version}</version><!--$NO-MVN-MAN-VER$-->
+				<version>${maven-assembly-plugin.version}</version> <!--$NO-MVN-MAN-VER$-->
 				<executions>
 					<execution>
 						<phase>package</phase>

+ 4 - 4
src/main/java/com/l2jserver/cli/command/AbstractCommand.java

@@ -28,19 +28,19 @@ import java.io.IOException;
  */
 public abstract class AbstractCommand implements Runnable {
 	protected static final String YES = "y";
-
+	
 	protected static final String DEFAULT_LOGIN_REPO = "https://bitbucket.org/l2jserver/l2j-server-login.git";
 	protected static final String DEFAULT_GAME_REPO = "https://bitbucket.org/l2jserver/l2j-server-game.git";
 	protected static final String DEFAULT_DATAPACK_REPO = "https://bitbucket.org/l2jserver/l2j-server-datapack.git";
-
+	
 	protected static final String DEFAULT_LOGIN_SOURCE_DIR = "./l2j/git/l2j-server-login";
 	protected static final String DEFAULT_GAME_SOURCE_DIR = "./l2j/git/l2j-server-game";
 	protected static final String DEFAULT_DATAPACK_SOURCE_DIR = "./l2j/git/l2j-server-datapack";
-
+	
 	protected static final String DEFAULT_LOGIN_DEPLOY_DIR = "./l2j/deploy/login";
 	protected static final String DEFAULT_GAME_DEPLOY_DIR = "./l2j/deploy/game";
 	protected static final String DEFAULT_DATAPACK_DEPLOY_DIR = DEFAULT_GAME_DEPLOY_DIR;
-
+	
 	protected static final FilterInputStream FILTER_INPUT_STREAM = new FilterInputStream(System.in) {
 		@Override
 		public void close() throws IOException {

+ 10 - 11
src/main/java/com/l2jserver/cli/command/BuildCommand.java

@@ -40,44 +40,43 @@ import picocli.CommandLine.Option;
  */
 @Command(name = "build", aliases = "b")
 public class BuildCommand extends AbstractCommand {
-
+	
 	private static final Logger LOG = LoggerFactory.getLogger(BuildCommand.class);
-
+	
 	@Option(names = {"--login-directory", "-lsdir"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
 	private String loginDirectory = DEFAULT_LOGIN_SOURCE_DIR;
 	@Option(names = {"--game-directory", "-gsdir"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
 	private String gameDirectory = DEFAULT_GAME_SOURCE_DIR;
 	@Option(names = {"--datapack-directory", "-dpdir"}, defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
 	private String datapackDirectory = DEFAULT_DATAPACK_SOURCE_DIR;
-	
+
 	@Option(names = {"--skip-tests", "-st"}, defaultValue = "true", description = "Skip Tests")
 	private boolean skipTests = true;
-
+	
 	@Override
 	public void run() {
 		try {
 			boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
-
+			
 			Properties properties = new Properties();
 			if (skipTests) {
 				properties.setProperty("skipTests", "true");
 			}
-
+			
 			System.out.println("Building L2J Loginserver");
 			executeMavenWrapper("install", loginDirectory, properties, isWindows);
-
+			
 			System.out.println("Building L2J Gameserver");
 			executeMavenWrapper("install", gameDirectory, properties, isWindows);
-
+			
 			System.out.println("Building L2J DataPack");
 			executeMavenWrapper("install", datapackDirectory, properties, isWindows);
 		} catch (Exception e) {
 			LOG.error("Unable to build the code!", e);
 		}
 	}
-
-	private final void executeMavenWrapper(String goal, String sourceDir, Properties properties, boolean isWindows)
-	        throws Exception {
+	
+	private final void executeMavenWrapper(String goal, String sourceDir, Properties properties, boolean isWindows) throws Exception {
 		String mavenExecutableName = "mvnw" + (isWindows ? ".cmd" : "");
 		File mavenExecutableFile = new File(sourceDir, mavenExecutableName).getAbsoluteFile();
 		mavenExecutableFile.setExecutable(true);

+ 32 - 32
src/main/java/com/l2jserver/cli/command/CodeCommand.java

@@ -38,11 +38,11 @@ import picocli.CommandLine.Option;
  */
 @Command(name = "code", aliases = "c")
 public class CodeCommand extends AbstractCommand {
-
+	
 	private static final Logger LOG = LoggerFactory.getLogger(CodeCommand.class);
-
+	
 	private static final LoggerProgressMonitor LOGGER_PROGRESS_MONITOR = new LoggerProgressMonitor(LOG);
-
+	
 	@Option(names = {"--login-repository", "-lsrepo"}, defaultValue = DEFAULT_LOGIN_REPO, description = "Login repository")
 	private String loginRepository = DEFAULT_LOGIN_REPO;
 	@Option(names = {"--game-repository", "-gsrepo"}, defaultValue = DEFAULT_GAME_REPO, description = "Game repository")
@@ -56,46 +56,46 @@ public class CodeCommand extends AbstractCommand {
 	private String gameDirectory = DEFAULT_GAME_SOURCE_DIR;
 	@Option(names = {"--datapack-directory", "-dpdir"}, defaultValue = DEFAULT_DATAPACK_SOURCE_DIR, description = "DataPack directory")
 	private String datapackDirectory = DEFAULT_DATAPACK_SOURCE_DIR;
-
+	
 	@Option(names = "--clone", defaultValue = "ALL", description = "Clone ALL|LOGIN|GAME|DATAPACK")
 	private CloneType cloneType = CloneType.ALL;
-
+	
 	@Override
 	public void run() {
 		try {
 			switch (cloneType) {
-			case ALL: {
-				LOG.info("Cloning L2J Loginserver");
-				cloneRepository(loginRepository, loginDirectory);
-
-				LOG.info("Cloning L2J Gameserver");
-				cloneRepository(gameRepository, gameDirectory);
-
-				LOG.info("Cloning L2J DataPack");
-				cloneRepository(datapackRepository, datapackDirectory);
-				break;
-			}
-			case LOGIN: {
-				LOG.info("Cloning L2J Loginserver");
-				cloneRepository(loginRepository, loginDirectory);
-				break;
-			}
-			case GAME: {
-				LOG.info("Cloning L2J Gameserver");
-				cloneRepository(gameRepository, gameDirectory);
-				break;
-			}
-			case DATAPACK: {
-				LOG.info("Cloning L2J DataPack");
-				cloneRepository(datapackRepository, datapackDirectory);
-				break;
-			}
+				case ALL: {
+					LOG.info("Cloning L2J Loginserver");
+					cloneRepository(loginRepository, loginDirectory);
+					
+					LOG.info("Cloning L2J Gameserver");
+					cloneRepository(gameRepository, gameDirectory);
+					
+					LOG.info("Cloning L2J DataPack");
+					cloneRepository(datapackRepository, datapackDirectory);
+					break;
+				}
+				case LOGIN: {
+					LOG.info("Cloning L2J Loginserver");
+					cloneRepository(loginRepository, loginDirectory);
+					break;
+				}
+				case GAME: {
+					LOG.info("Cloning L2J Gameserver");
+					cloneRepository(gameRepository, gameDirectory);
+					break;
+				}
+				case DATAPACK: {
+					LOG.info("Cloning L2J DataPack");
+					cloneRepository(datapackRepository, datapackDirectory);
+					break;
+				}
 			}
 		} catch (Exception ex) {
 			LOG.error("Unable to get the code!", ex);
 		}
 	}
-
+	
 	private void cloneRepository(String repository, String directoryStr) {
 		try {
 			File directory = new File(directoryStr);

+ 10 - 10
src/main/java/com/l2jserver/cli/command/DeployCommand.java

@@ -43,7 +43,7 @@ import picocli.CommandLine.Option;
 @Command(name = "deploy", aliases = "d")
 public class DeployCommand extends AbstractCommand {
 	private static final Logger LOG = LoggerFactory.getLogger(DeployCommand.class);
-
+	
 	@Option(names = {"--login-source-directory", "-lssrc"}, defaultValue = DEFAULT_LOGIN_SOURCE_DIR, description = "Login directory")
 	private String loginSourceDirectory = DEFAULT_LOGIN_SOURCE_DIR;
 	@Option(names = {"--game-source-directory", "-gssrc"}, defaultValue = DEFAULT_GAME_SOURCE_DIR, description = "Game directory")
@@ -73,15 +73,15 @@ public class DeployCommand extends AbstractCommand {
 			LOG.error("Unable to deploy components!", e);
 		}
 	}
-
+	
 	public void processArtifact(String srcDirPath, String dstDirPathStr) throws Exception {
-		Files.list(Paths.get(srcDirPath, "target")).forEach(p->{
+		Files.list(Paths.get(srcDirPath, "target")).forEach(p -> {
 			if (!p.toString().endsWith(".zip")) {
 				return;
 			}
 			
 			LOG.info("Processing zip file {}", p.toString());
-
+			
 			try {
 				processZip(p, Path.of(dstDirPathStr));
 			} catch (Exception e) {
@@ -99,7 +99,7 @@ public class DeployCommand extends AbstractCommand {
 			if (!Files.exists(dstDirPath)) {
 				dstDirPath.toFile().mkdirs();
 			}
-
+			
 			for (Path p : zipFs.getRootDirectories()) {
 				processZipEntry(p, dstDirPath);
 			}
@@ -109,7 +109,7 @@ public class DeployCommand extends AbstractCommand {
 	public void processZipEntry(Path zipFsPath, Path dstDirPath) throws Exception {
 		if (Files.isDirectory(zipFsPath)) {
 			LOG.info("Process directory {}", zipFsPath.toString());
-			Files.list(zipFsPath).forEach(p->{
+			Files.list(zipFsPath).forEach(p -> {
 				try {
 					processZipEntry(p, dstDirPath);
 				} catch (Exception e) {
@@ -118,20 +118,20 @@ public class DeployCommand extends AbstractCommand {
 			});
 		} else if (Files.isRegularFile(zipFsPath)) {
 			checkZipSlip(dstDirPath, zipFsPath);
-
+			
 			Path outFilePath = Paths.get(dstDirPath.toString(), zipFsPath.toString());
 			Path parentDirPath = outFilePath.getParent();
 			if (!Files.exists(parentDirPath)) {
 				parentDirPath.toFile().mkdirs();
 			}
-
+			
 			Files.copy(zipFsPath, Paths.get(dstDirPath.toString(), zipFsPath.toString()), StandardCopyOption.REPLACE_EXISTING);
 		}
 	}
-
+	
 	public static void checkZipSlip(Path dstDirPath, Path zipFsPath) throws Exception {
 		Path dstFilePath = Paths.get(dstDirPath.toString(), zipFsPath.toString());
-
+		
 		if (!dstFilePath.toAbsolutePath().startsWith(dstDirPath.toAbsolutePath())) {
 			throw new Exception("ZipSlipAttack detected: " + zipFsPath.toString());
 		}

+ 36 - 37
src/main/java/com/l2jserver/cli/dao/AbstractDatabaseDAO.java

@@ -28,16 +28,15 @@ import com.l2jserver.cli.util.SQLFilter;
 
 /**
  * Database DAO.
- * 
  * @author Zoey76
  * @version 1.0.0
  */
 public abstract class AbstractDatabaseDAO extends AbstractDAO {
-
+	
 	AbstractDatabaseDAO(ServerConfiguration server) {
 		super(server);
 	}
-
+	
 	public void mods(File sqlPath) {
 		final var modsPath = new File(sqlPath, "mods");
 		if (modsPath.exists()) {
@@ -45,7 +44,7 @@ public abstract class AbstractDatabaseDAO extends AbstractDAO {
 			runSQLFiles(modsPath.listFiles(new SQLFilter()));
 		}
 	}
-
+	
 	public void custom(File sqlPath) {
 		final var customPath = new File(sqlPath, "custom");
 		if (customPath.exists()) {
@@ -53,60 +52,60 @@ public abstract class AbstractDatabaseDAO extends AbstractDAO {
 			runSQLFiles(customPath.listFiles(new SQLFilter()));
 		}
 	}
-
+	
 	public void basic(File sqlPath) {
 		System.out.println("Installing basic SQL scripts...");
 		final var files = sqlPath.listFiles(new SQLFilter());
 		runSQLFiles(files);
 	}
-
+	
 	protected void updates(DatabaseInstallType mode, String cleanup, File sqlPath) {
 		final var userPreferences = Preferences.userRoot();
 		final var updatePath = new File(sqlPath, "updates");
 		final var updatePreferences = getDatabase() + "_update";
-
+		
 		switch (mode) {
-		case FULL: {
-			System.out.println("Executing cleanup script...");
-
-			runSQLFiles(new File(sqlPath, cleanup));
-
-			if (updatePath.exists()) {
-				final var sb = new StringBuilder();
-				for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
-					sb.append(sqlFile.getName() + ';');
+			case FULL: {
+				System.out.println("Executing cleanup script...");
+				
+				runSQLFiles(new File(sqlPath, cleanup));
+				
+				if (updatePath.exists()) {
+					final var sb = new StringBuilder();
+					for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
+						sb.append(sqlFile.getName() + ';');
+					}
+					userPreferences.put(updatePreferences, sb.toString());
 				}
-				userPreferences.put(updatePreferences, sb.toString());
+				break;
 			}
-			break;
-		}
-		case UPDATE: {
-			System.out.println("Installing update SQL scripts...");
-			final var updated = userPreferences.get(updatePreferences, "");
-			if (updatePath.exists()) {
-				for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
-					if (!updated.contains(sqlFile.getName())) {
-						try {
-							System.out.println("Installing " + sqlFile.getName() + "...");
-							executeSQLScript(sqlFile);
-						} catch (Exception ex) {
-							System.err.println("There has been an error executing SQL update!");
-							ex.printStackTrace();
-							return;
+			case UPDATE: {
+				System.out.println("Installing update SQL scripts...");
+				final var updated = userPreferences.get(updatePreferences, "");
+				if (updatePath.exists()) {
+					for (var sqlFile : updatePath.listFiles(new SQLFilter())) {
+						if (!updated.contains(sqlFile.getName())) {
+							try {
+								System.out.println("Installing " + sqlFile.getName() + "...");
+								executeSQLScript(sqlFile);
+							} catch (Exception ex) {
+								System.err.println("There has been an error executing SQL update!");
+								ex.printStackTrace();
+								return;
+							}
+							userPreferences.put(updatePreferences, updated + sqlFile.getName() + ";");
 						}
-						userPreferences.put(updatePreferences, updated + sqlFile.getName() + ";");
 					}
 				}
+				break;
 			}
-			break;
-		}
 		}
 	}
-
+	
 	public void updates(DatabaseInstallType mode, File sqlPath) {
 		updates(mode, "cleanup/cleanup.sql", sqlPath);
 	}
-
+	
 	private void runSQLFiles(File... sqlFiles) {
 		Arrays.sort(sqlFiles);
 		

+ 1 - 1
src/main/java/com/l2jserver/cli/dao/GameServerDatabaseDAO.java

@@ -26,7 +26,7 @@ import com.l2jserver.cli.config.Configuration;
  * @version 1.0.0
  */
 public class GameServerDatabaseDAO extends AbstractDatabaseDAO {
-
+	
 	public GameServerDatabaseDAO() {
 		super(Configuration.gameServer());
 	}