Skip to content

Commit

Permalink
lmConfigEditor with JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
guimard committed Aug 18, 2024
1 parent 3e41beb commit 0017b5d
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changes

* 2024-08-18: add --json option to lmConfigEditor
* 2024-08-18: add message-broker
* 2024-08-18(v2.19.1-3):
* add `TLS_CERT_FILE` and `TLS_KEY_FILE` variables
Expand Down
1 change: 1 addition & 0 deletions full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RUN \
echo patch crowdsec.patch && patch -p1 < crowdsec.patch && \
echo patch recaptcha.patch && patch -p1 < recaptcha.patch && \
echo patch msg-broker.patch && patch -p1 < msg-broker.patch && \
echo patch lmConfigEditor.patch && patch -p1 < lmConfigEditor.patch && \
rm -f *.patch && \
LLNG_DEFAULTCONFFILE=/etc/lemonldap-ng/lemonldap-ng.ini \
perl -MLemonldap::NG::Manager::Build -e 'Lemonldap::NG::Manager::Build->run( \
Expand Down
55 changes: 55 additions & 0 deletions full/lmConfigEditor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--- a/usr/share/lemonldap-ng/bin/lmConfigEditor
+++ b/usr/share/lemonldap-ng/bin/lmConfigEditor
@@ -18,10 +18,12 @@ my $cli = Lemonldap::NG::Manager::Cli::Lib->new;

our $opt_user = 'www-data';
our $opt_group = 'www-data';
+our $opt_json;

GetOptions(
"user=s" => \$opt_user,
- "group=s" => \$opt_group
+ "group=s" => \$opt_group,
+ "json" => \$opt_json,
) or die("Error in command line arguments\n");

eval {
@@ -45,10 +47,17 @@ delete $refConf->{cfgAuthorIP};
delete $refConf->{cfgDate};
$refConf->{cfgLog} = '';

-# Sort keys
-$Data::Dumper::Sortkeys = 1;
-$Data::Dumper::Useperl = 1;
-my $tmp = Dumper($refConf);
+my $tmp;
+if ($opt_json) {
+ require JSON;
+ $tmp = JSON->new->pretty->canonical->encode($refConf);
+}
+else {
+ # Sort keys
+ $Data::Dumper::Sortkeys = 1;
+ $Data::Dumper::Useperl = 1;
+ $tmp = Dumper($refConf);
+}

my $refFile = File::Temp->new( UNLINK => 1 );
my $editFile = File::Temp->new( UNLINK => 1 );
@@ -73,8 +82,14 @@ if ( $rc == 0 and compare( $refFile->filename, $editFile->filename ) == 1 ) {
my $buf = join( '', <$F1> );
close $F1;

- my $newConf = Safe->new->reval($buf);
- die $EVAL_ERROR if $EVAL_ERROR;
+ my $newConf;
+ if ($opt_json) {
+ $newConf = JSON::from_json($buf);
+ }
+ else {
+ $newConf = Safe->new->reval($buf);
+ die $EVAL_ERROR if $EVAL_ERROR;
+ }

# Update author and date
$newConf->{cfgAuthor} =
1 change: 1 addition & 0 deletions manager/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN \
echo patch crowdsec.patch && patch -p1 < crowdsec.patch && \
echo patch recaptcha.patch && patch -p1 < recaptcha.patch && \
echo patch msg-broker.patch && patch -p1 < msg-broker.patch && \
echo patch lmConfigEditor.patch && patch -p1 < lmConfigEditor.patch && \
rm -f *.patch && \
LLNG_DEFAULTCONFFILE=/etc/lemonldap-ng/lemonldap-ng.ini \
perl -MLemonldap::NG::Manager::Build -e 'Lemonldap::NG::Manager::Build->run( \
Expand Down
55 changes: 55 additions & 0 deletions manager/lmConfigEditor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--- a/usr/share/lemonldap-ng/bin/lmConfigEditor
+++ b/usr/share/lemonldap-ng/bin/lmConfigEditor
@@ -18,10 +18,12 @@ my $cli = Lemonldap::NG::Manager::Cli::Lib->new;

our $opt_user = 'www-data';
our $opt_group = 'www-data';
+our $opt_json;

GetOptions(
"user=s" => \$opt_user,
- "group=s" => \$opt_group
+ "group=s" => \$opt_group,
+ "json" => \$opt_json,
) or die("Error in command line arguments\n");

eval {
@@ -45,10 +47,17 @@ delete $refConf->{cfgAuthorIP};
delete $refConf->{cfgDate};
$refConf->{cfgLog} = '';

-# Sort keys
-$Data::Dumper::Sortkeys = 1;
-$Data::Dumper::Useperl = 1;
-my $tmp = Dumper($refConf);
+my $tmp;
+if ($opt_json) {
+ require JSON;
+ $tmp = JSON->new->pretty->canonical->encode($refConf);
+}
+else {
+ # Sort keys
+ $Data::Dumper::Sortkeys = 1;
+ $Data::Dumper::Useperl = 1;
+ $tmp = Dumper($refConf);
+}

my $refFile = File::Temp->new( UNLINK => 1 );
my $editFile = File::Temp->new( UNLINK => 1 );
@@ -73,8 +82,14 @@ if ( $rc == 0 and compare( $refFile->filename, $editFile->filename ) == 1 ) {
my $buf = join( '', <$F1> );
close $F1;

- my $newConf = Safe->new->reval($buf);
- die $EVAL_ERROR if $EVAL_ERROR;
+ my $newConf;
+ if ($opt_json) {
+ $newConf = JSON::from_json($buf);
+ }
+ else {
+ $newConf = Safe->new->reval($buf);
+ die $EVAL_ERROR if $EVAL_ERROR;
+ }

# Update author and date
$newConf->{cfgAuthor} =
1 change: 0 additions & 1 deletion portal/haproxy

This file was deleted.

1 change: 0 additions & 1 deletion uwsgi-portal/haproxy

This file was deleted.

0 comments on commit 0017b5d

Please sign in to comment.