You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.4 KiB

package app;
use v5.14;
use Moo;
use db;
use zone;
use configuration ':all';
has db => ( is => 'rw', builder => '_void');
has [qw/tld tmpdir database primarydnsserver secondarydnsserver/]
=> qw/is ro required 1/;
sub _void { my $x = ''; \$x; }
sub BUILD {
my ($self) = @_;
$$self{db} = db->new(data => $self);
my $tmpdir = get_tmpdir_from_uri($$self{tmpdir});
-f $tmpdir || qx/mkdir -p $tmpdir/;
my $db = $$self{database};
unless(exists $$db{sgbd} && exists $$db{name}
&& exists $$db{host} && exists $$db{port}
&& exists $$db{user} && exists $$db{passwd})
{
die "Unable to connect to the database.\n"
. "Check the existance of theses parameters in the config file :\n"
. "\tsgbd name host port user passwd";
}
}
# USER
sub auth {
my ($self, $login, $passwd) = @_;
$self->db->auth($login, $passwd)
}
sub update_passwd {
my ($self, $login, $newpass) = @_;
$self->db->update_passwd($login, $newpass)
}
sub register_user {
my ($self, $login, $passwd) = @_;
$self->db->register_user($login, $passwd)
}
sub toggle_admin {
my ($self, $login) = @_;
$self->db->toggle_admin($login)
}
sub delete_user {
my ($self, $login) = @_;
$self->db->delete_user($login)
}
sub get_all_users {
my ($self) = @_;
$self->db->get_all_users
}
sub is_owning_domain {
my ($self, $login, $domain) = @_;
$self->db->is_owning_domain($login, $domain)
}
# DOMAIN
sub get_zone {
my ($self, $domain) = @_;
# say "";
# say "GET ZONE";
# say "";
# say "";
# say "domain $domain";
# say "tmpdir $$self{tmpdir}";
# say "tld $$self{tld}";
zone->new( domain => $domain
, tmpdir => $$self{tmpdir}
, tld => $$self{tld}
, primarydnsserver => $$self{primarydnsserver}
, secondarydnsserver => $$self{secondarydnsserver}
, slavedzones => $self->get_all_domains()
)
}
sub add_domain {
my ($self, $login, $domain) = @_;
$self->db->add_domain($login, $domain);
$self->get_zone($domain)->addzone()
}
sub delete_domain {
my ($self, $domain) = @_;
$self->db->delete_domain($domain);
$self->get_zone($domain)->del()
}
sub get_domains {
my ($self, $login) = @_;
$self->db->get_domains($login)
}
sub get_all_domains {
my ($self) = @_;
$self->db->get_all_domains
}
sub disconnect {
my ($self) = @_;
$self->db->disconnect
}
1;