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. 7
      checker.php
  2. 30
      lib/bob.php

7
checker.php

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

30
lib/bob.php

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

Loading…
Cancel
Save