Kwartik's Blog

March 30, 2011

Use your screensaver to display your favorite quotes !

Filed under: General — Tags: , , , , — kwartik @ 9:16 pm

Xscreensaver used to display quotes randomly Screenshot of my new screensaver

The “challenge” I faced was to configure my screensaver to display randomly my favorite quotes, and this in my Linux KDE4 based environment.Unfortunately none of the screensavers shipped with KDE4 provides this option. I was ready to develop my own screensaver when I realized that the xscreensaver project provides several screensavers designed to display text coming from the output of a custom command. Xscreensaver has the great advantage of not being distribution dependant as it is shipped on most Linux and Unix systems running the X11 Window System. The good news also was that the Mandriva distribution I use provides an xcreensaver rpm that once installed integrates the different screensavers shipped with xcreensavers directly in the KDE4 list of screensavers so there is no need to manually modify the X11 configuration.

So the remaining problem was to create a custom command to print randomly one of my favorite quotes. I first defined a simple XML format to save my quotes. Below an example of an XML file that I named quotes.xml and in which I saved two quotes to illustrate the concept:

<?xml version="1.0" encoding="UTF-8"?>

<collection>

<quote id='orwell-01' category="literature" reference="George Orwell - Animal Farm - 1945">
Man is the only creature that consumes without producing. He does not give milk, he does not lay eggs, he is too weak to pull the plough, he cannot run fast enough to catch rabbits. Yet he is lord of all the animals. He sets them to work, he gives back to them the bare minimum that will prevent them from starving, and the rest he keeps for himself
</quote>

<quote id='shakespeare-01' category="literature" reference="William Shakespeare - Hamlet - ~1600">
To be, or not to be, that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing end them? To die, to sleep,
No more; and by a sleep to say we end
The heart-ache, and the thousand natural shocks
That flesh is heir to: 'tis a consummation
Devoutly to be wished. To die, to sleep;
To sleep, perchance to dream – ay, there's the rub:
For in that sleep of death what dreams may come,
When we have shuffled off this mortal coil,
Must give us pause – there's the respect
That makes calamity of so long life.
For who would bear the whips and scorns of time,
The oppressor's wrong, the proud man's contumely,
The pangs of disprized love, the law’s delay,
The insolence of office, and the spurns
That patient merit of the unworthy takes,
When he himself might his quietus make
With a bare bodkin? Who would fardels bear,
To grunt and sweat under a weary life,
But that the dread of something after death,
The undiscovered country from whose bourn
No traveller returns, puzzles the will,
And makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all,
And thus the native hue of resolution
Is sicklied o'er with the pale cast of thought,
And enterprises of great pith and moment,
With this regard their currents turn awry,
And lose the name of action. Soft you now,
The fair Ophelia! Nymph, in thy orisons
Be all my sins remembered.
</quote>

</collection>

Then I created a simple PERL script named gl that parses this XML file (it requires for this purpose the excellent XML::Twig perl module usually shipped with the perl-XML-Twig rpm), chooses randomly one quote and prints it to the standard output :

#!/usr/bin/perl

use strict;
use utf8;
use Encode qw(encode decode);
use Getopt::Long;
use XML::Twig; #PERL module usually shipped in the perl-XML-Twig rpms

#---------------- BEGINNING OF CONFIGURABLE SECTION -----------------------------#

my $xml_collection = '/home/kwartik/quotes.xml';

my $encoding='utf8';

#---------------- END OF CONFIGURABLE SECTION -----------------------------------#

GetOptions(
    "c|collection=s" => \$xml_collection,
    "e|encoding=s"  => \$encoding,
);

if ( $xml_collection eq "" )
{
  print
     "SYNTAX : gl [-c|--collection path_to_xml_collection] [-e|--encoding encoding]\n\n"
    ."encoding option examples : 'utf8' 'iso-8859-1'\n";
  exit 1;
}

(-f $xml_collection) or die ("Error: collection $xml_collection is not a file.\n");

my $nb_entries = 0;
my %hash_collection = ();

sub quote
{
    my( $twig, $item )= @_;
    my $id = $item->att('id');
    my $category  = $item->att('category');
    my $reference  = $item->att('reference');
    $hash_collection {$id} {'category'}  =  $category;
    $hash_collection {$id} {'reference'}  =  $reference;
    $hash_collection {$id} {'quote'}  =  $item->text;
    $twig->purge;
    $nb_entries ++;
}

my $twig= new XML::Twig( twig_handlers => { 'quote' => \&quote }   );
$twig->parsefile( $xml_collection );

sub print_quote( $ )
{
	my $entry = $_[0];
    my $category = $hash_collection{$entry}{'category'};
    my $quote = $hash_collection{$entry}{'quote'};
    my $reference = $hash_collection{$entry}{'reference'};
    printf("%s (%s)\n", encode($encoding, $quote) , encode($encoding, $reference) );
}

my $choice = int(rand($nb_entries));
my @entry = ( sort {$a cmp $b} keys %hash_collection );
print_quote($entry[$choice]);
exit 0;

print "\n";

The final step is to link xscreensaver to gl. I first chose the Phosphor screensaver in the KDE4 screensaver list (accessible in “Configure your desktop/desktop/screensaver”).

Phosphor screensaver appearing in the KDE4 screensaver list once xscreensaver installedSelection of Phosphor screensaver in the KDE4 screensaver list once the xscreensaver rpm has been installed

Then I used the screensaver-demo command to configure the Phosphor screensaver.

Phosphor configuration with sxcreensaver-demoConfiguration of the phosphor screensaver with the xscreensaver-demo command

The advanced tab allows to specify the custom command that xscreensaver must call to display text.

Configuration of the phosphor screensaver with the xscreensaver-demo command (advanced tab)

In the Program field, I have set the value sleep3;/usr/local/bin/gl -e iso-8859-1 to configure Phosphor to print every 3 seconds the output of gl. The -e iso-8859-1 option is used to make sure that gl prints the content in ISO-8859-1 (otherwise accents and other diacritics are badly displayed by Phosphor). It is important to notice in this example that both my XML collection file and gl script have been saved with in UTF-8. I could have also set sleep3;clear;/usr/local/bin/gl -e iso-8859-1 to ask xscreensaver to clear the screen between each quote. I have also discovered that the fortune command (usually shipped with the fortune-mod rpm) is a tool that provides many possibilities to randomly display quotes and it was indeed proposed by default by xscreensaver.

March 28, 2010

Chess Openings : a simple PERL script to practise chess openings

Filed under: Perl — Tags: , — kwartik @ 1:43 pm

I have just released CHESS OPENINGS, a simple PERL script to practise chess openings. It is provided with a default configuration file containing a list of 437 famous openings. CHESS OPENINGS chooses randomly one opening in the configuration file and displays it as a nice UTF-8 matrix (UTF-8 do support chess characters). CHESS OPENINGS may be simply used through the command line but may be also be called by other tools like screen savers.

This script is intended to be used in a UTF-8 environment supporting chess characters. It has been successfully tested in a Linux terminal. Unfortunately, under Windows, the “terminal” (cmd.exe) is not able to print UTF-8 characters, so Windows users might need to use a two steps approach :

  1. redirection of the output in a file: perl chess-openings > opening.out
  2. edition of the output file with a UTF-8 compliant editor providing a nice font for chess characters

Chess fans may want to improve the code to add features (comments on the moves, …).

The script can be downloaded HERE. Enjoy !

December 7, 2009

How to set up a free and practical parental control filter with Procon Latte

Filed under: General — Tags: , — kwartik @ 11:50 pm

I was looking for a simple parental control filter solution in order to be sure that my young daughter (4 years old who of course likes to click on any link she sees !) will not accidentally find herself on one of these numerous undesirable sites. My requirements were the following :

– white list feature (I want to block all sites by default and allow explicitly a small number of sites)

– configuration protected with a master password

– filtering at application level, ideally as a Firefox module (add-on). I consider as totally sufficient this solution for my daughter, as I am sure that she is too young to think of using a different browser. She would have indeed quite some difficulties to find one on the Linux system I have configured for her !

– free solution

I queried the Firefox module catalog ( Tools / Complementary Modules / Catalog ) and it basically proposed me two parental control modules :

foxfilter, promoted as “Simple and effective! FoxFilter is a personal content filter that helps block pornographic and other inappropriate content using customizable features. All filtering features are free! Premium features require a small support fee.”,

broozi, promoted as the “first Firefox add-on which enable kids to take their first steps on Internet, so simply and in full safety”.

I was amazed by the philosophy of FoxFilter. “All filtering features free”, but the most important one which is the master password to guarantee that your kid will not be able to add a site to a white list is a Premium feature ! More over, I had the impression that a lot of the configuration is done online as if the foxfilter is insterested by your parental configuration settings ! A few minutes of testing were sufficient to add the product to my black list!

– The philosophy of broozi to radically change the user interface was not at all what I was looking for. Moreover, control parental feature simply did not work, as it was possible to click on the firefox icon in the tasks bar to leave the broozi interface and to go back to the firefox interface and my daughter is clearly able to do this ! Once installed I was encouraged to purchase Rooki, which adds a real _safe_ parental control feature to broozi.

– Finally, I googled a little bit and found ProCon Latte described as a content filter for Forefox allowing to “filter any kind of material (pornography, gambling, hacking, cracking, etc…), it can also block all traffic, making sure that only desired websites (set in the Whitelist) can be accessed, and includes a profanity filter, all *like* a parental control filter.” I tested only the “block all traffic” and white list features and I really appreciated this tool. I found the interface really intuitive to use and not at all intrusive.

I have posted below a few screenshots showing how easy it was to set a configuration compliant to my requirements. My system uses french locales but of course internationalization is well managed by ProCon.

First, a master password needs to be set, it will be required at each settings modifications as shown on the picture below :

ProCon master password prompt

