From b4c55a6fd474b4190a86e211fb923f7f3ba3545f Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 23 Aug 2014 11:32:26 +0200 Subject: [PATCH] CLI disponible --- cli/README.markdown | 5 ++++ cli/daemon.pl | 59 +++++++++++++++++++++++++++++++++++++++++++ www/lib/DNSManager.pm | 38 ++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 cli/README.markdown create mode 100755 cli/daemon.pl diff --git a/cli/README.markdown b/cli/README.markdown new file mode 100644 index 0000000..8d7e464 --- /dev/null +++ b/cli/README.markdown @@ -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. diff --git a/cli/daemon.pl b/cli/daemon.pl new file mode 100755 index 0000000..e317aac --- /dev/null +++ b/cli/daemon.pl @@ -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; diff --git a/www/lib/DNSManager.pm b/www/lib/DNSManager.pm index ef954ca..fa70591 100755 --- a/www/lib/DNSManager.pm +++ b/www/lib/DNSManager.pm @@ -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 {