Obsolete
/
dnsmanagerv1
Archived
3
0
Fork 0

CLI disponible

master
Philippe Pittoli 2014-08-23 11:32:26 +02:00
parent dafda2310d
commit b4c55a6fd4
3 changed files with 102 additions and 0 deletions

5
cli/README.markdown Normal file
View File

@ -0,0 +1,5 @@
# mise à jour auto
Pour mettre à jour automatiquement une adresse IP d'un nom de domaine, il faut
changer les quelques valeurs du fichier daemon.pl (en haut) et avoir le
certificat du site netlib.re.

59
cli/daemon.pl Executable file
View File

@ -0,0 +1,59 @@
#!/usr/bin/perl -w
use strict;
use warnings;
use v5.14;
our $ndd = "netlib.re";
our $domain = "montest.netlib.re";
our $name = "www";
our $ttl = "3600";
our $login = "test";
our $pass = "test";
sub get_ip {
my @tmp_ip = split "\n", `wget -nv -O - http://t.karchnu.fr/ip.php`;
my $ip;
for(@tmp_ip) {
if($_ =~ /^[0-9.]+$/ || $_ =~ /^[0-9a-f:]+$/) {
$ip = $_;
}
}
$ip;
}
sub update {
my $ip = get_ip;
my $type;
if($ip =~ /:/) {
$type = "AAAA";
}
else {
$type = "A";
}
my $todig;
if($name =~ '@') {
$todig = $domain;
}
else {
$todig = "$name.$domain";
}
my $oldhost = `dig +short $todig`;
chomp $oldhost;
say "domain $domain";
say "name $name";
say "type $type";
say "oldhost $oldhost";
say "ttl $ttl";
say "ip $ip";
#say "wget -O - https://$ndd/domain/cli/$login/$pass/$domain/$name/$type/$oldhost/$ttl/$ip --ca-certificate=ca.cert";
say `wget -O - https://$ndd/domain/cli/$login/$pass/$domain/$name/$type/$oldhost/$ttl/$ip --ca-certificate=ca.cert`;
}
update;

View File

@ -464,6 +464,44 @@ prefix '/domain' => sub {
redirect '/domain/details/'. param('domain');
};
get '/cli/:login/:pass/:domain/:name/:type/:host/:ttl/:ip' => sub {
my $pass = sha256_hex(param('pass'));
my $app = initco();
my ($auth_ok, $user, $isadmin) = $app->auth(param('login'), $pass);
unless ( $auth_ok && ( $isadmin
|| grep { $_ =~ param('domain') } @{$user->domains})) {
say "ERROR";
return;
}
my $name = param('name');
my $domain = param('domain');
my $type = param('type');
my $host = param('host');
my $ttl = param('ttl');
my $ip = param('ip');
$app->modify_entry( param('domain'),
{
type => $type
, name => $name
, host => $host
, ttl => $ttl
},
{
newtype => $type
, newname => $name
, newhost => $ip
, newttl => $ttl
, newpriority => ''
});
say "OK";
};
};
any ['get', 'post'] => '/admin' => sub {