From 43dacf7f879af477b905179bd8e15406aebd173c Mon Sep 17 00:00:00 2001 From: kirillius Date: Fri, 27 Dec 2024 23:59:54 +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=BB=D0=BE=D1=81=D1=82=D1=84=D0=B8=D0=BB=D1=8C=D0=BC=20=D0=B8?= =?UTF-8?q?=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BE=D1=87=D0=BA=D1=83=20=D0=BE?= =?UTF-8?q?=D0=B2=D0=BF=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- networks/lostfilm.json | 7 +++++++ plugins/openvpn/Openvpn.php | 17 ++++++++++++++++- plugins/openvpn/metadata.json | 2 +- plugins/openvpn/plugin.js | 20 ++++++++++++++++++++ restart.php | 12 ++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 networks/lostfilm.json create mode 100644 plugins/openvpn/plugin.js create mode 100644 restart.php diff --git a/networks/lostfilm.json b/networks/lostfilm.json new file mode 100644 index 0000000..12b690c --- /dev/null +++ b/networks/lostfilm.json @@ -0,0 +1,7 @@ +{ + "description": "lostfilm", + "domains": [], + "networks": [ + "104.21.0.0/17" + ] +} \ No newline at end of file diff --git a/plugins/openvpn/Openvpn.php b/plugins/openvpn/Openvpn.php index 94968d3..8e8b349 100755 --- a/plugins/openvpn/Openvpn.php +++ b/plugins/openvpn/Openvpn.php @@ -5,9 +5,24 @@ class Openvpn implements IPluggable { private PluginContext $context; - public function init(PluginContext $context) + public function restart() + { + //restart ovpn + return shell_exec($this->context->getConfig()["ovpn"]["restart_cmd"]); + } + + public function init(PluginContext $context): void { $this->context = $context; + $this->checkConfig(); + } + + private function checkConfig(): void + { + $config = $this->context->getConfig(); + if (!isset($config["ovpn"])) { + $config["ovpn"] = $this->context->getMetadata()["config"]; + } } public function getRoutingConfig(): array diff --git a/plugins/openvpn/metadata.json b/plugins/openvpn/metadata.json index fe1b9d5..97ff5c7 100644 --- a/plugins/openvpn/metadata.json +++ b/plugins/openvpn/metadata.json @@ -1,6 +1,6 @@ { "class": "Openvpn", "config": { - + "restart_cmd": "/etc/init.d/zebra restart" } } \ No newline at end of file diff --git a/plugins/openvpn/plugin.js b/plugins/openvpn/plugin.js new file mode 100644 index 0000000..2954ee3 --- /dev/null +++ b/plugins/openvpn/plugin.js @@ -0,0 +1,20 @@ +import {App} from "/assets/App.js"; +(async function () { + $("#buttons").append(``); + $("#restart-ovpn").click(function () { + if (confirm("Are you sure?")) { + const self = $(this); + self.prop("disabled", true); + (async function () { + try { + alert(await App.RPC.__invoke("openvpn::restart")); + } finally { + setTimeout(() => { + self.prop("disabled", false); + }, 5000); + } + + })(); + } + }); +})(); \ No newline at end of file diff --git a/restart.php b/restart.php new file mode 100644 index 0000000..df4c10f --- /dev/null +++ b/restart.php @@ -0,0 +1,12 @@ +#!/usr/bin/php +