-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
c8a74f9
commit 9e68187
Showing
3 changed files
with
61 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) * | ||
|
@@ -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? | ||
|
@@ -228,6 +228,8 @@ class INWX | |
|
||
if($_) | ||
{ | ||
clearstatcache(); | ||
|
||
if(!file_exists($this->persistent)) | ||
{ | ||
if(!touch($this->persistent)) | ||
|
@@ -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 = '') | ||
|
@@ -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))); | ||
|
@@ -327,7 +337,6 @@ class INWX | |
} | ||
|
||
$result = xmlrpc_decode($result, 'UTF-8'); | ||
#sleep(mt_rand(3, 8)); // <-- required? | ||
|
||
if($return && $result['code'] === 2303) | ||
{ | ||
|
@@ -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(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters