1
0
mirror of https://github.com/billz/raspap-webgui.git synced 2023-10-10 13:37:24 +02:00
raspap-webgui/includes/wireguard.php

49 lines
1.4 KiB
PHP
Raw Normal View History

2020-04-20 13:53:46 +02:00
<?php
require_once 'includes/status_messages.php';
require_once 'config.php';
/**
* Manage WireGuard configuration
*/
function DisplayWireGuardConfig()
{
$status = new StatusMessages();
if (!RASPI_MONITOR_ENABLED) {
if (isset($_POST['savewgettings'])) {
if (isset($_POST['authUser'])) {
$authUser = strip_tags(trim($_POST['authUser']));
}
if (isset($_POST['authPassword'])) {
$authPassword = strip_tags(trim($_POST['authPassword']));
}
} elseif (isset($_POST['startwg'])) {
$status->addMessage('Attempting to start WireGuard', 'info');
2020-04-22 11:01:31 +02:00
exec('sudo /usr/bin/wg-quick up wg0', $return);
2020-04-20 13:53:46 +02:00
foreach ($return as $line) {
$status->addMessage($line, 'info');
}
} elseif (isset($_POST['stopwg'])) {
$status->addMessage('Attempting to stop WireGuard', 'info');
2020-04-22 11:01:31 +02:00
exec('sudo /usr/bin/wg-quick down wg0', $return);
2020-04-20 13:53:46 +02:00
foreach ($return as $line) {
$status->addMessage($line, 'info');
}
}
}
2020-04-22 11:01:31 +02:00
exec('pidof wg-crypt-wg0 | wc -l', $wgstatus);
2020-04-20 13:53:46 +02:00
$serviceStatus = $wgstatus[0] == 0 ? "down" : "up";
2020-04-22 11:01:31 +02:00
$wg_state = ($wgstatus[0] > 0);
2020-04-20 13:53:46 +02:00
echo renderTemplate(
"wireguard", compact(
"status",
2020-04-22 11:01:31 +02:00
"wg_state",
2020-04-20 13:53:46 +02:00
"serviceStatus"
)
);
}