Thursday, April 25, 2013

How can I export my emails from gmail programmatically?


Well this is a question I hear again and again. I decided to do something about it and the result is a short python utility that accesses gmail with a username and password over SSL.

You can get the export-gmail script here.

Execute like so:

#python export-gmail.py timtam t0psecret INBOX save

Running the script like the line above, with the save keyword will...

1.  Connect to the gmail service using the username timtam and the password t0psecret
2.  Select the folder INBOX (for Trash use Trash etc.)
3.  Retrieve a list of available messages uniques ids
4.  If save was given as a run line option compare the list from 3 with what is previously known
5.  Retrieve each email from 4 and print to screen
6.  If save was used then same the emails details into a local DB.

There are lots of places to improve this but for now it will get you going.

Monday, April 22, 2013

Discover what TLS ciphers a website supports.

Every now and again you might need to fine tune a website under your control that supports TLS - SSLv3. Part of that tuning might be a discussion about what ciphers to support or even things like key sizes you may want to tune.

Something that might help is ssl_cipher_test

This little utility will ask the openssl installation in the local machine for it's TLS cipher list. for each cipher in the list the script will attempt to download a user specified web page from that HTTPS server

The speed of the download is measured over x iterations.



Usage ./ssl_cipher_test.py hostname [file]

Installing apache Zookeeper RPM and python binding

This will be a short one today.

Want to install apache zookeeper onto a RH Centos type linux box? If yes then review and run the following lines in your shell. These should cut'n'paste cleanly as of post date.


rpm -Uvi  https://bigstreams.googlecode.com/files/zookeeper-3.4.1-1.x86_64.rpm
pip install --upgrade zc-zookeeper-static
pip install --upgrade zc.zk

# possibly you may have issues with the "service" script 
# not starting zookeeper properly. This can be due to the 
# visibility of JAVA_HOME to the service script
# The following 3 lines works around that.

mkdir -p /usr/java/
mkdir -p /var/lib/zookeeper
ln -s  /usr/lib/jvm/jre /usr/java/latest

chkconfig --level 345 zookeeper on


# create this file with the following 3 lines
# cat /opt/zookeeper/conf/zoo.cfg
echo "tickTime=2000
dataDir=/var/lib/zookeeper
clientPort=2181" > /opt/zookeeper/conf/zoo.cfg

chkconfig --level 345 zookeeper on


#save and maybe reboot or
service zookeeper start

#sample python binding example.py
echo "import zc.zk
zk = zc.zk.ZooKeeper('127.0.0.1:2181')
a = zk.children('/')
print a" > example.py

python example.py


# another binding that may be of interest
# https://github.com/python-zk which can be installed as
# pip install kazoo 


Saturday, April 6, 2013

Installing VNC server on a vanilla Linux machine successfully

Recently I had the need to install a VNC server onto a Linux instance hosted in AWS EC2.  Typically these linux instances run at init level 3 i.e., with no X or windowing capabilities.

Many times in the past I had managed to successfully get VNC working with little drama.  So I set to work.  

Unfortunately it was not as easy as before as there were a few annoying errors that would arise on stating the VNC server. 



Xvnc TigerVNC 1.1.0 - built Feb 22 2013 22:28:37
Copyright (C) 1999-2011 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Underlying X server release 11300000, The X.Org Foundation

Initializing built-in extension Generic Event Extension
Initializing built-in extension SHAPE
Initializing built-in extension MIT-SHM
Initializing built-in extension XInputExtension
Initializing built-in extension XTEST
Initializing built-in extension BIG-REQUESTS
Initializing built-in extension SYNC
Initializing built-in extension XKEYBOARD
Initializing built-in extension XC-MISC
Initializing built-in extension XFIXES
Initializing built-in extension RENDER
Initializing built-in extension RANDR
Initializing built-in extension DAMAGE
Initializing built-in extension MIT-SCREEN-SAVER
Initializing built-in extension DOUBLE-BUFFER
Initializing built-in extension RECORD
Initializing built-in extension DPMS
Initializing built-in extension X-Resource
Initializing built-in extension XVideo
Initializing built-in extension XVideo-MotionCompensation
Initializing built-in extension VNC

Mon Apr  1 01:09:13 2013
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on all interface(s), port 5902
 vncext:      created VNC server for screen 0
[dix] Could not init font path element catalogue:/etc/X11/fontpath.d, removing from list!
[dix] Could not init font path element built-ins, removing from list!

Fatal server error:
could not open default font 'fixed'






After many many hours following various advice, fixes and magical incantations to address the above error nothing worked.

Long story short the fix is indeed to do with fonts, installing libXfont to be exact.  This got me where I needed to be.

What follows below is the complete set of commands that will install, configure and run VNC on a vanilla RH or Centos box.



yum groupinstall -y "X Window System"
yum install -y  tigervnc-server tigervnc-server-module libXfont pixman xterm xorg-x11-twm

echo 'VNCSERVERS="2:root"' >> /etc/sysconfig/vncservers

mkdir -p ~/.vnc && chmod 755 ~/.vnc 
vncpasswd -f < /bin/echo "secret12" > ~/.vnc/passwd && chmod u+rw ~/.vnc/passwd

chkconfig --level 345 vncserver on

Reboot to test. You may need to tweak passwords etc.

Now I didn't want to use the default twm window manager but rather use FVWM. To do that do this...

yum install -y libstroke libstroke-devel libpng libpng-devel readline readline-devel libSM
yum install -y libSM-devel libXrender libXrender-devel libXinerama libXinerama-devel 
yum install -y freetype freetype-devel
yum install -y libXcursor libXcursor-devel libXft libXft-devel libXpm libXpm-devel librsvg2 librsvg2-devel libXt-devel gcc


wget ftp://ftp.fvwm.org/pub/fvwm/version-2/fvwm-2.6.5.tar.gz
tar zxvf fvwm-2.6.5.tar.gz
cd fvwm-2.6.5
./configure
make && make install

# Copy over a default fwvmrc config file.
cp /root/fvwm-2.6.5/sample.fvwmrc/system.fvwm2rc /root/.fvwm2rc

# To make VNC server use this add near the top of .vnc/xstartup
# a line like 
#
# fvwm -display localhost:2.0 &
#
# where 2 is the display number the VNC server is active and
# can be inspected in /etc/sysconfig/vncservers
# Remember to comment out any other window managers that may
# be here


Go here for More info