Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<dependency>
<groupId>de.rub.nds</groupId>
<artifactId>scanner-core</artifactId>
<version>5.5.0</version>
<version>6.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/de/rub/nds/crawler/CommonMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Common functionality for crawler main entry points. Provides functionality to parse command line arguments and start the worker/controller as specified by the user.
*/
public class CommonMain {
private static final Logger LOGGER = LogManager.getLogger();

/**
* Main entry point for the application. Uses JCommander to parse the controller/worker command and parse the arguments into the respective configuration object. Then starts the controller/worker.
*
* @param args Command line arguments
* @param controllerCommandConfig Configuration for the controller. Will be filled by JCommander from the command line if first argument is "controller".
* @param workerCommandConfig Configuration for the worker. Will be filled by JCommander from the command line if first argument is "worker".
*/
public static void main(
String[] args,
ControllerCommandConfig controllerCommandConfig,
Expand Down Expand Up @@ -71,6 +81,13 @@ public static void main(
}
}

/**
* Convenience method to start the application with just a controller configuration. Creates a
* default worker configuration. See {@link #main(String[], ControllerCommandConfig, WorkerCommandConfig)} for details.
*
* @param args Command line arguments
* @param controllerConfig Configuration for the controller. Will be filled by JCommander from the command line if first argument is "controller".
*/
public static void main(String[] args, ControllerCommandConfig controllerConfig) {
main(args, controllerConfig, new WorkerCommandConfig());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@
import org.apache.commons.validator.routines.UrlValidator;
import org.quartz.CronScheduleBuilder;

/**
* Configuration class for controller instances used to parse command line parameters. Contains settings for the controller's behavior,
* including scan parameters, target selection, and notification settings. This abstract class
* provides the base configuration, while specific scanner implementations must extend it to provide
* scanner-specific configuration.
*/
public abstract class ControllerCommandConfig {

@ParametersDelegate private final RabbitMqDelegate rabbitMqDelegate;
@ParametersDelegate
private final RabbitMqDelegate rabbitMqDelegate;

@ParametersDelegate private final MongoDbDelegate mongoDbDelegate;
@ParametersDelegate
private final MongoDbDelegate mongoDbDelegate;

@Parameter(names = "-portToBeScanned", description = "The port that should be scanned.")
private int port = 443;
Expand Down Expand Up @@ -112,7 +120,17 @@ public void validate() {
}
}

/**
* Validator that ensures parameter values are positive integers.
*/
public static class PositiveInteger implements IParameterValidator {
/**
* Validates that the parameter value is a positive integer.
*
* @param name The parameter name
* @param value The parameter value
* @throws ParameterException If the value is not a positive integer
*/
public void validate(String name, String value) throws ParameterException {
int n = Integer.parseInt(value);
if (n < 0) {
Expand All @@ -122,7 +140,17 @@ public void validate(String name, String value) throws ParameterException {
}
}

/**
* Validator that ensures parameter values are valid cron expressions.
*/
public static class CronSyntax implements IParameterValidator {
/**
* Validates that the parameter value is a valid cron expression.
*
* @param name The parameter name
* @param value The parameter value
* @throws ParameterException If the value is not a valid cron expression
*/
public void validate(String name, String value) throws ParameterException {
CronScheduleBuilder.cronSchedule(value);
}
Expand Down
50 changes: 48 additions & 2 deletions src/main/java/de/rub/nds/crawler/config/WorkerCommandConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
import de.rub.nds.crawler.config.delegate.MongoDbDelegate;
import de.rub.nds.crawler.config.delegate.RabbitMqDelegate;

/**
* Configuration class for worker instances used to parse command line parameters. Contains settings for the worker's behavior, including
* thread counts and timeouts, as well as MongoDB and RabbitMQ connection settings.
*/
public class WorkerCommandConfig {

@ParametersDelegate private final RabbitMqDelegate rabbitMqDelegate;
@ParametersDelegate
private final RabbitMqDelegate rabbitMqDelegate;

@ParametersDelegate private final MongoDbDelegate mongoDbDelegate;
@ParametersDelegate
private final MongoDbDelegate mongoDbDelegate;

@Parameter(
names = "-numberOfThreads",
Expand All @@ -43,34 +49,74 @@ public WorkerCommandConfig() {
mongoDbDelegate = new MongoDbDelegate();
}

/**
* Gets the configuration for RabbitMQ, which contains the connection settings for RabbitMQ.
*
* @return The RabbitMQ connection settings
*/
public RabbitMqDelegate getRabbitMqDelegate() {
return rabbitMqDelegate;
}

/**
* Gets the configuration for MongoDB, which contains the connection settings for MongoDB.
*
* @return The MongoDB connection settings
*/
public MongoDbDelegate getMongoDbDelegate() {
return mongoDbDelegate;
}

/**
* Gets the number of parallel scan threads to use. Each thread starts a scanner instance.
*
* @return The number of scan threads
*/
public int getParallelScanThreads() {
return parallelScanThreads;
}

/**
* Gets the number of parallel connection threads to use per bulk scan (i.e., per scan ID).
*
* @return The number of connection threads
*/
public int getParallelConnectionThreads() {
return parallelConnectionThreads;
}

/**
* Gets the timeout for scanning an individual target.
*
* @return The scan timeout in milliseconds
*/
public int getScanTimeout() {
return scanTimeout;
}

/**
* Sets the number of parallel scan threads to use. Each thread starts a scanner instance.
*
* @param parallelScanThreads The number of scan threads
*/
public void setParallelScanThreads(int parallelScanThreads) {
this.parallelScanThreads = parallelScanThreads;
}

/**
* Sets the number of parallel connection threads to use bulk scan (i.e., per scan ID).
*
* @param parallelConnectionThreads The number of connection threads
*/
public void setParallelConnectionThreads(int parallelConnectionThreads) {
this.parallelConnectionThreads = parallelConnectionThreads;
}

/**
* Sets the timeout for scanning an individual target.
*
* @param scanTimeout The scan timeout in milliseconds
*/
public void setScanTimeout(int scanTimeout) {
this.scanTimeout = scanTimeout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@

import com.beust.jcommander.Parameter;

/**
* Configuration delegate that holds MongoDB connection settings.
*/
public class MongoDbDelegate {

@Parameter(
names = "-mongoDbHost",
description = "Host of the MongoDB instance this crawler saves to.")
description = "Host of the MongoDB instance this crawler saves results to.")
private String mongoDbHost;

@Parameter(
names = "-mongoDbPort",
description = "Port of the MongoDB instance this crawler saves to.")
description = "Port of the MongoDB instance this crawler saves results to.")
private int mongoDbPort;

@Parameter(
Expand All @@ -29,63 +32,123 @@ public class MongoDbDelegate {

@Parameter(
names = "-mongoDbPass",
description = "The passwort to be used to authenticate with MongoDB.")
description = "The password to be used to authenticate with MongoDB.")
private String mongoDbPass;

@Parameter(
names = "-mongoDbPassFile",
description = "The passwort to be used to authenticate with MongoDB.")
description = "The password to be used to authenticate with MongoDB.")
private String mongoDbPassFile;

@Parameter(
names = "-mongoDbAuthSource",
description = "The DB within the MongoDB instance, in which the user:pass is defined.")
private String mongoDbAuthSource;

/**
* Gets the MongoDB host address.
*
* @return The MongoDB host address
*/
public String getMongoDbHost() {
return mongoDbHost;
}

/**
* Gets the MongoDB port number.
*
* @return The MongoDB port number
*/
public int getMongoDbPort() {
return mongoDbPort;
}

/**
* Gets the MongoDB username for authentication.
*
* @return The MongoDB username
*/
public String getMongoDbUser() {
return mongoDbUser;
}

/**
* Gets the MongoDB password for authentication.
*
* @return The MongoDB password
*/
public String getMongoDbPass() {
return mongoDbPass;
}

/**
* Gets the file path containing the MongoDB password.
*
* @return The MongoDB password file path
*/
public String getMongoDbPassFile() {
return mongoDbPassFile;
}

/**
* Gets the MongoDB authentication source database name.
*
* @return The authentication source database name
*/
public String getMongoDbAuthSource() {
return mongoDbAuthSource;
}

/**
* Sets the MongoDB host address.
*
* @param mongoDbHost The MongoDB host address
*/
public void setMongoDbHost(String mongoDbHost) {
this.mongoDbHost = mongoDbHost;
}

/**
* Sets the MongoDB port number.
*
* @param mongoDbPort The MongoDB port number
*/
public void setMongoDbPort(int mongoDbPort) {
this.mongoDbPort = mongoDbPort;
}

/**
* Sets the MongoDB username for authentication.
*
* @param mongoDbUser The MongoDB username
*/
public void setMongoDbUser(String mongoDbUser) {
this.mongoDbUser = mongoDbUser;
}

/**
* Sets the MongoDB password for authentication.
*
* @param mongoDbPass The MongoDB password
*/
public void setMongoDbPass(String mongoDbPass) {
this.mongoDbPass = mongoDbPass;
}

/**
* Sets the file path containing the MongoDB password.
*
* @param mongoDbPassFile The MongoDB password file path
*/
public void setMongoDbPassFile(String mongoDbPassFile) {
this.mongoDbPassFile = mongoDbPassFile;
}

/**
* Sets the MongoDB authentication source database name.
*
* @param mongoDbAuthSource The authentication source database name
*/
public void setMongoDbAuthSource(String mongoDbAuthSource) {
this.mongoDbAuthSource = mongoDbAuthSource;
}
Expand Down
Loading