Files
gateway01/openvpn-monitor/src/LogMonitor.php

42 lines
1.0 KiB
PHP

<?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;
}
}