Skip to content

Instantly share code, notes, and snippets.

View pmbuko's full-sized avatar
💁‍♂️
captive devopsian

Peter Bukowinski pmbuko

💁‍♂️
captive devopsian
View GitHub Profile
@pmbuko
pmbuko / password_dialog.py
Last active August 29, 2015 14:11
Simple python example of a Pashua password prompt dialog with a checkbox to save the password. Requires Pashua.app and the Pashua.py connector in the same path.
#!/usr/bin/python
#
# Simple python example of a Pashua password prompt window with a checkbox
# for saving the password to the keychain. None of it is wired up to
# actually function. It's just an example of what you can do.
#
# For easiest testing, you should have the Pashua.py connector and Pashua.app
# in the same directory as this script.
#
# The test password is 'password'.
@pmbuko
pmbuko / get_ordered_active_ens.py
Last active August 12, 2018 23:43
This python script returns a list of active ethernet interfaces in their service priority order. OS X only, as it depends on the 'networksetup' command.
#!/usr/bin/env python
from re import findall
from subprocess import check_output
def getOrderedInterfaces():
"""Returns all ethernet interfaces in service order."""
interfaces = check_output(['networksetup', '-listnetworkserviceorder'])
matches = findall(r' en[\d]+', interfaces)
return [ i.lstrip(' ') for i in matches ]
@pmbuko
pmbuko / tkinter_password.py
Last active August 29, 2015 14:10
Here's a tkinter password prompt that kinda works on OS X.
#!/usr/bin/pythonw
from Tkinter import Tk
from tkSimpleDialog import askstring
def passPrompt(title, prompt):
"""Prompts for a password."""
password = askstring(title, prompt, show="*")
print "Seriously? '" + password + "'?? That's a lame password."
@pmbuko
pmbuko / kerberos_id.sh
Created December 3, 2014 17:55
This snippet will retrieve the fully-qualified Kerberos authentication account used for retrieving tickets on OS X. Useful if you need to renew tickets programmatically.
dscl /Search read /Users/$USER AuthenticationAuthority | egrep -o "[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)"
@pmbuko
pmbuko / hdfsstruct.pp
Created November 25, 2014 17:49
I use this defined resource type set up HDFS volumes on servers that are part of our Hadoop system.
define hdfsstruct ($mountpoint = $name, $device) {
file { "$mountpoint":
ensure => directory,
}
exec { "format-$device":
command => "/sbin/mkfs.ext4 $device",
unless => "/bin/mount | /bin/grep $device",
refreshonly => true,
}
mount { $mountpoint:
@pmbuko
pmbuko / scratchdir_type.pp
Last active August 29, 2015 14:10
I use this defined resource type mostly as a space-saver. We have a few hundred HPC cluster nodes and each of the ~300 cluster users has their own scratch directory on each node. When a cluster user is added or removed, it triggers a script that programmatically generates an updated puppet manifest that manages these directories.
class cluster::scratchroot {
file { '/scratch':
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
}
}
define cluster::scratchdir( $u, $g, $m ) {
@pmbuko
pmbuko / os_decider.sh
Last active August 29, 2015 14:09
Script template that will do different things for bootable Mac and Windows volumes
#!/bin/bash
for vol in /Volumes/*; do
if [ -e "${vol}/System/Library/CoreServices/boot.efi" ]; then
echo "Partition info for Mac bootable volume:"
diskutil list "${vol}"
# more stuff here
elif [ -e "${vol}/Windows/System32/winload.exe" ]; then
echo "Partition info for Win bootable volume:"
diskutil list "${vol}"
@pmbuko
pmbuko / bad_puppet.pp
Created September 26, 2014 13:52
The worst example of puppet code I've seen in a long time, lifted from a blog commenter who suggested using this to patch bash.
exec { 'patch_shellshock_security_hole':
command => "/usr/bin/yes | /usr/bin/yum update bash; touch /root/shellshock_bug_has_been_patched",
creates => '/root/shellshock_bug_has_been_patched',
}
@pmbuko
pmbuko / character_test.applescript
Created September 16, 2014 13:20
Applescript apparently can't handle certain diacritics (those requiring multiple keystrokes) when using a hidden answer dialog prompt. You can use this simple test script to verify. If you remove "with hidden answer" from line 1, it will work as expected.
set testPass to text returned of (display dialog "Enter a test password:" default answer "" with hidden answer)
do shell script "/bin/echo '" & testPass & "' > /var/tmp/pass_file"
set echoedPass to (do shell script "/bin/cat /var/tmp/pass_file")
display dialog "This is what you typed:
" & testPass & "
This is what AppleScript echoed to a temp file:
" & echoedPass
@pmbuko
pmbuko / ad_pass_exp.sh
Last active August 13, 2021 17:15
This script contains all the logic I use to determine the number of days remaining until a user's Active Directory domain password expires. Helpful for troubleshooting where things are breaking down in ADPassMon. Make sure you have an active kerberos ticket before running or you will see 'ldap_sasl_interactive_bind_s' errors at the beginning of …
#!/bin/bash
myLDAP=$(scutil --dns | awk '/nameserver\[0\]/{print $3}' | head -1)
mySearchBase=$(ldapsearch -LLL -Q -s base -H ldap://${myLDAP} defaultNamingContext | awk '/defaultNamingContext/{print $2}')
uAC=$(dscl localhost read /Search/Users/$USER userAccountControl | awk '/:userAccountControl:/{print $2}')
if [[ $uAC =~ ^6 ]]; then
passExpires="no"
else