Browse Source

[bob] check for existing session

Signed-off-by: r4sas <r4sas@i2pmail.org>
master
R4SAS 2 years ago
parent
commit
614edcfe00
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 23
      checker.php
  2. 30
      lib/bob.php

23
checker.php

@ -25,15 +25,20 @@ $hosts = $STH->fetchAll(PDO::FETCH_KEY_PAIR); @@ -25,15 +25,20 @@ $hosts = $STH->fetchAll(PDO::FETCH_KEY_PAIR);
echo "[BOB] Starting session for checking" . PHP_EOL;
$bob = new BOB($options);
$bob->setnick();
$bob->options();
$bob->newkeys();
$bob->intun();
$bob->start();
/* Sleep 10 seconds awaitng tunnels get built */
echo "[BOB] Session started, awaiting 10 seconds for tunnels" . PHP_EOL;
sleep(10);
if ($bob->setnick()) {
$bob->options();
$bob->newkeys();
$bob->intun();
$bob->start();
/* Sleep 10 seconds awaitng tunnels get built */
echo "[BOB] Session started, awaiting 10 seconds for tunnels" . PHP_EOL;
sleep(10);
} else {
echo "[BOB] Stale session is found, using it" . PHP_EOL;
$bob->getnick();
}
/* Start async checker tasks */
Loop::run(function () use (&$results, $hosts, $options) {

30
lib/bob.php

@ -50,13 +50,17 @@ class BOB { @@ -50,13 +50,17 @@ class BOB {
socket_close($this->sock);
}
public function setnick() {
public function setnick(): bool {
$command = "setnick " . $this->options["bob_nick"] . "\n";
socket_write($this->sock, $command, strlen($command));
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
if(!preg_match('/^OK/', $response)) {
//echo "[BOB] setnick response: " . $response;
return false;
}
return true;
}
public function options() {
@ -68,7 +72,7 @@ class BOB { @@ -68,7 +72,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] options response: " . $response;
}
}
@ -78,7 +82,7 @@ class BOB { @@ -78,7 +82,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] newkeys response: " . $response;
}
public function start() {
@ -87,7 +91,7 @@ class BOB { @@ -87,7 +91,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] start response: " . $response;
}
public function intun() {
@ -96,14 +100,14 @@ class BOB { @@ -96,14 +100,14 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] inhost response: " . $response;
$command = "inport " . rand(1024, 65535) . "\n";
socket_write($this->sock, $command, strlen($command));
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] inport response: " . $response;
}
public function getnick() {
@ -112,7 +116,7 @@ class BOB { @@ -112,7 +116,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] getnick response: " . $response;
}
public function lookup(string $address): bool {
@ -122,6 +126,7 @@ class BOB { @@ -122,6 +126,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(preg_match('/^OK/', $response))
//echo "[BOB] lookup response: " . $response;
return true;
return false;
@ -134,6 +139,7 @@ class BOB { @@ -134,6 +139,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(preg_match('/^OK/', $response))
//echo "[BOB] lookup response: " . $response;
return true;
return false;
@ -145,7 +151,7 @@ class BOB { @@ -145,7 +151,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] stop response: " . $response;
}
public function clear() {
@ -154,7 +160,7 @@ class BOB { @@ -154,7 +160,7 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] clear response: " . $response;
}
public function zap() {
@ -163,6 +169,6 @@ class BOB { @@ -163,6 +169,6 @@ class BOB {
$response = socket_read($this->sock, 1024, PHP_NORMAL_READ);
if(!preg_match('/^OK/', $response))
echo "BOB response: " . $response;
echo "[BOB] zap response: " . $response;
}
}

Loading…
Cancel
Save