mirror of
https://github.com/unraid/webgui.git
synced 2026-03-20 20:02:44 -05:00
Added syslog server functionality
This commit is contained in:
90
plugins/dynamix/SyslogSettings.page
Normal file
90
plugins/dynamix/SyslogSettings.page
Normal file
@@ -0,0 +1,90 @@
|
||||
Menu="NetworkServices"
|
||||
Title="Syslog Server"
|
||||
Icon="file-text-o"
|
||||
Tag="file-text-o"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2018, Lime Technology
|
||||
* Copyright 2012-2018, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$syslog = @(array)parse_ini_file('/boot/config/rsyslog.cfg');
|
||||
?>
|
||||
<style>
|
||||
select.m130{margin-left:135px}
|
||||
select.m30{margin-left:35px}
|
||||
</style>
|
||||
<script>
|
||||
function localFolder(state) {
|
||||
if (state) $('#local_folder').show(); else $('#local_folder').hide();
|
||||
}
|
||||
$(function(){
|
||||
localFolder(document.syslog.local_server.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
<form markdown="1" name="syslog" method="POST" action="/update.php" target="progressFrame">
|
||||
<input type="hidden" name="#file" value="/boot/config/rsyslog.cfg">
|
||||
<input type="hidden" name="#command" value="/webGui/scripts/rsyslog_config">
|
||||
|
||||
Local syslog server:
|
||||
: <select name="local_server" class="narrow" size="1" onchange="localFolder(this.value)">
|
||||
<?=mk_option($syslog['local_server'], "", "Disabled")?>
|
||||
<?=mk_option($syslog['local_server'], "1", "Enabled")?>
|
||||
</select>
|
||||
<select name="server_protocol" class="narrow m130" size="1">
|
||||
<?=mk_option($syslog['server_protocol'], "udp", "UDP")?>
|
||||
<?=mk_option($syslog['server_protocol'], "tcp", "TCP")?>
|
||||
<?=mk_option($syslog['server_protocol'], "both", "Both")?>
|
||||
</select>
|
||||
<input type="text" name="server_port" class="trim" value="<?=$syslog['server_port']?>" maxlength="4" placeholder="514">
|
||||
|
||||
> Let the server act as a central syslog server and collect syslog messages from other systems.
|
||||
> The server can listen on UDP, TCP or both with a selectable port number.
|
||||
>
|
||||
> Syslog information is stored per IP address. That is every system gets its own syslog file.
|
||||
|
||||
<div markdown="1" id="local_folder" style="display:none">
|
||||
Local syslog folder:
|
||||
: <input type="text" name="server_folder" value="<?=$syslog['server_folder']?>" placeholder="/mnt/user/system">
|
||||
|
||||
> Enter the name of the local folder to store syslog information.
|
||||
> By default this is set to /mnt/user/system
|
||||
>
|
||||
> *Important: make sure the folder EXIST when changing this field*
|
||||
|
||||
</div>
|
||||
|
||||
Remote syslog server:
|
||||
: <input type="text" name="remote_server" class="narrow" value="<?=$syslog['remote_server']?>" maxlength="23" placeholder="name or ip address">
|
||||
<select name="remote_protocol" class="narrow m30" size="1">
|
||||
<?=mk_option($syslog['remote_protocol'], "udp", "UDP")?>
|
||||
<?=mk_option($syslog['remote_protocol'], "tcp", "TCP")?>
|
||||
</select>
|
||||
<input type="text" name="remote_port" class="trim" value="<?=$syslog['remote_port']?>" maxlength="4" placeholder="514">
|
||||
|
||||
> Enter a name or IP address of a remote syslog server.
|
||||
> This will send a copy of the syslog messages to the designated server.
|
||||
|
||||
Mirror syslog to flash:
|
||||
: <select name="syslog_flash" class="narrow" size="1">
|
||||
<?=mk_option($syslog['syslog_flash'], "", "No")?>
|
||||
<?=mk_option($syslog['syslog_flash'], "1", "Yes")?>
|
||||
</select>
|
||||
|
||||
> This setting is OFF by default and must be used with care to avoid unnecessary wear and tear of the USB device.
|
||||
>
|
||||
> Change this setting to YES when troubleshooting is required and it is not possible to get the regular diagnostics information.
|
||||
> A mirror of the syslog file is stored in the **logs** folder of the flash device.
|
||||
|
||||
|
||||
: <input type="submit" value="Apply" disabled><input type="button" value="Done" onclick="done()">
|
||||
</form>
|
||||
57
plugins/dynamix/scripts/rsyslog_config
Normal file
57
plugins/dynamix/scripts/rsyslog_config
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
CONF=/boot/config/rsyslog.conf
|
||||
ETC=/etc/rsyslog.conf
|
||||
|
||||
# read settings
|
||||
source /boot/config/rsyslog.cfg
|
||||
|
||||
# create local ruleset
|
||||
if ! grep -q '^\$RuleSet local$' $ETC; then
|
||||
sed -ri '/^# limetech - everything goes to syslog.$/a $RuleSet local' $ETC
|
||||
sed -ri '/^#?news.notice.*$/a $DefaultRuleset local' $ETC
|
||||
fi
|
||||
|
||||
# local syslog server
|
||||
if [[ -n $local_server ]]; then
|
||||
if [[ $server_protocol == tcp || $server_protocol == both ]]; then
|
||||
sed -ri "s/^#?(\\\$ModLoad imtcp)/\1/;s/^#?(\\\$InputTCPServerRun) [0-9]+/\1 ${server_port:-514}/" $ETC
|
||||
[[ $server_protocol == tcp ]] && sed -ri 's/^\$(ModLoad imudp|UDPServerRun)/#\$\1/' $ETC
|
||||
fi
|
||||
if [[ $server_protocol == udp || $server_protocol == both ]]; then
|
||||
sed -ri "s/^#?(\\\$ModLoad imudp)/\1/;s/^#?(\\\$UDPServerRun) [0-9]+/\1 ${server_port:-514}/" $ETC
|
||||
[[ $server_protocol == udp ]] && sed -ri 's/^\$(ModLoad imtcp|InputTCPServerRun)/#\$\1/' $ETC
|
||||
fi
|
||||
if grep -q '^\$template remote,' $ETC; then
|
||||
sed -ri '/^\$RuleSet remote$/d;/^\*\.\* \?remote$/d;/^\$template remote,".*"$/d' $ETC
|
||||
fi
|
||||
sed -ri "/^#?\\\$UDPServerRun [0-9]+.*$/a \\\$template remote,\"${server_folder:-/mnt/user/system}/syslog-%FROMHOST-IP%\"" $ETC
|
||||
sed -ri '/^# #+ Remote Logging/i $RuleSet remote\n*.* ?remote' $ETC
|
||||
else
|
||||
sed -ri 's/^#?\$(ModLoad imtcp|InputTCPServerRun|ModLoad imudp|UDPServerRun)/#\$\1/' $ETC
|
||||
sed -ri '/^\$RuleSet remote$/d;/^\*\.\* \?remote$/d;/^\$template remote,".*"$/d' $ETC
|
||||
fi
|
||||
|
||||
# remote syslog server
|
||||
if [[ -n $remote_server ]]; then
|
||||
[[ $remote_protocol == udp ]] && com='@' || com='@@'
|
||||
sed -ri "s/^#?(\*\.\*) @@?.*:[0-9]+$/\1 $com$remote_server:${remote_port:-514}/" $ETC
|
||||
else
|
||||
sed -ri 's/^#?(\*\.\* @@?.*:[0-9]+)$/#\1/' $ETC
|
||||
fi
|
||||
|
||||
# mirror syslog to flash
|
||||
if [[ -n $syslog_flash ]]; then
|
||||
if ! grep -q '^\$template flash,' $ETC; then
|
||||
sed -ri '/^#?\$UDPServerRun [0-9]+.*$/a $template flash,"/boot/logs/syslog"' $ETC
|
||||
sed -ri '/^\*\.debug .*syslog$/a *.debug ?flash' $ETC
|
||||
fi
|
||||
else
|
||||
sed -ri '/^\$template flash,"\/boot\/logs\/syslog"$/d;/^\*\.debug \?flash/d' $ETC
|
||||
fi
|
||||
|
||||
# copy conf to flash (read settings on reboot)
|
||||
cp -f $ETC $CONF
|
||||
|
||||
# update syslog daemon
|
||||
/etc/rc.d/rc.rsyslogd restart &> /dev/null
|
||||
Reference in New Issue
Block a user