Skip to content

Instantly share code, notes, and snippets.

@shagamemnon
shagamemnon / stick-session.js
Last active September 16, 2019 05:17
A Cloudflare Worker for session persistence
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
event.passThroughOnException()
})
const ORIGINS = [
'storage.googleapis.com',
'frank-io.herokuapp.com'
]
@shagamemnon
shagamemnon / getZones.sh
Last active January 17, 2020 10:26 — forked from cjus/jsonval.sh
Extract a JSON value from a BASH script
#!/bin/bash
function jsonval {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
echo ${temp##*|}
}
json=`curl -s -X GET https://api.cloudflare.com/client/v4/zones?account.name=$ACCT_NAME&page=1&per_page=1000&order=status&direction=desc&match=all`
prop='profile_image_url'
picurl=`jsonval`
@shagamemnon
shagamemnon / cloudflare-enable-logs.sh
Created January 21, 2020 19:30
Enable log file retention for a list of Cloudflare (Enterprise) zones.
#!/bin/sh
# Enable log retention for a list of Cloudflare zones
AUTH_EMAIL="xxxx@example.com" # the account you use to
AUTH_KEY="xxxxxxxxxxxx" # https://dash.cloudflare.com/profile/api-tokens --> "Global API Key"
ZONE_NAMES="franktaylor.io cfiq.io valleynet.io" # space-separated list of zone names
for ZONE in $ZONE_NAMES
do

You can unzip POST request bodies in Workers using the pako library.

Demo

# Download a gzipped file to send as the body of a POST request
# The Worker running on this route will decompress the file and
# echo the human-readable response. Sweet!
wget https://storage.franktaylor.io/d06cef5527f329e519553f649b3a76e219f2c9d6/admin.php.gz
curl "POST" "https://workers-unzip.cflr.workers.dev/" --data-binary @admin.php.gz -H 'Content-Type: application/gzip'
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
})
async function timeout (ms) {
return new Promise(accept => {
setTimeout(() => {
accept('timeout')
}, ms)
})
@shagamemnon
shagamemnon / cloudSettings
Last active November 19, 2020 17:31
vscode settings
{"lastUpload":"2020-11-19T17:31:19.906Z","extensionVersion":"v3.4.3"}
@shagamemnon
shagamemnon / dig.md
Last active April 24, 2020 18:15 — forked from tuksik/dig_cs.sh
Frank's dig cheat sheet
# force recursion back to root nameservers (helpful for bypassing caches)
dig www.cloudflare.com A +trace

# get the address(es) for yahoo.com
dig yahoo.com A +noall +answer

# get a list of yahoo's mail servers
dig yahoo.com MX +noall +answer
@shagamemnon
shagamemnon / cloudflare-workers-base64.js
Created October 2, 2020 07:23
Decode Base64 encoded text in Cloudflare Workers
/* Demo: https://cloudflareworkers.com/#6168c0dbeb076f1e3ac7eb102082361f:https://www.google.com/ */
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
function fromBinary(msg) {
const ui = new Uint8Array(msg.length)
for (let i = 0; i < msg.length; ++i) {
ui[i] = msg.charCodeAt(i)
@shagamemnon
shagamemnon / static_ip.sh
Last active October 5, 2020 02:17 — forked from RichardBronosky/static_ip.sh
Script to generate /etc/dhcpcd.conf for static IP on Raspbian Raspberry Pi
#!/bin/bash -e
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.backup
if [[ $# -ne 0 ]]; then
cat<<EOF
Usage:
$0
DEV=eth0 $0