#!/usr/bin/perl
#######################################################################
#
# Ldap2Zone - write DNS Zone file from LDAP informations
#
# Copyright (C) 2011-2014 FusionDirectory project
#
# Author: Come Bernigaud
#
# This program 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 of the License, 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 <http://www.gnu.org/licenses/>
#
#######################################################################

use strict;
use warnings;

use 5.008;

use Argonaut::Libraries::Ldap2zone qw(argonaut_ldap2zone);

my $zone_arg = undef;
my $verbose_arg = 0;
my $norefresh = 0;
my $dumpdir = '';

sub print_usage
{
  print "Usage : argonaut-ldap2zone [--verbose] [--norestart] [--dumpdir dir] ZONE\n";
  exit(0);
}

my $i_arg = 0;

foreach my $arg ( @ARGV ) {
  if (not defined $dumpdir) {
    $dumpdir = $arg;
  } elsif (lc($arg) eq "--verbose") {
    $verbose_arg = 1;
  } elsif (lc($arg) eq "--norestart") {
    $norefresh = 1;
  } elsif (lc($arg) eq "--dumpdir") {
    undef $dumpdir;
  } elsif ($i_arg==0) {
    $zone_arg = $arg;
    $i_arg++;
  } else {
    print_usage();
  }
}
if (not defined $dumpdir) {
  print_usage();
} elsif ($dumpdir eq '') {
  undef $dumpdir;
}

if (!$zone_arg) {
  print_usage();
}

argonaut_ldap2zone($zone_arg,$verbose_arg,$norefresh,$dumpdir);

__END__

=head1 NAME

argonaut-ldap2zone - creating bind zone files and refreshing the server

=head1 SYNOPSIS

argonaut-ldap2zone [--verbose] [--norestart] [--dumpdir dir] ZONE

=head1 DESCRIPTION

argonaut-ldap2zone is a program used to create bind zone files and refresh the bind service

=head1 OPTIONS

=over 3

=item B<--verbose>

be verbose

=item B<--norestart>

Do not refresh bind zone with rndc 

=item B<--dumpdir>

Dump the zones and bind configuration to another dir for testing purposes

=back

=head1 EXAMPLE

B<argonaut-ldap2zone --verbose fusiondirectory.org.>

 Write the updated zones from ldap and refresh bind
 
B<argonaut-ldap2zone --verbose --norestart --dumpdir dnszone/ master.fdi>

 Write the updated zones from ldap to another directory and don't refresh bind

=head1 BUGS

Please report any bugs, or post any suggestions, to the fusiondirectory mailing list fusiondirectory-users or to
<https://forge.fusiondirectory.org/projects/argonaut-agents/issues/new>

=head1 AUTHORS

Come Bernigaud

=head1 LICENCE AND COPYRIGHT

This code is part of FusionDirectory <http://www.fusiondirectory.org>

=over 1

=item Copyright (C) 2011-2014 FusionDirectory project

=back

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.

=cut
