Skip to content

Instantly share code, notes, and snippets.

View DrizzlyOwl's full-sized avatar

Ash Davies DrizzlyOwl

View GitHub Profile
@DrizzlyOwl
DrizzlyOwl / afd-domain-scan.sh
Last active February 8, 2024 09:40
Refresh domain validation tokens for AFD Custom Domains
#! /bin/bash
set -e
TODAY=$(date -Idate)
TZ=Europe/London
################################################################################
# Author:
# Ash Davies <@DrizzlyOwl>
# Version:
#! /bin/bash
set -e
TZ=Europe/London
TODAY=$(date -Idate)
DATE_90=$(date --date="90 days ago" +"%Y-%m-%d")
SILENT=0
################################################################################
# Author:
@DrizzlyOwl
DrizzlyOwl / query-audit-log.sh
Last active July 26, 2023 16:10
Can be used to query SQL Server Audit Logs that exist on a Storage Account to determine which users logged in and how many times in a given time period
#!/bin/bash
set -euo pipefail
# Default values for CLI flags
SERVER=""
DATABASE=""
# Use a Service Principal or an Azure AD user with admin rights for your SQL Server
USERNAME=""
PASSWORD="" # Or use "your_service_principal_client_secret" for Service Principal
@DrizzlyOwl
DrizzlyOwl / az-cmk-enable
Created January 16, 2023 16:43
Create and enable a Customer Managed Key for Azure Storage Account encryption
#! /bin/bash
# Echo usage if something isn't right.
usage() {
echo "Usage: $0"
echo " [-r <resource-group>] Name of the Azure Resource Group"
echo " [-v <keyvault>] Name of the Key Vault that will hold the Customer Managed Key"
echo " [-s <storage-account>] Name of the target Storage Account that needs to have CMK Encryption enabled"
echo " [-k <key-name>] Name of the new CMK"
echo " [-e <email>] Email address of the user-managed identity that can access the Key Vault" 1>&2; exit 1;
@DrizzlyOwl
DrizzlyOwl / mounty.sh
Created October 26, 2022 10:36
Test whether a Cloudfuse mount is writable. If it isn't then re-mount it.
#! /bin/bash
#
# Author: Ash Davies
# Description: Checks a Cloudfuse mountpoint and reinitialises it if the mount goes missing
#
VOLUME="/path/to/content/uploads"
PROBE="$VOLUME/mounty.probe"
FOLDER="/path/to/cloudfuse/mount/"
@DrizzlyOwl
DrizzlyOwl / rackspace-bill-into-gsheets.gs
Created September 5, 2022 10:43
Import Rackspace Bill into Google sheets using Google App Script
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Rackspace API')
.addItem('Fetch latest billing data','fetchBilling')
.addToUi();
}
function fetchBilling() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
console.log('Task started');
@DrizzlyOwl
DrizzlyOwl / db-migrator.sh
Created April 7, 2022 15:46
Migrate a database from one MySQL host to another
#! /bin/bash
# @author Ash Davies <a.davies@mixd.co.uk>
FROM=$1
TO=$2
FILENAME=wp-config.php
BACKUP_FIRST=yes
TMP=$(mktemp)
# Terminate on any errors
@DrizzlyOwl
DrizzlyOwl / composer.py
Last active January 19, 2022 15:25
Parse composer outdated into a markdown table
import json,sys;
a = json.load(sys.stdin);
packages = a['installed'];
num_packages = len(packages);
are_available_updates = bool(num_packages);
if are_available_updates:
print("There are "+str(num_packages)+" package updates available");
print("\n");
@DrizzlyOwl
DrizzlyOwl / calendars.txt
Last active November 26, 2021 17:02
Add to Calendar link examples
# Google Calendar
https://calendar.google.com/calendar/render
?action=TEMPLATE
# dates: URL Encoded start and end dates with TZ and / separator
# e.g. "20211126T161500Z/20211126T164500Z"
&dates=20211126T161500Z%2F20211126T164500Z
# details: URL encoded event description
# e.g. "Here's my event description"
&details=Here%27s%20my%20event%20description
# location: URL encoded address
@DrizzlyOwl
DrizzlyOwl / ldap-test.php
Created September 28, 2021 11:22
Query LDAP using PHP
<?php
$sam = 'user.name';
$username = $sam . "@mydomain.co.uk";
$password = "foobar";
$port = 636;
$host = "111.222.333.444";
$ldaphost = "ldaps://$host:$port";
$ldap_base_dn = 'DC=MyDomain,DC=co,DC=uk';
$ldapUsername = "cn=" .$username . "," . $ldap_base_dn;