Obsolete
/
dnsmanagerv1
Archived
3
0
Fork 0

réécriture légère, suppression d'un fichier non utilisé pour le moment

master
Philippe Pittoli 2014-01-20 22:58:30 +01:00
parent ac41629891
commit 3c78751240
5 changed files with 74 additions and 330 deletions

View File

@ -1,165 +0,0 @@
use Modern::Perl;
use strict;
use warnings;
use Data::Dump "dump";
use v5.14;
use re '/x'; # very important
use lib '../../';
package app::zone::bind_interface;
use Moose;
#use Sudo;
# to know where the zone files are stored / to execute a sudo command
# has [ qw/zone_path sudo_pass/ ] => qw/is ro required 1/;
has [ qw/zone_path/ ] => qw/is ro required 1/;
sub activate_zone {
my ($self, $domain, $admin_file) = @_;
open(my $file, ">>", $admin_file)
or die("error : impossible to open admin file");
}
=pod
zone "karchnu.fr" {
type master;
file "/srv/named/karchnu.fr";
forwarders { 8.8.8.8; };
allow-update { key DDNS\_UPDATER ; };
allow-transfer { any; };
allow-query { any; };
};
zone "0.0.1.0.0.0.0.0.0.0.0.0.0.0.f.c.ip6.arpa" {
type master;
file "/srv/named/karchnu.fr.rv";
allow-update { key DDNS\_UPDATER ; };
allow-transfer { any; };
allow-query { any; };
};
=cut
# TODO
sub update {
my ($self) = @_;
#open(my $process, "service bind9 reload|");
#say while(<$process>);
#close($process);
#my $su = Sudo->new(
# {
# sudo => '/usr/bin/sudo',
# username => 'root',
# password => $self->sudo_pass,
# program => '/usr/bin/service',
# program_args => 'bind9 reload',
# }
#);
# my $result = $su->sudo_run();
# if (exists($result->{error})) {
# return 0;
# }
#
# printf "STDOUT: %s\n",$result->{stdout};
# printf "STDERR: %s\n",$result->{stderr};
# printf "return: %s\n",$result->{rc};
# return 1;
}
sub parse {
my ($self, $file) = @_;
my $fh;
open($fh, "<", $self->zone_path . $file) or return;
my %zone = $self->parse_zone_file($fh) ;
close($fh);
return %zone;
}
sub comment {
my $self = shift;
m{ ^ \s* ; \s* ( .+ ) }
and return { comment => $1 };
}
sub SOA {
my $self = shift;
m{ ^\s* (?<addr> \S+)
\s+ (?<domain> \S+)
\s+ SOA
\s+(?<primary> \S+)
\s+(?<admin> \S+)
\s+ \(
\s*(?<serial> \d+)
\s+(?<refresh> \d+)
\s+(?<retry> \d+)
\s+(?<expire> \d+)
\s+(?<serial> \d+)
\s*
\)
} and return {%+}
}
sub TTL {
my $self = shift;
m{ ^ \s* \$TTL \s+ (\d+) \s* $ }
and return { TTL => $1 }
}
# rocoto IN A 192.168.0.180
# karchnu.fr. IN MX 5 rocoto
# exemple:
# karchnu.fr. IN MX 5 rocoto
sub entry {
my $self = shift;
m{ ^
\s* (?<host> \S+)
\s+ (?<domain> \S+)
(?:
\s+ (?<type> MX)
\s+ (?<check> \S+)
\s+ (?<addr> \S+)
|
\s+ (?<type> A | AAAA | CNAME)
\s+ (?<addr> \S+)
|
\s+ TXT
\s+ "(?<text> \\. | [^"]+)"
)
} and return {%+};
}
sub empty_line {
my $self = shift;
/^ \s* $/x
}
# element must be used without args
# () is very important
sub alias {
my $self = shift;
m{^
\s* \@
\s+ (?<domain> IN )
\s+ (?<type> A | AAAA | NS | MX | SOA )
\s+ (?<alias> .* )
} and return {%+}
}
sub element () {
my $self = shift;
return if empty_line || comment;
SOA || TTL
|| alias
|| entry
|| die "unparsable $_";
}
sub parse_zone_file {
my ($self, $fh) = @_;
map element, <$fh>;
}
1;

View File

@ -14,8 +14,7 @@ has [ qw/zname zdir/ ] => qw/is ro required 1/;
sub get {
my ($self) = @_;
my $file = $self->zdir.'/'.$self->zname;
my $zonefile = DNS::ZoneParse->new($file, $self->zname);
return $zonefile;
return DNS::ZoneParse->new($file, $self->zname);
}
=pod

