diff --git a/www/conf/config.ini b/www/conf/config.ini index f4d9df0..3772c75 100644 --- a/www/conf/config.ini +++ b/www/conf/config.ini @@ -1,11 +1,18 @@ +# TLD +# Must contains the first "." +tld = ".netlib.re" + +# Database Options +sgbd = mysql dbname = dnsmanager host = localhost -# other options : see DBI module -sgbd = mysql + # default port for mysql port = 3306 user = bla passwd = HardPass4bla +# other options : see DBI module + # possible options for dnsserver : bind rndc dnsapp = rndc zones_path = "/srv/named/" diff --git a/www/lib/DNSManager.pm b/www/lib/DNSManager.pm index 193e9a6..ece6160 100644 --- a/www/lib/DNSManager.pm +++ b/www/lib/DNSManager.pm @@ -67,15 +67,35 @@ get '/home' => sub { my %domains = (); my %zone_properties = (); - my @d = @{$app->get_domains( session('login') )}; - - template home => { - login => session('login') - , domains => $app->get_domains(session('login')) - , zones_domains => \%domains - , zone_properties => \%zone_properties - , admin => session('admin') }; + # my @d = @{$app->get_domains( session('login') )}; + if( session('creationSuccess') || session('creationFailure') ) + { + my $cs = session('creationSuccess'); + session 'creationSuccess' => ''; + my $cf = session('creationFailure'); + session 'creationFailure' => ''; + my $dn = session('domainName'); + session 'domainName' => ''; + template home => + { 'login' => session('login'), + 'domains' => $app->get_domains(session('login')), + 'zones_domains' => \%domains, + 'zone_properties' => \%zone_properties, + 'admin' => session('admin'), + 'creationSuccess' => $cs, + 'creationFailure' => $cf, + 'domainName' => $dn }; + } + else + { + template home => + { 'login' => session('login'), + 'domains' => $app->get_domains(session('login')), + 'zones_domains' => \%domains, + 'zone_properties' => \%zone_properties, + 'admin' => session('admin') }; + } } }; @@ -137,8 +157,32 @@ prefix '/domain' => sub { else { - my $app = initco(); - $app->add_domain( session('login'), param('domain') ); + my $creationSuccess = false; + my $creationFailure = false; + if( param('domain') =~ /^[a-zA-Z0-9]+[a-zA-Z0-9-]+[a-zA-Z0-9]+$|^[a-zA-Z0-9]+$/ ) + { + + my $cfg = new Config::Simple(dirname(__FILE__).'/../conf/config.ini'); + my $domain = param('domain').$cfg->param('tld'); + # $domain =~ s/\.{2,}/\./g; + # say "domain after sed : $domain"; + # create domain + my $app = initco(); + # Add tld + # create domain + $app->add_domain( session('login'), $domain ); + $creationSuccess = true; + + } + else + { + # say param('domain')." contains a char not valid"; + $creationFailure = true; + } + + session 'creationSuccess' => $creationSuccess; + session 'creationFailure' => $creationFailure; + session 'domainName' => param('domain'); redirect '/home'; } diff --git a/www/views/home.tt b/www/views/home.tt index 6de350c..896488f 100644 --- a/www/views/home.tt +++ b/www/views/home.tt @@ -16,6 +16,17 @@
+ Le domaine "<% domainName %>" a bien été créée. +
+ <% ELSIF creationFailure == 1 %> ++ Le domaine "<% domainName %>" n'a pas été créée. +
+ <% END %> + <% IF domains && domains.size %>