blob: 94ec2ef4a0c96bc4292995795735872e964f6fad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#!/bin/sh
# ONE.COM DDNS SCRIPT
# REQUIRES CURL
# $ opkg install curl
# SCRIPT BY LUGICO
# CONTACT: main@lugico.de
[ -z "$CURL" ] && [ -z "$CURL_SSL" ] && write_log 14 "one.com communication require cURL with SSL support. Please install"
[ -z "$domain" ] && write_log 14 "Service section not configured correctly! Missing 'domain'"
[ -z "$username" ] && write_log 14 "Service section not configured correctly! Missing 'username'"
[ -z "$password" ] && write_log 14 "Service section not configured correctly! Missing 'password'"
. /usr/share/libubox/jshn.sh
write_log 0 "one.com ddns script started"
local __SUBDOMAIN __MAINDOMAIN __LOGINURL __RECORDID
local __TTL=3600
COOKIEJAR=$(mktemp /tmp/one_com_cookiejar.XXXXXX) || exit 1
__SUBDOMAIN=$(echo $domain | sed -e 's/[^\.]*\.[^\.]*$//' -e 's/\.$//' )
__MAINDOMAIN=$(echo $domain | sed -e "s/${__SUBDOMAIN}\.//" )
# LOGGING IN
# GET LOGIN POST URL FROM FORM
__LOGINURL=$( $CURL \
-RsSL \
--stderr $ERRFILE \
-c $COOKIEJAR \
"https://www.one.com/admin/" \
| grep 'Login-form login autofill' \
| sed -e 's/.*action="//' -e 's/".*//' -e 's/\&/\&/g' \
)
# POST LOGIN DATA
$CURL \
-RsSL \
--stderr $ERRFILE \
-c $COOKIEJAR \
-b $COOKIEJAR \
"${__LOGINURL}" \
-H "Content-Type: application/x-www-form-urlencoded" \
-X POST \
-d "username=${username}&password=${password}&credentialId=" \
| grep "Invalid username or password." > $DATFILE
if [ "$?" == "0" ] ; then
write_log 14 "Invalid credentials"
return 1
fi
# SETTING DOMAIN
$CURL -RsSL \
--stderr $ERRFILE \
-c $COOKIEJAR \
-b $COOKIEJAR \
"https://www.one.com/admin/select-admin-domain.do?domain=${__MAINDOMAIN}" \
| grep "<meta name=\"one.com:active-domain\" content=\"${__MAINDOMAIN}\"/>" > $DATFILE
if [ "$?" != "0" ] ; then
write_log 14 "Failed to select domain '${__MAINDOMAIN}'"
return 1
fi
# GETTING RECORD ID
records=$( $CURL \
-RsSL \
--stderr $ERRFILE \
-c $COOKIEJAR \
-b $COOKIEJAR \
"https://www.one.com/admin/api/domains/${__MAINDOMAIN}/dns/custom_records"
)
json_load "$records"
if json_is_a "result" "object" && \
json_select "result" && \
json_is_a "data" "array"
then
json_select "data"
i=1
while json_is_a ${i} "object" ; do
json_select "${i}"
json_select "attributes"
json_get_var "prefix" "prefix"
json_close_object
if [ "$prefix" == "$__SUBDOMAIN" ] ; then
json_get_var "__RECORDID" "id"
write_log 0 "Found record id : ${__RECORDID}"
break
fi
json_close_object
i=$(($i + 1))
done
fi
if [ "${__RECORDID}" == "" ] ; then
write_log 14 "domain record not found"
return 1
fi
# CREATING PATCH DATA
json_init
json_add_string "type" "dns_service_records"
json_add_string "id" "${__RECORDID}"
json_add_object "attributes"
json_add_string "type" "A"
json_add_string "prefix" "${__SUBDOMAIN}"
json_add_string "content" "${__IP}"
json_add_int "ttl" ${__TTL}
patchdata=$(json_dump)
# SENDING PATCH
$CURL \
-RsSL \
--stderr $ERRFILE \
-c $COOKIEJAR \
-b $COOKIEJAR \
-X PATCH \
-d "$patchdata" \
-H "Content-Type: application/json" \
"https://www.one.com/admin/api/domains/${__MAINDOMAIN}/dns/custom_records/${__RECORDID}" \
| grep "priority" > $DATFILE
if [ "$?" != "0" ] ; then
write_log 14 "one.com gave an unexpected response"
return 1
fi
rm $COOKIEJAR
write_log 0 "one.com ddns script finished without errors"
return 0
|