]> git.ipfire.org Git - people/stevee/guardian.git/commitdiff
Add support for command line arguments and usage of "Config" module.
authorStefan Schantl <stefan.schantl@ipfire.org>
Mon, 23 Nov 2015 08:57:25 +0000 (09:57 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Mon, 23 Nov 2015 08:57:25 +0000 (09:57 +0100)
guardian now can be called with some additional command line arguments, like
"--config" to specify a different config file than the default one. The optoions
"--help" and "--vesion" will display some help texts and version informations on
the console. The "--foreground" option is not supported/implemented yet and will
be used to keep the process in the foreground and not fork into background at a later
time.

The "Config" module now also is used to get all settings from the config file and
store them into a hash called mainsettings for a later usage.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
guardian

index c0773eef175bd1b4e137898b6f56704dfd3fd22d..3435c096690ec8a8f4d27342b51b7e17416c5e5b 100644 (file)
--- a/guardian
+++ b/guardian
 use strict;
 use threads;
 use threads::shared;
+use Getopt::Long;
 use Thread::Queue;
 use Linux::Inotify2;
 
+require Guardian::Config;
 require Guardian::Parser;
 require Guardian::Socket;
 
+# Define version.
+my $version ="2.0";
+
 # Array to store the monitored logfiles.
 my @monitored_files = (
        "/var/log/snort/alert",
 );
 
+# Get and store the given command line arguments in a hash.
+my %cmdargs = ();
+
+&GetOptions (\%cmdargs,
+       'foreground|f',
+       'config|c=s',
+       'help|h',
+       'version|v',
+);
+
+# Show help / version information.
+if (defined($cmdargs{"help"})) {
+       print "Guardian $version \n";
+       print "Usage: guardian <optional arguments>\n";
+       print " -c, --config\t\tspecifiy a configuration file other than the default (/etc/guardian/guardian.conf)\n";
+       print " -f, --foreground\trun in the foreground (doesn't fork, any output goes to STDOUT)\n";
+       print " -h, --help\t\tshows this help\n";
+       print " -v, --version\t\tdisplay programm version and exit.\n";
+       exit;
+} elsif (defined($cmdargs{"version"})) {
+       print "Guardian $version \n";
+       exit;
+}
+
+# Read-in the configuration file and store the settings.
+# Push the may be given config file argument.
+my %mainsettings = &Guardian::Config::UseConfig($cmdargs{"config"});
+
 # Create the main queue. It is used to store and process all events which are
 # reported and enqueued by the worker threads.
 my $queue :shared = new Thread::Queue or die "Could not create new, empty queue. $!\n";;