Skip to content

Instantly share code, notes, and snippets.

@jpluscplusm
jpluscplusm / dec2ip.awk
Created February 5, 2020 22:32
AWK IPv4 to/from decimal
#!/usr/bin/awk
# 1-liner: awk '{for(i=0;i<4;i++){byte=$1%256;ip="." byte ip;$1-=byte;$1/=256}}END{sub(".","",ip);print ip}'
{
for(i=0; i<4; i++) {
byte = $1 % 256
ip = "." byte ip
$1 -= byte
$1 /= 256
}
@jpluscplusm
jpluscplusm / README.md
Last active February 22, 2020 22:36
A primitive Double A (AAA-minus-Accounting) RBAC system implemented in declarative Nginx config

Nginx Double A

A primitive Double A (AAA-minus-Accounting) RBAC system implemented in declarative Nginx config.

Background

So I noticed https://github.com/alexaandru/elastic_guardian, a simple AAA reverse-proxy to sit in front of Elasticsearch. Reading the source and comments tickled my "why is this in code not config?" funnybone.

I asked @alexaandru (https://twitter.com/jpluscplusm/status/438339557906735104) who told me it was mostly the resulting complexity of the nginx config he tried that prompted him to write it.

@jpluscplusm
jpluscplusm / gist:4366287
Last active December 24, 2019 23:23 — forked from anonymous/gist:4366284
Nginx TPB proxy
server {
listen [::]:80;
listen 80;
server_name "~^(?<thishost>[^.]+.)?(subdomain.example.com)$";
access_log off;
location / {
resolver 8.8.8.8; # or whatever your server can use
sub_filter_once off;
sub_filter 'thepiratebay.se' 'subdomain.example.com';
@jpluscplusm
jpluscplusm / log-indent-test.sh
Created December 3, 2019 21:39
Shell log formatter with increment/decrement indentation thingy
#!/usr/bin/env bash
set -ueo pipefail
outofbandlogstring="This string must NEVER appear in the script's stdout/err ..." # or, like, simply "§" ...
function enter() {
echo "$@"
echo "${outofbandlogstring}+2"
}
@jpluscplusm
jpluscplusm / vpnc-script-aws
Last active July 12, 2018 12:53 — forked from alext/vpnc-script-aws
vpnc script to route all AWS IP ranges over VPN.
#!/bin/bash
# vpnc-script wrapper for use with openconnect that routes all AWS IP ranges over the VPN.
# Pass any additional IP ranges to be routed as args to the script.
#
# Requirements: bash, curl and jq.
#
# Example usage:
# openconnect https://vpn.example.com/profile --script '/path/to/vpnc-script-aws'
#
@jpluscplusm
jpluscplusm / test.bats
Last active July 22, 2017 01:34
Per-file setup/teardown support for BATS
setup() {
# Global setup
if [ $BATS_TEST_NUMBER -eq 1 ]; then
{
echo export FOO=bar
} >${BATS_TMPDIR}/bats.import.$PPID
fi
. ${BATS_TMPDIR}/bats.import.$PPID
# Per-test setup as per documentation
@jpluscplusm
jpluscplusm / instance.tf
Created July 13, 2017 11:10
Dagnammit, Terraform
resource "aws_instance" "instance" {
ami = "ami-32rrg4334f"
instance_type = "t2.small"
subnet_id = "subnet-abc123dasf"
key_name = "key"
associate_public_ip_address = false
vpc_security_group_ids = [
"${aws_security_group.1.id}",
@jpluscplusm
jpluscplusm / .gitignore
Last active September 17, 2016 00:03
Terraform Makefile wrapper with remote state mgmt/bootstrap
/.terraform/terraform.tfstate*
/plan.out
/.plan.out.*
@jpluscplusm
jpluscplusm / awk-ad
Last active August 22, 2016 15:21
AWK invocations for ASCII-delimited operation
#!/bin/bash
# ASCII-delimited input and output
awk -vFS="\x1F" -vRS="\x1E" -vOFS="\x1F" -vORS="\x1E" "$@"