diff options
author | Guilhem Moulin <guilhem.moulin@fripost.org> | 2012-04-18 02:06:01 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem.moulin@fripost.org> | 2012-04-18 02:06:01 +0200 |
commit | 0467c0a622c5aa0b2b63615b2b36f31f4272bcd1 (patch) | |
tree | d6bf9a35484cb189ca0503b43e79fb8d7f125b7c /fripost-newdomain | |
parent | c108460517f2569b9cfeca073c889a35d6d77cd4 (diff) |
Implemented the changes on the LDAP schema.
Diffstat (limited to 'fripost-newdomain')
-rwxr-xr-x | fripost-newdomain | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/fripost-newdomain b/fripost-newdomain index 155e6ae..8ab48bf 100755 --- a/fripost-newdomain +++ b/fripost-newdomain @@ -11,14 +11,14 @@ fripost-newdomain - Add a new domain to the system =head1 SYNOPSIS -B<fripost-newdomain> [B<--debug>] [B<--pretend>] +B<fripost-newdomain> [B<--verbose>] [B<--debug>] [B<--pretend>] [B<--owner=>I<username>] [I<domain>] =head1 DESCRIPTION B<fripost-newdomain> adds a new virtual domain to the system, unless B<--pretend> is set. -If no I<domain> is given, the user is prompted for it. +If I<domain> is not given, the user is prompted for it. By default, B<fripost-newdomain> prompts for the owner of the new domain; Use B<--owner=>I<''> to create a "global" domain, only managed by the administrators. @@ -64,6 +64,10 @@ The default value is read from the configuration file, see B<CONFIGURATION>. The root DN for everything done by B<fripost-newdomain>. The default value is read from the configuration file, see B<CONFIGURATION>. +=item B<-v>, B<--verbose> + +Verbose mode. + =item B<--debug> Debug mode. @@ -128,10 +132,13 @@ GetOptions( 'pretend' => \$conf->{pretend}, 'owner=s' => \$conf->{owner}, 'debug' => \$conf->{debug}, + 'v|verbose' => \$conf->{verbose}, 'man' => sub { pod2usage(-exitstatus => 0, -verbose => 2) } ) or pod2usage(2); +sub vsay { say STDERR @_ if $conf->{verbose} || $conf->{debug}; } + # Connect to the LDAP server my $ldap = Fripost::Schema->new( $conf ); @@ -141,6 +148,7 @@ my $ldap = Fripost::Schema->new( $conf ); my %domain; $domain{domain} = $ARGV[0]; $domain{domain} //= prompt "Domain name: "; +# TODO: Ensure that the domain is valid. $domain{isActive} = 'TRUE'; if (defined $conf->{owner}) { if ($conf->{owner} eq '') { @@ -157,7 +165,6 @@ else { } -# Checks. { # Check that the owner exists. die "Error: Unknown user `" .$domain{owner}. "'.\n" @@ -177,7 +184,7 @@ else { # warning. my $res = $ldap->domain->search({ domain => $domain{domain} }); if ($res->count) { - print STDERR "Warning: Domain `" .$domain{domain}. "' already exists."; + print STDERR "WARN: Domain `" .$domain{domain}. "' already exists."; my @owners; map { push @owners, $_->{owner} if defined $_->{owner} } ($res->entries); if (@owners) { @@ -191,16 +198,21 @@ else { if ($conf->{pretend}) { - say "Nothing to do since we are only pretending..."; + vsay "Nothing to do since we are only pretending..."; exit 0; } # Add the domain. $ldap->domain->add(\%domain); -print "New domain `" .$domain{domain}. "' added"; -print " for user `" .$domain{owner}. "'" if defined $domain{owner}; -say "."; +if (defined $domain{owner}) { + print "New domain `" .$domain{domain}. "' added"; + print " for user `" .$domain{owner}. "'" if defined $domain{owner}; + say "."; +} +else { + say "New non self-managed domain `" .$domain{domain}. "' added."; +} # Create aliases. @@ -211,7 +223,7 @@ sub create_alias { my $res = $ldap->alias->search(\%alias); if ($res->count) { - print STDERR "Warning: Alias `" .$alias{address}. "' already exists."; + print STDERR "WARN: Alias `" .$alias{address}. "' already exists."; print STDERR "(Targetting to "; print STDERR (join ', ', map { '`' .$_->{goto}. "'"} ($res->entries)); say STDERR ".)"; |