Skip to content

Instantly share code, notes, and snippets.

View mortn's full-sized avatar

Morten Abildgaard mortn

View GitHub Profile
# Since I ask this of people before using their code samples, anyone can
# use this under BSD.
import os
import M2Crypto
def empty_callback():
return
# Seed the random number generator with 1024 random bytes (8192 bits)
@mortn
mortn / geoblocker
Last active April 24, 2024 16:55
nginx geoip blocking with network exceptions.
# /etc/nginx/geoblocker
# This will block anything but the defined countries and the networks defined in the $localnet variable
set $geoblock 0;
if ($geoip_country_code !~ (DK|NO|SE)) { set $geoblock 1; }
if ($localnet = 1){ set $geoblock 0; }
if ($geoblock = 1){ return 403; }
@mortn
mortn / dhcp-leases-changed.py
Created June 12, 2014 21:32
pyinotify example for watching DHCP leases file
import pyinotify,subprocess
def onChange(ev):
cmd = ['/bin/echo', 'File', ev.pathname, 'changed']
subprocess.Popen(cmd).communicate()
wm = pyinotify.WatchManager()
wm.add_watch('/var/lib/dhcp/dhcpd.leases', pyinotify.IN_MODIFY, onChange)
notifier = pyinotify.Notifier(wm)
notifier.loop()
#!/bin/bash
function main()
{
monitor_from_file $*
}
function monitor_vpn_ip_port()
{
local CONN_NAME=$1
@mortn
mortn / apg-30.sh
Last active November 12, 2015 10:39
Generate passwords for use or inspiration
apg -n30 -MCLNS -E "'~\`><{}[]()|\"\\/^"
# This will generate 30 passwords that will contain
# - at least one digit
# - at least one Capital letter
# - at least one special symbol
# - at least one lower cased
# -E is for Excluding certain characters I dislike in my passwords
@mortn
mortn / vlan.sh
Last active August 29, 2015 14:09
Expect script for vlan tagging on 4 HP Procurve (Really have to find a better way)
#!/usr/bin/env expect
set CTRLZ \032
set action [lindex $argv 0]
set vlan [lindex $argv 1]
if {[llength $vlan] == 0} { exit 0; }
if {$vlan < 3000} { exit 0; }
if {$vlan > 9100} { exit 0; }
stty -echo
send_user -- "Gimme Passwordz: "
expect_user -re "(.*)\n"
#!/usr/bin/env python
#Copyright (C) 2009 Allen Sanabria
#This program is free software; you can redistribute it and/or modify it under
#the terms of the GNU General Public License as published by the Free Software Foundation;
#either version 2 of the License, or (at your option) any later version.
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
#without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#See the GNU General Public License for more details. You should have received a copy of i
@mortn
mortn / djablo.sh
Last active August 29, 2015 14:10
Method for starting a Mezzanine/Django site via Upstart script on Ubuntu 14.04
#!/bin/bash
set -e
NUM_WORKERS=3
USER=www-data
GROUP=users
DIR=$(dirname $0)
APPNAME=${DIR##*/}
LOGFILE=/var/log/gunicorn/$APPNAME.log
LOGDIR=$(dirname $LOGFILE)
cd $DIR
@mortn
mortn / resize-qemu-img
Last active December 15, 2022 23:30
online resize qemu image
F=/var/lib/libvirt/images/ubuntu.img
sudo qemu-img resize $F 50G
sudo virsh blockresize --path $F --size $(qemu-img info $F|sed -n '/virtual size/ s/^.*: //;s/(.*//p') <domain-id>
@mortn
mortn / kvm_backup.sh
Created November 30, 2014 20:34
Script to backup KVM-machines using snapshots.
#!/bin/bash
#Script to backup KVM-machines using snapshots.
#Written by Jonas "Drakfot" Andersson
#Changelog
# Version 1.1
#20140309 - Initial scripting started.
#20140316 - Fixed an issue where a nonmounted drive (CD) could cause the script to fail.
#also sorted the part where the converted image will end up. Now the file is written