добавил плагин для кастомных настроек

This commit is contained in:
kirillius 2025-06-05 13:55:36 +03:00
parent de90a544c3
commit d34753128a
10 changed files with 45 additions and 10 deletions

View File

@ -15,7 +15,7 @@ try {
throw new RuntimeException("Plugin is not enabled");
}
/**
* @var Openvpn $instance
* @var Custom $instance
*/
$config = $instance->getRoutingConfig();

View File

@ -4,5 +4,5 @@ interface IPluggable
{
public function onServerStarted();
public function onInit(PluginContext $context);
public function onSync();
public function onSync(array $remote_config);
}

View File

@ -10,7 +10,7 @@ abstract class Plugin implements IPluggable
}
public function onSync()
public function onSync($remote_config)
{
}

25
plugins/custom/Custom.php Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/php
<?php
class Custom extends Plugin
{
public function onSync($remote_config)
{
if (!isset($remote_config["custom"])) {
return;
}
$this->config = $remote_config["custom"];
$this->saveConfig();
$path = dirname(__DIR__) . "/networks/custom.json";
file_put_contents($path, json_encode($this->config));
}
protected function checkConfig(): void
{
parent::checkConfig();
}
}

View File

@ -0,0 +1,10 @@
{
"class": "Custom",
"config": {
"description": "Custom routes",
"domains": [
],
"networks": [
]
}
}

0
plugins/custom/plugin.js Normal file
View File

View File

@ -50,7 +50,7 @@ TXT;
$this->restart();
}
public function onSync()
public function onSync($remote_config)
{
$this->restart();
}

View File

@ -40,10 +40,10 @@ class Netsync extends Plugin
$header = @json_decode($output, true);
$result = $header["result"] ?? null;
$remote_config = $header["result"] ?? null;
$networks = $result["networks"] ?? null;
if ($result === null or $networks === null) {
$networks = $remote_config["networks"] ?? null;
if ($remote_config === null or $networks === null) {
throw new RuntimeException("Response has invalid data");
}
@ -63,7 +63,7 @@ class Netsync extends Plugin
* @var IPluggable $plugin
*/
$plugin->onSync();
$plugin->onSync($remote_config);
}
}

View File

@ -36,7 +36,7 @@ class Openvpn extends Plugin
$this->restart();
}
public function onSync()
public function onSync($remote_config)
{
$this->restart();
}

View File

@ -75,7 +75,7 @@ class QuaggaPlugin extends Plugin
$this->restart();
}
public function onSync()
public function onSync($remote_config)
{
$this->restart();
}