代码拉取完成,页面将自动刷新
同步操作将从 F.Y/perl_dnspod_ddns 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/perl
# author : fy@yiyou.org
# 2015-01-12
# http://www.yiyou.org
use strict;
use warnings;
#use Smart::Comments; #uncomment to DEBUG
use dnspodApi;
use HTTP::Tiny;
use utf8;
use DB_File;
use Data::Dumper;
use Log::Log4perl qw(:easy);
#------- CONFIG ------#
my $domain = 'yiyou.org';
my $sub_domain = 'home';
my $email = ''; #dnspod account
my $password = ''; #dnspod password
#------ END CONFIG -------#
Log::Log4perl->init(\ qq{
log4perl.logger = DEBUG, FileApp
log4perl.appender.FileApp = Log::Log4perl::Appender::File
log4perl.appender.FileApp.filename = /var/log/dnspod_ddns.log
log4perl.appender.FileApp.owner = root
# this umask is only temporary
log4perl.appender.FileApp.umask = 0133
log4perl.appender.FileApp.layout = PatternLayout
log4perl.appender.FileApp.layout.ConversionPattern = %d %m%n
});
my $tiny = HTTP::Tiny->new->get('http://members.3322.org/dyndns/getip');
my $ip;
if($tiny->{success}){
$ip = $tiny->{content};
chomp $ip;
my %ipcache;
tie(%ipcache, 'DB_File','/dev/shm/lastip'.$sub_domain.$domain, O_CREAT|O_RDWR, 0666, $DB_BTREE)
or die "Cannot open file : $!\n";
if($ipcache{lastip} && $ipcache{lastip} eq $ip){
# INFO "ip not update\n";
}else{
$ipcache{lastip}=$ip;
INFO "IP update:".$ip;
updateip($email,$password,$domain,$sub_domain,$ip);
}
}else{
ERROR "can't get ip\n";
}
sub updateip{
my $email = shift;
my $password = shift;
my $domain = shift;
my $sub_domain = shift;
my $ip = shift;
my $obj = dnspodApi->new(
email => $email,
password => $password
);
my $res = $obj->DomainId({domain => $domain});
### $res;
my $domainid;
if($res->{status}->{code}){
$domainid=$res->{domains}->{id};
}else{
ERROR $res->{status}->{message};
return ;
}
my $recordlist = $obj->RecordList({domain_id=>$domainid});
### $recordlist;
unless($recordlist->{status}->{code}){
ERROR $recordlist->{status}->{message};
return ;
}
my $sub_id;
for my $r(@{$recordlist->{records}}){
if($r->{name} eq $sub_domain){
$sub_id=$r->{id};
last;
}
}
unless ($sub_id){
ERROR "sub domain not found ,please add on your DNSPOD\n";
return ;
}
my $result=$obj->RecordDdns({
domain_id=>$domainid
,record_id=>$sub_id
,sub_domain=>$sub_domain
,record_line=>'默认'
,value=>$ip
});
### $result
if($result->{status}->{code}){
# INFO "SUCCESS!\n";
}else{
ERROR "FAIL!\n";
ERROR $result->{status}->{message}."\n";
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。