File fail2ban.spec of Package fail2ban

#
# spec file for package fail2ban
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           fail2ban
Version:        0.9.3
Release:        0
Summary:        Bans IP addresses that make too many authentication failures
License:        GPL-2.0+
Group:          Productivity/Networking/Security
Url:            http://www.fail2ban.org/
Source0:        https://github.com/fail2ban/fail2ban/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source2:        %{name}.sysconfig
Source3:        %{name}.logrotate
Source5:        %{name}.tmpfiles
Source6:        sfw-fail2ban.conf
Source7:        f2b-restart.conf
# Path definitions have been submitted to upstream
Source8:        paths-opensuse.conf
# ignore some rpm-lint messages
Source200:      %{name}-rpmlintrc
# PATCH-FIX-OPENSUSE fail2ban-opensuse-locations.patch bnc#878028 jweberhofer@weberhofer.at -- update default locations for logfiles
Patch100:       fail2ban-opensuse-locations.patch
# PATCH-FIX-OPENSUSE fail2ban-opensuse-service.patch jweberhofer@weberhofer.at -- openSUSE modifications to the service file
Patch101:       fail2ban-opensuse-service.patch
# PATCH-FIX-OPENSUSE fail2ban-exclude-ExecuteTimeoutWithNastyChildren-test.patch jweberhofer@weberhofer.at -- disable test which currently fails on some systems
Patch102:       fail2ban-exclude-ExecuteTimeoutWithNastyChildren-test.patch
# PATCH-FIX-OPENSUSE fail2ban-disable-iptables-w-option.patch jweberhofer@weberhofer.at -- disable iptables "-w" option for older releases
Patch200:       fail2ban-disable-iptables-w-option.patch
# PATCH-FIX-OPENSUSE fail2ban-exclude-dev-log-tests.patch jweberhofer@weberhofer.at -- remove tests that can't work on opensuse < 13.3
Patch201:       fail2ban-exclude-dev-log-tests.patch
BuildRequires:  fdupes
BuildRequires:  logrotate
BuildRequires:  python-devel
# timezone package is required to run the tests
BuildRequires:  timezone
Requires:       cron
Requires:       ed
Requires:       iptables
Requires:       logrotate
Requires:       python >= 2.5
Requires:       whois
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%if 0%{?suse_version} != 1110
BuildArch:      noarch
%endif
%if 0%{?suse_version} < 1230
# the init-script requires lsof
Requires:       lsof
Requires:       syslog
%else
BuildRequires:  systemd
Requires:       systemd
%{?systemd_requires}
%endif
%if 0%{?suse_version} >= 1140 && 0%{?suse_version} != 1010  && 0%{?suse_version} != 1110 && 0%{?suse_version} != 1315
BuildRequires:  python-pyinotify
Requires:       python-pyinotify
%endif
%if 0%{?suse_version} >= 1220
Requires:       python-gamin
%endif

%description
Fail2ban scans log files like %{_localstatedir}/log/messages and bans IP
addresses that makes too many password failures. It updates firewall rules to
reject the IP address, can send e-mails, or set host.deny entries.  These rules
can be defined by the user. Fail2Ban can read multiple log files such as sshd
or Apache web server ones.

%package tests
Summary:        Test-cases for fail2ban
Group:          System/Monitoring

%description tests
This package contains fail2ban's testcases

%package -n SuSEfirewall2-fail2ban
Summary:        Files for integrating fail2ban into SuSEfirewall2 via systemd
Group:          Productivity/Networking/Security
Requires:       SuSEfirewall2
Requires:       fail2ban
Recommends:     packageand(SuSEfirewall2:fail2ban)

%description -n SuSEfirewall2-fail2ban
This package ships systemd files which will cause fail2ban to be ordered in
relation to SuSEfirewall2 such that the two can be run concurrently within
reason, i.e. SFW will always run first because it does a table flush.

%package -n nagios-plugins-fail2ban
%define         nagios_plugindir %{_libexecdir}/nagios/plugins
Summary:        Check fail2ban server and how many IPs are currently banned
Group:          System/Monitoring

%description -n nagios-plugins-fail2ban
This plugin checks if the fail2ban server is running and how many IPs are
currently banned.  You can use this plugin to monitor all the jails or just a
specific jail.

How to use
----------
Just have to run the following command:
  $ ./check_fail2ban --help

%prep
%setup -q
install -m644 %{SOURCE8} config/paths-opensuse.conf

# Use openSUSE paths
sed -i -e 's/^before = paths-.*/before = paths-opensuse.conf/' config/jail.conf

%patch100 -p1
%patch101 -p1
%patch102 -p1
%if 0%{?suse_version} < 1310
%patch200 -p1
%endif
%if 0%{?suse_version} < 1321
%patch201 -p1
%endif

rm 	config/paths-debian.conf \
	config/paths-fedora.conf \
	config/paths-freebsd.conf \
	config/paths-osx.conf

# correct doc-path
sed -i -e 's|%{_datadir}/doc/fail2ban|%{_docdir}/%{name}|' setup.py

%build
export CFLAGS="%{optflags}"
python setup.py build
gzip man/*.{1,5}

%install
python setup.py install \
	--root=%{buildroot} \
	--prefix=%{_prefix}

install -d -m 755 %{buildroot}%{_mandir}/man{1,5}
install -p -m 644 man/fail2ban-*.1.gz %{buildroot}%{_mandir}/man1
install -p -m 644 man/jail.conf.5.gz %{buildroot}%{_mandir}/man5

install -d -m 755 %{buildroot}%{_initrddir}
install -d -m 755 %{buildroot}%{_sbindir}

%if 0%{?suse_version} >= 1230

install -d -m 755 %{buildroot}%{_unitdir}
install -p -m 644 files/%{name}.service %{buildroot}%{_unitdir}/%{name}.service

install -d -m 755 %{buildroot}%{_libexecdir}/tmpfiles.d/
install -p -m 644 %{SOURCE5} %{buildroot}%{_libexecdir}/tmpfiles.d/%{name}.conf

sed -i -e 's/^backend = auto/backend = systemd/' %{buildroot}%{_sysconfdir}/%{name}/paths-opensuse.conf
%else

install -m 755 files/suse-initd %{buildroot}%{_initddir}/%{name}
ln -sf %{_initddir}/%{name} %{buildroot}%{_sbindir}/rc%{name}
install -d -m 755 %{buildroot}%{_localstatedir}/run/%{name}
%endif

install -d -m 0755 %{buildroot}%{_localstatedir}/lib/fail2ban/

install -d -m 755 %{buildroot}%{_localstatedir}/adm/fillup-templates
install -p -m 644 %{SOURCE2} %{buildroot}%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}

install -d -m 755 %{buildroot}%{_sysconfdir}/logrotate.d
install -p -m 644 %{SOURCE3}  %{buildroot}%{_sysconfdir}/logrotate.d/fail2ban

%if 0%{?_unitdir:1}
install -Dm 0644 "%{_sourcedir}/sfw-fail2ban.conf" \
	"%{buildroot}%{_unitdir}/SuSEfirewall2.service.d/fail2ban.conf"
install -D -m 0644 "%{_sourcedir}/f2b-restart.conf" \
	"%{buildroot}%{_unitdir}/fail2ban.service.d/SuSEfirewall2.conf"
%endif
install -D -m 755 files/nagios/check_fail2ban %{buildroot}%{nagios_plugindir}/check_fail2ban

# install docs using the macro
rm -r %{buildroot}%{_docdir}/%{name}

# remove duplicates
%fdupes -s %{buildroot}%{python_sitelib}

%check
#stat /dev/log
#python -c "import platform; print(platform.system())"
# tests require python-pyinotify to be installed, so don't run them on older versions
%if 0%{?suse_version} >= 1140 && 0%{?suse_version} != 1010  && 0%{?suse_version} != 1110 && 0%{?suse_version} != 1315
# Need a UTF-8 locale to work
export LANG=en_US.UTF-8
./fail2ban-testcases-all --no-network
%endif

%pre
%if 0%{?suse_version} >= 1230
%service_add_pre %{name}.service
%endif

%post
%fillup_only
%if 0%{?suse_version} >= 1230
systemd-tmpfiles --create %{_libexecdir}/tmpfiles.d/%{name}.conf
%service_add_post %{name}.service
%endif

%preun
%if 0%{?suse_version} >= 1230
%service_del_preun %{name}.service
%else
%stop_on_removal %{name}
%endif

%postun
%if 0%{?suse_version} >= 1230
%service_del_postun %{name}.service
%else
%restart_on_update %{name}
%insserv_cleanup
%endif

%if 0%{?_unitdir:1}
%post -n SuSEfirewall2-fail2ban
%{_bindir}/systemctl daemon-reload >/dev/null 2>&1 || :

%postun -n SuSEfirewall2-fail2ban
%{_bindir}/systemctl daemon-reload >/dev/null 2>&1 || :
%endif

%files
%defattr(-, root, root)
%config(noreplace) %{_sysconfdir}/%{name}
%config %{_sysconfdir}/logrotate.d/fail2ban
%dir %{_localstatedir}/lib/fail2ban/
%if 0%{?suse_version} >= 1230
%{_unitdir}/%{name}.service
%{_libexecdir}/tmpfiles.d/%{name}.conf
%else
%{_initddir}/%{name}
%{_sbindir}/rc%{name}
%dir %ghost %{_localstatedir}/run/%{name}
%endif
%{_bindir}/fail2ban-server
%{_bindir}/fail2ban-client
%{_bindir}/fail2ban-regex
%{python_sitelib}/%{name}
%exclude %{python_sitelib}/%{name}/tests
%{python_sitelib}/%{name}-*
%{_localstatedir}/adm/fillup-templates/sysconfig.%{name}
%{_mandir}/man1/*
%{_mandir}/man5/*
%doc README.md TODO ChangeLog COPYING doc/*.txt

%if 0%{?_unitdir:1}
%files -n SuSEfirewall2-fail2ban
%defattr(-,root,root)
%{_unitdir}/SuSEfirewall2.service.d
%{_unitdir}/fail2ban.service.d
%endif

%files tests
%defattr(-,root,root)
%{_bindir}/fail2ban-testcases
%{python_sitelib}/%{name}/tests

%files -n nagios-plugins-fail2ban
%defattr(-,root,root)
%doc files/nagios/README COPYING
%dir %{_libexecdir}/nagios
%dir %{nagios_plugindir}
%{nagios_plugindir}/check_fail2ban

%changelog
openSUSE Build Service is sponsored by