Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
ca1d62be
Unverified
Commit
ca1d62be
authored
May 15, 2018
by
linux-insideDE
Committed by
GitHub
May 15, 2018
Browse files
removed jq dependencies
parent
6a4aad1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_netcup.sh
View file @
ca1d62be
#!/usr/bin/env sh
#!/usr/bin/env sh
#Requirments: jq
#developed by linux-insideDE
#developed by linux-insideDE
NC_Apikey
=
"
${
NC_Apikey
:-
$(
_readaccountconf_mutable NC_Apikey
)
}
"
NC_Apikey
=
"
${
NC_Apikey
:-
$(
_readaccountconf_mutable NC_Apikey
)
}
"
...
@@ -58,7 +58,7 @@ dns_netcup_add() {
...
@@ -58,7 +58,7 @@ dns_netcup_add() {
tmp
=
$(
echo
"
$fulldomain
"
|
cut
-d
'.'
-f
$inc
)
tmp
=
$(
echo
"
$fulldomain
"
|
cut
-d
'.'
-f
$inc
)
msg
=
$(
_post
"{
\"
action
\"
:
\"
updateDnsRecords
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
,
\"
clientrequestid
\"
:
\"
$client
\"
,
\"
domainname
\"
:
\"
$domain
.
$tld
\"
,
\"
dnsrecordset
\"
: {
\"
dnsrecords
\"
: [ {
\"
id
\"
:
\"\"
,
\"
hostname
\"
:
\"
$tmp
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
priority
\"
:
\"\"
,
\"
destination
\"
:
\"
$txtvalue
\"
,
\"
deleterecord
\"
:
\"
false
\"
,
\"
state
\"
:
\"
yes
\"
} ]}}}"
"
$end
"
""
"POST"
)
msg
=
$(
_post
"{
\"
action
\"
:
\"
updateDnsRecords
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
,
\"
clientrequestid
\"
:
\"
$client
\"
,
\"
domainname
\"
:
\"
$domain
.
$tld
\"
,
\"
dnsrecordset
\"
: {
\"
dnsrecords
\"
: [ {
\"
id
\"
:
\"\"
,
\"
hostname
\"
:
\"
$tmp
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
priority
\"
:
\"\"
,
\"
destination
\"
:
\"
$txtvalue
\"
,
\"
deleterecord
\"
:
\"
false
\"
,
\"
state
\"
:
\"
yes
\"
} ]}}}"
"
$end
"
""
"POST"
)
_debug
"
$msg
"
_debug
"
$msg
"
if
[
"
$(
echo
"
$msg
"
| jq
-r
.status
)
"
!=
"success"
]
;
then
if
[
"
$(
_getfield
"
$msg
"
"4"
|
sed
s/
\"
status
\"
:
\"
//g |
sed
s/
\"
//g
)
"
!=
"success"
]
;
then
_err
"
$msg
"
_err
"
$msg
"
return
1
return
1
fi
fi
...
@@ -106,10 +106,29 @@ dns_netcup_rm() {
...
@@ -106,10 +106,29 @@ dns_netcup_rm() {
tmp
=
$(
echo
"
$fulldomain
"
|
cut
-d
'.'
-f
$inc
)
tmp
=
$(
echo
"
$fulldomain
"
|
cut
-d
'.'
-f
$inc
)
doma
=
"
$domain
.
$tld
"
doma
=
"
$domain
.
$tld
"
rec
=
$(
getRecords
"
$doma
"
)
rec
=
$(
getRecords
"
$doma
"
)
ids
=
$(
echo
"
$rec
"
| jq
-r
".[]|select(.destination==
\"
$txtvalue
\"
)|.id"
)
ida
=
0000
idv
=
0001
ids
=
0000000000
i
=
1
while
[
"
$i
"
-ne
0
]
;
do
specrec
=
$(
_getfield
"
$rec
"
"
$i
"
";"
)
idv
=
"
$ida
"
ida
=
$(
_getfield
"
$specrec
"
"1"
","
|
sed
's/\"id\":\"//g'
|
sed
's/\"//g'
)
txtv
=
$(
_getfield
"
$specrec
"
"5"
","
|
sed
's/\"destination\":\"//g'
|
sed
's/\"//g'
)
i
=
$(
_math
"
$i
"
+ 1
)
if
[
"
$txtvalue
"
=
"
$txtv
"
]
;
then
i
=
0
ids
=
"
$ida
"
fi
if
[
"
$ida
"
=
"
$idv
"
]
;
then
i
=
0
fi
done
msg
=
$(
_post
"{
\"
action
\"
:
\"
updateDnsRecords
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
,
\"
clientrequestid
\"
:
\"
$client
\"
,
\"
domainname
\"
:
\"
$doma
\"
,
\"
dnsrecordset
\"
: {
\"
dnsrecords
\"
: [ {
\"
id
\"
:
\"
$ids
\"
,
\"
hostname
\"
:
\"
$tmp
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
priority
\"
:
\"\"
,
\"
destination
\"
:
\"
$txtvalue
\"
,
\"
deleterecord
\"
:
\"
TRUE
\"
,
\"
state
\"
:
\"
yes
\"
} ]}}}"
"
$end
"
""
"POST"
)
msg
=
$(
_post
"{
\"
action
\"
:
\"
updateDnsRecords
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
,
\"
clientrequestid
\"
:
\"
$client
\"
,
\"
domainname
\"
:
\"
$doma
\"
,
\"
dnsrecordset
\"
: {
\"
dnsrecords
\"
: [ {
\"
id
\"
:
\"
$ids
\"
,
\"
hostname
\"
:
\"
$tmp
\"
,
\"
type
\"
:
\"
TXT
\"
,
\"
priority
\"
:
\"\"
,
\"
destination
\"
:
\"
$txtvalue
\"
,
\"
deleterecord
\"
:
\"
TRUE
\"
,
\"
state
\"
:
\"
yes
\"
} ]}}}"
"
$end
"
""
"POST"
)
_debug
"
$msg
"
_debug
"
$msg
"
if
[
"
$(
echo
"
$msg
"
| jq
-r
.status
)
"
!=
"success"
]
;
then
if
[
"
$(
_getfield
"
$msg
"
"4"
|
sed
s/
\"
status
\"
:
\"
//g |
sed
s/
\"
//g
)
"
!=
"success"
]
;
then
_err
"
$msg
"
_err
"
$msg
"
return
1
return
1
fi
fi
...
@@ -117,30 +136,28 @@ dns_netcup_rm() {
...
@@ -117,30 +136,28 @@ dns_netcup_rm() {
}
}
login
()
{
login
()
{
tmp
=
$(
_post
"{
\"
action
\"
:
\"
login
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apipassword
\"
:
\"
$NC_Apipw
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
}}"
"
$end
"
""
"POST"
)
tmp
=
$(
_post
"{
\"
action
\"
:
\"
login
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apipassword
\"
:
\"
$NC_Apipw
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
}}"
"
$end
"
""
"POST"
)
sid
=
$(
echo
"
$tmp
"
| jq
-r
.
responsedata
.
apisessionid
)
sid
=
$(
_getfield
"
$tmp
"
"8"
|
sed
s/
\"
responsedata
\"
:
\{\"
apisessionid
\"
:
\"
//g |
sed
's/\"\}\}//g'
)
_debug
"
$tmp
"
_debug
"
$tmp
"
if
[
"
$(
echo
"
$tmp
"
| jq
-r
.status
)
"
!=
"success"
]
;
then
if
[
"
$(
_getfield
"
$msg
"
"4"
|
sed
s/
\"
status
\"
:
\"
//g |
sed
s/
\"
//g
)
"
!=
"success"
]
;
then
_err
"
$
tmp
"
_err
"
$
msg
"
return
1
return
1
fi
fi
}
}
logout
()
{
logout
()
{
tmp
=
$(
_post
"{
\"
action
\"
:
\"
logout
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
}}"
"
$end
"
""
"POST"
)
tmp
=
$(
_post
"{
\"
action
\"
:
\"
logout
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
}}"
"
$end
"
""
"POST"
)
_debug
"
$tmp
"
_debug
"
$tmp
"
if
[
"
$(
echo
"
$tmp
"
| jq
-r
.status
)
"
!=
"success"
]
;
then
if
[
"
$(
_getfield
"
$msg
"
"4"
|
sed
s/
\"
status
\"
:
\"
//g |
sed
s/
\"
//g
)
"
!=
"success"
]
;
then
_err
"
$
tmp
"
_err
"
$
msg
"
return
1
return
1
fi
fi
}
}
getRecords
()
{
getRecords
()
{
tmp2
=
$(
_post
"{
\"
action
\"
:
\"
infoDnsRecords
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
,
\"
domainname
\"
:
\"
$1
\"
}}"
"
$end
"
""
"POST"
)
tmp2
=
$(
_post
"{
\"
action
\"
:
\"
infoDnsRecords
\"
,
\"
param
\"
: {
\"
apikey
\"
:
\"
$NC_Apikey
\"
,
\"
apisessionid
\"
:
\"
$sid
\"
,
\"
customernumber
\"
:
\"
$NC_CID
\"
,
\"
domainname
\"
:
\"
$1
\"
}}"
"
$end
"
""
"POST"
)
xxd
=
$(
echo
"
$tmp2
"
| jq
-r
".responsedata.dnsrecords"
|
tr
'['
' '
|
tr
']'
' '
)
echo
$(
echo
"
$tmp2
"
|
sed
's/\[//g'
|
sed
's/\]//g'
|
sed
's/{\"serverrequestid\".*\"dnsrecords\"://g'
|
sed
's/},{/};{/g'
|
sed
's/{//g'
|
sed
's/}//g'
)
xcd
=
$(
echo
"
$xxd
"
|
sed
's/}\s{/},{/g'
)
echo
"[
$xcd
]"
_debug
"
$tmp2
"
_debug
"
$tmp2
"
if
[
"
$(
echo
"
$tmp2
"
| jq
-r
.status
)
"
!=
"success"
]
;
then
if
[
"
$(
_getfield
"
$msg
"
"4"
|
sed
s/
\"
status
\"
:
\"
//g |
sed
s/
\"
//g
)
"
!=
"success"
]
;
then
_err
"
$
tmp2
"
_err
"
$
msg
"
return
1
return
1
fi
fi
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment