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
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
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 (http://httpd.apache.org/docs/current/mod/mod_setenvif.html)
# 2 - mod_headers (http://httpd.apache.org/docs/current/mod/mod_headers.html)
<IfModule mod_setenvif.c>
# Add envirinment variables from a request header
SetEnvIf CF-Connecting-IP "^(.+)$" CF_Connecting_IP=$1
@AndisGrossteins
AndisGrossteins / iptables-multiport.conf
Created Sep 20, 2018
Updated correct fail2ban for permanent and persistent bans from https://wp.me/p5Ub2q-7w because WordPress.com comments suck for code snippets.
View iptables-multiport.conf
[Definition]
# 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
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
<?php
/**
* Dynamically allocate memory based on image dimensions, bit-depth and channels
* Shamelessly stolen somewhere online years ago.
* Probably from https://alvarotrigo.com/blog/allocate-memory-on-the-fly-PHP-image-resizing/
*
* @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: http://php.net/imagecreatefromjpeg#76968
* @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.