Obsolete
/
dnsmanagerv1
Archived
3
0
Fork 0

Update de l'IP que si elle a changé

master^2
haseo51 2019-07-31 21:05:30 +02:00 committed by GitHub
parent abbc673368
commit 6843bc5f0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -18,6 +18,10 @@ our $domain = "test.netlib.re";
our $login = "idtest"; our $login = "idtest";
our $pass = "mdptest"; our $pass = "mdptest";
# Saving our previous IP to update only on change
our $filename = 'saved_ip.txt';
our $saved_ip = "0.0.0.0";
# Your entry to change # Your entry to change
# #
# here, the entry is www.test.netlib.re # here, the entry is www.test.netlib.re
@ -38,10 +42,27 @@ sub get_ip {
undef undef
} }
# Saving IP to file
sub save_ip {
open(my $fhw, '>', $filename) or die "Could not open file '$filename' $!";
$saved_ip = get_ip;
print $fhw "$saved_ip";
close $fhw;
}
# Loading IP from file
sub load_ip {
open(my $fho, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!";
$saved_ip = <$fho>;
}
sub update { sub update {
my $ip = get_ip; my $ip = get_ip;
die "Can't get your IP address !" unless $ip; die "Can't get your IP address !" unless $ip;
load_ip;
if ($saved_ip ne $ip) {
say "UPDATE :: domain $name.$domain => IP $ip, type $type"; say "UPDATE :: domain $name.$domain => IP $ip, type $type";
my $passb64 = encode_base64($pass); my $passb64 = encode_base64($pass);
chomp $passb64; chomp $passb64;
@ -51,6 +72,8 @@ sub update {
"https://$nddservice/domain/cliup/$login/$passb64/$domain/$name/$type/$ip"; "https://$nddservice/domain/cliup/$login/$passb64/$domain/$name/$type/$ip";
say "CMD :: $cmd"; say "CMD :: $cmd";
`$cmd`; `$cmd`;
save_ip;
}
} }
update; update;