Skip to content

Instantly share code, notes, and snippets.

@p120ph37
p120ph37 / gist:1239069
Created September 24, 2011 07:12
Run a command in another session's X-Windows environment, even under gdm3 where the .Xauthority file is hard to find.
# This can be copied+pasted directly into a terminal window
# and the display-authority function will become available.
# usage example:
# display-authority :1 'notify-send "hello, stranger!"'
# Note: this uses sudo access to find the appropriate XAUTHORITY file,
# so you'll need to be a sudoer to use this.
function display-authority() {
export DISPLAY=:${1#:}
PROC=$(sudo fuser /tmp/.X11-unix/X${1#:} 2>/dev/null | sed -re 's/^\s*([0-9]+)\s*$/\1/')
@p120ph37
p120ph37 / unexpire-password.pl
Created October 25, 2011 02:54
Script which may be run when your domain policy forces you to reset your password. Uses smbclient to repeatedly change your Active Directory password until it is allowed to set it back to your original password again.
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
use IO::Handle;
use IPC::Open3;
use Term::ReadKey;
use vars '$chpw_msg';
my $usage = <<END;
@p120ph37
p120ph37 / VIPAccess.exp
Created January 2, 2014 01:34
Command-line implementation of Symantec's "VIP Access" token application on OSX. This will read from the same secret key and produce the same time-based one-time-passwords as the GUI application, but with output that can be captured and used in scripts. This can be useful for things like automating two-factor AnyConnect VPN logins through openco…
#!/usr/bin/expect -f
#
# VIPAccess.exp
#
# Command-line emulation of Symantec's VIP Access software token.
# Usage:
# ./VIPAccess.exp [v]
# If the "v" argument (or any argument) is specified, verbose output
# will be produced on stderr. The OTP value will be output on stdout.
#
@p120ph37
p120ph37 / gdrive-dropbox-sync.plist
Last active February 20, 2019 11:55
This is the launchd.plist file that keeps my Dropbox and Google Drive folders synchronized.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>local.gdrive-dropbox-sync</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string><string>-c</string>
<string>/usr/local/bin/unison \
-times \
@p120ph37
p120ph37 / vpnc-script.patch
Last active October 18, 2016 21:15
A patch to vpnc-script to support $SPLIT_DNS when used with openconnect and a Cisco AnyConnect server.
--- vpnc-script.orig 2016-10-18 16:13:30.000000000 -0500
+++ vpnc-script 2016-10-18 16:14:27.000000000 -0500
@@ -435,10 +435,10 @@
# DNS matching when available. When multiple DNS matching
# is present, anything reading the /etc/resolv.conf file
# directly will probably not work as intended.
- #if [ -z "$CISCO_DEF_DOMAIN" ]; then
+ if [ -z "$CISCO_DEF_DOMAIN" ]; then
# Cannot use multiple DNS matching without a domain
OVERRIDE_PRIMARY='d.add OverridePrimary # 1'
@p120ph37
p120ph37 / dualfactor_anyconnect.md
Last active September 29, 2022 03:39
How to connect to a Cisco AnyConnect VPN server from the OSX (or Linux) command-line without using the AnyConnect client. Specifically, one which uses VeriSign/Symantec VIP Access dual-factor tokens.

(For Linux users, make sure you have oathtool and openconnect, then start from Step 6. If you don't have a token secret key, have a friend generate one for you on OSX via steps 3-5)

Step 1

Get homebrew and install oath-toolkit, openconnect, and tuntap.
And follow the additional tuntap installation instructions!

Step 2

After the tuntap module is installed, reboot or use kextload to activate it.

@p120ph37
p120ph37 / vpn.expect
Last active December 19, 2021 23:08
Expect script to connect to an AnyConnect VPN server on OSX using only oathtool and openconnect (not the Cisco AnyConnect client)
!/usr/bin/expect -f
set timeout 30
log_user 0
puts stderr "Generating OTP"
spawn oathtool --totp YOUR_SECRET_KEY_HERE
expect -re \\d+
set otp $expect_out(0,string)
puts stderr "Connecting to VPN server $server"
@p120ph37
p120ph37 / gist:acd3e20797f07670d927
Created June 17, 2014 17:24
Fetch and build a DEB of Bashrun2
#!/bin/sh
VERSION=0.2.2
wget https://bashrun2.googlecode.com/files/bashrun2-$VERSION.tar.gz
tar -xzvf bashrun2-$VERSION.tar.gz
cd bashrun2-$VERSION/
dh_make -f ../bashrun2-$VERSION.tar.gz --single --copyright gpl2
dpkg-buildpackage
@p120ph37
p120ph37 / ip-up
Created June 30, 2014 16:27
PPP VPN split-network/split-DNS script for OSX
#!/bin/sh
####################################################
## ##
## PPP VPN split-network/split-DNS script for OSX ##
## by Aaron Meriwether ##
## ##
## installation: ##
## sudo cp thisfile /etc/ppp/ip-up ##
## sudo chmod 755 /etc/ppp/ip-up ##
## ##
@p120ph37
p120ph37 / date-popup.xml
Created July 21, 2014 14:20
Date/time popup action for openbox
<openbox_menu>
<menu id="date-popup" label="Date &amp; Time"
execute="date +'&lt;openbox_pipe_menu&gt;&lt;item label=&quot;: %a %B %d, %Y %H:%M:%S&quot;/&gt;&lt;/openbox_pipe_menu&gt;'"
/>
</openbox_menu>