Saturday 8 September 2012
Listen to mouse events in Linux (text mode)
By dooblem on Saturday 8 September 2012, 23h59
- Linux
- MPD
- Raspberry Pi
A small script to listen to mouse events with the mev
command using gpm
(General Purpose Mouse).
Can be used for example on the Raspberry Pi to run mpd commands, to use a mouse as a remote control.
I didn't find how to isolate the wheel events in order to control the volume. Any idea somebody?
In Archlinux, you can add the following command in /etc/rc.local
to start it at boot time:
nohup /usr/local/bin/mpd_mouse.sh > /tmp/mpd_mouse.log 2>&1 &
#!/bin/sh # This script listen to mouse events with the mev command using gpm. # Can be used for example on the Raspberry Pi to run mpd commands, to use a mouse as a remote control. # You can start it as a daemon with: # nohup /usr/local/bin/mpd_mouse.sh > /tmp/mpd_mouse.log 2>&1 & # start gpm if not already started gpm -m /dev/input/mice -t imps2 # unset TERM variable, otherwise mev refuses to start when detecting xterm unset TERM echo "Listening to mouse events..." # we use script to fake a tty for mev, otherwise it exits (note: mev logs errors in syslog) script -qc "mev -E" /dev/null </dev/null | grep --line-buffered -v "mouse-movement" | while read LINE do echo echo "$LINE" EVENT=$(echo "$LINE" | cut -d' ' -f1 | cut -d'(' -f2) if [ "$EVENT" = "down-mouse-1" ] then echo mpc stop mpc stop elif [ "$EVENT" = "down-mouse-2" ] then echo mpc toggle mpc toggle elif [ "$EVENT" = "down-mouse-3" ] then echo mpc next mpc next else echo "nothing" fi done
no comment
ssh-agent: automatic ssh-add on demand
By dooblem on Saturday 8 September 2012, 23h40
- SSH
Several desktop environments (Gnome, KDE) automatically start an SSH agent at startup. However, you have to think of running ssh-add before connecting to a server.
Waiting for automatic ssh-add in OpenSSH, you can add this to your .bashrc
:
ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh'
The alias is created only if the identity is not added, and the alias destroys itself once run.
This way the regular ssh command is used after the identity has been added.
superuser.com/questions/325662/how-to-make-ssh-agent-automatically-add-the-key-on-demand/471640#471640
no comment
Friday 11 May 2012
An outgoing port tester
By dooblem on Friday 11 May 2012, 13h22
- network
The server hosting this blog respond on all ipv4 TCP ports from 1 to 65535.
See: portquiz.positon.org
The following URLs should also work if you are not filtered :
- portquiz.positon.org:443
- portquiz.positon.org:8080
- portquiz.positon.org:8
This allows you to test what TCP ports are filtered by your local network.
Command line example with netcat:
$ nc -v portquiz.positon.org 1 electron.positon.org [178.33.250.62] 1 (tcpmux) open $ nc -v portquiz.positon.org 65535 electron.positon.org [178.33.250.62] 65535 (?) open
no comment
Sunday 29 April 2012
Pixel crisis: resolution regression
By dooblem on Sunday 29 April 2012, 15h53
I'm looking for a new laptop. My old T42p Thinkpad is becoming old. I'm looking for a laptop with a good screen...
However... finding a laptop with a resolution similar to my T42p is impossible on today's market. The T42p has been released for more than 8 years now!! When I'm speaking resolution, I mean pixel density in PPI. My resolution is of 1400x1050 for 14.1 inches, which is good! it gives a density of 124 PPI.
Nowadays, all laptops have the same unique 1366x768 resolution. The last thinkpad X1 from Lenovo with 13.3 inches is only 118 PPI.
It's revolting! I want my pixels!
Apparently I'm not the only one in this situation...
- 10rem.net/blog/2010/04/22/rant-hdtv-has-ruined-the-lcd-display-market-or-i-want-my-pixels-and-dpi-now
- boards.straightdope.com/sdmb/showthread.php?t=421095
- www.tabletpcbuzz.com/showthread.php?1624-Pixel-Density-Hostage-Crisis!&s=32e284cd59d44346c32f2471636389f2
- www.tomshardware.co.uk/forum/59742-29-higher-pixel-pitch
It's sad. Maybe it will be better in the future... with our cell phones screens having far better resolutions...
Other usefull links :
- en.wikipedia.org/wiki/Pixel_density
- PPI Calculator
3 comments
Monday 16 April 2012
Compare / diff between two images
By dooblem on Monday 16 April 2012, 14h00
- bash
- diff
- ImageMagick
After searching a long time on the Net, here is how to use ImageMagick to compare two images (diff), to determine if the images are similar, or if one image is a resize version of the other.
convert image1 image2 -resize '400x300!' MIFF:- | compare -metric AE -fuzz '10%' - null:
The convert command takes 2 images and scale them to a smaller identical size. We then pipe them to the compare command. The compare command will count the number of different pixels.
The command displays the number of different pixels. If it's zero then pictures are similar.
2 parameters can increase the similarity tolerance:
- The size of thumbnails to compare: the smaller it is, the more details are removed. You can use 1/4 of the smaller image for example.
- The -fuzz parameter: the color distance tolerance. The more you increase this param, the more you allow different colors. Color difference is almost undetectable below 2%.
Notes:
- It's better to keep ratio while generating thumbnails.
- The exclamation mark is needed to force image scale without preserving ratio. Otherwise in some cases the 2 thumbs are not strictly the same size and the compare command fails.
I also made a small script to scale at 1/4 of the small image and displays the percentage of different pixels: imdiff
./imdiff /tmp/bad.jpg ../Public/images/bad.jpg pixel difference: 2.927% NOK
Links:
- www.imagemagick.org/script/compare.php
- www.imagemagick.org/Usage/compare/
2 comments
Saturday 25 February 2012
Android HTC Dream AZERTY keyboard
By dooblem on Saturday 25 February 2012, 19h28
- Android
- CyanogenMod
Small contribution to CyanogenMod wiki
Physical keyboard is changed to QWERTY after CyanogenMod 6 flash. if your HTC Dream has an AZERTY keyboard:
- Download www.mon-cobaye.net/vrac/modif.zip (see SPF forum post)
- Copy
trout-keypad-v3.kl
andazerty.kcm.bin
to your sdcard - Then run the commands:
adb remount adb shell cat /sdcard/trout-keypad-v3.kl > /system/usr/keylayout/trout-keypad-v3.kl cat /sdcard/azerty.kcm.bin > /system/usr/keychars/trout-keypad-v3.kcm.bin
- Then reboot your phone
Some doc: source.android.com/tech/input/key-layout-files.html
no comment
Monday 30 January 2012
Remove Mobipocket DRM (.prc file)
By dooblem on Monday 30 January 2012, 01h11
- bookeen
- DRM
- ebook
The user manual of my Bookeen Cybook Gen 3 is DRM protected ! irrk..
Download last version of DRM Tools Archive here : stream-recorder.com/forum/download-drm-tools-archive-t7955p3.html
Extract the archive, then :
tools_v4.7/Mobi_Additional_Tools$ python MobiDeDRM_032.py /tmp/XXXXX.prc /tmp/decrypted.prc
You can now open the file with fbreader.
I'm not sure it works with all PRC files. Maybo you have to give the device PID for some.
no comment
Sunday 13 November 2011
Import CSV file to MySQL
By dooblem on Sunday 13 November 2011, 21h32
- bash
- csv
- MySQL
Here is the little sh script I made to do that. The LOAD DATA INFILE command exists but is not capable of creating the table structure.
#!/bin/sh MYSQL_ARGS="--defaults-file=/etc/mysql/debian.cnf" DB="mbctest" DELIM=";" CSV="$1" TABLE="$2" [ "$CSV" = "" -o "$TABLE" = "" ] && echo "Syntax: $0 csvfile tablename" && exit 1 FIELDS=$(head -1 "$CSV" | sed -e 's/'$DELIM'/` varchar(255),\n`/g' -e 's/\r//g') FIELDS='`'"$FIELDS"'` varchar(255)' #echo "$FIELDS" && exit mysql $MYSQL_ARGS $DB -e " DROP TABLE IF EXISTS $TABLE; CREATE TABLE $TABLE ($FIELDS); LOAD DATA INFILE '$(pwd)/$CSV' INTO TABLE $TABLE FIELDS TERMINATED BY '$DELIM' IGNORE 1 LINES ; "
dev.mysql.com/doc/refman/5.1/en/load-data.html
(See comment: "Posted by John Swapceinski on September 5 2011 5:33am")
no comment
Tuesday 14 June 2011
PHP escapeshellarg function, UTF8 and locales
By dooblem on Tuesday 14 June 2011, 23h09
- locales
- PHP
- UTF8
The PHP escapeshellarg
function depends on your current locale. I think it's bad, but PHP developers made this choice. If like me your default locale is 'C' you lose all UTF8 characters.
They suggest you to call something like setlocale(LC_CTYPE, "en_US.UTF-8")
. It doesn't work if the en_US.utf8
locale is not installed on your system. Of course maybe you have the fr_FR.utf8
, or de_DE.utf8
, but you will have to try all of them until you find one utf8 matching locale. And if there is not, you're screwed. It's also bad if you want code that runs everywhere.
Simply use that:
$escapedArg = "'".str_replace("'", "'\\''", $arg)."'";
It will do the same as the escapeshellarg
function: replace yourstringthat'slong
by
'yourstringthat'\''slong'
as described in the escapeshellarg manual (and I also looked into the PHP source code to be sure).
See also:
- www.php.net/escapeshellarg
- bugs.php.net/bug.php?id=44945
- bugs.php.net/bug.php?id=44564
no comment
Sunday 13 March 2011
A very simple mysqldump script to backup your databases
By dooblem on Sunday 13 March 2011, 21h42
- Debian
- MySQL
- shell script
Here are some lines I'm using to backup my MySQL databases on my Debian server:
#!/bin/sh # This will dump all your databases DATE=$(date +%Y%m%d%H%M) for DB in $(echo "show databases" | mysql --defaults-file=/etc/mysql/debian.cnf -N) do mysqldump --defaults-file=/etc/mysql/debian.cnf $DB > /backup/mysql/${DB}_${DATE}.sql gzip /backup/mysql/${DB}_${DATE}.sql done # purge old dumps find /backup/mysql/ -name "*.sql*" -mtime +8 -exec rm -vf {} \;
You can run it in a cron:
11 1 * * * /usr/local/bin/mysqldump.sh > /tmp/mysqldump.log
This way any error displayed by the script will be sent by mail to the root user (mail address in /etc/aliases
).
If you are not under Debian and there is no password file in /etc/mysql, you should create such file.
6 comments
Thursday 13 January 2011
positon.42 and dnsmasq as a DNS proxy to resolve .42 domains
By dooblem on Thursday 13 January 2011, 23h32
- 42registry
- dnsmasq
I am now the owner of a .42 domain !
positon.42
.42 are not official domains (yet). Official top level domains are managed by ICANN and served by root DNS servers.
To resolve .42 domains, you have to query a DNS server knowing .42 domains.
Here is my small contribution to the 42registry.org wiki, explaining a way to configure it with Ubuntu:
---
The following allows you to use Geeknode DNS only for .42 domains while keeping your regular DNS provider for other domains.
Install dnsmasq :
aptitude install dnsmasq
Edit /etc/dnsmasq.conf
and add the line :
server=/42/81.93.248.69
Restart dnsmasq :
sudo /etc/init.d/dnsmasq restart
Edit /etc/dhcp3/dhclient.conf
, then uncomment or add the line :
prepend domain-name-servers 127.0.0.1;
Now disconnect and reconnect to you local network, to refresh the /etc/resolv.conf file, then test it !
---
Links:
- https://www.42registry.org/
- wiki.42registry.org/
- wiki.42registry.org/page/Resolve#Ubuntu_and_Dnsmasq
2 comments
Wednesday 29 December 2010
Rsync command restriction over SSH
By dooblem on Wednesday 29 December 2010, 18h36
- rsync
- backup
- SSH
You have 2 systems and you want to set up a secure backup with rsync + SSH of one system to the other.
Very simply, you can use:
backup.example.com# rsync -avz --numeric-ids --delete root@myserver.example.com:/path/ /backup/myserver/
To do the backup, you have to be root on the remote server, because some files are only root readable.
Problem: you will allow backup.example.com to do anything on myserver.example.com, where just read only access on the directory is sufficient.
To solve it, you can use the command=""
directive in the authorized_keys
file to filter the command.
To find this command, start rsync adding the -e'ssh -v'
option:
rsync -avz -e'ssh -v' --numeric-ids --delete root@myserver.example.com:/path/ /backup/myserver/ 2>&1 | grep "Sending command"
You get a result like:
debug1: Sending command: rsync --server --sender -vlogDtprze.iLsf --numeric-ids . /path/
Now, just add the command before the key in /root/.ssh/authorized_keys
:
command="rsync --server --sender -vlogDtprze.iLsf --numeric-ids . /path/" ssh-rsa AAAAB3NzaC1in2EAAAABIwAAABio......
And for even more security, you can add an IP filter, and other options:
from="backup.example.com",command="rsync --server --sender -vlogDtprze.iLsf --numeric-ids . /path/",no-agent-forwarding,no-port-forwarding,no-pty,no-user-rc,no-X11-forwarding ssh-rsa AAAAB3NzaC1in2EAAAABIwAAABio......
Now try to open a ssh shell on the remote server.. and try some unauthorized rsync commands...
Notes:
- Beware that if you change rsync command options, change also the
authorized_keys
file. - No need for complex chroot anymore. Forget my previous article: /post/SFTP-chroot-rsync
See also:
man ssh #/AUTHORIZED_KEYS FILE FORMAT
man rsync
view /usr/share/doc/rsync/scripts/rrsync.gz
(restricted rsync, allows you to manage allowed options precisely)
no comment
Sunday 19 December 2010
I2P proxy configuration via PAC file
By dooblem on Sunday 19 December 2010, 23h16
- Firefox
- Hadopi
- I2P
With the new french Hadopi law... I just tested the I2P nework, which works fairly well.
Installation is very easy. Just download the .exe file. Then launch it with the java -jar
command, like explained on the official site (and it works on Linux, yes !).
Now, if you want to access .i2p sites, like forum.i2p, you must configure your browser to use the I2P proxy: localhost:4444
If you don't want to use the proxy when connecting to standard non-i2p sites, you can use the FoxyProxy Firefox extension.
You can also use a PAC (Proxy Auto-Config) file:
function FindProxyForURL(url, host) { if (dnsDomainIs(host, ".i2p")) { return "PROXY localhost:4444"; } else { return "DIRECT"; } }
Then configure Firefox, or proxy configuration in Gnome to use the file:///path/to/proxy.pac
file as configuration.
Warning: a bad eepsite (.i2p site), can detect your real IP address with that.
Links:
- www.i2p2.de/ I2P site
- forum.i2p/viewtopic.php?p=30030
- forum.i2p2.de/viewtopic.php?p=30030
no comment
Tuesday 30 November 2010
Clementine: a good music player
By dooblem on Tuesday 30 November 2010, 21h11
- Amarok
- Clementine
- Debian
- music
- Ubuntu
I discovered Clementine some time ago.
There is not any package for Ubuntu or Debian, but the official site gives you a .deb for your favorite Ubuntu version. And you'll also find Mac OS X and Windows versions...
A small click on the good .deb file for your Ubuntu distro and it should install.
I tested tons of players (Amarok, Rythmbox, old XMMS, Exaile, Listen, Totem...).
Clementine is based on Amarok, it's far simpler and integrates very well in Gnome desktop using Qt4 librairies.
I'm happy to know this software and I recommend it to you.
4 comments
Tuesday 9 November 2010
Exim Router: recipient filter
By dooblem on Tuesday 9 November 2010, 23h51
- Debian
- Exim
- Spam
In a previous post, I explained how to setup a catchall with Exim. This to create multiple addresses all redirecting to the same destination:
catchall_pub: driver = redirect domains = ads.mydomain.com data = user@mydomain.com
Then, I wrote that on destination address we could setup a Sieve or Exim filter with a .forward
file.
If you want to do that directly in Exim, to have all config in one place, or simply if your destination mail box doesn't supports filters...
Just add a local_parts
option:
catchall_pub: driver = redirect domains = ads.mydomain.com local_parts = !/etc/exim4/ads.mydomain.com.blacklist data = user@mydomain.com
In /etc/exim4/ads.mydomain.com.blacklist
we put all rejected addresses, one per line:
foo1 bar2
This way foo1@ads.mydomain.com and bar2@ads.mydomain.com will be rejected.
Exim4 Doc:
- The redirect router
- Router preconditions
- File names in lists
2 comments
Saturday 30 October 2010
Preload web content using link prefetch or javascript
By dooblem on Saturday 30 October 2010, 16h50
- Bizou
- Chromium
- Firefox
- HTTP
- Javascript
- PHP
For the Bizou php gallery, I looked for different ways of preloading next image in "view" mode (example).
With Firefox it's very simple. Just use the following element and the browser will preload your contents. Contents are preloaded in background, once the whole current page is loaded.
<link rel="prefetch" href="/images/nextimage.jpg" />
Problem: only Firefox supports this currently. Note: a ticket is opened about this in the Chromium project.
For other browsers, use some Javascript triggered by the window.onload
event:
<script type="text/javascript"> window.onload = function() { // for images var im = new Image(); im.src = '/images/nextimage.jpg'; // and for other content var req = new XMLHttpRequest(); req.open('GET', 'nextpage.php', false); req.send(null); }; </script>
Beware of HTTP cache headers sent by the server to the browser. To preload correctly PHP pages, make your script send an Expires header:
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
Then, for a simple browser detection from your PHP script:
<?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) { ?> <link rel="prefetch" href="nextpage.php" /> <?php } else { ?> <script type="text/javascript"> window.onload = function() { var req = new XMLHttpRequest(); req.open('GET', 'nextpage.php', false); req.send(null); }; </script> <?php } ?>
Links :
- https://developer.mozilla.org/en/Link_prefetching_FAQ
- www.4thkingdom.com/public/computers/789073-web-site-speed-prefetching-images-css/view-post.html (using jQuery)
- orip.org/2009/03/prefetching-javascript-or-anything-with.html (using jQuery)
- commit sur Bizou
no comment
Sunday 24 October 2010
Bizou - a (french) KISS php image gallery
By dooblem on Sunday 24 October 2010, 23h34
I spent hours on the Web looking for THE PHP software I need with no success.
Required features:
- Free-libre software
- No database, just images in a directory, that's all.
- Easy to understand source code, easy to patch for my needs
- Variable number of thumbs fitting the browser width.
And I spent another weekend happy coding something that may already exist. But my gallery is simple and does what I want:
www.positon.org/bizou/en.html
Demo here
12 comments
Friday 22 October 2010
A solution to the umask problem: inotify to force permissions
By dooblem on Friday 22 October 2010, 00h29
- bash
- inotify
- Linux
- SFTP
- umask
Finding a good solution for sharing files between Linux users is a nightmare.
If using a unique UID is not a problem, it's the most simple solution. All clients access files with the same UID. This way you cannot know who does what, and users cannot fine tune access rights.
The problem: default umask is ALWAYS 0022, so that any created file will get rw– r–– r––
permissions. Only the owner can write. Nobody else. To share files, a group must have write access.
You can change the umask. For command line, you set it in .bashrc
or .profile
, or /etc/profile
for all users. For a SFTP share, you can set it with a trick. For Apache HTTP server, you can set it with /etc/apache2/envvars
under Debian.
If file sharing is only done via on service, changing umask is simple, otherwise