Subjectively

dd if=/dev/random | kirk > blog

Subjectively header image 1

How to configure vpnc for cisco concentrator with RSA SecurID on ubuntu

August 24th, 2010 · Linux

Do this in a shell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sudo su -
#Make sure you have what it takes to compile it.
apt-get install dpkg-dev
#Here are the libraries that are missing
#  that we need for the cisco concentrator
apt-get install libgcrypt11-dev
apt-get install libssl-dev
# So we have to get the source and compile it ourselves
apt-get source vpnc
cd vpnc-0.5.3
# and remove the comment so it will actually *USE*
#   the libraries we added
sed -i 's/^#OPENSSL/OPENSSL/' Makefile
# Prepare the dependencies for compiling
apt-get build-dep vpnc
# Compile and make an installable package
dpkg-buildpackage
cd ..
# Install the package
dpkg -i vpnc_0.5.3-1_i386.deb

Then, create a file with your personal vpn settings. Here is mine as an example. Put this file in /etc/vpnc/yourfile.conf. It must be in this folder, and the name must end in .conf.

1
2
3
4
5
IPSec gateway vpn.yourdomain.com
IPSec ID thenameofyourgroup
IPSec secret passwordyeradmingaveyou
Xauth username yername
Xauth password yersupersecretpassword

If you are using an RSA SecureID, you should leave off the Xauth password line in the configuration. You will be prompted for the password later, and it will not echo anything to the console.

After that, create a startup/shutdown script This one is like an init.d script, but we will have to run it interactively. This script will be in the root home directory:

/root/mytunnel

Remember to change line 4 to the name of the configuration file you created earlier.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
 
vpnc=/usr/local/sbin/vpnc
conf=/etc/vpnc/yourfile.conf
pid=/var/run/vpnc/pid
 
function start () {
  echo "Enter VPN password:"
  $vpnc $conf > /dev/null
}
 
function stop () {
  [[ ! -f $pid ]] && exit
  vpid=$(cat $pid)
  kill $vpid
}
 
function status () {
  [[ ! -f $pid ]] && {
        echo "$0 is not running"
        exit
  }
  vpid=$(cat $pid)
  instance=$(ps aux | grep $vpid | sed "/grep $vpid/d")
  [[ ! -z "$instance" ]] && echo "$0 is running" || echo "$0 is not running"
}
 
function reload () {
 echo "Reload is not supported for cisco vpn"
}
 
function restart () {
  stop
  start
}
 
VERSION=0.1
 
case "$1" in
    start)
        start $VERSION
        ;;
    stop)
        stop "$VERSION"
        ;;
    restart)
        restart "$VERSION"
        ;;
    reload)
        reload $VERSION
        ;;
    status)
        status $VERSION
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|status}"
        exit 1
        ;;
esac
 
exit 0

Make it executable:

chmod +x mytunnel

You are now ready to start vpnc!

./mytunnel start
Enter VPN password:

There will be no response. That is a good thing, because the vpn is now running in the background. Test this with:

./mytunnel status
./mytunnel is running

Have fun mucking around in somebody else’s network!

When you’re done with your evil intentions:

./mytunnel stop

You’re now done with the thing you had to do, to get to the thing you had to do, so you could do some work.

→ No CommentsTags:

macports portfile for xlsx2csv

January 22nd, 2010 · Uncategorized

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id$
PortSystem       1.0
name		xlsx2csv
version		1.1
categories	textproc
platforms	darwin
maintainers	webfinish.com:kirk
description	Convert MS Word/Excel openspreadsheetML to plain CSV.
long_description xlsx2csv is bash shell script which reads one Microsoft \
		 Excel file and outputs all tabs contained insinde it \
		 to CSV files. It handles dates and string data as well \
		 as numeric. 
 
homepage	http://kirk.webfinish.com/2009/12/xlsx2csv/
master_sites	http://kirk.webfinish.com/xlsx2csv/ 
 
checksums     md5    a5625497acffa71adca1eddc2dc3414a \
              sha1   4902fbb091342aad51d2baf4e566f3e64287d8be \
              rmd160 5704096dfcec3cec810fc7b46eb592a31d2ca30b
 
depends_lib	port:libxslt \
                port:gsed \
                port:sqlite3
use_configure	no
build {}
destroot {
  xinstall -m 755 -d ${destroot}${prefix}/bin
  xinstall -m 755 ${workpath}/xlsx2csv.sh ${destroot}${prefix}/bin
}

→ No CommentsTags:

csv2pg — Load a comma separated values file into postgresql

January 22nd, 2010 · Linux, OS X

Here’s a simple wrapper script that I wrote in bash for bulk loading data into PostgreSQL from csv files. Beware, it also does a code page conversion at the end that you may not want. That part should be parameterized, I just haven’t gotten around to it yet.

