Skip to content

Instantly share code, notes, and snippets.

Andis AndisGrossteins

Block or report user

Report or block AndisGrossteins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
AndisGrossteins / httpd.conf
Last active Jan 18, 2019
Custom Apache log format for better logging and reporting by @krader1961
View httpd.conf
# --- [SNIP] ---
# Special format by @krader1961
# His comment: I use a format that provides a human readable local time and a seconds since the UNIX epoch at UTC:
LogFormat "%{%Y-%m-%dT%H:%M:%S}t %{sec}t.%{usec_frac}t %>s %{error_notes}e %D %B %h %{Host}i \"%r\" \"%{Referer}i\" \"%{User-Agent}i\"" krader_custom
# I think I've removed and recreaed his original timestamp part (or something) because it caused my Apache to crash
### USAGE:
# In the global or vhost config...
# CustomLog "/var/log/apache2/krader_custom_access_%Y-%m-%d.log" krader_custom
AndisGrossteins / .htaccess
Last active Oct 11, 2019
A hack to log real IP addresses on share Apache hosting behind CloudFlare (or other) reverse proxy
View .htaccess
# Set environment variables from request headers and add them to User-Agent header
# it's not much but it works
# Requirements:
# 1 - mod_setenvif (
# 2 - mod_headers (
<IfModule mod_setenvif.c>
# Add envirinment variables from a request header
SetEnvIf CF-Connecting-IP "^(.+)$" CF_Connecting_IP=$1
AndisGrossteins / iptables-multiport.conf
Created Sep 20, 2018
Updated correct fail2ban for permanent and persistent bans from because comments suck for code snippets.
View iptables-multiport.conf
# Option: actionstart
# Notes.: command executed once at the start of Fail2Ban.
# Values: CMD
actionstart = iptables -N fail2ban-<name>
iptables -A fail2ban-<name> -j RETURN
iptables -I <chain> -p <protocol> -m multiport --dports <port> -j fail2ban-<name>
cat /etc/fail2ban/persistent.bans | awk '/^fail2ban-<name>/ {print $2}' \
AndisGrossteins / image-allocate-memory.php
Last active Jun 30, 2018
Function to allocate memory for image processing with PHP in a smart way.
View image-allocate-memory.php
* Dynamically allocate memory based on image dimensions, bit-depth and channels
* Shamelessly stolen somewhere online years ago.
* Probably from
* @param string $filename Full path to a file supported by getimagesize() function
* @param int $tweak_factor Multiplier for tweaking required memory. 1.8 seems fine. More info:
* @param string $original_name Used purely for reporting actual file name instead of uploaded temp file (e.g. /tmp/RaNd0m.tmp)
You can’t perform that action at this time.