Browse Source

Merge pull request #1235 from RaspAP/feature/clear-log

Adds a 'clear log' button to service logging UIs
pull/1113/merge
Bill Zimmerman 2 months ago
committed by GitHub
parent
commit
4c23b45375
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ajax/logging/clearlog.php
  2. 22
      app/js/custom.js
  3. 2
      installers/raspap.sudoers
  4. BIN
      locale/en_US/LC_MESSAGES/messages.mo
  5. 7
      locale/en_US/LC_MESSAGES/messages.po
  6. 7
      templates/dhcp/logging.php
  7. 5
      templates/hostapd/logging.php
  8. 5
      templates/openvpn/logging.php

12
ajax/logging/clearlog.php

@ -0,0 +1,12 @@
<?php
require_once '../../includes/config.php';
require_once '../../includes/functions.php';
if (isset($_POST['logfile'])) {
$logfile = $_POST['logfile'];
// truncate requested log file
exec("sudo truncate -s 0 $logfile", $return);
echo json_encode($return);
}

22
app/js/custom.js

@ -122,6 +122,28 @@ $(document).on("click", "#gen_wpa_passphrase", function(e) {
$('#txtwpapassphrase').val(genPassword(63));
});
$(document).on("click", "#js-clearhostapd-log", function(e) {
$.post('ajax/logging/clearlog.php?',{'logfile':'/tmp/hostapd.log'},function(data){
jsonData = JSON.parse(data);
$("#hostapd-log").val("");
});
});
$(document).on("click", "#js-cleardnsmasq-log", function(e) {
$.post('ajax/logging/clearlog.php?',{'logfile':'/var/log/dnsmasq.log'},function(data){
jsonData = JSON.parse(data);
$("#dnsmasq-log").val("");
});
});
$(document).on("click", "#js-clearopenvpn-log", function(e) {
$.post('ajax/logging/clearlog.php?',{'logfile':'/tmp/openvpn.log'},function(data){
jsonData = JSON.parse(data);
$("#openvpn-log").val("");
});
});
// Enable Bootstrap tooltips
$(function () {
$('[data-toggle="tooltip"]').tooltip()

2
installers/raspap.sudoers

@ -63,4 +63,4 @@ www-data ALL=(ALL) NOPASSWD:/bin/cat /etc/wireguard/wg-*.key
www-data ALL=(ALL) NOPASSWD:/bin/rm /etc/wireguard/*.conf
www-data ALL=(ALL) NOPASSWD:/bin/rm /etc/wireguard/wg-*.key
www-data ALL=(ALL) NOPASSWD:/usr/sbin/netplan
www-data ALL=(ALL) NOPASSWD:/bin/truncate -s 0 /tmp/*.log,/bin/truncate -s 0 /var/log/dnsmasq.log

BIN
locale/en_US/LC_MESSAGES/messages.mo

7
locale/en_US/LC_MESSAGES/messages.po

@ -434,8 +434,8 @@ msgstr "Format"
msgid "Choose a hosted server"
msgstr "Choose a hosted server"
msgid "Enable these options to log DHCP server activity."
msgstr "Enable these options to log DHCP server activity."
msgid "Enable these options to log <code>dhcpcd</code> and <code>dnsmasq</code> activity."
msgstr "Enable these options to log <code>dhcpcd</code> and <code>dnsmasq</code> activity."
msgid "Log DHCP requests"
msgstr "Log DHCP requests"
@ -971,6 +971,9 @@ msgstr "up"
msgid "down"
msgstr "down"
msgid "Clear log"
msgstr "Clear log"
#: includes/adblock.php
msgid "adblock"

7
templates/dhcp/logging.php

@ -1,7 +1,7 @@
<!-- logfile output tab -->
<div class="tab-pane fade" id="logging">
<h4><?php echo _("Logging") ?></h4>
<p><?php echo _("Enable these options to log DHCP server activity.") ?></p>
<p><?php echo _("Enable these options to log <code>dhcpcd</code> and <code>dnsmasq</code> activity.") ?></p>
<div class="custom-control custom-switch">
<input class="custom-control-input" id="log-dhcp" type="checkbox" name="log-dhcp" value="1" <?php echo $conf['log-dhcp'] ? ' checked="checked"' : "" ?> aria-describedby="log-dhcp-requests">
@ -9,7 +9,8 @@
</div>
<div class="custom-control custom-switch">
<input class="custom-control-input" id="log-queries" type="checkbox" name="log-queries" value="1" <?php echo $conf['log-queries'] ? ' checked="checked"' : "" ?> aria-describedby="log-dhcp-queries">
<label class="custom-control-label" for="log-queries"><?php echo _("Log DNS queries") ?></label>
<label class="custom-control-label align-middle" for="log-queries"><?php echo _("Log DNS queries") ?></label>
<input type="button" class="btn btn-outline btn-warning btn-sm align-top ml-4" id="js-cleardnsmasq-log" value="<?php echo _("Clear log"); ?>" />
</div>
<div class="row">
@ -18,7 +19,7 @@
if ($conf['log-dhcp'] == 1 || $conf['log-queries'] == 1) {
exec('sudo /bin/chmod o+r '.RASPI_DHCPCD_LOG);
$log = file_get_contents(RASPI_DHCPCD_LOG);
echo '<textarea class="logoutput">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>';
echo '<textarea class="logoutput" id="dnsmasq-log">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>';
} else {
echo '<textarea class="logoutput my-3"></textarea>';
}

5
templates/hostapd/logging.php

@ -6,7 +6,8 @@
<div class="custom-control custom-switch">
<?php $checked = $arrHostapdConf['LogEnable'] == 1 ? 'checked="checked"' : '' ?>
<input class="custom-control-input" id="chxlogenable" name="logEnable" type="checkbox" value="1" <?php echo $checked ?> />
<label class="custom-control-label" for="chxlogenable"><?php echo _("Logfile output"); ?></label>
<label class="custom-control-label align-middle" for="chxlogenable"><?php echo _("Logfile output"); ?></label>
<input type="button" class="btn btn-outline btn-warning btn-sm align-top ml-2" id="js-clearhostapd-log" value="<?php echo _("Clear log"); ?>" />
</div>
<div class="row">
@ -15,7 +16,7 @@
if ($arrHostapdConf['LogEnable'] == 1) {
exec('sudo /bin/chmod o+r /tmp/hostapd.log');
$log = file_get_contents('/tmp/hostapd.log');
echo '<textarea class="logoutput">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>';
echo '<textarea class="logoutput" id="hostapd-log">'.htmlspecialchars($log, ENT_QUOTES).'</textarea>';
} else {
echo '<textarea class="logoutput my-3"></textarea>';
}

5
templates/openvpn/logging.php

@ -5,11 +5,12 @@
<div class="custom-control custom-switch">
<input class="custom-control-input" id="log-openvpn" type="checkbox" name="log-openvpn" value="1" <?php echo $logEnable ? ' checked="checked"' : "" ?> aria-describedby="log-openvpn">
<label class="custom-control-label" for="log-openvpn"><?php echo _("Enable logging") ?></label>
<label class="custom-control-label align-middle" for="log-openvpn"><?php echo _("Enable logging") ?></label>
<input type="button" class="btn btn-outline btn-warning btn-sm align-top ml-2" id="js-clearopenvpn-log" value="<?php echo _("Clear log"); ?>" />
</div>
<div class="row">
<div class="form-group col-md-8 mt-2">
<textarea class="logoutput"><?php echo htmlspecialchars($logOutput, ENT_QUOTES); ?></textarea>
<textarea class="logoutput" id="openvpn-log"><?php echo htmlspecialchars($logOutput, ENT_QUOTES); ?></textarea>
</div>
</div>
</div><!-- /.tab-pane -->

Loading…
Cancel
Save