Skip to content

Instantly share code, notes, and snippets.

Avatar

GB gbot

View GitHub Profile
@gbot
gbot / wp-login-jail.local
Last active Oct 10, 2015
Fail2Ban WordPress login failure Jail and Filter. Notes:The log path uses 'access*_log' to monitor http and https logins. This will only work if WordPress is installed the webroot. Tweaking the failregex would be required to work with installs in sub-directories.
View wp-login-jail.local
[wp-login]
enabled = true
filter = wp-login
action = iptables-multiport[name=wp-login, port="http,https"]
sendmail[dest="name@domain.com", sendername="Fail2Ban", sender="fail2ban", name="wp-login"]
logpath = /var/www/vhosts/system/*/logs/access*_log
maxretry = 5
findtime = 60
bantime = 1200
@gbot
gbot / hash_password.php
Created Oct 16, 2018
Hash a string with PHP's password_hash() function.
View hash_password.php
<?php
// Hash a password
// by Gavin Botica
// requires PHP 5.5+
define("RQD_PHP_VER", "5.5");
// check php version
if (version_compare(PHP_VERSION, RQD_PHP_VER) == -1 ) {
echo "<p><b>ERROR:</b> PHP <i>" . RQD_PHP_VER . "</i> required. Version <i>" . PHP_VERSION . "</i> installed.</p>";
@gbot
gbot / wp-xmlrpc-jail.local
Last active Sep 9, 2020
Fail2Ban WordPress XMLRPC Jail and Filter. Notes: log path is set for Plesk v12.x. Change this to appropriate path for your set up. Only works if WordPress is installed in webroot, edit the Filter failregex if installed in sub-directory.
View wp-xmlrpc-jail.local
[wp-xmlrpc]
enabled = true
filter = wp-xmlrpc
action = iptables-multiport[name=wp-xmlrpc, port="http,https"]
logpath = /var/www/vhosts/system/*/logs/*access*log
/var/log/httpd/*access_log
bantime = 86400
maxretry = 0
@gbot
gbot / wp_multisite_cron.sh
Last active Sep 1, 2021
Call wp-cron.php on WP Multisite installations
View wp_multisite_cron.sh
#!/bin/bash
# Call wp-cron.php on WP Multisite installations
# Requires WP-CLI
# Looks for WP_PATH in {user_home}/wp-cli.yml, otherwise must pass in as $1
# Set up cron job with crontab -e
# Use MAILTO to send output to email or write to a log file 'bash ~/wp_multisite_cron.sh >> crontab.log'
# MAILTO=admin@email.nz
# */1 * * * * bash ~/wp_multisite_cron.sh [WP_PATH]
@gbot
gbot / jail.local
Last active Oct 6, 2021
Fail2Ban filter, jail and action (Slack message) for WordPress login failures on Spinup WP servers
View jail.local
[wordpress]
enabled = true
filter = wordpress
action = iptables-multiport[name="wordpress", port="http,https"]
slack-notify[name="wordpress"]
logpath = /sites/*/logs/access.log
/var/log/nginx/access.log
maxretry = 5
@gbot
gbot / wp_offload_media_db_migrate.json
Last active Oct 28, 2021
Migrate a WordPress database so that existing media items are served from Amazon S3 or CloudFront. Requires the WP Offload S3 Lite plugin.
View wp_offload_media_db_migrate.json
{
"use_https": "",
"purge_amazonS3_info": ""
}
@gbot
gbot / woocommerce-login-logout-redirects.php
Last active Nov 16, 2021
WP: Redirect to home page for WooCommerce login and logout. #ST3
View woocommerce-login-logout-redirects.php
/*----------------------------------------------------------------------------*/
// redirects for login / logout
/*----------------------------------------------------------------------------*/
add_filter('woocommerce_login_redirect', 'login_redirect');
function login_redirect($redirect_to) {
return home_url();
}