You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
6.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. #!/usr/bin/env sh
  2. #
  3. #INWX_User="username"
  4. #
  5. #INWX_Password="password"
  6. INWX_Api="https://api.domrobot.com/xmlrpc/"
  7. ######## Public functions #####################
  8. #Usage: add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  9. dns_inwx_add() {
  10. fulldomain=$1
  11. txtvalue=$2
  12. INWX_User="${INWX_User:-$(_readaccountconf_mutable INWX_User)}"
  13. INWX_Password="${INWX_Password:-$(_readaccountconf_mutable INWX_Password)}"
  14. if [ -z "$INWX_User" ] || [ -z "$INWX_Password" ]; then
  15. INWX_User=""
  16. INWX_Password=""
  17. _err "You don't specify inwx user and password yet."
  18. _err "Please create you key and try again."
  19. return 1
  20. fi
  21. #save the api key and email to the account conf file.
  22. _saveaccountconf_mutable INWX_User "$INWX_User"
  23. _saveaccountconf_mutable INWX_Password "$INWX_Password"
  24. _debug "First detect the root zone"
  25. if ! _get_root "$fulldomain"; then
  26. _err "invalid domain"
  27. return 1
  28. fi
  29. _debug _sub_domain "$_sub_domain"
  30. _debug _domain "$_domain"
  31. _info "Adding record"
  32. _inwx_add_record "$_domain" "$_sub_domain" "$txtvalue"
  33. }
  34. #fulldomain txtvalue
  35. dns_inwx_rm() {
  36. fulldomain=$1
  37. txtvalue=$2
  38. INWX_User="${INWX_User:-$(_readaccountconf_mutable INWX_User)}"
  39. INWX_Password="${INWX_Password:-$(_readaccountconf_mutable INWX_Password)}"
  40. if [ -z "$INWX_User" ] || [ -z "$INWX_Password" ]; then
  41. INWX_User=""
  42. INWX_Password=""
  43. _err "You don't specify inwx user and password yet."
  44. _err "Please create you key and try again."
  45. return 1
  46. fi
  47. #save the api key and email to the account conf file.
  48. _saveaccountconf_mutable INWX_User "$INWX_User"
  49. _saveaccountconf_mutable INWX_Password "$INWX_Password"
  50. _debug "First detect the root zone"
  51. if ! _get_root "$fulldomain"; then
  52. _err "invalid domain"
  53. return 1
  54. fi
  55. _debug _sub_domain "$_sub_domain"
  56. _debug _domain "$_domain"
  57. _debug "Getting txt records"
  58. xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
  59. <methodCall>
  60. <methodName>nameserver.info</methodName>
  61. <params>
  62. <param>
  63. <value>
  64. <struct>
  65. <member>
  66. <name>domain</name>
  67. <value>
  68. <string>%s</string>
  69. </value>
  70. </member>
  71. <member>
  72. <name>type</name>
  73. <value>
  74. <string>TXT</string>
  75. </value>
  76. </member>
  77. <member>
  78. <name>name</name>
  79. <value>
  80. <string>%s</string>
  81. </value>
  82. </member>
  83. </struct>
  84. </value>
  85. </param>
  86. </params>
  87. </methodCall>' "$_domain" "$_sub_domain")
  88. response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
  89. if ! _contains "$response" "Command completed successfully"; then
  90. _err "Error could not get txt records"
  91. return 1
  92. fi
  93. if ! printf "%s" "$response" | grep "count" >/dev/null; then
  94. _info "Do not need to delete record"
  95. else
  96. _record_id=$(printf '%s' "$response" | _egrep_o '.*(<member><name>record){1}(.*)([0-9]+){1}' | _egrep_o '<name>id<\/name><value><int>[0-9]+' | _egrep_o '[0-9]+')
  97. _info "Deleting record"
  98. _inwx_delete_record "$_record_id"
  99. fi
  100. }
  101. #################### Private functions below ##################################
  102. _inwx_login() {
  103. xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
  104. <methodCall>
  105. <methodName>account.login</methodName>
  106. <params>
  107. <param>
  108. <value>
  109. <struct>
  110. <member>
  111. <name>user</name>
  112. <value>
  113. <string>%s</string>
  114. </value>
  115. </member>
  116. <member>
  117. <name>pass</name>
  118. <value>
  119. <string>%s</string>
  120. </value>
  121. </member>
  122. </struct>
  123. </value>
  124. </param>
  125. </params>
  126. </methodCall>' $INWX_User $INWX_Password)
  127. response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
  128. printf "Cookie: %s" "$(grep "domrobot=" "$HTTP_HEADER" | grep "^Set-Cookie:" | _tail_n 1 | _egrep_o 'domrobot=[^;]*;' | tr -d ';')"
  129. }
  130. _get_root() {
  131. domain=$1
  132. _debug "get root"
  133. domain=$1
  134. i=2
  135. p=1
  136. _H1=$(_inwx_login)
  137. export _H1
  138. xml_content='<?xml version="1.0" encoding="UTF-8"?>
  139. <methodCall>
  140. <methodName>nameserver.list</methodName>
  141. </methodCall>'
  142. response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
  143. while true; do
  144. h=$(printf "%s" "$domain" | cut -d . -f $i-100)
  145. _debug h "$h"
  146. if [ -z "$h" ]; then
  147. #not valid
  148. return 1
  149. fi
  150. if _contains "$response" "$h"; then
  151. _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$p)
  152. _domain="$h"
  153. return 0
  154. fi
  155. p=$i
  156. i=$(_math "$i" + 1)
  157. done
  158. return 1
  159. }
  160. _inwx_delete_record() {
  161. record_id=$1
  162. xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
  163. <methodCall>
  164. <methodName>nameserver.deleteRecord</methodName>
  165. <params>
  166. <param>
  167. <value>
  168. <struct>
  169. <member>
  170. <name>id</name>
  171. <value>
  172. <int>%s</int>
  173. </value>
  174. </member>
  175. </struct>
  176. </value>
  177. </param>
  178. </params>
  179. </methodCall>' "$record_id")
  180. response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
  181. if ! printf "%s" "$response" | grep "Command completed successfully" >/dev/null; then
  182. _err "Error"
  183. return 1
  184. fi
  185. return 0
  186. }
  187. _inwx_update_record() {
  188. record_id=$1
  189. txtval=$2
  190. xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
  191. <methodCall>
  192. <methodName>nameserver.updateRecord</methodName>
  193. <params>
  194. <param>
  195. <value>
  196. <struct>
  197. <member>
  198. <name>content</name>
  199. <value>
  200. <string>%s</string>
  201. </value>
  202. </member>
  203. <member>
  204. <name>id</name>
  205. <value>
  206. <int>%s</int>
  207. </value>
  208. </member>
  209. </struct>
  210. </value>
  211. </param>
  212. </params>
  213. </methodCall>' "$txtval" "$record_id")
  214. response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
  215. if ! printf "%s" "$response" | grep "Command completed successfully" >/dev/null; then
  216. _err "Error"
  217. return 1
  218. fi
  219. return 0
  220. }
  221. _inwx_add_record() {
  222. domain=$1
  223. sub_domain=$2
  224. txtval=$3
  225. xml_content=$(printf '<?xml version="1.0" encoding="UTF-8"?>
  226. <methodCall>
  227. <methodName>nameserver.createRecord</methodName>
  228. <params>
  229. <param>
  230. <value>
  231. <struct>
  232. <member>
  233. <name>domain</name>
  234. <value>
  235. <string>%s</string>
  236. </value>
  237. </member>
  238. <member>
  239. <name>type</name>
  240. <value>
  241. <string>TXT</string>
  242. </value>
  243. </member>
  244. <member>
  245. <name>content</name>
  246. <value>
  247. <string>%s</string>
  248. </value>
  249. </member>
  250. <member>
  251. <name>name</name>
  252. <value>
  253. <string>%s</string>
  254. </value>
  255. </member>
  256. </struct>
  257. </value>
  258. </param>
  259. </params>
  260. </methodCall>' "$domain" "$txtval" "$sub_domain")
  261. response="$(_post "$xml_content" "$INWX_Api" "" "POST")"
  262. if ! printf "%s" "$response" | grep "Command completed successfully" >/dev/null; then
  263. _err "Error"
  264. return 1
  265. fi
  266. return 0
  267. }