Skip to content

Instantly share code, notes, and snippets.

@dkrusky
dkrusky / wow-bag-items.lua
Created January 9, 2017 10:49
Loop through all items in bags in World of Warcraft
local function countItem(item)
local c
for bag=0,NUM_BAG_SLOTS do
for slot=1,GetContainerNumSlots(bag) do
if item == GetContainerItemID(bag,slot) then
c=c+(select(2,GetContainerItemInfo(bag,slot)))
end
end
end
return c
@dkrusky
dkrusky / .htaccess
Created January 9, 2017 10:46
handle modern favicons, app path exclusion, seo files, ignore images scripts and fonts, redirect all to page handler and if file not found send different query string to page handler.
RewriteEngine On
# handle modern favicons
RewriteRule ^(browserconfig.xml|manifest.json|safari-pinned-tab.svg|(android-chrome|favicon|mstile)-[0-9]+x[0-9]+.png|apple-touch-icon(-precompressed.png|-[0-9]+x[0-9]+.png|.png)|manifest.json)$ /favicon/$1 [L]
# exclude editor path
RewriteRule ^app\/ - [L]
# handle all seo files
RewriteRule ^(epndomain.txt|LiveSearchSiteAuth.xml|google[A-Za-z0-9]+.xml|[A-Za-z0-9]+.txt|(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})[A-Za-z0-9]+.html|robots.txt|sitemap.xml)$ display.php?seo=$1 [NC,L]
@dkrusky
dkrusky / jsupdate.sh
Created January 8, 2017 06:55
Copy or Update projects from windows host to Bash on Ubuntu on Windows and set permissions
#!/bin/bash
# source folder as mount path on linux
WINPATH="/mnt/d/bash"
# destination root folder
LINPATH="/home/nodejs"
# check if <project> param received
if [ $# -ne 1 ]; then
@dkrusky
dkrusky / wordpress-force-login-as-admin.php
Created March 13, 2016 23:48
Login to WordPress as administrator (or any other user) without knowing the username or password.
<?php
include('wp-config.php');
$user_id = 1; // Default admin user id. (usually the first user entered into the database)
$remember = 1; // Remember Session (14 days approx)
$secure = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on') ? 0 : 1; // Use SSL
// Force authorization as the above user without password
wp_set_auth_cookie( $user_id, $remember, $secure );
@dkrusky
dkrusky / fixperms.sh
Created March 12, 2016 05:54
Bash file to correct web permissions. Accepts folder as a parameter, or in the absence, uses the current folder
#!/bin/sh
#mode=$1; shift
find "$@" -type f -exec chmod "0644" {} +
find "$@" -type d -exec chmod "0755" {} +
@dkrusky
dkrusky / getRawSecureWebsite.php
Last active March 11, 2016 12:43
Get SSL/TLS certificate details and full headers from a secure website.
<?php
$details = getRawSecureWebsite('www.google.com');
echo '<textarea>' . $details['raw'] . '</details>';
function getRawSecureWebsite( $domain ) {
$raw = '';
$headers = '';
@dkrusky
dkrusky / letsencrypt-cpanel.sh
Last active March 11, 2016 12:45
Install or update letsencrypt and generate a certificate for a cPanel user and domain, and email it to the user.
#!/bin/sh
INSTRUCTIONS="
<html>
<head>
</head>
<body>
<h3>Installation Instructions</h3>
<b>Step 1</b>
<p>Login to your cPanel account and look for the following icon and click it</p>
@dkrusky
dkrusky / cpanel-strengthen-dhparams-in-dovecot.sh
Last active March 11, 2016 12:46
Set dovecot to generate 2048 bit dhparams on a cPanel/WHM box.
#!/bin/sh
# if no local config for dovecot exists, make one
if[ ! -e /var/cpanel/templates/dovecot2.2/main.local ]; then
cp /var/cpanel/templates/dovecot2.2/main.default /var/cpanel/templates/dovecot2.2/main.local
fi
# check if ssl_dh_parameters exists already. if it doesn't exist, insert it
if [ -z "$(grep "ssl_dh_parameters_length" /var/cpanel/templates/dovecot2.2/main.local)" ]; then
sed -i '/ssl = \[% ssl %\]/,/\[%- ELSE %\]/ {/\[%- ELSE %\]/i ssl_dh_parameters_length = 2048}' /var/cpanel/templates/dovecot2.2/main.local
@dkrusky
dkrusky / apache-secure-virtualhost.conf
Last active March 11, 2016 12:48
Demonstrates best practices for security in an Apache virtual host. A+ rating on ssllabs.com with good backwards compatibility.
# Enable stapling. This should only be enabled ONCE and is server-wide.
SSLUseStapling on
SSLStaplingCache "shmcb:logs/stapling_cache(128000)"
# Enable strict transport
<IfModule mod_headers.c>
Header Always set Strict-Transport-Security "max-age=15638400; preload" env=HTTPS
#Header Always set Strict-Transport-Security "max-age=15638400; includeSubdomains; preload" env=HTTPS
</IfModule>