45 lines
953 B
PHP
Executable File
45 lines
953 B
PHP
Executable File
#!/usr/bin/php
|
|
<?php
|
|
|
|
class Openvpn extends Plugin
|
|
{
|
|
|
|
public function restart()
|
|
{
|
|
//restart ovpn
|
|
return shell_exec($this->config["restart_cmd"]);
|
|
}
|
|
|
|
|
|
public function getRoutingConfig(): array
|
|
{
|
|
$networks = (new NetworkConfigReader())->getConfigs();
|
|
$data = [];
|
|
|
|
//add new routes
|
|
foreach ($this->context->getConfig() ["networks"] as $key) {
|
|
if (isset($networks[$key])) {
|
|
foreach ($networks[$key]["networks"] as $route) {
|
|
$parts = explode("/", $route);
|
|
$mask = long2ip(-1 << (32 - (int)$parts[1]));
|
|
$dst = $parts[0];
|
|
$data[] = "push \"route {$dst} {$mask}\"";
|
|
}
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function onServerStarted()
|
|
{
|
|
$this->restart();
|
|
}
|
|
|
|
public function onSync()
|
|
{
|
|
$this->restart();
|
|
}
|
|
}
|
|
|