View File

@ -1,12 +1,10 @@
use lib '../../';
use app::zone::bind_interface;
use app::zone::rndc_interface;
package app::zone::interface;
use Moose;
sub get_interface {
my ($self, $type, $zp) = @_;
return 1, app::zone::bind_interface->new(zone_path => $zp) if $type eq 'bind';
return 1, app::zone::rndc_interface->new(zdir => $zp) if $type eq 'rndc';
return 0;
}

View File

@ -20,7 +20,6 @@ sub addzone {
$command .= "'{ type master; file \"$zdir/$zname\"; };'"
}
$command .= " 2>/dev/null 1>/dev/null";
system($command);

View File

@ -14,35 +14,39 @@ $Storable::Deparse = true;
$Storable::Eval=true;
# Include other libs relative to current path
use Find::Lib '../../';
use Find::Lib '../../'; # TODO remove it when it won't be usefull anymore
use app::app;
my $success;
our $cfg = new Config::Simple(dirname(__FILE__).'/../conf/config.ini');
our $VERSION = '0.1';
# eventually change place
sub initco {
my $cfg = new Config::Simple(dirname(__FILE__).'/../conf/config.ini');
my $app = app->new( zdir => $cfg->param('zones_path'),
dbname => $cfg->param('dbname'),
dbhost => $cfg->param('host'),
dbport => $cfg->param('port'),
dbuser => $cfg->param('user'),
dbpass => $cfg->param('passwd'),
sgbd => $cfg->param('sgbd'),
dnsapp => $cfg->param('dnsapp') );
$app->init();
return $app;
}
get '/' => sub {
if( session('login') )
{
# my ($auth_ok, $user, $admin) =
# $usermanagement->auth( session('login'), session('password') );
my $app = app->new( zdir => $cfg->param('zones_path'),
dbname => $cfg->param('dbname'),
dbhost => $cfg->param('host'),
dbport => $cfg->param('port'),
dbuser => $cfg->param('user'),
dbpass => $cfg->param('passwd'),
sgbd => $cfg->param('sgbd'),
dnsapp => $cfg->param('dnsapp') );
$app->init();
my $app = initco();
$app->get_domains( session('login') );
template 'index' =>
{ 'logged' => true,
'login' => session('login'),
'admin' => session('admin'),
'domains' => $app->get_domains(session('login'))
};
template index => {
logged => true
, login => session('login')
, admin => session('admin')
, domains => $app->get_domains(session('login')) };
}
else
{
@ -58,17 +62,9 @@ post '/login' => sub {
# Check user login and password
if ( param('login') && param('password') )
{
my $app = app->new( zdir => $cfg->param('zones_path'),
dbname => $cfg->param('dbname'),
dbhost => $cfg->param('host'),
dbport => $cfg->param('port'),
dbuser => $cfg->param('user'),
dbpass => $cfg->param('passwd'),
sgbd => $cfg->param('sgbd'),
dnsapp => $cfg->param('dnsapp') );
$app->init();
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(param('login'),
param('password') );
param('password') );
if( $auth_ok )
{
@ -96,118 +92,52 @@ get '/mapage' => sub {
}
else
{
# my ($auth_ok, $user, $admin) =
# $usermanagement->auth( session('login'), session('password') );
my $app = app->new( zdir => $cfg->param('zones_path'),
dbname => $cfg->param('dbname'),
dbhost => $cfg->param('host'),
dbport => $cfg->param('port'),
dbuser => $cfg->param('user'),
dbpass => $cfg->param('passwd'),
sgbd => $cfg->param('sgbd'),
dnsapp => $cfg->param('dnsapp') );
$app->init();
my $app = initco();
my %domains = ();
my %zone_properties = ();
my @d = @{$app->get_domains( session('login') )};
template mapage => {
login => session('login')
, domains => $app->get_domains(session('login'))
, zones_domains => \%domains
, zone_properties => \%zone_properties
, admin => session('admin') };
# loop on domains
#foreach( @{ $app->get_domains( session('login') )} )
#{
# my @zones = ();
# # TODO
# foreach my $zone ( $app->get_domain($_)->output() )
# {
# # avoid some var
# # keep only hash type
# if( ref($zone) eq 'HASH' )
# {
# if( $zone->{'addr'} )
# {
# unless( $zone->{'addr'} eq '@' )
# {
# # normal zone, push it
# push( @zones, $zone );
# }
# else
# {
# # domain properties
# $zone_properties{$_} = $zone;
# }
# }
# }
# }
# $domains{$_} = [ @zones ];
#}
#my @keys = keys(%domains);
#print "key : $_ value : $domains{$_}\n" foreach(@keys);
# foreach my $k ( keys %domains) {
# foreach my $v ( keys @{ $domains{$k} } ) {
# #print "dump : ".dump( $v )."\n";
# if( UNIVERSAL::isa($domains{$k}[$v], "HASH" ) )
# {
# print "hash...\n";
# print "start ------\n";
# print "$_ => $domains{$k}[$v]{$_}\n" foreach( keys $domains{$k}[$v] );
# print "end ------\n\n";
# }
# print "value : " . dump( $domains{$k}[$v] ) . "\n";
# }
# }
#print 'manual dump : ' . dump( $domains{'karchnu.fr'} )."\n";
#print 'prop dump : ' . dump( %zone_properties ) . "\n";
template 'mapage' =>
{ 'login' => session('login'),
'domains' => $app->get_domains(session('login')),
'zones_domains' => \%domains,
'zone_properties' => \%zone_properties,
'admin' => session('admin') };
}
}
};
get '/details' => sub {
# check if user is logged & if domain parameter is set
unless( session('login') && param('domain'))
{
redirect '/';
}
else
{
# check if user is logged & if domain parameter is set
unless( session('login') && param('domain'))
{
redirect '/';
}
else
{
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth( param('login') );
my @zones = ();
my $zone_properties;
#say 'dump : ' . dump $user->get_zone( param('domain') );
# my ($auth_ok, $user, $admin) =
# $usermanagement->auth( session('login'), session('password') );
my $app = app->new( zdir => $cfg->param('zones_path'),
dbname => $cfg->param('dbname'),
dbhost => $cfg->param('host'),
dbport => $cfg->param('port'),
dbuser => $cfg->param('user'),
dbpass => $cfg->param('passwd'),
sgbd => $cfg->param('sgbd'),
dnsapp => $cfg->param('dnsapp') );
$app->init();
my ($auth_ok, $user, $isadmin) = $app->auth( param('login') );
my @zones = ();
my $zone_properties;
#say 'dump : ' . dump $user->get_zone( param('domain') );
for( $user->get_zone( param('domain') ) )
{
for( $user->get_zone( param('domain') ) ) {
if( ref($_) eq 'HASH' and exists $_->{addr} ) {
push( @zones, $_ ) when $_->{addr} ne '@';
$zone_properties = $_ when $_->{addr} eq '@';
}
if( ref($_) eq 'HASH' and exists $_->{addr} ) {
push( @zones, $_ ) when $_->{addr} ne '@';
$zone_properties = $_ when $_->{addr} eq '@';
}
}
}
template 'details' =>
{ 'login' => session('login'),
'domain' => param('domain'),
'zones' => \@zones,
'zone_properties' => $zone_properties };
}
template details => {
login => session('login')
, domain => param('domain')
, zones => \@zones
, zone_properties => $zone_properties };
}
};
@ -219,9 +149,9 @@ any ['get', 'post'] => '/administration' => sub {
}
else
{
template 'administration' =>
{ 'login' => session('login'),
'admin' => session('admin') };
template administration => {
login => session('login')
, admin => session('admin') };
}
};
@ -231,23 +161,15 @@ any ['post', 'get'] => '/logout' => sub {
};
get '/domainadd' => sub {
# check if user is logged & if domain parameter is set
unless( session('login') )
{
redirect '/';
}
else
{
# check if user is logged & if domain parameter is set
unless( session('login') )
{
redirect '/';
}
else
{
my $app = app->new( zdir => $cfg->param('zones_path'),
dbname => $cfg->param('dbname'),
dbhost => $cfg->param('host'),
dbport => $cfg->param('port'),
dbuser => $cfg->param('user'),
dbpass => $cfg->param('passwd'),
sgbd => $cfg->param('sgbd'),
dnsapp => $cfg->param('dnsapp') );
$app->init();
my $app = initco();
if( param('domain') )
{
@ -257,22 +179,13 @@ get '/domainadd' => sub {
redirect '/mapage';
}
}
}
};
get qr{/domaindel/(.*)} => sub {
my ($domainToDelete) = splat;
my $app = app->new( zdir => $cfg->param('zones_path'),
dbname => $cfg->param('dbname'),
dbhost => $cfg->param('host'),
dbport => $cfg->param('port'),
dbuser => $cfg->param('user'),
dbpass => $cfg->param('passwd'),
sgbd => $cfg->param('sgbd'),
dnsapp => $cfg->param('dnsapp') );
$app->init();
my $app = initco();
$app->delete_domain(session('login'), $domainToDelete);
redirect '/mapage';
}