Skip to content

Commit

Permalink
fix issue metioned in #1
Browse files Browse the repository at this point in the history
  • Loading branch information
honwen committed Aug 16, 2017
1 parent 00e8107 commit 0b86c7f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=luci-app-aliddns
PKG_VERSION:=0.1.2
PKG_VERSION:=0.1.3
PKG_RELEASE:=1

PKG_LICENSE:=MIT
Expand Down
30 changes: 24 additions & 6 deletions files/root/etc/init.d/aliddns
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
#!/bin/sh /etc/rc.common

START=80
NAME=aliddns

NE_TIPS='AliDDNS NOT ENABLED'

restart() {
start
}

uci_get_by_name() {
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
echo ${ret:=$3}
}

uci_bool_by_name() {
case "$(uci_get_by_name $1 $2)" in
1|on|true|yes|enabled) return 0;;
esac
return 1
}

start() {
[ "Z$(uci -q get aliddns.base.enable)" != "Z1" ] && ( echo "AliDDNS NOT ENABLED!" > /var/log/aliddns.log ) && exit 0
sed -i '/AliDDNS NOT ENABLED/d' /var/log/aliddns.log
$(uci_bool_by_name base enable) || {
stop
return 0
}
sed -i "/${NE_TIPS}/d" /var/log/aliddns.log

time=`uci -q get aliddns.base.time 2>/dev/null`
[ "Z$time" == "Z" ] && time=10
time=$(uci_get_by_name base time 10)
[ 0 -lt $time -a $time -lt 60 ] || time=10

sed -i '/aliddns/d' /etc/crontabs/root
echo "*/$time * * * * /usr/sbin/aliddns >> /var/log/aliddns.log 2>&1" >> /etc/crontabs/root
/etc/init.d/cron restart
/usr/sbin/aliddns

( /usr/sbin/aliddns >> /var/log/aliddns.log 2>&1 ) &
}

stop() {
sed -i '/aliddns/d' /etc/crontabs/root
/etc/init.d/cron restart
echo "AliDDNS NOT ENABLED!" > /var/log/aliddns.log
echo "${NE_TIPS}" > /var/log/aliddns.log
}
27 changes: 17 additions & 10 deletions files/root/usr/sbin/aliddns
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/bin/sh
#/bin/sh

ak_id=$(uci -q get aliddns.base.app_key)
ak_sec=$(uci -q get aliddns.base.app_secret)
rrid=$(uci -q get aliddns.base.record_id)
main_dm=$(uci -q get aliddns.base.main_domain)
sub_dm=$(uci -q get aliddns.base.sub_domain)
iface=$(uci -q get aliddns.base.interface)
NAME=aliddns

uci_get_by_name() {
local ret=$(uci get $NAME.$1.$2 2>/dev/null)
echo ${ret:=$3}
}

ak_id=$(uci_get_by_name base app_key)
ak_sec=$(uci_get_by_name base app_secret)
rrid=$(uci_get_by_name base record_id)
main_dm=$(uci_get_by_name base main_domain)
sub_dm=$(uci_get_by_name base sub_domain)
iface=$(uci_get_by_name base interface)

DATE=$(date +'%Y-%m-%d %H:%M:%S')
timestamp=$(date -u "+%Y-%m-%dT%H%%3A%M%%3A%SZ")
Expand Down Expand Up @@ -91,7 +98,7 @@ do_ddns_record() {
fi
if [ "Z$rrid" == "Z" ]; then
# failed
echo "$DATE # ERROR, Please Check Config/Time"
echo "$DATE # ERROR, Please Check Config/Time"
else
# save rrid
uci set aliddns.base.record_id=$rrid
Expand All @@ -103,12 +110,12 @@ do_ddns_record() {
clean_log() {
if [ $(cat $log_file 2>/dev/null | wc -l) -ge 16 ]; then
rm -f $log_file && touch $log_file
echo "$DATE Log Cleaned"
echo "$DATE Log Cleaned"
fi
}

[ -x /usr/bin/openssl -a -x /usr/bin/curl -a -x /bin/sed ] ||
( echo "Need openssl + curl + sed !" && exit 1 )
( echo "Need [ openssl + curl + sed ]" && exit 1 )

clean_log
check_aliddns || do_ddns_record

0 comments on commit 0b86c7f

Please sign in to comment.