XRunHProf

November 22, 2009

Extending Adsweep, a Google Chrome ads blocker

Filed under: Uncategorized — Tags: , — xrunhprof @ 10:26 pm

Adding a rule to Adsweep is not as easy as in Adblock. Below is a patch for Adsweep 2.0.1 to remove ads on 2 web sites I often use. On Debian the AdSweep.js file can be found in this directory:

$HOME/.config/google-chrome/Default/Extensions/*/2.0.1
diff --git a/AdSweep.js b/AdSweep.js
index a7d0d8b..96dba20 100644
--- a/AdSweep.js
+++ b/AdSweep.js
@@ -91,6 +91,25 @@ function adsweep_removeAdNodes()
        adsweep_YouTube();
        window.setTimeout(function()
        {
+               if(URL.match("meteofrance.com")) {
+                       ad=document.getElementById("topAd");
+                       if(ad) ad.parentNode.removeChild(ad);
+                       ad=document.getElementById("adColumn3");
+                       if(ad) ad.parentNode.removeChild(ad);
+                       ad=document.getElementById("HighDiv_LB");
+                       if(ad) ad.parentNode.removeChild(ad);
+                       ad=document.getElementById("HighDiv_PV");
+                       if(ad) ad.parentNode.removeChild(ad);
+               }
+               if(URL.match("allocine.fr")) {
+                       divs = document.getElementsByTagName("div")
+                       for(var i = 0; i < divs.length; i++) {
+                               var c = divs[i].className
+                               if(c && c.match('adbox'))
+                                       divs[i].parentNode.removeChild(divs[i]);
+                       }
+               }
+
                // AdBrite
                if(document.getElementsByTagName("A")){var anchorTags=document.getElementsByTagName("A");for(var a=0;a<anchorTags.length;a++){for(var x=0;x<anchorTags[a].attributes.length;x++){if(anchorTags[a].attributes[x].nodeName.toLowerCase()=='id'){if(anchorTags[a].attributes[x].nodeValue.indexOf("AdBriteInlineAd")!=-1){var textString=anchorTags[a].innerHTML;var newNode=document.createElement('SPAN');newNode.innerHTML=textString;anchorTags[a].parentNode.insertBefore(newNode,anchorTags[a]);}}}}}

September 19, 2009

Setup wpa_gui and roaming on Debian

Filed under: Uncategorized — xrunhprof @ 2:10 pm

Until recently I was editing my /etc/network/interfaces file each time I wanted to change my wifi connexion parameters:

iface wlan0 inet dhcp
    wpa-ssid somewhere
    wpa-key-mgmt WPA-PSK
    wpa-psk "secret"
    wpa-proto WPA
    wpa-pairwise TKIP
    wpa-group TKIP

I’m now using wpa_gui which is part from wpasupplicant. To install wpa_gui just do:

apt-get install wpagui

My /etc/network/interfaces file now only contains this 3 blocks:

auto wlan0
iface wlan0 inet manual
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

The auto statment is required to automatically start the wpa_supplicant daemon at startup. The /etc/wpa_supplicant/wpa_supplicant.conf file should at least contains the 2 following lines:

update_config=1
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

The update_config parameter let users add AP parameters from the GUI. GROUP=netdev let netdev group member control wpa_supplicant from wpa_cli or wpa_gui. Here is how to add a member to the netdev group:

adduser johndoe netdev

wpa_supplicant.conf will contains sensible data, like AP keys, so its access should be limited:

chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf

Finally I added wpa_gui in the session startup of XFCE. It’s in the Session and startup configuration GUI. KDE users would type ln -s /usr/sbin/wpa_gui in the .kde/Autostart directory.

References: /usr/share/doc/wpasupplicant/README.Debian.gz

September 5, 2009

Removing decoration in xfwm or metacity (again)

Filed under: Uncategorized — Tags: , — xrunhprof @ 9:22 am

Here is a simpler version of this post, using PyGTK:

#! /usr/bin/python
from gtk.gdk import *

w=window_foreign_new((get_default_root_window().property_get("_NET_ACTIVE_WINDOW")[2][0]))
state = w.property_get("_NET_WM_STATE")[2]
maximized='_NET_WM_STATE_MAXIMIZED_HORZ' in state and '_NET_WM_STATE_MAXIMIZED_VERT' in state
if maximized: w.unmaximize()
if w.get_decorations() == 0 :
    w.set_decorations(DECOR_ALL)
else:
    w.set_decorations(0)

if maximized: w.maximize()
window_process_all_updates()

This script can be used in XFCE thanks to xfce4-keyboard-settings:

xfce4-keyboard-settings

xfce4-keyboard-settings

August 7, 2009

Encrypting a laptop with dm-crypt without reinstalling from scratch

Filed under: Uncategorized — Tags: , , , — xrunhprof @ 4:56 pm

First you need to backup the partition you want to encrypt. If like me you are using samba sharing not supporting large files you will probably want to compress and split you backup. Tar does’nt support multi-volume compressed archive, but you can create them using the split command:

tar --one-file-system -cvfz - / | split -b 700M - /mnt/backup/backup

Then boot your laptop with a live CD or USB stick. It needs to include at least cryptsetup, chroot and all tools required to get you backup back. I use a custom debian live USB key created with live-helper:

sudo apt-get install live-helper

lh_config -b usb-hdd -p standard \
--mirror-binary http://ftp.fr.debian.org/debian \
--mirror-binary-security http://ftp.fr.debian.org/security \
--mirror-bootstrap http://ftp.fr.debian.org/debian \
--mirror-chroot http://ftp.fr.debian.org/debian \
--mirror-chroot-security http://ftp.fr.debian.org/security \
--hostname "rescue" --packages "ntfsprogs cryptseup bzip2 smbclient lftp
openssh-server elinks vim-nox pciutils lshw ntfs-3g rsync debootstrap" \
--bootappend-live "locale=fr"

sudo lh_build

sudo dd if=binary.img of=/dev/sdf

Once booted, you have to prepare your partitions. The requirements are:

  • A partition for /boot (will be unencrypted
  • A partition for / (wil be encrypted)

You may also want to have an encrypted swap. I personally do not use any swap partition. Here is my configuration before partitioning modifications (yes, I have a Windows dual boot):

# fdisk -l /dev/sda

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xeede9d79

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          13      104391   de  Dell Utility
/dev/sda2   *          14        7327    58749705    7  HPFS/NTFS
/dev/sda3            7328       14593    58364145   83  Linux

I just removed the partition 3 and create 2 new ones using fdisk. Here is my new partition table:

# fdisk -l /dev/sda

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xeede9d79

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          13      104391   de  Dell Utility
/dev/sda2   *          14        7327    58749705    7  HPFS/NTFS
/dev/sda3            7328       14583    58283820   83  Linux
/dev/sda4           14584       14593       80325   83  Linux

Now let’s create the encrypted file system:

cryptsetup create sda3 /dev/sda3

It will ask for a password. You will have to enter this password at each boot. The encrypted partition should now appear as /dev/mapper/sda3. Format it and mount it:

mkfs.ext3 /dev/mapper/sda3
mkdir /mnt/sda3
mount /dev/mapper/sda3 /mnt/sd3

You can now restore your backup. If you used tar and split as said before, the untar command will look like this:

cd /mnt/sda3
cat /mnt/backup/backup* | tar -zxvf -

Later to configure initrd we will need to know the ciper, hash and key size used to encrypt the partition:

# cryptsetup status sda3

/dev/mapper/sda3 is active:
  cipher:  aes-cbc-plain
  keysize: 256 bits
  device:  /dev/sda3
  offset:  0 sectors
  size:    116567640 sectors
  mode:    read/write

Now let's configure the restored system to make it able to boot on an encrypted file system. First chroot it:

mount --bind /proc /mnt/sda3/proc
mount --bind /sys /mnt/sda3/sys
mount --bind /dev /mnt/sda3/dev
chroot /mnt/sda3

You have to write a /etc/crypttab file so initramfs-tools know what to include in the initrd image.

#<target name>	<source device>		<key file>	<options>
sda3 /dev/sda3 none cipher=aes-cbc-plain,hash=ripemd160,size=256

initramfs-tools need some parts of the cryptsetup package to create the initrd:

apt-get install cryptsetup

During the installation of this package the initrd images will be recreated to take the new /etc/crypttab file into account. If cryptsetup was already installed you would have to update the initrd images manually:

update-initramfs

Final step... As your /boot directory as been moved, grub need to be reinstalled:

grub-install /dev/sda
update-grub

May 21, 2009

Image tiling for poster printing

Filed under: Uncategorized — Tags: , , — xrunhprof @ 8:36 am

Here is what I tried to print a large image (6000×4000 px) tiled on 16 A4 pages.

Jos van Eijndhoven poster

convert oisan2.png eps:- | poster -c2% -p111.76x68.58cm | ps2pdf - output2.pdf

It works but need one hour to  do the conversion. I guess it’s because it work on a Postscript file.

pdfposter

It’s fast but it does not manage overlap. This is something I really need.

A tiling script with Python imaging.

#! /usr/bin/python
import Image, ImageDraw, ImageFont
im = Image.open("input.png")
ni = 4
nj = 4
imarging = 40
jmarging = 40

width=(im.size[0] + (ni-1) * 2 * imarging) / ni
height=(im.size[1] + (nj-1) * 2 * jmarging) / nj
iincr=width - 2 * imarging
jincr=height - 2 * jmarging

f = ImageFont.truetype("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf", 25)

for i in xrange(ni):
    for j in xrange(nj):
        ipos = iincr * i
        jpos = jincr * j
        box = (ipos, jpos, ipos + width, jpos + height)
        print box
        thumb = im.crop(box)
        d = ImageDraw.Draw(thumb)
        d.text( (5,0), str(j+1) + ',' + str(i+1), font=f, fill='blue')
        thumb.save( '/tmp/im' + str(i) + '_' + str(j) + '.png' )

Then with ImageMagick:

convert -units PixelsPerInch -density 160x160 /tmp/im*.png output.pdf

May 14, 2009

How Vista protect you against dangerous installers

Filed under: Uncategorized — Tags: — xrunhprof @ 2:17 pm

I’m using 7-zip to create simple installer for the software I develop. Many of my customers doesn’t have administrators rights and it was not a problem until recently. Vista wants adminstrator privileges to run my installers (actually a simple self extracting archive). I was wondering why Vista would require administrator privilieges to extract an archive so I tried with simple executables in Cygwin:

$ cat > foo.c
int main(void) {
   return 0;
}
$ gcc foo.c -o installer.exe
$ ./installer.exe
bash: ./installer.exe: Permission denied
$ mv installer.exe foo.exe
$ ./foo.exe

The conclusion of my errors and trials is that, on Vista, a dangerous file is a file wich contains the string instal in its name. I will just non longer name my archive foo-version-installer.exe but foo-version-inst.exe.

I’m now really looking forward to find other such easter eggs in Vista.

April 13, 2009

Removing decorations in Metacity

Filed under: Uncategorized — Tags: , , — xrunhprof @ 8:12 am

I switched to gnome and I miss one wonderful feature of kwin. By combining always on top and remove decoration, kwin allow to transform any window into a kind of post-it embedded into an other window. For example I use it to add an xterm in Netbeans. I don’t know any other window manager than kwin being able to hide decoration with a hot key.

From Devil’s pie source code I found that it was possible to remove decoration using the _MOTIF_WM_HINTS window property. It first tried it with the xprop command, but I had some trouble to handle the maximized window case. Then I found the Ralf Neupert wmctrl patch. I used it as inspiration to write my wmctrl patch, which toggle decoration and ensure that maximized window spread on the whole screen. See the patch bellow.

Metacity have a built-in support for binding custom action to shortcut. In gconf-editor:

  • /apps/metacity/keybinding_commands/command_1 = wmctrl -r :ACTIVE: -B
  • /apps/metacity/global_keybindings/run_command_1 = <mod4>H

(more…)

March 3, 2009

Create resizable SVG with inkscape

Filed under: Uncategorized — Tags: , — xrunhprof @ 6:56 pm

Inkscape currently create fixed size SVG files. Firefox does not resize them when they are set into an object tag. This is a known limitation:
https://blueprints.launchpad.net/inkscape/+spec/allow-browser-resizing

A work around is to add preserveAspectRatio and viewBox to the root svg tag:

<svg
...
width="310"
height="180"
preserveAspectRatio="xMinYMin meet"
viewBox="0 0 310 180"

February 14, 2009

Lenny in virtualbox, RAM 26Mb, boot time 17s

Filed under: Uncategorized — Tags: — xrunhprof @ 9:12 pm

Here is how I configured a Lenny Virtualbox for desktop and development usage on Windows laptop. I tried to make it as slim as possible because the host OS use a lot of RAM.

First install a minimal Lenny. It means uncheck all box at the end of the installation even the “Standard system” one. Then install xserver-xorg, xinit, xauth, x11-server-utils, openbox, lxterminal, fbpanel. We will not install any login manager nor session manager.

To start X11 and login automatically at boot time add this line to /etc/inittab:
x:2345:once:/bin/su PREFERED_USER -l -c "/bin/bash --login -c startx >/dev/null 2>&1"

Modify /etc/X11/Xwrapper.config as the user do not run startx from the console but from init:
allowed_users=anybody

Create a .xinitrc file in the home directory:
openbox &
lxterminal &
xsetroot -solid black
fbpanel

Reboot and 17 seconds later check your memory as said in this post.

A variant without auto-login is to do not modify inittab but add this to ~/.bash_profile:
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
 startx
 logout
fi

Reference:
http://wiki.archlinux.org/index.php/Start_X_at_boot

January 26, 2009

VBoxAddIF no longer in Virtualbox 2.1.x

Filed under: Uncategorized — Tags: — xrunhprof @ 11:44 am

In Virtualbox 2.1.x. available network modes are:

  • NAT which allows guest to see the Internet but no to be seen by the host
  • Host network which give the guest a public IP
  • Internal network which allows several virtual machines to see each other, but still not to be seen by the host

The VBoxAddIF as disappeared so network between host and guest is no longer supported as a native option of Virtualbox 2.1.x. It easy to replace it by a TUN/TAP interface. Here is a /etc/network/interface example to do so:

iface eth0 inet dhcp
#allow routing for vmware and vbox
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE

iface tap0 inet static
pre-up tunctl -t tap0 -u xrunhprof
address 192.168.0.1
netmask 255.255.255.0

The virtual machine must then be configured to use a static IP from the 192.168.0.x range.

Older Posts »

Blog at WordPress.com.