Skip to content

Instantly share code, notes, and snippets.

@lunitrixx
lunitrixx / nonce.php
Created July 14, 2024 20:13 — forked from johanguse/nonce.php
Add nonce to script and styles on WordPress
add_action( 'template_redirect', function () {
ob_start( function ( $output ) {
$nonces = [];
$output = preg_replace_callback( '#<script.*?\>#', function ( $matches ) use ( &$nonces ) {
$nonce = wp_create_nonce( $matches[0] );
$nonces[] = $nonce;
@lunitrixx
lunitrixx / csp-mu-plugin.php
Created July 14, 2024 20:15 — forked from joshuafredrickson/csp-mu-plugin.php
Add CSP to WordPress, including nonces for inline scripts
<?php
/**
* Plugin Name: Content Security Policy
* Version: 1.0.0
* Description: Adds a Content-Security-Policy header to all non-admin requests.
* License: GNU General Public License v2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Original Inspiration: https://gist.github.com/westonruter/c8b49406391a8d86a5864fb41a523ae9
*/
@lunitrixx
lunitrixx / .stglobalignore
Created July 26, 2024 20:21 — forked from jult/.stglobalignore
syncthing ignore file(s) .stglobalignore and .stignore
// .stglobalignore
// These prevent SyncThing from trying to sync data that's locked, constantly changing, going to be thrown out, unimportant, etc.
// Lots of conflicts/issues disappeared using these ignores, but do check to prevent major disappointment!
// *.log and *cache* are in there, just so you know.. but firefox' startupCache and offlineCache will be synced.
// Ignores are case sensitive.
// Put both .stignore and this .stglobalignore in the root of your sync folder(s) (where .stfolder resides)
$RECYCLE.BIN
$WINDOWS.~BT
@lunitrixx
lunitrixx / delete-thumbnails.php
Created September 19, 2024 08:39 — forked from chandrapatel/delete-thumbnails.php
WP-CLI command to delete all the thumbnails.
<?php
/**
* WP-CLI command to delete all the thumbnails.
*
* Note: First do dry-run, verify log and then do actual run.
*
* @package delete-thumbnails
*/
if ( defined( 'WP_CLI') && WP_CLI ) {

Better SSH Authorized Keys Management

A seemingly common problem that people encounter is how to handle all of your users authorized_keys file.

People struggle over management, ensuring that users only have specific keys in the authorized_keys file or even a method for expiring keys. A centralized key management system could help provide all of this functionality with a little scripting.

One piece of functionality overlooked in OpenSSH is the AuthorizedKeysCommand configuration keyword. This configuration allows you to specify a command that will run during login to retrieve a users public key file from a remote source and perform validation just as if the authorized_keys file was local.

Here is an example directory structure for a set of users with SSH public keys that can be shared out via a web server: