From 0af3e7a7c6a7ed473ee5b6e57d84b1522b00dff2 Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 31 Dec 2021 13:10:27 +0000 Subject: [PATCH] Update wg logging facility --- includes/wireguard.php | 25 ++++++++++++++++++++----- installers/raspap.sudoers | 2 +- templates/wg/logging.php | 6 +++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/includes/wireguard.php b/includes/wireguard.php index cb66341b..a5b96ac9 100644 --- a/includes/wireguard.php +++ b/includes/wireguard.php @@ -13,6 +13,7 @@ function DisplayWireGuardConfig() $optRules = $_POST['wgRules']; $optConf = $_POST['wgCnfOpt']; $optSrvEnable = $_POST['wgSrvEnable']; + $optLogEnable = $_POST['wgLogEnable']; if (isset($_POST['savewgsettings']) && $optConf == 'manual' && $optSrvEnable == 1 ) { SaveWireGuardConfig($status); } elseif (isset($_POST['savewgsettings']) && $optConf == 'upload' && is_uploaded_file($_FILES["wgFile"]["tmp_name"])) { @@ -30,6 +31,7 @@ function DisplayWireGuardConfig() $status->addMessage($line, 'info'); } } + CheckWireGuardLog( $optLogEnable, $status ); } // fetch server config @@ -69,7 +71,7 @@ function DisplayWireGuardConfig() "serviceStatus", "public_ip", "optRules", - "wg_log", + "optLogEnable", "peer_id", "wg_srvpubkey", "wg_srvport", @@ -218,8 +220,11 @@ function SaveWireGuardConfig($status) } } } + // Save settings if ($good_input) { + var_dump($_POST); + // server (wg0.conf) if ($_POST['wg_senabled'] == 1) { // fetch server private key from filesytem @@ -278,10 +283,6 @@ function SaveWireGuardConfig($status) system('sudo rm '. RASPI_WIREGUARD_PATH.'client.conf', $return); } - // handle log option - if ($_POST['wg_log'] == "1") { - exec("sudo /bin/systemctl status wg-quick@wg0 | sudo tee /tmp/wireguard.log > /dev/null"); - } foreach ($return as $line) { $status->addMessage($line, 'info'); } @@ -293,3 +294,17 @@ function SaveWireGuardConfig($status) } } +/** + * + * @return object $status + */ +function CheckWireGuardLog( $opt, $status ) +{ + // handle log option + if ( $opt == "1") { + exec("sudo journalctl --identifier wg-quick > /tmp/wireguard.log"); + $status->addMessage('WireGuard debug log updated', 'success'); + } + return $status; +} + diff --git a/installers/raspap.sudoers b/installers/raspap.sudoers index db5154e5..8acfabdd 100644 --- a/installers/raspap.sudoers +++ b/installers/raspap.sudoers @@ -55,7 +55,7 @@ www-data ALL=(ALL) NOPASSWD:/usr/local/sbin/onoff_huawei_hilink.sh * www-data ALL=(ALL) NOPASSWD:/bin/sed -i * /etc/wvdial.conf www-data ALL=(ALL) NOPASSWD:/bin/sed -i * /etc/udev/rules.d/80-raspap-net-devices.rules www-data ALL=(ALL) NOPASSWD:/usr/bin/tee -a /etc/udev/rules.d/80-raspap-net-devices.rules -www-data ALL=(ALL) NOPASSWD:/usr/bin/tee /tmp/wireguard.log +www-data ALL=(ALL) NOPASSWD:/usr/bin/journalctl --identifier wg-quick www-data ALL=(ALL) NOPASSWD:/bin/systemctl * wg-quick@wg0 www-data ALL=(ALL) NOPASSWD:/usr/bin/wg www-data ALL=(ALL) NOPASSWD:/bin/cat /etc/wireguard/*.conf diff --git a/templates/wg/logging.php b/templates/wg/logging.php index c9cb4185..d7dfe582 100644 --- a/templates/wg/logging.php +++ b/templates/wg/logging.php @@ -4,10 +4,10 @@

- aria-describedby="wg_log"> - + aria-describedby="wgLogEnable"> +
-

+