Skip to content

Commit

Permalink
[whois] fail/timeout better if we cannot hit the server we are referr…
Browse files Browse the repository at this point in the history
…ed to

Signed-off-by: Ricky Elrod <ricky@elrod.me>
  • Loading branch information
relrod committed Jan 26, 2017
1 parent e0cf443 commit 878699e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/applications/whois/resources/dagd_whois.php
Expand Up @@ -8,6 +8,9 @@ class DaGdWhois {
private $whois_server;
private $whois_port = 43;
private $skip_detail = false;
// Keep the transient result around in case we can't connect to the server
// we're redirected to. In that case, we return this result.
private $first_query_result = '';

public function __construct($domain) {
$this->domain = $domain;
Expand Down Expand Up @@ -99,6 +102,7 @@ public function fetchWhoisServer() {
$whois_info .= $line;
}
fclose($transient_sock);
$this->first_query_result = $whois_info;
if ($whois_server && !empty($referral_server_name)) {
$whois_server = $whois_server[1];
$whois_server = preg_replace('#r?whois://#', '', $whois_server);
Expand Down Expand Up @@ -128,9 +132,18 @@ public function fetchWhoisServer() {
* @returns <bool> false if non successful.
*/
private function fetchWhoisDetails() {
$sock = fsockopen($this->whois_server, (int)$this->whois_port);
$timeout = DaGdConfig::get('whois.redirect_timeout');
$errno = 0;
$errstr = '';
$sock = fsockopen(
$this->whois_server,
(int)$this->whois_port,
$errno,
$errstr,
null,
$timeout);
if (!$sock) {
return false;
return $this->first_query_result;
}
fwrite($sock, $this->query.$this->domain."\r\n");
$response = '';
Expand Down
4 changes: 4 additions & 0 deletions src/config.dev.php
Expand Up @@ -130,6 +130,10 @@ class DaGdConfig {
'ipmt.rr.com',
),

// How long should we wait before timing out trying to hit a server we are
// referred to? (in seconds)
'whois.redirect_timeout' => 2,

// Should error emails get sent out?
'exceptions.email' => false,

Expand Down

0 comments on commit 878699e

Please sign in to comment.