Skip to content

Commit

Permalink
Release 0.1.3
Browse files Browse the repository at this point in the history
* Cross-merge changes from acme-dns-nc (closes #13, closes #14, closes #15)
* Use message.poll instead of account.info for session check (closes #5)
* Update testscript (closes #16)
* Fix persistent connections
* Update README
  • Loading branch information
killerbees19 committed May 30, 2018
1 parent c8a74f9 commit 9e68187
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 42 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Important: This project is **not** affiliated with INWX GmbH!
## Important links...
* [Bugtracker](https://github.com/froonix/acme-dns-inwx/issues)
* [Wiki pages](https://github.com/froonix/acme-dns-inwx/wiki)
* [INWX DNS API](https://www.inwx.com/en/offer/api)
* [INWX DNS-API (DE)](https://www.inwx.com/de/offer/api)
* [INWX DNS-API (EN)](https://www.inwx.com/en/offer/api)
* [Let's Encrypt](https://letsencrypt.org/)

[1]: https://letsencrypt.org/docs/client-options/
Expand Down
51 changes: 27 additions & 24 deletions scripts/acme-dns-inwx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* *
* ACME-DNS-INWX *
* ------------------------------------------------------------------ *
* v0.1.2 (2018-05-26) *
* v0.1.3 (2018-05-30) *
* *
* Author: Christian Schrötter <[email protected]> *
* License: GNU GENERAL PUBLIC LICENSE (Version 3) *
Expand Down Expand Up @@ -63,7 +63,7 @@ if($argc < 2 || $argc > 3)
exit(1);
}

$hostname = $argv[1];
$hostname = strtolower($argv[1]);
$recordvalue = isset($argv[2]) ? $argv[2] : null;

# TODO: Read path from ENV var?
Expand Down Expand Up @@ -228,6 +228,8 @@ class INWX

if($_)
{
clearstatcache();

if(!file_exists($this->persistent))
{
if(!touch($this->persistent))
Expand All @@ -250,16 +252,23 @@ class INWX
}
else
{
if($this->persistent && file_exists($this->persistent))
{
unlink($this->persistent);
}
$this->destroySessionStorage();
}
}

private function destroySessionStorage()
{
clearstatcache();

$this->persistent = false;
$this->setOpt(CURLOPT_COOKIEJAR, '');
$this->setOpt(CURLOPT_COOKIEFILE, '');
$this->setOpt(CURLOPT_COOKIESESSION, true);
if($this->persistent && file_exists($this->persistent))
{
unlink($this->persistent);
}

$this->persistent = false;
$this->setOpt(CURLOPT_COOKIEJAR, '');
$this->setOpt(CURLOPT_COOKIEFILE, '');
$this->setOpt(CURLOPT_COOKIESESSION, true);
}

public function setAuthData($username, $password, $secret = '')
Expand Down Expand Up @@ -301,7 +310,8 @@ class INWX

$this->setOpt(CURLOPT_POSTFIELDS, xmlrpc_encode_request(strtolower(sprintf('%s.%s', $object, $method)), $args, ['verbosity' => 'no_white_space', 'escaping' => 'markup', 'encoding' => 'UTF-8']));

for($i = 0; $i < 5; $i++)
#for($i = 0; $i < 5; $i++)
for($i = 0; $i < 1; $i++)
{
// Send action with cleaned arguments to syslog. Retries will be logged too!
syslog(LOG_INFO, sprintf('%s.%s: %s', $object, $method, json_encode($safe_args)));
Expand All @@ -327,7 +337,6 @@ class INWX
}

$result = xmlrpc_decode($result, 'UTF-8');
#sleep(mt_rand(3, 8)); // <-- required?

if($return && $result['code'] === 2303)
{
Expand All @@ -350,32 +359,26 @@ class INWX
private function logout()
{
$this->doRequest('account', 'logout');
$this->destroySessionStorage();
}

public function login()
{
if($this->persistent)
clearstatcache();

if($this->persistent && file_exists($this->persistent) && filesize($this->persistent))
{
try
{
$this->doRequest('account', 'info');
#$this->doRequest('account', 'info');
$this->doRequest('message', 'poll');
return;
}
catch(RuntimeException $e)
{
# TODO: Check for code 2002?
# ...

try
{
$this->logout();
}
catch(Exception $e)
{
// Ignore all errors, it does not matter.
// Otherwise we would get strange errors!
}

$this->resetSessionStorage();
}
}
Expand Down
49 changes: 32 additions & 17 deletions tests/simple-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# First simple test script for ACME-DNS-INWX. #
# Try to add and delete 100 random records. #
# #
# Example: simple-test.sh fnx.li ns1.fnx.li #
# Example: simple-test.sh example.org \ #
# ns.domrobot.com #
# #
###############################################

Expand All @@ -13,7 +14,7 @@ cd "$(dirname "$(readlink -f "$0")")"

DOMAIN=${1-}; NS=${2-DEFAULT}
SCRIPT=${3-../scripts/acme-dns-inwx}
WAIT_DNS=60; WAIT_CACHE=301; WAIT_NEXT=10
WAIT_TRIES=100; WAIT_DNS=12; WAIT_NEXT=5
CHALLENGE_PREFIX="_acme-challenge"

if [[ "$DOMAIN" == "" ]]; then echo "Usage: $0 <domain> [<primary-nameserver> [<path-to-script>]]" 1>&2; exit 1
Expand Down Expand Up @@ -54,15 +55,22 @@ do
continue
fi

# Wait for the primary NS to update its zone...
status "${YELLOW}WAIT#1${RESET}" "$hostname"
sleep "$WAIT_DNS"
final=-1
for((w=1; w<=WAIT_TRIES; w++))
do
# Wait for the primary NS to update its zone...
status "${YELLOW}WAIT#1${RESET}" "$hostname" "($w/$WAIT_TRIES) "
sleep "$WAIT_DNS"

# Check the DNS record.
status "${YELLOW}CHK #1${RESET}" "$hostname"
return=0; dig +short "TXT" "$CHALLENGE_PREFIX.$hostname" "$NS" 1>"$tmpfile" 2>/dev/null || return=$? && :
# Check the DNS record.
status "${YELLOW}CHK #1${RESET}" "$hostname"
return=0; dig +short "TXT" "$CHALLENGE_PREFIX.$hostname" "$NS" 1>"$tmpfile" 2>/dev/null || return=$? && :

if [[ "$return" != "0" || "$(cat "$tmpfile")" != "\"$txtvalue\"" ]]
if [[ "$return" == "0" && "$(cat "$tmpfile")" == "\"$txtvalue\"" ]]
then final=0; break; else final=1; fi
done

if [[ "$final" != "0" ]]
then
status "${RED}CHK #1${RESET}" "$hostname" "Failed! (value not found in DNS)"
continue
Expand All @@ -78,22 +86,29 @@ do
continue
fi

# Wait for the DNS cache to expire...
status "${YELLOW}WAIT#2${RESET}" "$hostname"
sleep "$WAIT_CACHE"
final=-1
for((w=1; w<=WAIT_TRIES; w++))
do
# Wait for the DNS cache to expire...
status "${YELLOW}WAIT#2${RESET}" "$hostname" "($w/$WAIT_TRIES) "
sleep "$WAIT_DNS"

# Check the DNS record.
status "${YELLOW}CHK #2${RESET}" "$hostname"
return=0; dig +short "TXT" "$CHALLENGE_PREFIX.$hostname" "${NS}" 1>"$tmpfile" 2>/dev/null || return=$? && :

# Check the DNS record.
status "${YELLOW}CHK #2${RESET}" "$hostname"
return=0; dig +short "TXT" "$CHALLENGE_PREFIX.$hostname" "${NS}" 1>"$tmpfile" 2>/dev/null || return=$? && :
if [[ "$return" == "0" && "$(cat "$tmpfile")" == "" ]]
then final=0; break; else final=1; fi
done

if [[ "$return" != "0" || "$(cat "$tmpfile")" != "" ]]
if [[ "$final" != "0" ]]
then
status "${RED}CHK #2${RESET}" "$hostname" "Failed! (record still exists)"
continue
fi

# Wait for the next test run...
status "${GREEN} OK ${RESET}" "$hostname" "Success!"
status "${GREEN} OK ${RESET}" "$hostname" "Success! "
sleep "$WAIT_NEXT"

done
Expand Down

0 comments on commit 9e68187

Please sign in to comment.