From d34753128ad2591c4689610dea3f9b35abe65cdf Mon Sep 17 00:00:00 2001 From: kirillius Date: Thu, 5 Jun 2025 13:55:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=81=D1=82=D0=BE=D0=BC=D0=BD=D1=8B=D1=85=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/ovpn-connect | 2 +- classes/IPluggable.php | 2 +- classes/Plugin.php | 2 +- plugins/custom/Custom.php | 25 +++++++++++++++++++++++++ plugins/custom/metadata.json | 10 ++++++++++ plugins/custom/plugin.js | 0 plugins/named/BindPlugin.php | 2 +- plugins/netsync/Netsync.php | 8 ++++---- plugins/openvpn/Openvpn.php | 2 +- plugins/quagga/QuaggaPlugin.php | 2 +- 10 files changed, 45 insertions(+), 10 deletions(-) create mode 100755 plugins/custom/Custom.php create mode 100644 plugins/custom/metadata.json create mode 100644 plugins/custom/plugin.js diff --git a/bin/ovpn-connect b/bin/ovpn-connect index cf9b845..c6aa96d 100755 --- a/bin/ovpn-connect +++ b/bin/ovpn-connect @@ -15,7 +15,7 @@ try { throw new RuntimeException("Plugin is not enabled"); } /** - * @var Openvpn $instance + * @var Custom $instance */ $config = $instance->getRoutingConfig(); diff --git a/classes/IPluggable.php b/classes/IPluggable.php index c8c4349..60fee4c 100644 --- a/classes/IPluggable.php +++ b/classes/IPluggable.php @@ -4,5 +4,5 @@ interface IPluggable { public function onServerStarted(); public function onInit(PluginContext $context); - public function onSync(); + public function onSync(array $remote_config); } \ No newline at end of file diff --git a/classes/Plugin.php b/classes/Plugin.php index d8089bf..3ab545d 100644 --- a/classes/Plugin.php +++ b/classes/Plugin.php @@ -10,7 +10,7 @@ abstract class Plugin implements IPluggable } - public function onSync() + public function onSync($remote_config) { } diff --git a/plugins/custom/Custom.php b/plugins/custom/Custom.php new file mode 100755 index 0000000..cccdd98 --- /dev/null +++ b/plugins/custom/Custom.php @@ -0,0 +1,25 @@ +#!/usr/bin/php +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(); + } + + +} + diff --git a/plugins/custom/metadata.json b/plugins/custom/metadata.json new file mode 100644 index 0000000..47d6838 --- /dev/null +++ b/plugins/custom/metadata.json @@ -0,0 +1,10 @@ +{ + "class": "Custom", + "config": { + "description": "Custom routes", + "domains": [ + ], + "networks": [ + ] + } +} \ No newline at end of file diff --git a/plugins/custom/plugin.js b/plugins/custom/plugin.js new file mode 100644 index 0000000..e69de29 diff --git a/plugins/named/BindPlugin.php b/plugins/named/BindPlugin.php index 8f4723b..f4e2c9c 100644 --- a/plugins/named/BindPlugin.php +++ b/plugins/named/BindPlugin.php @@ -50,7 +50,7 @@ TXT; $this->restart(); } - public function onSync() + public function onSync($remote_config) { $this->restart(); } diff --git a/plugins/netsync/Netsync.php b/plugins/netsync/Netsync.php index 5bf9be7..0351a05 100644 --- a/plugins/netsync/Netsync.php +++ b/plugins/netsync/Netsync.php @@ -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); } } diff --git a/plugins/openvpn/Openvpn.php b/plugins/openvpn/Openvpn.php index a042b47..b2f9a89 100755 --- a/plugins/openvpn/Openvpn.php +++ b/plugins/openvpn/Openvpn.php @@ -36,7 +36,7 @@ class Openvpn extends Plugin $this->restart(); } - public function onSync() + public function onSync($remote_config) { $this->restart(); } diff --git a/plugins/quagga/QuaggaPlugin.php b/plugins/quagga/QuaggaPlugin.php index 4b504bb..6618612 100644 --- a/plugins/quagga/QuaggaPlugin.php +++ b/plugins/quagga/QuaggaPlugin.php @@ -75,7 +75,7 @@ class QuaggaPlugin extends Plugin $this->restart(); } - public function onSync() + public function onSync($remote_config) { $this->restart(); }