Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
mttjohnson / magento2_tfa_from_cli.sh
Created February 23, 2021 23:08
Magento 2 TFA (Two-Factor Auth) usage from CLI
# Dependencies (oathtool, pwgen, python or python3)
yum install oathtool pwgen
MAGENTO_DOMAIN="xxxxxxxx_site_domain_xxxxxxxx" # example.lan
ADMIN_USER="xxxxxxxx_admin_username_xxxxxxxx" # example_admin
@mttjohnson
mttjohnson / json_encoded_complex_commands.sh
Created February 21, 2021 01:51
JSON Encode Complex Commands
# Capture complex commands using HEREDOC
set +H
COMMAND=$(cat <<'COMMAND_HEREDOC'
# disable history expansion
set +H
PHP_CODE=$(cat <<'PHP_CODE'
<?php
print 'hello ';
print "world!";
@mttjohnson
mttjohnson / macos_ruby_setup.sh
Created February 18, 2021 23:03
macOS Ruby Manager Setup
# Online references:
# https://www.moncefbelyamani.com/the-definitive-guide-to-installing-ruby-gems-on-a-mac/
# https://github.com/rbenv/rbenv
brew install rbenv
# or
brew upgrade rbenv ruby-build
# Add rbenv init to shell profile
echo '
@mttjohnson
mttjohnson / m2_env_update_db_creds.sh
Created January 14, 2021 16:42
Update Magento 2 env.php Database Credentials from MySQL .my.cnf
# Found this nice mashup Jason Tolhurst posted specifically for updating DB credentials from the current user's .my.cnf
# Get DB Credentials
DB_HOST=$(echo $(grep "^\s*host " ~/.my.cnf | cut -d= -f2 | perl -p -e 's/^\s*(.*?)\s*$/$1/'))
DB_USER=$(echo $(grep "^\s*user " ~/.my.cnf | cut -d= -f2 | perl -p -e 's/^\s*(.*?)\s*$/$1/'))
DB_PASS=$(echo $(grep "^\s*password " ~/.my.cnf | cut -d= -f2 | perl -p -e 's/^\s*(.*?)\s*$/$1/'))
DB_NAME=$(echo $(grep "^\s*database " ~/.my.cnf | cut -d= -f2 | perl -p -e 's/^\s*(.*?)\s*$/$1/'))
# Merge DB configs into existing app/etc/env.php
set +H
PHP_CODE=$(cat <<PHP_CODE_HEREDOC
@mttjohnson
mttjohnson / AuthyToOtherAuthenticator.md
Created November 16, 2020 20:27 — forked from gboudreau/AuthyToOtherAuthenticator.md
Export TOTP tokens from Authy

Generating Authy passwords on other authenticators


There is an increasing count of applications which use Authy for two-factor authentication. However many users who aren't using Authy, have their own authenticator setup up already and do not wish to use two applications for generating passwords.

Since I use 1Password for all of my password storing/generating needs, I was looking for a solution to use Authy passwords on that. I couldn't find any completely working solutions, however I stumbled upon a gist by Brian Hartvigsen. His post had a neat code with it to generate QR codes for you to use on your favorite authenticator.

His method is to extract the secret keys using Authy's Google Chrome app via Developer Tools. If this was not possible, I guess people would be reverse engineering the Android app or something like that. But when I tried that code, nothing appeared on the screen. My guess is that Brian used the

@mttjohnson
mttjohnson / magento2_dev_admin_tfa.sh
Last active November 12, 2020 17:09
Magento 2 Admin Creation with TFA for Development Sandbox environments
# Don't use this in any pubically accessible site, this is intended for use in a sandbox environment for development purposes.
# OTP secrets should not be stored on disk in plain text files, they are inteded to be used and stored by a secure app
# Make sure oathtool utility is installed
sudo dnf -y install oathtool
# Set some paths for the environment
ENV_ROOT_DIR="/var/www/data"
MAGENTO_ROOT_DIR="/var/www/data/magento"
@mttjohnson
mttjohnson / expiring_phpinfo.php
Created September 7, 2020 20:43
Expiring PHP Info
<?php
header('Cache-Control: private');
$token_hash = $_GET["token"];
$shared_secret = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
$expected_hash = "cccccccccccccccccccccccccccccc";
$expiring_hash = hash_hmac("sha256", date("Ymd"), $shared_secret);
$hashed_value = hash_hmac("sha256", $expiring_hash.$token_hash, $shared_secret);
if (hash_equals($expected_hash, $hashed_value) ) {
phpinfo();
} else {
@mttjohnson
mttjohnson / sodium_diagnostics.md
Created September 3, 2020 22:24
Troubleshooting diagnosing sodium libsodium with PHP

Check for polyfill use on specific algorithms

# Testing
set +H # disable history expansion
PHP_CODE=$(cat <<'PHP_CODE'
<?php
require_once "/var/www/html/magento/vendor/paragonie/sodium_compat/autoload.php";
if (ParagonIE_Sodium_Compat::polyfill_is_fast()) {
 // Use libsodium now
@mttjohnson
mttjohnson / php_redis_compression_support.sh
Created August 11, 2020 02:00
PHP Redis Compression Support and Validation
# When installing php redis via pecl the installation prompts for configuration options
pecl install redis
# Some PECL installation methods such as Ansible pecl_module do not allow
# for configuration options to be passed in during the installation
# Check for php redis supported compression types
PHP_CODE=$(cat <<'PHP_CODE'
<?php
echo "Redis Support:\n";
@mttjohnson
mttjohnson / search_db_for_string.sql
Last active May 26, 2021 19:08
MySQL Search Entire DB for String
-- Be careful using this on large or on servers with production databases, it could take a long time, and is very invasive to performance.
-- Example, searching a 6GB Magento database on an idle dedicated server took 2 minutes.
set @search = 'my_search_text';
set @database = 'database_name';
select CONCAT('select \'', tbl.`TABLE_NAME`,'\' as TableName, \'', col.`COLUMN_NAME`,'\' as Col, `',col.`COLUMN_NAME`,'` as value from ' ,@database, '.`' , tbl.`TABLE_NAME`,'` where `' ,
col.`COLUMN_NAME` , '` like \'%' ,@search, '%\' UNION') AS q
from information_schema.`tables` tbl
inner join information_schema.`columns` col on tbl.TABLE_SCHEMA = col.TABLE_SCHEMA and tbl.`TABLE_NAME` = col.`TABLE_NAME`and (col.DATA_TYPE='varchar' or col.DATA_TYPE='text')