Update wg logging facility

This commit is contained in:
billz 2021-12-31 13:10:27 +00:00
parent 5fe58be79e
commit 0af3e7a7c6
3 changed files with 24 additions and 9 deletions

View file

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

View file

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

View file

@ -4,10 +4,10 @@
<div class="col-md-12">
<h4 class="mt-3"><?php echo _("Logging"); ?></h4>
<div class="custom-control custom-switch">
<input class="custom-control-input" id="wg_log" type="checkbox" name="wg_log" value="1" <?php echo $wg_log ? ' checked="checked"' : "" ?> aria-describedby="wg_log">
<label class="custom-control-label" for="wg_log"><?php echo _("Display WireGuard status") ?></label>
<input class="custom-control-input" id="wgLogEnable" type="checkbox" name="wgLogEnable" value="1" <?php echo $optLogEnable ? ' checked="checked"' : "" ?> aria-describedby="wgLogEnable">
<label class="custom-control-label" for="wgLogEnable"><?php echo _("Display WireGuard debug log") ?></label>
</div>
<p><small><?php echo _("Enable this option to display an updated WireGuard status.") ?></small></p>
<p><small><?php echo _("Enable this option to display an updated WireGuard debug log.") ?></small></p>
<?php
exec('sudo chmod o+r /tmp/wireguard.log');
$log = file_get_contents('/tmp/wireguard.log');