mirror of
https://github.com/swissmakers/fail2ban-ui.git
synced 2026-04-17 05:53:15 +02:00
convert boolean values to Python boolean literals in UpdateDefaultSettings function
This commit is contained in:
@@ -1361,6 +1361,16 @@ func (sc *SSHConnector) UpdateDefaultSettings(ctx context.Context, settings conf
|
|||||||
return strings.ReplaceAll(s, "'", "'\"'\"'")
|
return strings.ReplaceAll(s, "'", "'\"'\"'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert boolean values to Python boolean literals
|
||||||
|
defaultJailEnablePython := "False"
|
||||||
|
if settings.DefaultJailEnable {
|
||||||
|
defaultJailEnablePython = "True"
|
||||||
|
}
|
||||||
|
bantimeIncrementPython := "False"
|
||||||
|
if settings.BantimeIncrement {
|
||||||
|
bantimeIncrementPython = "True"
|
||||||
|
}
|
||||||
|
|
||||||
updateScript := fmt.Sprintf(`python3 <<'PY'
|
updateScript := fmt.Sprintf(`python3 <<'PY'
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -1368,15 +1378,15 @@ jail_file = '%s'
|
|||||||
ignore_ip_str = '%s'
|
ignore_ip_str = '%s'
|
||||||
banaction_val = '%s'
|
banaction_val = '%s'
|
||||||
banaction_allports_val = '%s'
|
banaction_allports_val = '%s'
|
||||||
default_jail_enable_val = '%t'
|
default_jail_enable_val = %s
|
||||||
bantime_increment_val = '%t'
|
bantime_increment_val = %s
|
||||||
bantime_val = '%s'
|
bantime_val = '%s'
|
||||||
findtime_val = '%s'
|
findtime_val = '%s'
|
||||||
maxretry_val = %d
|
maxretry_val = %d
|
||||||
destemail_val = '%s'
|
destemail_val = '%s'
|
||||||
keys_to_update = {
|
keys_to_update = {
|
||||||
'enabled': 'enabled = ' + str(default_jail_enable_val),
|
'enabled': 'enabled = ' + str(default_jail_enable_val).lower(),
|
||||||
'bantime.increment': 'bantime.increment = ' + str(bantime_increment_val),
|
'bantime.increment': 'bantime.increment = ' + str(bantime_increment_val).lower(),
|
||||||
'ignoreip': 'ignoreip = ' + ignore_ip_str,
|
'ignoreip': 'ignoreip = ' + ignore_ip_str,
|
||||||
'bantime': 'bantime = ' + bantime_val,
|
'bantime': 'bantime = ' + bantime_val,
|
||||||
'findtime': 'findtime = ' + findtime_val,
|
'findtime': 'findtime = ' + findtime_val,
|
||||||
@@ -1450,7 +1460,7 @@ else:
|
|||||||
|
|
||||||
with open(jail_file, 'w') as f:
|
with open(jail_file, 'w') as f:
|
||||||
f.writelines(output_lines)
|
f.writelines(output_lines)
|
||||||
PY`, escapeForShell(jailLocalPath), escapeForShell(ignoreIPStr), escapeForShell(banactionVal), escapeForShell(banactionAllportsVal), settings.BantimeIncrement, settings.DefaultJailEnable, escapeForShell(settings.Bantime), escapeForShell(settings.Findtime), settings.Maxretry, escapeForShell(settings.Destemail))
|
PY`, escapeForShell(jailLocalPath), escapeForShell(ignoreIPStr), escapeForShell(banactionVal), escapeForShell(banactionAllportsVal), defaultJailEnablePython, bantimeIncrementPython, escapeForShell(settings.Bantime), escapeForShell(settings.Findtime), settings.Maxretry, escapeForShell(settings.Destemail))
|
||||||
|
|
||||||
_, err = sc.runRemoteCommand(ctx, []string{updateScript})
|
_, err = sc.runRemoteCommand(ctx, []string{updateScript})
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user