summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Mazoyer <gmazoyer@gravitons.in>2016-08-24 21:27:26 +0200
committerGuillaume Mazoyer <gmazoyer@gravitons.in>2016-08-24 21:27:26 +0200
commitb125fa0ca129beaf819f10e7399c9878b47e905e (patch)
treee4eb5a7bb1babc6d02300f753aa3bc1265dfc0c0
parent027cd66297c0f56579db99d97d5fc3122ab4fe4b (diff)
Add configuration option to change connection timeout.
The timeout can be specified in seconds with the ['timeout'] array index within the router configuration. The default value is 30 seconds.
-rw-r--r--auth/ssh.php1
-rw-r--r--auth/telnet.php6
-rw-r--r--docs/configuration.md5
-rw-r--r--includes/config.defaults.php1
4 files changed, 11 insertions, 2 deletions
diff --git a/auth/ssh.php b/auth/ssh.php
index bce82ab..e870861 100644
--- a/auth/ssh.php
+++ b/auth/ssh.php
@@ -48,6 +48,7 @@ final class SSH extends Authentication {
public function connect() {
$this->connection = new Net_SSH2($this->config['host'], $this->port);
+ $this->connection->setTimeout($this->config['timeout']);
$success = false;
if ($this->config['auth'] == 'ssh-password') {
diff --git a/auth/telnet.php b/auth/telnet.php
index 20b85a6..4aa7a64 100644
--- a/auth/telnet.php
+++ b/auth/telnet.php
@@ -37,9 +37,11 @@ final class Telnet extends Authentication {
}
public function connect() {
- $this->connection = fsockopen($this->config['host'], $this->port);
+ $this->connection = fsockopen($this->config['host'], $this->port, $errno,
+ $errstr, $this->config['timeout']);
if (!$this->connection) {
- throw new Exception('Cannot connect to router.');
+ throw new Exception('Cannot connect to router (code '.$errno.'['.
+ $errstr.']).');
}
fputs($this->connection, $this->config['user']."\r\n");
diff --git a/docs/configuration.md b/docs/configuration.md
index 25f99b6..bb1a210 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -155,6 +155,11 @@ $config['routers']['router1']['disable_ipv4'] = false;
```
If set to true, disable the use of IPv4 for the router.
+```php
+$config['routers']['router1']['timeout'] = 30;
+```
+Used to set the timeout (in seconds) for the connection to the router. The
+default value is 30 seconds.
#### Telnet
diff --git a/includes/config.defaults.php b/includes/config.defaults.php
index fa17f66..4439410 100644
--- a/includes/config.defaults.php
+++ b/includes/config.defaults.php
@@ -26,6 +26,7 @@
function set_defaults_for_routers(&$parsed_config) {
$router_defaults = array(
+ 'timeout' => 30,
'disable_ipv6' => false,
'disable_ipv4' => false
);