mirror of
https://github.com/unraid/webgui.git
synced 2026-01-01 15:10:19 -06:00
189 lines
7.0 KiB
Plaintext
189 lines
7.0 KiB
Plaintext
Menu="NetworkServices"
|
|
Title="Syslog Server"
|
|
Icon="icon-eula"
|
|
Tag="file-text-o"
|
|
---
|
|
<?PHP
|
|
/* Copyright 2005-2023, Lime Technology
|
|
* Copyright 2012-2023, 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');
|
|
|
|
function plain($ip) {
|
|
return str_replace(['[',']'],'',$ip);
|
|
}
|
|
// Get ports in use
|
|
$portsInUse = [];
|
|
exec("lsof -Pni|awk '/LISTEN/ && \$9!~/127.0.0.1/ && \$9!~/\\[::1\\]/{print \$9}'|sort -u", $output);
|
|
|
|
$ethX = 'eth0';
|
|
$addr = ipaddr($ethX);
|
|
$bind = _var($var,'BIND_MGT')=='yes';
|
|
$list = ['*',$addr];
|
|
|
|
foreach ($output as $line) {
|
|
[$ip, $port] = my_explode(':', $line);
|
|
if (!in_array($port,$portsInUse) && (!$bind || in_array(plain($ip),$list))) $portsInUse[] = $port;
|
|
}
|
|
?>
|
|
<script>
|
|
function localFolder(local,time) {
|
|
if (local) $('#local_folder').show(time); else $('#local_folder').hide(time);
|
|
}
|
|
function logOptions(log,time) {
|
|
if (log) $('#log_options').show(time); else $('#log_options').hide(time);
|
|
}
|
|
|
|
$(function(){
|
|
localFolder(document.syslog.local_server.value);
|
|
logOptions(document.syslog.log_rotation.value);
|
|
});
|
|
function validatePort(form) {
|
|
var portsInUse = JSON.parse('<?=json_encode($portsInUse)?>');
|
|
var currentPort = "<?=(_var($syslog,'local_server') && _var($syslog,'server_protocol')!='udp') ? _var($syslog,'server_port',514) : 514?>";
|
|
var port = $(form).find('input[name="server_port"]');
|
|
var remotePort = $(form).find('input[name="remote_port"]');
|
|
var protocol = $(form).find('select[name="server_protocol"]').val();
|
|
if ( !port.val() ) port.val("514");
|
|
port.val(parseInt(port.val()));
|
|
remotePort.val(parseInt(remotePort.val()));
|
|
var newport = port.val();
|
|
if (newport != currentPort && protocol != "udp" && $(form).find('select[name="local_server"]').val()) {
|
|
if (portsInUse.includes(newport)) {
|
|
swal({title:'_(Port already in use)_',text:sprintf('_(Port %s is already in use by other services)_',newport),type:'error',showCancelButton:false,confirmButtonText:"_(OK)_"});
|
|
return;
|
|
}
|
|
}
|
|
var list = [];
|
|
if (newport < 1 || newport > 65535) {
|
|
list.push("_(Local syslog port)_");
|
|
}
|
|
var remote = remotePort.val();
|
|
if (!remote) remote = 514;
|
|
if (remote < 1 || remote > 65535) {
|
|
list.push("_(Remote syslog port)_");
|
|
}
|
|
if (list.length > 0) {
|
|
swal({title:'_(Port out of range)_',text:sprintf('_(%s is out of range (minimum 1 maximum 65535))_',list.join(", ")),type:'error',showCancelButton:false,confirmButtonText:"_(OK)_"});
|
|
return;
|
|
}
|
|
form.submit();
|
|
}
|
|
|
|
</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)_:
|
|
: <span class="span"><select name="local_server" onchange="localFolder(this.value,'slow')">
|
|
<?=mk_option(_var($syslog,'local_server'), "", _("Disabled"))?>
|
|
<?=mk_option(_var($syslog,'local_server'), "1", _("Enabled"))?>
|
|
</select></span>
|
|
<select name="server_protocol" class="narrow">
|
|
<?=mk_option(_var($syslog,'server_protocol'), "udp", _("UDP"))?>
|
|
<?=mk_option(_var($syslog,'server_protocol'), "tcp", _("TCP"))?>
|
|
<?=mk_option(_var($syslog,'server_protocol'), "both", _("Both"))?>
|
|
</select>
|
|
<input type="number" name="server_port" class="trim" value="<?=_var($syslog,'server_port')?>" maxlength="5" placeholder="514" pattern="([0-9]{1,5})">
|
|
|
|
:syslog_local_server_help:
|
|
|
|
<div markdown="1" id="local_folder" style="display:none">
|
|
_(Local syslog folder)_:
|
|
: <select name="server_folder">
|
|
<?=mk_option(0,'','<'._('custom').'>','disabled')?>
|
|
<?foreach ($shares as $share){echo mk_option(_var($syslog,'server_folder'), '/mnt/user/'.$share['name'], $share['name']);}?>
|
|
</select>
|
|
|
|
:syslog_local_folder_help:
|
|
|
|
_(System identifier for logfile name)_:
|
|
: <select name="server_filename">
|
|
<?=mk_option(_var($syslog, 'server_filename'), "syslog-%FROMHOST-IP%.log", _("IP Address"))?>
|
|
<?=mk_option(_var($syslog, 'server_filename'), "syslog-%HOSTNAME%.log", _("Hostname (from syslog message)"))?>
|
|
<?=mk_option(_var($syslog, 'server_filename'), "syslog-%FROMHOST%.log", _("Hostname (from DNS reverse lookup)"))?>
|
|
</select>
|
|
|
|
:syslog_remote_system_identifier_help:
|
|
|
|
_(Local syslog rotation)_:
|
|
: <select name="log_rotation" onchange="logOptions(this.value,'slow')">
|
|
<?=mk_option(_var($syslog,'log_rotation'), "", _("Disabled"))?>
|
|
<?=mk_option(_var($syslog,'log_rotation'), "1", _("Enabled"))?>
|
|
</select>
|
|
|
|
:syslog_local_rotation_help:
|
|
|
|
<div markdown="1" id="log_options" style="display:none">
|
|
_(Local syslog maximum file size)_:
|
|
: <select name="log_size">
|
|
<?=mk_option(_var($syslog,'log_size'), '1M', '1 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '2M', '2 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '5M', '5 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '10M', '10 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '20M', '20 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '50M', '50 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '100M', '100 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '200M', '200 '._('MB'))?>
|
|
<?=mk_option(_var($syslog,'log_size'), '500M', '500 '._('MB'))?>
|
|
</select>
|
|
|
|
:syslog_local_file_size_help:
|
|
|
|
_(Local syslog number of files)_:
|
|
: <select name="log_files">
|
|
<?=mk_option(_var($syslog,'log_files'), '1', '1')?>
|
|
<?=mk_option(_var($syslog,'log_files'), '2', '2')?>
|
|
<?=mk_option(_var($syslog,'log_files'), '3', '3')?>
|
|
<?=mk_option(_var($syslog,'log_files'), '4', '4')?>
|
|
</select>
|
|
|
|
:syslog_local_file_number_help:
|
|
|
|
</div>
|
|
</div>
|
|
|
|
_(Remote syslog server)_:
|
|
: <span class="span"><input type="text" name="remote_server" class="narrow" value="<?=htmlspecialchars(_var($syslog,'remote_server'))?>" maxlength="50" placeholder="_(name or ip address)_"></span>
|
|
<select name="remote_protocol" class="narrow">
|
|
<?=mk_option(_var($syslog,'remote_protocol'), "udp", _("UDP"))?>
|
|
<?=mk_option(_var($syslog,'remote_protocol'), "tcp", _("TCP"))?>
|
|
</select>
|
|
<input type="number" name="remote_port" class="trim" value="<?=_var($syslog,'remote_port')?>" maxlength="5" placeholder="514" pattern="([0-9]{1,5})">
|
|
|
|
:syslog_remote_server_help:
|
|
|
|
_(Mirror syslog to flash)_:
|
|
: <select name="syslog_flash">
|
|
<?=mk_option(_var($syslog,'syslog_flash'), "", _("No"))?>
|
|
<?=mk_option(_var($syslog,'syslog_flash'), "1", _("Yes"))?>
|
|
</select>
|
|
|
|
:syslog_mirror_flash_help:
|
|
|
|
_(Copy syslog to flash on shutdown)_:
|
|
: <select name="syslog_shutdown">
|
|
<?=mk_option(_var($syslog,'syslog_shutdown'), "", _("Yes"))?>
|
|
<?=mk_option(_var($syslog,'syslog_shutdown'), "1", _("No"))?>
|
|
</select>
|
|
|
|
:syslog_shutdown_flash_help:
|
|
|
|
|
|
: <span class="inline-block">
|
|
<input type="button" value="_(Apply)_" onclick='validatePort(this.form)' disabled>
|
|
<input type="button" value="_(Done)_" onclick="done()">
|
|
</span>
|
|
</form>
|