From 0467c0a622c5aa0b2b63615b2b36f31f4272bcd1 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 18 Apr 2012 02:06:01 +0200 Subject: Implemented the changes on the LDAP schema. --- fripost-newdomain | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'fripost-newdomain') 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 [B<--debug>] [B<--pretend>] +B [B<--verbose>] [B<--debug>] [B<--pretend>] [B<--owner=>I] [I] =head1 DESCRIPTION B adds a new virtual domain to the system, unless B<--pretend> is set. -If no I is given, the user is prompted for it. +If I is not given, the user is prompted for it. By default, B 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. The root DN for everything done by B. The default value is read from the configuration file, see B. +=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 ".)"; -- cgit v1.2.3