Skip to content

Instantly share code, notes, and snippets.

View jamesdavidson's full-sized avatar

James Davidson jamesdavidson

View GitHub Profile
@jamesdavidson
jamesdavidson / ipsec.conf
Created January 25, 2019 08:50
IPsec VPN with StrongSwan with a Let's Encrypt certificate https://jamesd3142.wordpress.com/2019/01/25/ipsec-vpn-with-strongswan/
config setup
uniqueids=no
charondebug = ike 3, cfg 3
conn %default
dpdaction=clear
dpddelay=35s
dpdtimeout=2000s
keyexchange=ikev2
@jamesdavidson
jamesdavidson / es_ping.py
Last active October 28, 2019 05:50
Ping Amazon Elasticsearch Service in Python3
import sys
from elasticsearch import Elasticsearch, RequestsHttpConnection
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
# sanity check Python version
assert(sys.version_info >= (3,6))
ES_ENDPOINT = 'search-dev-logs-kxsz2asdflkjlaksdfie7i36iry.ap-southeast-2.es.amazonaws.com'
AWS_REGION = 'ap-southeast-2'
@jamesdavidson
jamesdavidson / jenkins-saml-sp-experiments.clj
Last active October 23, 2018 07:11
Could some bits from the SAML Plugin for Jenkins (particularly SamlSecurityRealm.java) be reused to implement a Service Provider in Clojure?
(def idpMetadata (slurp "FederationMetadata.xml"))
(defn encode64 [b]
(. (new sun.misc.BASE64Encoder) encode b))
(defn str-to-bytes [s] (.getBytes s))
(def saml-response (encode64 (str-to-bytes (slurp "saml-response.xml"))))
(def sts-cookie "MSISAuth=AAEasdfasdfasdfqp")
@jamesdavidson
jamesdavidson / Dockerfile
Last active October 3, 2018 06:08
Launch a CentOS Linux shell as a Docker container on your Windows machine.
FROM centos
RUN yum makecache fast
RUN yum update -y
RUN yum install -y tree
WORKDIR /mnt
@jamesdavidson
jamesdavidson / convenient_temporary_credentials_20180823.tf
Created August 23, 2018 13:43
Terraform code to set up a convenient and secure way to get temporary credentials for AWS.
// ## Goal
//
// A convenient and secure way to get temporary credentials for AWS which I can use
// with Terraform or the Python CLI. Sort of like `saml2aws` but in the browser.
//
// ## Implementation
//
// A client-side JS app which uses Cognito and IAM resources as the backend.
//
// 1) Open the app
@jamesdavidson
jamesdavidson / tls_connect.js
Last active February 19, 2019 06:34
Open a TLS connection to a remote host on and verify its cert.
/* Open a TLS connection to a remote host and verify its cert.
* Usage: node tls_connect.js -connect thewest.com.au:443
*/
var tls = require('tls');
var i = process.argv.indexOf('-connect');
var connect = process.argv[1+i].split(':');
var servername = connect[0];
var port = Number(connect[1]);
if (0 < i && connect && servername && port) {
@jamesdavidson
jamesdavidson / subtract.py
Created May 2, 2018 06:42
Subtracts one list of address ranges from another list of ranges, returning a list of addresses as /32 ranges.
#!/usr/bin/env python
# This program requires two filename arguments. Each file should contain a list
# of address ranges (CIDR blocks). The output will be a list of address which
# are in the first list but not the second expressed as /32 ranges.
from __future__ import unicode_literals
import sys
import ipaddress
@jamesdavidson
jamesdavidson / asdf.tf
Created May 2, 2018 06:39
Experimental job queue system
variable jobnumber {
default = "201802061831"
}
provider aws {
region = "ap-southeast-2"
}
resource aws_sqs_queue asdf {
receive_wait_time_seconds = 20 # enable long polling by default
@jamesdavidson
jamesdavidson / wowza.pp
Created April 6, 2018 05:37
Puppet code to configure Nginx to proxy Wowza and SHOUTcast streams.
# install and configure Wowza Streaming Engine
class profile::wowza {
# Placeholder to install Wowza Streaming Engine (WowzaStreamingEngine-4.7.1-linux-x64-installer.run)
$config = hiera('wowza')
$audio_upstream = 'http://localhost:1935'
$wowza_upstream = 'http://localhost:8088'
$shoutcast_upstream = 'http://localhost:8000'
# The following URLs are for management:
@jamesdavidson
jamesdavidson / MYSQL.txt
Last active January 4, 2019 03:51
Notes from automating the installation of MySQL on CentOS.
So, what did I try?
Well, first I tried to find a CMS that didn't need MySQL. Painful.
Then, I tried installing MySQL. They have made this very hard to
automate.
Then, I tried running MySQL in a Docker container. The first annoying
thing here was that I needed a specific version of Docker's API but that
also meant a specific version of the Python library and adding