Then all sites can be blocked by default by clicking on the “Block all traffic checkbox” :

ProCon : activation of the "all sites are blocked by default" rule

Finally, a white list can be easily created by clicking on the “Activate white list” check box :

ProCon: activating the white list

And that’s it ! After this straight-forward configuration step, I can safely leave my daughter in front of the screen. ProCon implements also much more elaborated filtering logic that is detailed on its web site.

I was also very impressed by the support provided by corvineum, the author of ProCon. After a ProCon minor release update (v1.7.9.7 => 1.7.9.8), I was not able to use ProCon anymore and an error related to the french accents was displayed in a popup. I sent a email to corvineum and twelve hours latter he sent me the fix ! I am not even sure that if I had experimented a similar problem with a proprietary solution, I would have observed the same reactivity !

November 28, 2009

Designing a safe and practical long-term backup solution

Filed under: SysAdmin — Tags: , , , — kwartik @ 10:26 pm

1. The paradox

A worrying tendency has been growing exponentially in the last two decades, worrying because it can give a totally false impression of security to its adepts. This tendency has several denominations like digitization or de-materialization.

All the knowledge that has been archived on traditional support (stone, paper) by our ancestors since the invention of writing, approximately 5300 years ago, is being migrated onto this new so-called “numerical” support, fundamentally different. Functionally fundamentally different because it gives data a new dimension which can be defined as the intersection of ubiquity and instantaneousness and which literally revolutionizes sharing capabilities. But also fundamentally different by essence. Data becomes virtual, its physical representations and locations obscure for most of the humanity, the knowledge of the machinery of this new technology is shared only by a relatively small community of skilled technicians. A characteristic of this new support is its dependency to energy. Depending of the numerical support, absence of electrical power, means at least impossibility to read the data, and at most total loss of the data. We know that energy management is going to be a key challenge in this millennium. What would be the consequences if energy resources were to be one day insufficient to keep alive this gigantic amount of virtual data which is growing at such an incredible speed ?

Data destruction sinistrality takes also a new dimension with this technology revolution. History has been marked by several acts of intentional or accidental data destruction (acts often materialized as book burnings) and such regrettable events continue and will for sure continue to happen in this new numerical era. The two main differences that can be noticed in the new destruction events are their magnitude and instantaneousness. Who has not experimented a data loss or corruption due to a virus (criminal event) or hard disk failure (accidental event) ? How much data was present on this hard disk that just failed ? Today, 1 Tera bytes disks are common, they can easily host the equivalent of a million of books ! The next generation saving units will  be more and more capacitive, probably in the order of the Peta bytes in 2025 if we consider that Moore’s Law also applies to hard disks!  Risks take definitely a new magnitude. The reasoning can also be pushed at organization level. Consequences for an organization that would lost its data after an electromagnetic attack are disastrous. Electromagnetic weapons do exist and have already been successfully tested on real companies ! It is not an hazard if companies that are totally dependent on their information systems choose, if they can afford it, to bury their electronic equipments in bunkers !

I have the feeling to observe a paradox in my daily life. On the one hand we are (or can be if we decide to) aware of the dimension of these new risks, on the other hand we blindly archive under this new format every single event of our daily life ! The next part of this article tries to define the security measures that should be taken to limit the risk of personal data lost and proposes a practical technical implementation.

2. Risks Analysis

Data loss causes are either accidental or criminal.

Accidental causes are events such as :

  • hardware failures (electronic or mechanicals components)
  • human error
  • software bugs

Criminal causes are events such as :

  • hardware thefts
  • hacking (viruses, system compromising ..)
  • Electromagnetic attack

3. Requirements for a safe backup policy

Backup (or more generally redundancy) is certainly the best and only parade to data loss but it has to be done carefully as it can give a real false impression of security if not done properly. Indeed, defining and implementing a back-up policy is quite challenging as all the different risks should be taken into consideration. We will focus here on the use case concerning individuals willing to deploy a practical solution to secure their personal data. The case of data backup management within an organization is more complex to address as there are real-time security requirements, also because of its important size and the fact that it is usually spread on many physical locations, but the general principles exposed here are still valid.

A crucial parameter to take into consideration in the backup policy is the fact that damages after any of the previous causes are not necessarily immediately visible – part of the data may be in a incoherent state while the other isn’t. If the concerned incoherent files are diagnosed as corrupted too late, restoring the back-up may not help if this back-up has been done after the compromising. This is why it is fundamental to have a data backup technology allowing to restore the state of a file at different points in time. The earlier state it is possible to restore, the safer the backup is.

An other crucial principle is that the backup should be performed on a non-rewritable medium. It is indeed very easy to imagine a nasty virus capable of deleting in a few seconds all the data present on a rewritable backup medium like a external hard drive as soon as it is plugged into the system.

Backup (or more generally redundancy ) is certainly the best and only parade to data loss but it has to be done carefully as it can give a real false impression of security if not done properly. Indeed, defining and implementing a back-up policy is quite challenging as all the different risks should be taken into consideration.

Blog at WordPress.com.