告知:本程序源码来自于linux/FreeBSD下的dnspod动态域名客户端一文,由 vinoca 开发,由于 vinoca 没有开发针对 busybox 的版本,遂将其代码进行改编!请到 vinoca 博客获取源代码,再参考本文进行修改!
本文使用的源代码发布版本号: 0.0.9-2 本文案例使用的OpenWrt版本:Backfire r33081;busybox版本:v1.15.3
配置过程
1. sddns 0.0.9-2 需要curl支持:
opkg install curl
2. DnsPod API需要SSL支持,而OpenWrt(busybox)安装的curl默认无证书,需要到官方下载,并将下载完成的证书移动到指定位置:
wget http://curl.haxx.se/ca/cacert.pem
mkdir /etc/ssl
mv cacert.pem /etc/ssl/
3. 获取由 vinoca 开发的sddns 0.0.9-2:为保障原创作者权益,此处地址省略,请到作者博客查找下载链接!
4. 解压缩:
tar -xzf sddns_0.0.9-2_all.tar.gz
本条目中,修改了DnsPod的API用法( vinoca 的可能是早期的API,反正我在查手册的时候,要求是这样的!)
post() {curl $addon_opt -sL -A $SIGN --data "login_email=$login_email&login_password=$login_password&format=json&error_on_empty=no&$1" "https://dnsapi.cn/$2"}
为:
post() { curl $addon_opt -sL -X POST "https://dnsapi.cn/$2" --data "login_email=$login_email&login_password=$login_password&format=json&error_on_empty=no&$1"}
6. 修改源代码文件sddbs中get_record_id函数所使用的正则:
本条中将原有针对子域名,获取其records_id的通配方法由“.*”改为“[^}]*”以防止主机名为“@”时,修改NS或者MX记录!这个问题我遇到过,它竟然将我的一条NS记录给修改成A记录,并动态了,真是吓死个人,我以为这下彻底玩儿完,没想到原本不能配置的NS记录竟然可以新增!还可以修改回来,万幸,万幸!
sed -rn "s/.*(\"records\":\[.[^]]+\]).*/\1/g;s/.*\{\"id\":\"([0-9]+)\",\"name\":\"$1\".*\"type\":\"A\".*/\1/p"
为:
sed -rn "s/.*(\"records\":\[.[^]]+\]).*/\1/g;s/.*\{\"id\":\"([0-9]+)\",\"name\":\"$1\"[^}]*\"type\":\"A\".*/\1/p"
7. 修改采集wan口IP中的正则表达式:
这里原有的正则限定有些不足,对PPPOE用户来说(也可能是busybox用户)无法得到IP,得到的IP为空,修改后可从pppoe-wan口获取到IP
cur_wanip=`ifconfig $port | sed -n '/inet addr:/s/.*inet addr:\(.*\) Bcast:.*/\1/p'`
为:
cur_wanip=`ifconfig pppoe-wan | sed -n '/inet addr:/s/.*inet addr:\([0-9.]\{6,15\}\).*/\1/p'`
8. 修改sddns.conf文件(特别注意,要将addon_opt前面的#号去掉!):
如果是主域名,可使用@;另外如果是pppoe拨号的用户,想要使用wan口的IP,那么去掉port和mode前面的#号,并将port改为pppoe-wan,或者ifconfig一下,看看你的IP在哪个口上,这样比较准确!
login_email='[email protected]'
login_password='xxx'
main_domain='eg.com'
sub_domain='@,www'
wanip='http://c.lexun.com/ip/'
port=pppoe-wan
mode=port
addon_opt='--cacert /etc/ssl/cacert.pem'
### DOT NOT MODIFY THE FOLLOWING
9. 将sddns可执行文件放置到/usr/bin中去:
mv sddns /usr/bin/
10. 将sddns.conf配置文件放置到/etc目录中去:
mv sddns.conf /etc/
11. 删除或备份sddns_0.0.9-2_all.tar.gz
#删除:
rm sddns_0.0.9-2_all.tar.gz
#备份:
mv sddns_0.0.9-2_all.tar.gz /backup/
12. 将sddn加入任务计划:
crontab -e
在使用vi打开的文本中添加一行:
其中,“/15”表示每15分钟执行一次,
“>> /dev/null 2>&1”表示不进行任何输出(否则cron会email通知)
*/15 * * * * sddns >> /dev/null 2>&1
13.将cron设置为开机启动:
vi /etc/rc.local
在其中添加一行:
crond start
使用过程中需要注意的事项
1. 如果你修改了sddns.conf文件“### DOT NOT MODIFY THE FOLLOWING”上方的任何参数,最好将“### DOT NOT MODIFY THE FOLLOWING”下方所有的信息删除掉,否则可能会出现意想不到的意外事件!
2. 下载cacert.pem时,如果速度太慢,可以用电脑下载后上传(如果电脑使用的路由器正是openwrt所在的路由器,当电脑下载完成的时候,路由器也会同步完成。
3. 调试时不要太过频繁,(指删除“### DOT NOT MODIFY THE FOLLOWING”下方信息后执行sddns命令),每分钟不超过5次最好,否则可能有被DnsPod临时封禁账号的危险,虽然封禁时间不长,但毕竟有了案底就不好了。
备忘和参考
1. Domain.Info返参
{"status":{"code":"1","message":"Action completed successful","created_at":"2014-05-14 20:19:04"},"domain":{"id":"111","name":"vss.so","punycode":"vss.so","grade":"DP_Free","grade_title":"\u65b0\u514d\u8d39\u5957\u9910","status":"enable","ext_status":"","records":"5","group_id":"1","is_mark":"no","remark":false,"is_vip":"no","searchengine_push":"no","beian":"no","user_id":"11","created_on":"2014-01-02 18:11:20","updated_on":"2014-05-14 15:41:06","ttl":"600","owner":"[email protected]","auth_to_anquanbao":true}}
2. Record.List返参
{"status":{"code":"1","message":"Action completed successful","created_at":"2014-05-14 21:23:32"},"domain":{"id":111,"name":"vss.so","punycode":"vss.so","grade":"DP_Free","owner":"[email protected]"},"info":{"sub_domains":"5","record_total":"5"},"records":[{"id":"112","name":"@","line":"\u9ed8\u8ba4","type":"A","ttl":"600","value":"1.1.1.1","mx":"0","enabled":"1","status":"enabled","monitor_status":"","remark":"","updated_on":"2014-05-14 20:58:44","use_aqb":"no"},{"id":"113","name":"@","line":"\u9ed8\u8ba4","type":"MX","ttl":"600","value":"vss.so.","mx":"5","enabled":"1","status":"enabled","monitor_status":"","remark":"","updated_on":"2014-04-25 01:51:07","use_aqb":"no"},{"id":"114","name":"@","line":"\u9ed8\u8ba4","type":"NS","ttl":"600","value":"f1g1ns1.dnspod.net.","mx":"0","enabled":"1","status":"enabled","monitor_status":"","remark":"","updated_on":"2014-01-02 18:11:20","use_aqb":"no","hold":"hold"},{"id":"115","name":"@","line":"\u9ed8\u8ba4","type":"NS","ttl":"10","value":"f1g1ns2.dnspod.net.","mx":"0","enabled":"1","status":"enabled","monitor_status":"","remark":"","updated_on":"2014-05-14 20:58:04","use_aqb":"no","hold":"hold"},{"id":"116","name":"www","line":"\u9ed8\u8ba4","type":"A","ttl":"10","value":"1.1.1.1","mx":"0","enabled":"1","status":"enabled","monitor_status":"","remark":"","updated_on":"2014-05-14 20:51:20","use_aqb":"no"}]}