Link to the download is here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#===============================================================================
#
#          FILE:  csv2pg
# 
#         USAGE:  ./csv2pg [-d|--debug] [-v|--version] -c[|--csv] filename [-s|--schema schemaname]
#                 [-b|--database database] [-u|--user username] -t[|--table] tablename [-o|--ouput]
# 
#   DESCRIPTION:  load a csv file into a prepared table
# 
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  This script can be used in conjunction with csvheader2createtable
#                 to create a table with ETL tracking fields and load the data.
#                 (e.g.
#                   for file in *.csv
#                   do
#                     csvheader2createtable -s myschema $file | psql
#                     csv2pg -s myschema -t ${file//.csv} $file
#                   done
#                 )
#                 Assuming the naming convention for the files was sane...
#        AUTHOR:  Kirk Roybal (DBA), kirk.roybal@javelindirect.com
#       COMPANY:  Javelin
#       VERSION:  1.0
#       CREATED:  12/21/2009 14:32:37 CST
#      REVISION:  ---
#===============================================================================
 
function usage () {
cat <<EOS
  $0 [--help] [-d|--debug] [-v|--version] -c[|--csv] filename [-s|--schema schemaname]
     [-b|--database database] [-u|--user username] -t[|--table] tablename [-o|--ouput]
EOS
}
 
[[ ${#*} -eq 0 ]] && {
  usage
  exit
}
 
version="0.1"
for arg 
do
  delim=""
  case "$arg" in
    #translate --gnu-long-options to -g (short options) 
    --help) args="${args}-z ";;
    --csv) args="${args}-c ";;
    --host) args="${args}-h ";;
    --database) args="${args}-b ";;
    --user) args="${args}-u ";;
    --schema) args="${args}-s ";;
    --output) args="${args}-o ";;
    --table) args="${args}-t ";;
    --debug) args="${args}-d ";;
    --version) args="${args}-v ";;
  #pass through anything else
    *) leftchar=$(printf %1.1s "$arg")
      if [[ ! "$leftchar" == "-" ]]
      then
        delim="\""
      fi
      args="${args}${delim}${arg}${delim} "
      ;;
  esac
done
 
#Reset the positional parameters to the short options
eval set -- $args
 
schema=public
host=db1
database=warehouse
user=warehouse
 
while getopts ":b:c:dh:os:t:u:vz" option 2>/dev/null
do
  case $option in
    o) output=true;;
    h) host="${OPTARG}";;
    b) database="${OPTARG}";;
    u) user="${OPTARG}";;
    d) set -x ; debug=true ;;
    v) echo "$(basename $0) $version"; exit;;
    c) csvfile="${OPTARG}";;
    s) schema="${OPTARG}";;
    t) table="${OPTARG}";;
    z) usage; exit;;
    *) echo $OPTARG is an unrecognized option; usage; exit;;
  esac
done
 
[[ -z "$csvfile" ]] && {
  echo "must have csv file"
  exit 1
}
[[ -f "$csvfile" ]] || {
  echo "csv file not found"
  exit 1
}
 
[[ -z "$table" ]] && {
  echo "table name is required"
  exit 1
}
 
sql="SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS 
      WHERE table_name = '$table' and table_schema='$schema'
      AND column_name NOT IN ('id','date_stamp')
      ORDER BY ordinal_position;"
fields=$(psql -h $host -U $user $database -qtAc "$sql" | tr '\n' ', ' | sed -e 's/, "$//' -e 's/^/"/' -e 's/,/", "/g' | sed 's/loaded_from.*/loaded_from"/')
[[ "$fields" == "" ]] && {
  echo "table $table does not exist"
  exit 1
}
 
trailing_comma=$(cat "$csvfile" | head -n 1 | sed 's/[[:space:]]*$//g')
trailing_comma=${trailing_comma:${#trailing_comma}-1:1}
[[ "$trailing_comma" == "," ]] && sed -i '' 's/,[[:space:]]*$//' "$csvfile"
 
sql="COPY $schema.$table($fields) FROM STDIN WITH CSV HEADER;"
#code page conversion, append control data, insert
[[ -z "$output" ]] || echo "iconv -f ibm850 -t utf8 \"$csvfile\" | 
  tr -d '\\000' | tr '\\r' '\\n' | 
  sed -e '/^[[:space:]]*\$/d' -e '/^,*$/d' -e \"s/\\$/,klr,$csvfile/\" | 
  psql -h $host -U $user $database -c \"$sql\""
 
iconv -f ibm850 -t utf8 "$csvfile" | tr -d '\000' | tr '\r' '\n' | 
  sed -e '/^[[:space:]]*$/d' -e '/^,*$/d' -e "s/\$/,klr,$csvfile/" | 
  psql -h $host -U $user $database -c "$sql"

→ No CommentsTags: