monitoring-plugins/.github/prepare_debian.sh
inqrphl b9cd60ec3a
add proxy argument and improve dns cache usage (#2209)
* add proxy argument and improve dns cache usage

add proxy argument that useing the -x and --proxy argument. add it to
the static curl config struct, command usage and help outputs of the
cli.

parse these argument together with the environment variables like
http_proxy before setting the CURLOPT_PROXY in the curl configuration
option. this is required, as there is no easy way to ascertain/get what
the CURLOPT_PROXY that libcurl will use. by the point it is set by
libcurl, we have no control over it anymore, and need it for the other
steps in the configuration.

if the CURLOPT_PROXY is set, skip the DNS cache population which would
set the CURLOPT_RESOLVE. this is currently not perfect however. if a
proxy is set with socks4 or socks5 scheme, the host should be resolving
the hostname.

* codespell, clang-format and hints fixes

* add curl version and ssl enabelement macro checks

might fix rocky linux 8 compilation issues.

* add proxy_resolves_hostname, determined by proxy scheme

leave the functions that print out an curl_easyoption, but dont use it. organize the code slightly, print out the final CURLOPT_PROXY and proxy_resolves_hostname flag on verbose mode, add comments

* remove unused handle_curl_easyoption and format_curl_easyoption functions

* fix typo in the proxy argument

* fix typo with proxy scheme socks5a->socks5h

* improve proxy environment parsing

add another argument: --no-proxy , which is used when setting
CURL_NOPROXY

additionally parse all_proxy, ALL_PROXY, no_proxy and NO_PROXY
environment variables in the correct order.

set the curlopt_proxy and curlopt_noproxy of libcurl, and additionally
save them in check_curl_working_state.

add function determine_hostname_resolver, uses the working state and
static config. it can tokenize the no_proxy variable and check for exact
matches, but cannot determine subnet matches for ip addresses yet.

* document proxy cli arguments

clarify and add more examples of proxy environment variables and their
behavior when multiple are specified, overriden etc.

add single wildcard '*' checking for no_proxy to
determine_hostname_resolver, special case per curlopt_noproxy
documentation

* check curlopt_noproxy before accessing it

* switch argument from --no-proxy to --noproxy like curl cli

* check if host name is a subdomain of an noproxy item

* use strdup where destination working_state.curlopt_proxy may be NULL

* add disclaimer about uppercase HTTP_PROXY

* add subdomain checks for each item in the no_proxy, if the target host is a subdomain proxy wont resolve it

add function ip_addr_inside_cidr, use it for checking possible cidr ranges  given in the no_proxy

* wip tests that work on local perl http/https server

* wip tests that work on the live debian image

* fix subnet definition

* make apache2 listen on [::1] for ipv6 tests

* remove squid certificate

* rewrite ip_addr_inside_cidr, split ipv4 and ipv6 parsing path and copy them to a shared buffer later on for prefix check

* Adapt tests for the squid sever, disable checking return code for socks 4/5 proxies. Squid does not support it, and we do not install a capable proxy for these schemes.

* specify localhost acl and allow it through the proxy. used in check_curl tests

* typo in comment

* move function comments to header

* fix failing tests

* handle case where proxy is set as empty string

* removed duplicate tests, corrected wrong comments

* corrected some annotations

* move docker apache subdomain setup files to /tools/subdomain1

* add a newline before dying in handle_curl_option_return_code

* fix the -ssl better, now does not segfault on empty --ssl argument as well.


---------

Co-authored-by: Ahmet Oeztuerk <Ahmet.Oeztuerk@consol.de>
2026-03-13 15:54:23 +01:00

149 lines
3.6 KiB
Bash
Executable file

#!/bin/bash
set -x
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
source /etc/os-release
if [ ${ID} = "debian" ]; then
if [ -f /etc/apt/sources.list.d/debian.sources ]; then
sed "s/main/non-free contrib/g" /etc/apt/sources.list.d/debian.sources > /etc/apt/sources.list.d/debian-nonfree.sources
else
apt-get update
apt-get -y install software-properties-common
apt-add-repository non-free
fi
fi
apt-get update
apt-get -y install perl \
autotools-dev \
libdbi-dev \
libldap2-dev \
libpq-dev \
libradcli-dev \
libnet-snmp-perl \
libsnmp-dev \
procps \
libdbi0-dev \
libdbd-sqlite3 \
libssl-dev \
dnsutils \
snmp-mibs-downloader \
libsnmp-perl \
snmpd \
fping \
snmp \
netcat-openbsd \
smbclient \
vsftpd \
apache2 \
ssl-cert \
postfix \
libhttp-daemon-ssl-perl \
libdbd-sybase-perl \
libnet-dns-perl \
slapd \
ldap-utils \
gcc \
make \
autoconf \
automake \
gettext \
faketime \
libmonitoring-plugin-perl \
libcurl4-openssl-dev \
liburiparser-dev \
squid \
openssh-server \
mariadb-server \
mariadb-client \
libmariadb-dev \
libmariadb-dev-compat \
cron \
iputils-ping \
iproute2 \
libjson-perl
# remove ipv6 interface from hosts
# sed '/^::1/d' /etc/hosts > /tmp/hosts
# cp -f /tmp/hosts /etc/hosts
# ip addr show
# cat /etc/hosts
# apache
a2enmod ssl
a2ensite default-ssl
# replace snakeoil certs with openssl generated ones as the make-ssl-cert ones
# seems to cause problems with our plugins
rm /etc/ssl/certs/ssl-cert-snakeoil.pem
rm /etc/ssl/private/ssl-cert-snakeoil.key
openssl req -nodes -newkey rsa:2048 -x509 -sha256 -days 365 -nodes -keyout /etc/ssl/private/ssl-cert-snakeoil.key -out /etc/ssl/certs/ssl-cert-snakeoil.pem -subj "/C=GB/ST=London/L=London/O=Global Security/OU=IT Department/CN=$(hostname)"
# add a subdomain for testing
cp tools/subdomain1/subdomain1.conf /etc/apache2/sites-available/
mkdir -p /var/www/subdomain1
cp tools/subdomain1/index.php /var/www/subdomain1/
echo '127.0.0.1 subdomain1.localhost' >> /etc/hosts
echo '127.0.0.1 subdomain1.localhost.com' >> /etc/hosts
apache2ctl configtest
a2ensite subdomain1.conf
# Make it listen to both IPv4 on IPv6 on localhost
sed -i 's/^Listen 80/Listen 0.0.0.0:80\nListen [::1]:80/' /etc/apache2/ports.conf
sed -i 's/^[[:space:]]*Listen 443/Listen 0.0.0.0:443\nListen [::1]:443/' /etc/apache2/ports.conf
service apache2 restart
# squid
cp tools/squid.conf /etc/squid/squid.conf
service squid start
# mariadb
service mariadb start || service mysql start
mysql -e "create database IF NOT EXISTS test;" -uroot
# ldap
sed -e 's/cn=admin,dc=nodomain/'$(/usr/sbin/slapcat|grep ^dn:|awk '{print $2}')'/' -i .github/NPTest.cache
service slapd start
# sshd
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
service ssh start
sleep 1
ssh-keyscan localhost >> ~/.ssh/known_hosts
touch ~/.ssh/config
# start one login session, required for check_users
ssh -tt localhost </dev/null >/dev/null 2>/dev/null &
disown %1
# snmpd
service snmpd stop
mkdir -p /var/lib/snmp/mib_indexes
sed -e 's/^agentaddress.*/agentaddress 127.0.0.1/' -i /etc/snmp/snmpd.conf
service snmpd start
sed 's/^mibs ://' -i /etc/snmp/snmp.conf
# start cron, will be used by check_nagios
cron
# postfix
cat <<EOD >> /etc/postfix/master.cf
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes
EOD
service postfix start
# start ftpd
service vsftpd start
# hostname
sed "/NP_HOST_TLS_CERT/s/.*/'NP_HOST_TLS_CERT' => '$(hostname)',/" -i /src/.github/NPTest.cache
# create some test files to lower inodes
for i in $(seq 10); do
touch /media/ramdisk2/test.$i
done