CLI disponible

master
Philippe Pittoli 10 years ago
parent dafda2310d
commit b4c55a6fd4

@ -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.

@ -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;

@ -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 {

Loading…
Cancel
Save