lemonldap-ng-cli 6.17 KB
Newer Older
1
#!/usr/bin/perl
Yadd's avatar
Yadd committed
2
3
4

use warnings;
use strict;
5
use POSIX;
6
7
use Getopt::Long;

Alex Kelly's avatar
Alex Kelly committed
8
9
our $opt_user = '__APACHEUSER__';
our $opt_group = '__APACHEGROUP';
10
11
12
13
14
GetOptions (
        "user=s" => \$opt_user,
        "group=s"   => \$opt_group
)
or die("Error in command line arguments\n");
Yadd's avatar
Yadd committed
15

Yadd's avatar
Yadd committed
16
17
my $action;

18
eval {
Alex Kelly's avatar
Alex Kelly committed
19
20
    POSIX::setgid( scalar( getgrnam($opt_group) ) );
    POSIX::setuid( scalar( getpwnam($opt_user) ) );
21
22
};

Yadd's avatar
Yadd committed
23
24
25
26
27
28
29
30
31
for ( my $i = 0 ; $i < @ARGV ; $i++ ) {
    if ( $ARGV[$i] =~ /^-/ ) {
        $i++;
        next;
    }
    $action = $ARGV[$i];
    last;
}

32
33
$action ||= "help";

34
35
36
37
if ( $action =~
    /^(?:[gs]et|del|(?:add|del)Key|(?:add|del)PostVars|save|restore|rollback)$/
  )
{
Yadd's avatar
Yadd committed
38
    eval { require Lemonldap::NG::Manager::Cli; };
Yadd's avatar
Yadd committed
39
    die "Manager libraries not available, aborting ($@)" if ($@);
Yadd's avatar
Yadd committed
40
41
    Lemonldap::NG::Manager::Cli->run(@ARGV);
}
42
elsif ( $action =~ /^(?:info|update-cache|test-email)$/ ) {
Yadd's avatar
Yadd committed
43
    eval { require Lemonldap::NG::Common::Cli; };
Yadd's avatar
Yadd committed
44
    die "Lemonldap::NG common libraries not available, aborting ($@)" if ($@);
Yadd's avatar
Yadd committed
45
46
47
48
49
50
51
52
53
54
    Lemonldap::NG::Common::Cli->run(@ARGV);
}
else {
    help();
}

sub help {
    print STDERR qq{Usage: $0 <options> action <parameters>

Available actions:
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 - help                                      : print this
 - info                                      : get currentconfiguration info
 - update-cache                              : force configuration cache to be updated
 - test-email <destination>                  : send a test email
 - get <key>                                 : get values of parameters
 - set <key> <value>                         : set parameter(s) value(s)
 - del <key>                                 : delete parameters
 - addKey <key> <subkey> <value>             : add or set a subkey in a parameter
 - delKey <key> <subkey>                     : delete subkey of a parameter
 - addPostVars <host> <uri> <key> <value>    : add post vars for form replay
 - delPostVars <host> <uri> <key>            : delete post vars for form replay
 - save                                      : export configuration to STDOUT
 - restore -                                 : import configuration from STDIN
 - restore <file>                            : import configuration from file
 - rollback                                  : restore previous configuration
Yadd's avatar
Yadd committed
70

Maxime Besson's avatar
Maxime Besson committed
71
72
73
74
75
76
Options:
 - yes <0|1>                     : accept confirmation prompt automatically
 - log <msg>                     : set configuration log message
 - safe <0|1>                    : fail in case the requested configuration is invalid
 - force <0|1>                   : allow overwrite of existing config number
 - cfgNum <num>                  : set new configuration number (requires -force 1)
77
 - sep <char>                    : separator of hierarchical values (by default: /)
Christophe Maudoux's avatar
Christophe Maudoux committed
78
 - iniFile <file>                : path to an alternate lemonldap-ng.ini file
Maxime Besson's avatar
Maxime Besson committed
79

Maxime Besson's avatar
Maxime Besson committed
80
See Lemonldap::NG::Manager::Cli(3) for more
Yadd's avatar
Yadd committed
81
};
Yadd's avatar
Yadd committed
82
}
Yadd's avatar
Yadd committed
83
__END__
Yadd's avatar
Yadd committed
84

Yadd's avatar
Yadd committed
85
86
87
88
89
90
91
92
=head1 NAME

=encoding utf8

lemonldap-ng-cli - Command-line manager for Lemonldap::NG web-SSO system.

=head1 SYNOPSIS

Yadd's avatar
Yadd committed
93
94
Get information about current configuration

Yadd's avatar
Yadd committed
95
96
  $ lemonldap-ng-cli info

Yadd's avatar
Yadd committed
97
98
Update local configuration cache

Yadd's avatar
Yadd committed
99
100
  $ lemonldap-ng-cli update-cache

