добавил плагин для кастомных настроек
This commit is contained in:
parent
de90a544c3
commit
d34753128a
|
|
@ -15,7 +15,7 @@ try {
|
|||
throw new RuntimeException("Plugin is not enabled");
|
||||
}
|
||||
/**
|
||||
* @var Openvpn $instance
|
||||
* @var Custom $instance
|
||||
*/
|
||||
|
||||
$config = $instance->getRoutingConfig();
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@ interface IPluggable
|
|||
{
|
||||
public function onServerStarted();
|
||||
public function onInit(PluginContext $context);
|
||||
public function onSync();
|
||||
public function onSync(array $remote_config);
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ abstract class Plugin implements IPluggable
|
|||
|
||||
}
|
||||
|
||||
public function onSync()
|
||||
public function onSync($remote_config)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"class": "Custom",
|
||||
"config": {
|
||||
"description": "Custom routes",
|
||||
"domains": [
|
||||
],
|
||||
"networks": [
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ TXT;
|
|||
$this->restart();
|
||||
}
|
||||
|
||||
public function onSync()
|
||||
public function onSync($remote_config)
|
||||
{
|
||||
$this->restart();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Openvpn extends Plugin
|
|||
$this->restart();
|
||||
}
|
||||
|
||||
public function onSync()
|
||||
public function onSync($remote_config)
|
||||
{
|
||||
$this->restart();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class QuaggaPlugin extends Plugin
|
|||
$this->restart();
|
||||
}
|
||||
|
||||
public function onSync()
|
||||
public function onSync($remote_config)
|
||||
{
|
||||
$this->restart();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue