mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-17 05:53:15 +02:00
Consolidate JailInfo function to own connector_global.go and also remove old FetchBanEvents function
This commit is contained in:
@@ -2313,42 +2313,6 @@ func DeleteFilterHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": fmt.Sprintf("Filter '%s' deleted successfully", filterName)})
|
||||
}
|
||||
|
||||
// Updates /etc/fail2ban/jail.local [DEFAULT] with our JSON
|
||||
// TODO: @matthias we need to further enhance this
|
||||
func ApplyFail2banSettings(jailLocalPath string) error {
|
||||
config.DebugLog("----------------------------")
|
||||
config.DebugLog("ApplyFail2banSettings called (handlers.go)")
|
||||
s := config.GetSettings()
|
||||
|
||||
// open /etc/fail2ban/jail.local, parse or do a simplistic approach:
|
||||
// TODO: -> maybe we store [DEFAULT] block in memory, replace lines
|
||||
// or do a line-based approach. Example is simplistic:
|
||||
|
||||
chain := s.Chain
|
||||
if chain == "" {
|
||||
chain = "INPUT"
|
||||
}
|
||||
newLines := []string{
|
||||
"[DEFAULT]",
|
||||
fmt.Sprintf("enabled = %t", s.DefaultJailEnable),
|
||||
fmt.Sprintf("bantime.increment = %t", s.BantimeIncrement),
|
||||
fmt.Sprintf("ignoreip = %s", strings.Join(s.IgnoreIPs, " ")),
|
||||
fmt.Sprintf("bantime = %s", s.Bantime),
|
||||
fmt.Sprintf("findtime = %s", s.Findtime),
|
||||
fmt.Sprintf("maxretry = %d", s.Maxretry),
|
||||
fmt.Sprintf("banaction = %s", s.Banaction),
|
||||
fmt.Sprintf("banaction_allports = %s", s.BanactionAllports),
|
||||
fmt.Sprintf("chain = %s", chain),
|
||||
}
|
||||
if s.BantimeRndtime != "" {
|
||||
newLines = append(newLines, fmt.Sprintf("bantime.rndtime = %s", s.BantimeRndtime))
|
||||
}
|
||||
newLines = append(newLines, "")
|
||||
content := strings.Join(newLines, "\n")
|
||||
|
||||
return os.WriteFile(jailLocalPath, []byte(content), 0644)
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Restart
|
||||
// =========================================================================
|
||||
@@ -2484,18 +2448,6 @@ func getEmailStyle() string {
|
||||
return "modern"
|
||||
}
|
||||
|
||||
// Checks whether "LOTR" is among the configured alert countries.
|
||||
func isLOTRModeActive(alertCountries []string) bool {
|
||||
if len(alertCountries) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, country := range alertCountries {
|
||||
if strings.EqualFold(country, "LOTR") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Connects to the SMTP server and delivers a single HTML message.
|
||||
func sendEmail(to, subject, body string, settings config.AppSettings) error {
|
||||
@@ -3005,7 +2957,7 @@ func sendBanAlert(ip, jail, hostname, failures, whois, logs, country string, set
|
||||
if lang == "" {
|
||||
lang = "en"
|
||||
}
|
||||
isLOTRMode := isLOTRModeActive(settings.AlertCountries)
|
||||
isLOTRMode := config.IsLOTRModeActive(settings.AlertCountries)
|
||||
var subject string
|
||||
if isLOTRMode {
|
||||
subject = fmt.Sprintf("[Middle-earth] %s: %s %s %s",
|
||||
@@ -3092,7 +3044,7 @@ func sendUnbanAlert(ip, jail, hostname, whois, country string, settings config.A
|
||||
if lang == "" {
|
||||
lang = "en"
|
||||
}
|
||||
isLOTRMode := isLOTRModeActive(settings.AlertCountries)
|
||||
isLOTRMode := config.IsLOTRModeActive(settings.AlertCountries)
|
||||
var subject string
|
||||
if isLOTRMode {
|
||||
subject = fmt.Sprintf("[Middle-earth] %s: %s %s %s",
|
||||
|
||||
@@ -218,7 +218,6 @@ function resetServerForm() {
|
||||
document.getElementById('serverHost').value = '';
|
||||
document.getElementById('serverPort').value = '22';
|
||||
document.getElementById('serverSocket').value = '/var/run/fail2ban/fail2ban.sock';
|
||||
document.getElementById('serverLogPath').value = '/var/log/fail2ban.log';
|
||||
document.getElementById('serverHostname').value = '';
|
||||
document.getElementById('serverSSHUser').value = '';
|
||||
document.getElementById('serverSSHKey').value = '';
|
||||
@@ -240,7 +239,6 @@ function editServer(serverId) {
|
||||
document.getElementById('serverHost').value = server.host || '';
|
||||
document.getElementById('serverPort').value = server.port || '';
|
||||
document.getElementById('serverSocket').value = server.socketPath || '/var/run/fail2ban/fail2ban.sock';
|
||||
document.getElementById('serverLogPath').value = server.logPath || '/var/log/fail2ban.log';
|
||||
document.getElementById('serverHostname').value = server.hostname || '';
|
||||
document.getElementById('serverSSHUser').value = server.sshUser || '';
|
||||
document.getElementById('serverSSHKey').value = server.sshKeyPath || '';
|
||||
@@ -299,7 +297,6 @@ function submitServerForm(event) {
|
||||
host: document.getElementById('serverHost').value.trim(),
|
||||
port: document.getElementById('serverPort').value ? parseInt(document.getElementById('serverPort').value, 10) : undefined,
|
||||
socketPath: document.getElementById('serverSocket').value.trim(),
|
||||
logPath: document.getElementById('serverLogPath').value.trim(),
|
||||
hostname: document.getElementById('serverHostname').value.trim(),
|
||||
sshUser: document.getElementById('serverSSHUser').value.trim(),
|
||||
sshKeyPath: document.getElementById('serverSSHKey').value.trim(),
|
||||
@@ -311,7 +308,6 @@ function submitServerForm(event) {
|
||||
enabled: document.getElementById('serverEnabled').checked
|
||||
};
|
||||
if (!payload.socketPath) delete payload.socketPath;
|
||||
if (!payload.logPath) delete payload.logPath;
|
||||
if (!payload.hostname) delete payload.hostname;
|
||||
if (!payload.agentUrl) delete payload.agentUrl;
|
||||
if (!payload.agentSecret) delete payload.agentSecret;
|
||||
@@ -324,9 +320,6 @@ function submitServerForm(event) {
|
||||
if (payload.type !== 'local' && payload.type !== 'ssh') {
|
||||
delete payload.socketPath;
|
||||
}
|
||||
if (payload.type !== 'local') {
|
||||
delete payload.logPath;
|
||||
}
|
||||
if (payload.type !== 'ssh') {
|
||||
delete payload.sshUser;
|
||||
delete payload.sshKeyPath;
|
||||
|
||||
@@ -1210,10 +1210,6 @@
|
||||
<label for="serverSocket" class="block text-sm font-medium text-gray-700 mb-1" data-i18n="servers.form.socket_path">Fail2ban Socket Path</label>
|
||||
<input type="text" id="serverSocket" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" data-i18n-placeholder="servers.form.socket_path_placeholder" placeholder="/var/run/fail2ban/fail2ban.sock">
|
||||
</div>
|
||||
<div data-server-fields="local">
|
||||
<label for="serverLogPath" class="block text-sm font-medium text-gray-700 mb-1" data-i18n="servers.form.log_path">Fail2ban Log Path</label>
|
||||
<input type="text" id="serverLogPath" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" data-i18n-placeholder="servers.form.log_path_placeholder" placeholder="/var/log/fail2ban.log">
|
||||
</div>
|
||||
<div data-server-fields="local">
|
||||
<label for="serverHostname" class="block text-sm font-medium text-gray-700 mb-1" data-i18n="servers.form.hostname">Server Hostname</label>
|
||||
<input type="text" id="serverHostname" class="w-full border border-gray-300 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" data-i18n-placeholder="servers.form.hostname_placeholder" placeholder="optional">
|
||||
|
||||
Reference in New Issue
Block a user