101
102
103
104
Send a test email

  $ lemonldap-ng-cli test-email dwho@badwolf.org

Yadd's avatar
Yadd committed
105
106
107
Save configuration

  $ lemonldap-ng-cli save >conf.json
108
  $ lemonldap-ng-cli -cfgNum 19 save >conf-19.json
Yadd's avatar
Yadd committed
109

Yadd's avatar
Yadd committed
110
111
112
113
114
115
Restore configuration

  $ lemonldap-ng-cli restore conf.json
  # OR
  $ lemonldap-ng-cli restore - <conf.json

116
117
118
119
Cancel the last configuration change

  $ lemonldap-ng-cli rollback

Yadd's avatar
Yadd committed
120
121
Get a configuration parameter value

Yadd's avatar
Yadd committed
122
123
  $ lemonldap-ng-cli get portal domain cookieName

Yadd's avatar
Yadd committed
124
Set some values
Yadd's avatar
Yadd committed
125

Yadd's avatar
Yadd committed
126
  $ lemonldap-ng-cli set portal http://auth.e.com/ domain e.com
Yadd's avatar
Yadd committed
127
128
129
  # add or set a key
  $ lemonldap-ng-cli addKey macro fullname '$givenName." ".$lastName'

Maxime Besson's avatar
Maxime Besson committed
130
131
132
133
134
135
  # without changing the version number
  $ lemonldap-ng-cli -force 1 -cfgNum 1 set portal http://auth.e.com/ domain e.com

  # without asking for confirmation
  $ lemonldap-ng-cli -yes 1 set portal http://auth.e.com/ domain e.com

Yadd's avatar
Yadd committed
136
137
=head1 DESCRIPTION

Christophe Maudoux's avatar
Christophe Maudoux committed
138
139
lemonldap-ng-cli is a command line interface to interact with Lemonldap::NG
configuration. Commands are described in L<Lemonldap::NG::Manager::Cli>
Maxime Besson's avatar
Maxime Besson committed
140
and L<Lemonldap::NG::Common::Cli>
Yadd's avatar
Yadd committed
141

Yadd's avatar
Yadd committed
142
143
144
145
146
147
148
149
=head2 Available commands

=over

=item info

=item update-cache

150
151
=item test-email

Yadd's avatar
Yadd committed
152
153
=item save

Yadd's avatar
Yadd committed
154
155
=item restore

Yadd's avatar
Yadd committed
156
157
158
159
160
161
162
163
164
165
=item get

=item set

=item addKey

=item delKey

=back

Maxime Besson's avatar
Maxime Besson committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
=head2 Available options

=over

=item -yes

Confirm modification automatically (default: 0)

=item -log

Allows you to set the log message that will be displayed in the manager

=item -safe

The configuration change will be aborted if it contains errors (default: 0)

182
183
184
185
=item -force

Allows you to force overwriting an existing configuration (default: 0)

Maxime Besson's avatar
Maxime Besson committed
186
187
188
189
=item -cfgNum

Choose a particular configuration number (default: latest)

190
191
192
193
194
195
196
=item -sep 

Allows you to define hierarchical separator

=item -iniFile

Allows you to set an alternative ini file
Maxime Besson's avatar
Maxime Besson committed
197
198
199

=back

Yadd's avatar
Yadd committed
200
201
=head1 SEE ALSO

Maxime Besson's avatar
Maxime Besson committed
202
L<Lemonldap::NG::Manager::Cli>, L<Lemonldap::NG::Common::Cli>
Yadd's avatar
Yadd committed
203
204
205
206
207
208
L<http://lemonldap-ng.org/>

=head1 AUTHORS

=over

209
210
211
=item Clement Oudot, E<lt>clement@oodo.netE<gt>

=item Xavier Guimard, E<lt>yadd@debian.orgE<gt>
Yadd's avatar
Yadd committed
212

213
=item Maxime Besson, E<lt>maxime.besson@worteks.comE<gt>
Yadd's avatar
Yadd committed
214

215
=item Christophe Maudoux, E<lt>chrmdx@gmail.comE<gt>
Yadd's avatar
Yadd committed
216
217
218
219
220
221

=back

=head1 BUG REPORT

Use OW2 system to report bug or ask for features:
Yadd's avatar
Yadd committed
222
L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues>
Yadd's avatar
Yadd committed
223
224
225
226

=head1 DOWNLOAD

Lemonldap::NG is available at
227
L<https://release.ow2.org/lemonldap/>
Yadd's avatar
Yadd committed
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

=head1 COPYRIGHT AND LICENSE

=over

=item Copyright (C) 2016 by Xavier Guimard, E<lt>x.guimard@free.frE<gt>

=item Copyright (C) 2016 by Clément Oudot, E<lt>clem.oudot@gmail.comE<gt>

=back

This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see L<http://www.gnu.org/licenses/>.

=cut