Skip to content

Instantly share code, notes, and snippets.

@roojs
roojs / gist:d065c29b1d35d2b9d754cc78fc8f3b56
Last active October 8, 2025 08:21
Dovecot 2.3 to 2.4 Migration Guide - short cut for dummies and AI agents

Dovecot 2.3 to 2.4 Migration Guide

This document outlines the necessary changes to upgrade a Dovecot installation from version 2.3 to 2.4.

Prerequisites

  • Backup your existing configuration before making changes
  • Ensure you have access to the original configuration files
  • Test the migration in a non-production environment first
@roojs
roojs / nginx-bot-detect.sh
Created February 17, 2025 07:31
parse ngnix logs and find bad bots using mulitple user agents
#!/bin/bash
# Analyze Nginx logs for IPs with multiple User-Agent strings
LOG_FILE="/var/log/nginx/access.log"
TMP_FILE="/tmp/nginx-bot-detect.tmp"
# Extract IPs with multiple User-Agent strings
awk '{ a=$1; $1=""; print "\"" a "\" " $0 }' "$LOG_FILE" | awk -F'"' '{ gsub(/ /, "_", $(NF-1)); print $2, $(NF-1)}' | sort | uniq | awk '{ print $1 }' | sort | uniq -c | awk '{if ($1 > 5) print $2}' | sort | uniq > "$TMP_FILE"
# Ban IPs using Fail2Ban
@roojs
roojs / fail2ban-cloudflare.txt
Last active September 16, 2024 04:19
fail2ban nginx banned with cloudflare - usefull for load balanced servers - so all of the block the IP's trying to attack
From https://github.com/mitchellkrogza/Fail2Ban.WebExploits (filters)
* still being tested
From https://www.abemposta.com/posts/fail2ban-nginx/ (actions)
** testing cloudflare.conf (in fail2ban) - to ban IP's there.
Needed as we proxy cloudflare <-> nginx <-> apache
Get quite a few scans..
#!/bin/sh
########################################################
# #
# www.361way.com #
# Useage: check_traffic -i Interface -w warn -c cirt #
# it's for pnp4nagios check the traffic #
# based on https://exchange.nagios.org/directory/Plugins/Network-Connections%2C-Stats-and-Bandwidth/check_traffic_pnp4naios/details
########################################################
@roojs
roojs / check_wordpress
Last active November 30, 2023 04:23
check_wordpress
#!/usr/bin/php
<?php
###################################
#
# WordPress Updates Monitoring
# written by Martin Scharm
# see http://binfalse.de
#
# Modified to all skip-plugin (and hide erorrs on include)
#
@roojs
roojs / default-debian.conf
Last active November 28, 2023 01:56
fail2ban - jail.d debian default
#try and get those sneaky slow brute force ssh attackers to slow down
[sshd]
enabled = true
port = 8022
maxretry=3
bantime = 24h
findtime = 1d
#this fixes booting with new kernels - breaking cgroups on lxc and /dev/net/tun not being available in containers
GRUB_CMDLINE_LINUX="console=ttyS0,19200n8 net.ifnames=0 systemd.unified_cgroup_hierarchy=false systemd.legacy_systemd_cgroup_controller=false cgroup_enable=memo
ry swapaccount=1"
#!/bin/sh
## you might want to add some user authentication here
# from - https://tech.labelleassiette.com/how-to-reduce-the-memory-usage-of-mysql-61ea7d1a9bd
# (credits to Eduardo Franceschi)
mysql -e "show variables; show status" | awk '
{
VAR[$1]=$2
}
END {
#tends to bork containers getty + just a mess
apt install -y sysvinit-core systemd-sysv-
#reboot
apt remove -y systemd
apt-mark hold systemd systemd-sysv
#nice cleanup
apt autoremove --purge
#!/bin/bash
# find the last error - so it might change if we fix it...
# core:error - not php code related
# not found or unable to stat - are just hackers trying to break in.. can ignore
RES=$(/bin/grep PHP /var/log/apache2/error.log | /usr/bin/egrep -v 'PHP\s+[0-9]+' | /bin/grep -v 'PHP Stack' | grep -v 'Deadlock found when trying to get lock' | grep -v max_input_vars | /usr/bin/tail -1)
if [[ ( $RES == "" ) ]]; then
echo "OK"
else