|
|
@ -12,32 +12,27 @@ class BOB { |
|
|
|
"bob_nick" => "hostchecker", |
|
|
|
"bob_nick" => "hostchecker", |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
public function __construct(array $options = []) |
|
|
|
public function __construct(array $options = []) { |
|
|
|
{ |
|
|
|
|
|
|
|
ob_implicit_flush(); |
|
|
|
ob_implicit_flush(); |
|
|
|
|
|
|
|
|
|
|
|
$this->options = array_merge($this->options, (array) $options); |
|
|
|
$this->options = array_merge($this->options, (array) $options); |
|
|
|
|
|
|
|
|
|
|
|
$this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
|
|
|
$this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); |
|
|
|
if ($this->sock === false) |
|
|
|
if ($this->sock === false) { |
|
|
|
{ |
|
|
|
|
|
|
|
throw new \ErrorException("socket_create() failed: reason: " . socket_strerror(socket_last_error())); |
|
|
|
throw new \ErrorException("socket_create() failed: reason: " . socket_strerror(socket_last_error())); |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
} else { |
|
|
|
{ |
|
|
|
|
|
|
|
socket_set_option($this->sock, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 10, 'usec' => 10 * 1000]); |
|
|
|
socket_set_option($this->sock, SOL_SOCKET, SO_RCVTIMEO, ['sec' => 10, 'usec' => 10 * 1000]); |
|
|
|
socket_set_option($this->sock, SOL_SOCKET, SO_SNDTIMEO, ['sec' => 10, 'usec' => 10 * 1000]); |
|
|
|
socket_set_option($this->sock, SOL_SOCKET, SO_SNDTIMEO, ['sec' => 10, 'usec' => 10 * 1000]); |
|
|
|
|
|
|
|
|
|
|
|
$result = socket_connect($this->sock, $this->options["bob_host"], $this->options["bob_port"]); |
|
|
|
$result = socket_connect($this->sock, $this->options["bob_host"], $this->options["bob_port"]); |
|
|
|
if ($result === false) |
|
|
|
if ($result === false) { |
|
|
|
{ |
|
|
|
|
|
|
|
throw new \ErrorException("socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket))); |
|
|
|
throw new \ErrorException("socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Reading BOB greeting */ |
|
|
|
/* Reading BOB greeting */ |
|
|
|
$response = socket_read($this->sock, 1024); |
|
|
|
$response = socket_read($this->sock, 1024); |
|
|
|
if(!preg_match('/OK/', $response)) |
|
|
|
if(!preg_match('/OK/', $response)) { |
|
|
|
{ |
|
|
|
|
|
|
|
throw new \ErrorException("BOB returned incorrect response on connect or timed out"); |
|
|
|
throw new \ErrorException("BOB returned incorrect response on connect or timed out"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -46,8 +41,7 @@ class BOB { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function __destruct() |
|
|
|
public function __destruct() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "quit\n"; |
|
|
|
$command = "quit\n"; |
|
|
|
|
|
|
|
|
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
@ -56,8 +50,7 @@ class BOB { |
|
|
|
socket_close($this->sock); |
|
|
|
socket_close($this->sock); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function setnick() |
|
|
|
public function setnick() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "setnick " . $this->options["bob_nick"] . "\n"; |
|
|
|
$command = "setnick " . $this->options["bob_nick"] . "\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -66,12 +59,10 @@ class BOB { |
|
|
|
echo "BOB response: " . $response; |
|
|
|
echo "BOB response: " . $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function options() |
|
|
|
public function options() { |
|
|
|
{ |
|
|
|
|
|
|
|
$options = explode(" ", $this->options["bob_options"]); |
|
|
|
$options = explode(" ", $this->options["bob_options"]); |
|
|
|
|
|
|
|
|
|
|
|
foreach($options as $option) |
|
|
|
foreach($options as $option) { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "option " . $option . "\n"; |
|
|
|
$command = "option " . $option . "\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -81,8 +72,7 @@ class BOB { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function newkeys() |
|
|
|
public function newkeys() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "newkeys\n"; |
|
|
|
$command = "newkeys\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -91,8 +81,7 @@ class BOB { |
|
|
|
echo "BOB response: " . $response; |
|
|
|
echo "BOB response: " . $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function start() |
|
|
|
public function start() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "start\n"; |
|
|
|
$command = "start\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -101,8 +90,7 @@ class BOB { |
|
|
|
echo "BOB response: " . $response; |
|
|
|
echo "BOB response: " . $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function intun() |
|
|
|
public function intun() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "inhost 127.0.0.1\n"; |
|
|
|
$command = "inhost 127.0.0.1\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -118,8 +106,7 @@ class BOB { |
|
|
|
echo "BOB response: " . $response; |
|
|
|
echo "BOB response: " . $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getnick() |
|
|
|
public function getnick() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "getnick " . $this->options["bob_nick"] . "\n"; |
|
|
|
$command = "getnick " . $this->options["bob_nick"] . "\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -128,8 +115,7 @@ class BOB { |
|
|
|
echo "BOB response: " . $response; |
|
|
|
echo "BOB response: " . $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function lookup(string $address): bool |
|
|
|
public function lookup(string $address): bool { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "lookup " . $address . "\n"; |
|
|
|
$command = "lookup " . $address . "\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -141,8 +127,7 @@ class BOB { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function lookuplocal(string $address): bool |
|
|
|
public function lookuplocal(string $address): bool { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "lookuplocal " . $address . "\n"; |
|
|
|
$command = "lookuplocal " . $address . "\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -154,8 +139,7 @@ class BOB { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function stop() |
|
|
|
public function stop() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "stop\n"; |
|
|
|
$command = "stop\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -164,8 +148,7 @@ class BOB { |
|
|
|
echo "BOB response: " . $response; |
|
|
|
echo "BOB response: " . $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function clear() |
|
|
|
public function clear() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "clear\n"; |
|
|
|
$command = "clear\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
@ -174,8 +157,7 @@ class BOB { |
|
|
|
echo "BOB response: " . $response; |
|
|
|
echo "BOB response: " . $response; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function zap() |
|
|
|
public function zap() { |
|
|
|
{ |
|
|
|
|
|
|
|
$command = "zap\n"; |
|
|
|
$command = "zap\n"; |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
socket_write($this->sock, $command, strlen($command)); |
|
|
|
|
|
|
|
|
|
|
|