Few improvements: put the help print in a function. Make sure all the things we update are commented and do not push commented configuration.

pull/5904/head
Sebastien Tricaud 2020-05-13 15:22:00 -07:00
parent 18a8bc0781
commit 2bccfb027e
1 changed files with 25 additions and 6 deletions

View File

@ -36,7 +36,7 @@ my $create=0;
my $apply=0;
my %CATEGORIES_CREATED = ();
if ($#ARGV < 0) {
sub print_help_exit {
print "\nUsage: misp-config --user www-data
\t --misp-path /usr/share/misp
\t --prefix /usr/local
@ -45,6 +45,10 @@ if ($#ARGV < 0) {
exit;
}
if ($#ARGV < 0) {
print_help_exit();
}
sub replace_inplace_content {
my ($filename, $buftoreplace, $replacement) = @_;
@ -77,6 +81,9 @@ while (my ($i, $arg) = each @ARGV) {
if ($arg eq "--apply") {
$apply = 1;
}
if ($arg eq "--help") {
print_help_exit();
}
}
if ( ! $apply && ! $create ) {
@ -154,7 +161,7 @@ if ($create) {
}
$CATEGORIES_CREATED{"$category"} = 1;
open(my $fh, ">>", "$conf_to_write");
print $fh "$key $value\n";
print $fh "#$key $value\n";
close $fh;
# Unset those two variables to be filled again!
@ -182,20 +189,32 @@ if ($apply) {
$line =~ /(\S+) (.*)/;
my $key = "";
my $config_el = $1;
my $first_config_char = substr($config_el, 0, 1);
my $is_comment = 0;
if ($first_config_char eq "#") {
$is_comment = 1;
}
# print("config element: $config_el\n");
if ($category eq "Debug") {
# The Debug category does not... have a category
$key = $1;
$key = $config_el;
} elsif ($category eq "Internal") {
# Internal means we are patching portions of the code to configure
if ($1 eq "redis_host") {
if ($config_el eq "redis_host") {
replace_inplace_content("$misp_path/app/Lib/Tools/PubSubTool.php", "localhost", $2);
replace_inplace_content("$misp_path/app/Plugin/CakeResque/Config/config.php", "localhost", $2);
replace_inplace_content("$misp_path/app/Vendor/kamisama/php-resque-ex/lib/Resque.php", "localhost", $2);
replace_inplace_content("$misp_path/app/Vendor/monolog/monolog/src/Monolog/Handler/RedisHandler.php", "localhost", $2);
}
} else {
$key = "$category.$1";
$key = "$category.$config_el";
}
if ($cake_config) {
if ($cake_config && !$is_comment) {
# print("sudo -u $misp_user $misp_path/app/Console/cake admin setSetting $key $2\n");
system("sudo -u $misp_user $misp_path/app/Console/cake admin setSetting $key $2");
}