Initial commit: project openvpn-monitor
This commit is contained in:
41
openvpn-monitor/src/LogMonitor.php
Normal file
41
openvpn-monitor/src/LogMonitor.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace OpenVPN;
|
||||
|
||||
class LogMonitor {
|
||||
private $host;
|
||||
private $port;
|
||||
private $socket;
|
||||
|
||||
public function __construct($host = '127.0.0.1', $port = 7505) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
}
|
||||
|
||||
public function connect() {
|
||||
$this->socket = fsockopen($this->host, $this->port, $errno, $errstr, 5);
|
||||
if (!$this->socket) {
|
||||
throw new \Exception("Management connection failed: $errstr ($errno)");
|
||||
}
|
||||
stream_set_timeout($this->socket, 2);
|
||||
$this->send("log on");
|
||||
}
|
||||
|
||||
private function send($cmd) {
|
||||
fwrite($this->socket, "$cmd\n");
|
||||
}
|
||||
|
||||
public function getTlsErrors() {
|
||||
$this->connect();
|
||||
$errors = [];
|
||||
|
||||
while (!feof($this->socket)) {
|
||||
$line = fgets($this->socket);
|
||||
if (str_contains($line, 'TLS Error') || str_contains($line, 'VERIFY ERROR')) {
|
||||
$errors[] = trim($line);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($this->socket);
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user