Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log encoding=auto ends up being ANSI_X3.4-1968 #1587

Closed
szepeviktor opened this issue Oct 23, 2016 · 14 comments
Closed

Log encoding=auto ends up being ANSI_X3.4-1968 #1587

szepeviktor opened this issue Oct 23, 2016 · 14 comments

Comments

@szepeviktor
Copy link
Member

szepeviktor commented Oct 23, 2016

# fail2ban-client get recidive logencoding
Current log encoding is set to:
ANSI_X3.4-1968

Fail2ban v0.9.5 is started by SysVinit.

Should I add LC_ALL="en_US.UTF-8" to /etc/defaults/fail2ban to set auto logencoding to UTF-8?
The Debian system locale is en_US.UTF-8.

Please advise.

@szepeviktor szepeviktor changed the title Log encoding auto ends up being ANSI_X3.4-1968 Log encoding=auto ends up being ANSI_X3.4-1968 Oct 23, 2016
@szepeviktor
Copy link
Member Author

Logged in as root:

$ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> print(locale.getpreferredencoding())
UTF-8

@sebres
Copy link
Contributor

sebres commented Apr 11, 2017

No idea why...
Still acute issue?
Only recidive, or another jails affected also?

@szepeviktor
Copy link
Member Author

I have not backported 0.9.6.
In 0.9.5-1 it is still ANSI_X3.4-1968

$ fail2ban-client get recidive logencoding
Current log encoding is set to:
ANSI_X3.4-1968

@sebres
Copy link
Contributor

sebres commented Apr 11, 2017

recidive only?

@szepeviktor
Copy link
Member Author

Excuse me.
No.

$ fail2ban-client get apache-instant logencoding
Current log encoding is set to:
ANSI_X3.4-1968

@sebres
Copy link
Contributor

sebres commented Apr 13, 2017

Could you provide results of:

python -c "from fail2ban.server.filter import Filter; f = Filter(None); print(f.getLogEncoding())"
fail2ban-client -d | grep -E "(recidive|apache).*encoding"

No idea about default encoding by services starting via SysVinit, but I think it not matters normally, and should use the system encoding (at least I've never seen something others).

@szepeviktor
Copy link
Member Author

Here it is

cd /usr/lib/python3/dist-packages/
python -c "from fail2ban.server.filter import Filter; f = Filter(None); print(f.getLogEncoding())"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "fail2ban/server/filter.py", line 38, in <module>
    from .action import CommandAction
  File "fail2ban/server/action.py", line 109
    class ActionBase(object, metaclass=ABCMeta):
                                      ^
SyntaxError: invalid syntax

fail2ban-client -d | grep -E "(recidive|apache).*encoding"
['set', 'recidive', 'logencoding', 'auto']
['set', 'apache-default', 'logencoding', 'auto']
['set', 'apache-combined', 'logencoding', 'auto']
['set', 'apache-instant', 'logencoding', 'auto']
['set', 'apache-cf1-combined', 'logencoding', 'auto']
['set', 'apache-cf1-instant', 'logencoding', 'auto']

@szepeviktor
Copy link
Member Author

Excuse me, Fail2ban runs on Python 3

python3 -c "from fail2ban.server.filter import Filter; f = Filter(None); print(f.getLogEncoding())"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'Filter' object has no attribute 'getLogEncoding'

@szepeviktor
Copy link
Member Author

This is the env of /usr/bin/fail2ban-server

BOOT_IMAGE=/boot/vmlinuz-3.16.0-4-amd64
COLUMNS=80
CONSOLE=/dev/console
HOME=/root
INIT_VERSION=sysvinit-2.88
LINES=25
PATH=/usr/sbin:/usr/bin:/sbin:/bin
PREVLEVEL=N
PWD=/
RUNLEVEL=2
SHELL=/bin/sh
SHLVL=3
TERM=linux
_=/sbin/start-stop-daemon
drop_caps=
init=/sbin/init
previous=N
rootmnt=/root
runlevel=2

@szepeviktor
Copy link
Member Author

But 😄

python3 -c "import locale; print(locale.getpreferredencoding())"
UTF-8

@szepeviktor
Copy link
Member Author

szepeviktor commented Apr 13, 2017

But I think on the terminal it comes from LC_ALL=en_US.UTF-8

And fail2ban-server has no such env variable.

@sebres
Copy link
Contributor

sebres commented Apr 19, 2017

IMHO the debian way is to set locale as LANG and not LC_ALL...

And corresponding this man sysvinit-utils/service.8, service should pass LANG (as well as LC_ALL) to the calling init script.

What did you have in /etc/default/locale (resp. in /etc/environment, but no idea about this in sysvinit)?

Check the locales are installed and select system locale via dpkg-reconfigure...

?sudo? apt-get install locales
?sudo? dpkg-reconfigure locales

Which env has your init process? (cat /proc/1/environ)

@szepeviktor
Copy link
Member Author

cat /proc/1/environ|tr '\0' '\n'
SHLVL=1
HOME=/
init=/sbin/init
TERM=linux
drop_caps=
BOOT_IMAGE=/boot/vmlinuz-3.16.0-4-amd64
PATH=/sbin:/usr/sbin:/bin:/usr/bin
PWD=/
rootmnt=/root


cat /etc/default/locale
#  File generated by update-locale
LANG=en_US.UTF-8

/etc/environment is empty as in all Debian

@sebres
Copy link
Contributor

sebres commented Aug 18, 2017

Fixed on the code-level in #1868, but ...

Note: Notwithstanding, this fixes many encoding problems, would be a good idea correctly set all expected environment variables for fail2ban daemon in init- resp. systemd-scripts or server configuration.

@sebres sebres closed this as completed Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants