Skip to content

Instantly share code, notes, and snippets.

@dhaupin
dhaupin / dev_script_bot_tarpit.php
Last active December 12, 2022 03:19
Function - Bot honeypot + timewaster tarpit + Fail2Ban
<?php
// Dribbler Tarbaby Community v.0.1.0 - Copyright 2013-2014 under GNU/GPL
// Original script by Mike (zaphod@spambotsecurity.com)
// http://www.stopforumspam.com/forum/viewtopic.php?pid=41173
//
// Contributors:
// John Darkhorse
// Derek Haupin (dhaupin@gmail.com)
//
// @@ WARNING @@
@dhaupin
dhaupin / dev_script_simple_web_app_firewall.php
Last active April 21, 2022 18:20
Function - WAF - Look for common injection, traversal, or escalation hits, then init an action
<?php
// @@TODO@@ classify this as a pub pre-controller
// @@TODO@@ semicolin var, might help edge \xYZ style hexors -- might affect speed though
// @@TOTO@@ make vars to turn on blocking of common WP and enterprise requests
// @@TODO@@ make modes to check in user agent, referrer, post, headers
// @@TODO@@ mode for strict validation of IP in addr + forwarder style headers
// @@TODO@@ testing mode (still allows traffic)
// @@TODO@@ log wrapper and modes
@dhaupin
dhaupin / dev_script_google_merch_taxonomy.php
Last active September 12, 2021 09:26
Function - Parse Google merchant center shopping categories into Array or JSON - works with search url param or direct category_id argument
<?php
// This is part of a product class, this function shalt also be available via route with optional ?search= param
// $this->request->get is platform specific, change it to whatever your request wrapper uses
public function googlecats($cat_ids = false) {
// default format
$json = true;
@dhaupin
dhaupin / userDefineLang.xml
Created April 20, 2017 18:25
Config - Notepad++ Smarty TPL Highlighting
<NotepadPlus>
<UserLang name="Smarty-DH" ext="tpl" udlVersion="2.1">
<Settings>
<Global caseIgnored="no" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="yes" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00{* 01 02*} 03 04*</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@dhaupin
dhaupin / dev_cli_cpanel_update_hooks.txt
Created April 28, 2017 15:03
Example - WHM/cPanel Update Hooks
# https://documentation.cpanel.net/display/SDK/Guide+to+Standardized+Hooks+-+The+manage_hooks+Utility
# To add a script to upcp schema (as a hook)
/usr/local/cpanel/bin/manage_hooks add script /root/src/cpanel-hooks/postupcp.sh --manual --category System --event upcp --stage post
# To remove a script as hook from upcp schema
/usr/local/cpanel/bin/manage_hooks delete script /root/src/cpanel-hooks/postupcp.sh --manual --category System --event upcp --stage post
# To list current hooks (
/usr/local/cpanel/bin/manage_hooks list
@dhaupin
dhaupin / dev_wp_shortcode_woo_login_register.php
Last active November 15, 2020 06:16
Wordpress shortcode to display WP or Woocommerce login forms
<?php
/**
* Shortcode - Render Wordpress login form
**/
add_shortcode('wp_login_form', function() {
if (is_user_logged_in()) {
} else {
ob_start();
@dhaupin
dhaupin / dev_script_routing_proxy_ssl.php
Last active June 23, 2020 16:21
Function - Route reverse proxy SSL flags, rewrite REMOTE_ADDR, and add PROTOCOL index
<?php
// Rewrite client IP based on proxy headers
$ip_pool = array(
!empty($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : '',
!empty($_SERVER['HTTP_CF_PSEUDO_IPV4']) ? $_SERVER['HTTP_CF_PSEUDO_IPV4'] : '',
!empty($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '',
!empty($_SERVER['HTTP_X_FORWARDED']) ? $_SERVER['HTTP_X_FORWARDED'] : '',
!empty($_SERVER['HTTP_FORWARDED_FOR']) ? $_SERVER['HTTP_FORWARDED_FOR'] : '',
@dhaupin
dhaupin / dev_script_ui_breakpoint_listener.css
Last active December 2, 2019 03:16
Function - Listen for changes in CSS media breakpoints - append UI attribs to <html>
/* UI Breakpoint Listener
* Requires underscore/lodash for _debounce
*/
body:after {
content: 'widescreen';
display: none;
}
@media screen and (max-width: 1024px){
body:after {
@dhaupin
dhaupin / dev_opencart_img_check.php
Last active October 3, 2018 04:47
Opencart - Crawls over database looking for images/pdfs used and outputs them as a simple text list. CP/Rclone/PHP can use this list to truncate out unused files.
<?php
# Idea from: https://github.com/zenseo/opencart-needless-image
# PHP is not good enough to run this through a large store with many images
# Bash cp cant hold enough arguments from file output unless its batched
# Rclone is the best bet:
# rsync -asv --dry-run --recursive --remove-source-files --checksum --files-from=some-file.txt . destination/
function findImages() {
$tables_to_check = array(
@dhaupin
dhaupin / etc_bash.bashrc.sh-apps
Last active November 20, 2017 15:05
Random Bash Aliases & Functions
backup-oc() {
accnt=account
prefix=prefix
path=subfolder (no pre or trailing slash)
if [ ! -d "/backup/_SYNC/${accnt}" ]; then
mkdir -p /backup/_SYNC/${accnt}
fi
if [ ! -d "/home/${accnt}/_SYNC" ]; then