Skip to content

Instantly share code, notes, and snippets.

View pmeulen's full-sized avatar

Pieter van der Meulen pmeulen

View GitHub Profile
@pmeulen
pmeulen / get-entity-by-scope.py
Last active August 2, 2023 15:41
Python script to get the first EntityDescriptor from a SAML 2.0 metadata file that has a shibmd:Scope Extension with the specified value and return the EntityDescriptor as XML
#!/usr/bin/env python3
"""
Script to get the first EntityDescriptor from a SAML 2.0 metadata file that has a shibmd:Scope Extension with the specified
value and return the EntityDescriptor as XML.
This allows you to get an EntityDescriptor from a large metadata file by the scope of the EntityDescriptor.
The script uses XSLT to do the matching, so it can be easily modified to match on other criteria.
"""
@pmeulen
pmeulen / public_encrypt_decrypt.php
Last active February 9, 2021 13:59
Functions for encrypting and decrypting data with RSA public key crypto using the PHP openssl_* functions.
<?php
/**
* Encrypt $plaintext using $rsa_public_key
*
* To decrypt the data the RSA private that corresponds to the $rsa_public_key is required.
*
* Because public key crypto is not suitable for arbitrary length data, encryption is done in two steps
* 1. Generate a random symmetric key and encrypt the plaintext with that key
@pmeulen
pmeulen / snapshot.sh
Last active September 27, 2022 17:53
Script to create and restore snapshots of Azure VMs using azure-cli (az)
#!/usr/bin/env bash
# Script to create and restore snapshots of the OS disk of Azure VMs
# Copyright 2018 SURFnet B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@pmeulen
pmeulen / repair-timemachine-disk-network.sh
Created September 22, 2017 17:58
Script to repair a Time Machine network volume
#!/bin/bash
set -e
###############################################################################
# This script tries to repair a Time Machine *network* backup (i.e. an APF
# share containing a sparsebundle) that is shared over a network using e.g. an
# Apple TimeCapsule, a NAS, Raspberry PI, ...
# The script must be run on the computer that created the backup
#
@pmeulen
pmeulen / clamav.pm
Created September 9, 2017 16:03
A spamassassin plugin that calls clamav
## A spamassassin plugin for calling clamav
# Version 2.0 was downloaded from https://wiki.apache.org/spamassassin/ClamAVPlugin
#
# # version 2.0, 2010-01-07
# - use SA public interface set_tag() and add_header, instead of
# pushing a header field directly into $conf->{headers_spam}
#
# # version 2.1, 2017-09-09 (pmeulen):
# - Allow ClamAV::Client, which is provided by debian package libclamav-client-perl, to be used
# in addition to File::Scan::ClamAV
@pmeulen
pmeulen / HTMLColorFingerprint.php
Created August 19, 2017 11:51
Making random opaque strings much more easy to compare by giving them a backgroud color that is derived from the value of the sring
<?php
/** Making opaque values like GUIDs or session identifiers easier to compare and distinguish
*
* By giving each opaque value a background color that is derived from the value itself, it
* becomes much easier to eyeball whether two values are likely to be the same. This really helps
* when reading logs or other diagnostic output that contain opaque identifiers like GUIDs or other
* opaque identifiers.
*
* Testing:
@pmeulen
pmeulen / git_remote_in_dropbox.md
Last active November 26, 2018 12:33
Create a brare git repository in dropbox that can be used as a remote

It is possible to use Dropbox as a "remote" repository. It is not perfect, updating or pushing to the remote from two location simultaniously will surely corrupt the repository. That being said it is a practical trick for syncing repositories between computers without both having write access to "origin" (i.e. github, gitlab or the like).

I store the repositories in a directory "git" in my dropbox folder. Create it if it does not yet exist, or make up you own name: mkdir ~/Dropbox/git/

  1. Change to the repository for which you want to create a remote
@pmeulen
pmeulen / cidr_merge.py
Last active November 3, 2018 21:58
Python script to represent a list of CIDR network ranges in the smallest number of CIDR subnets. Subnets can be added and substracted.
#!/usr/bin/env python
import argparse, sys
from netaddr import IPNetwork, IPSet
class IPNetworkArg:
def __init__(self, network):
network.strip()
self.add = True
if network[0] == '-':
@pmeulen
pmeulen / shibmd-1.0.xsd
Last active October 20, 2016 20:09
XML Schema for urn:mace:shibboleth:metadata:1.0 namespace
<?xml version="1.0" encoding="US-ASCII"?>
<schema targetNamespace="urn:mace:shibboleth:metadata:1.0"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
version="1.0">
<import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd"/>
@pmeulen
pmeulen / accountgen.php
Created July 19, 2015 13:49
Generate user accounts for SimpleSAMLphp example-userpass
<?php
/*
$config: php config array
$group: account name prefix
$email: A pollibly existing email addres so you can receive mail
$scope: Used as schachome, EPPN scope and names
$count: number of accounts to generate
Example: