добавил лостфильм и кнопочку овпн

This commit is contained in:
kirillius 2024-12-27 23:59:54 +03:00
parent 2e27ad81f2
commit 43dacf7f87
5 changed files with 56 additions and 2 deletions

7
networks/lostfilm.json Normal file
View File

@ -0,0 +1,7 @@
{
"description": "lostfilm",
"domains": [],
"networks": [
"104.21.0.0/17"
]
}

View File

@ -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

View File

@ -1,6 +1,6 @@
{
"class": "Openvpn",
"config": {
"restart_cmd": "/etc/init.d/zebra restart"
}
}

20
plugins/openvpn/plugin.js Normal file
View File

@ -0,0 +1,20 @@
import {App} from "/assets/App.js";
(async function () {
$("#buttons").append(`<button id="restart-ovpn">Restart openvpn server</button>`);
$("#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);
}
})();
}
});
})();

12
restart.php Normal file
View File

@ -0,0 +1,12 @@
#!/usr/bin/php
<?php
$memory = trim(shell_exec("free -b | grep Mem:"));
$memory = str_replace(" ", " ", $memory);
while (str_contains($memory, " ")) $memory = str_replace(" ", " ", $memory);
$items = explode(" ", $memory);
$available = intval($items[count($items) - 1]) / 1024 / 1024;
if ($available < 25) {
shell_exec("systemctl restart grass");
}