binfalse

bioinformatics and system administration

  • Home
  • /usr/local
    • $SHELL
    • adjustPKL
    • conf.rc
      • R.rc
      • screen.rc
    • iso2l
      • iso2l – Usage
      • iso2l – Download
    • Jabber -vs- Twitter
    • Monitoring plugins
      • check_catalyst_fans.pl
      • check_catalyst_flash.pl
      • check_catalyst_load.pl
      • check_catalyst_mem.pl
      • check_catalyst_temp.pl
      • check_hp_health.pl
      • check_imapds.sh
      • check_mount.pl
      • check_pykota.sh
      • check_UBC.pl
      • check_url_shortener.pl
      • check_wp.php
    • MS-Mapper
    • ParseAble BioData
      • Amino acids
      • Isotopic distributions
    • Snippets
      • backup
      • mediadump
      • MySQL backup
      • tweet
      • twitstat
      • unforgotten
      • unpack
    • UserScripts
      • 3sat-repair
      • SquirrelMail search reorder
      • web.de navi blocker
      • ZDF without flash
    • YOURLS Firefox extension
  • /media
  • ls -alh
  • top
  • man
  • more
  • ping
  • whoami
  • top
  • /opt

KDE file type actions

By Martin Scharm on January 24, 2013 at 1:52 am

Vote +1
Vote -1

Annoyingly, KDE‘s PDF viewer okluar always opened links to websites with an editor presenting me the source code. But I just figured out how to change this behavior.

kcmshell4 dialog to configure filetype-application-mappings

kcmshell4 dialog to configure filetype-application-mappings

KDE maintains a central config defining what to do with certain file types. Unfortunately, in my case the default application for HTML files was an editor (kwrite/kate). I don’t know who or what defined this stupid behavior, but there is a tool called kcmshell4 to edit the KDE configuration. That said, to edit the filetype-application-mapping hand it the parameter filetypes:

1
usr@srv % kcmshell4 filetypes

You’ll get a dialog to define a mapping for each known file type. In my case I had to configure okular to open links to HTML pages with konqueror.
Hope that helps you to save some time ;-)

Posted in Media, Network, Software, Web
Tagged kde, Media, okular, user interaction
Leave a response

encfs: transparent crypto overlay

By Martin Scharm on January 16, 2013 at 4:08 am

Vote +1
3
Vote -1

encfs is a cryptographic file system (encfs-website). The principle is very easy, you “bind-mount” one directory (containing the crypt stuff) to another directory (where it’s unencrypted). Thus, you can share the encrypted stuff and nobody but you can read your data. So this system is excellent applicable for cloud services like Dropbox, which trap you with some space in the cloud “for free“, but want you to share your private data with them. In some <p>‘s we’ll see how to setup encfs for Dropbox, but let’s first take a look at encfs itself.

encfs

First of all you have to install encfs. Assuming you’re sitting in front of a Debian-based os:

1
root@abakus ~ # aptitude install encfs

Since encfs is fuse-based the user who wants to use encfs has to be member of the group fuse. You may use the groups command to make sure you belong to fuse:

1
2
martin@abakus ~ % groups
martin mail fuse

If you’re not yet member of that group edit the /etc/group file or use the useradd command (howto). To apply the changes you need to re-login or use newgrp (man newgrp).

That’s it, now the way to use encfs is parved. Let’s say we want to work with our data in /dir/clear, while the whole stuff is stored encrypted in /dir/crypt. It’s quite simple to setup this environment, just call encfs [crypt-dir] [decrypt-dir] :

1
2
3
4
5
6
7
martin@abakus ~ % encfs /dir/crypt /dir/clear
Creating new encrypted volume.
Please choose from one of the following options:
 enter "x" for expert configuration mode,
 enter "p" for pre-configured paranoia mode,
 anything else, or an empty line will select standard mode.
?>

Give it a p and choose a password. This command will install an encrypted container in /dir/crypt and immediately mount it to /dir/clear. Feel free to create some files in /dir/clear (you’re new working directory) and compare this directory with /dir/crypt. You’ll see that you are not able to understand the files in /dir/crypt, unless you’re a genius or the setup failed. Thus, it’s no issue if anyone might have access to the content in /dir/crypt.

To unmount the clear data use fusermount -u /dir/clear. To remount it just call again encfs /dir/crypt /dir/clear, it will just ask you for the password to decrypt the data.

Of course it’s not very convenient to mount the directory every time manually, hence there is a workaround to automount your encfs directories on login. You need to install libpam-mount and libpam-encfs:

1
root@abakus ~ # aptitude install libpam-mount libpam-encfs

To automatically mount an encfs on login the password for the crypt-fs has to be the same as the password for your user account! If that’s the case, add a line like the following to /etc/security/pam_mount.conf.xml:

1
2
3
4
5
<pam_mount>
    [...]
    <volume user="martin" fstype="fuse" path="encfs#/dir/crypt" mountpoint="/dir/clear" />
    [...]
</pam_mount>

On your next login this directory will automatically be mounted. Very smart!

Using encfs for the cloud

Ok, let’s get to the main reason for this article, winking towards Norway ;) .
As you might have heard, there are some file hosting services out there, like Dropbox or Ubuntu One. They provide some space in the cloud which can be mounted to different devices, so that your data is sync’ed between your systems.
Unfortunately, most of these services want to read your data. E.g. the Dropbox system wants to store a file used by multiple users only once. Even if they pretend to assure that nobody’s able to read your private data, you all know that this is bullshit nearly impossible! However, I strongly recommend to not push critical/private files to these kind of providers.

But, thada, you’ve just learned how to sync your files using the cloud while keeping them private! Let’s assume the directory /home/martin/Dropbox is monitored by Dropbox, you just need to create two more directories, like /home/martin/Dropbox/private (for encrypted files to be sync’ed) and /home/martin/Dropbox-decrypt (for decryption). Mount /home/martin/Dropbox/private to /home/martin/Dropbox-decrypt using encfs and work in /home/martin/Dropbox-decrypt. As explained above, feel free to setup an automount using pam ;-)
Everything in /home/martin/Dropbox but not in the private directory will be sync’ed unencrypted, so you won’t loose the opportunity to share some open data with [whoever] e.g. via web browser.

Of course, this method comes with some drawbacks:

  • It is a bit more work to setup every client, before you can start working with your private data (fortunately the overhead is kept in reasonable limits)
  • You cannot access these files through the web browser, or using your mobile phone (unless your phone comes with encfs-support)

All in all, you need to decide on your own, how much you trust Dropbox (and alike) and which kind of data you commit to Dropbox unencrypted.

Posted in Linux/Unix, Media, Network, Security, Software, Unix, Web
Tagged cloud, crypt, Debian, explained, Media, pam, Security, share, sync
Leave a response

Sync the clock w/o NTP

By Martin Scharm on January 11, 2013 at 2:37 am

Vote +1
2
Vote -1

The network time protocol (NTP) is a really smart and useful protocol to synchronize the time of your systems, but even if we are in two-thousand-whatever there are reasons why you need to seek for alternatives…

You may now have some kind of »what the [cussword of your choice]« in mind, but I have just been in an ugly situation. All UDP traffic is dropped and I don’t have permissions to adjust the firewall.. And you might have heard about the consequences of time differences between servers. Long story short, there is a good solution to sync the time via TCP, using the Time Protocol and a tool called rdate.

Time Master

First off all you need another server having a correct time (e.g. NTP sync’ed), which can be reached at port 37. Let’s call this server $MASTER. To enable the Time Protocol on $MASTER you have to enable the time service in (x)inetd. For instance to enable the TCP service for a current xinetd you could create a file in /etc/xinetd.d/time with the following contents:

1
2
3
4
5
6
7
8
9
10
service time
{
    disable     = no
    type        = INTERNAL
    id          = time-stream
    socket_type = stream
    protocol    = tcp
    user        = root
    wait        = no
}

Such a file may already exist, so you just have to change the value of the disable-key to no. Still using inetd? I’m sure you’ll find your way to enable the time server on your system :)

Time Slave

On the client, which is not allowed to use NTP (wtfh!?), you need to install rdate:

1
aptitude install rdate

Just call the following command to synchronize the time of the client with $MASTER:

1
rdate $MASTER

Since rdate immediately corrects the time of your system you need to be root to run this command.

Finally, to readjust the time periodically you might want to install a cronjob. Beeing root call crontab -e to edit root’s crontab and append a line like the following:

1
2
# m     h       dom     mon     dow     command
0       */6     *       *       *       [ -x /usr/bin/rdate ] &amp;&amp; /usr/bin/rdate $MASTER &gt;&gt; /dev/null

This will synchronize the time of your client with the time of $MASTER every six hours. (Don’t forget to substitute $MASTER using your desired server IP or DNS.)

Notes

Last but not least I want you to be aware that this workaround just keeps the difference in time between both systems less than 0.5 secs. Beyond all doubt, looking at NTP that’s very poor. Nevertheless, 0.5 secs delay is much better than several minutes or even hours!

If it is also not permitted to speak to port 37 you need to tunnel your connections or you have to tell the time server to listen to another, more common port (e.g. 80, 443, or 993), as long as they are not already allocated by other services..

Posted in Administration, Debian, Linux/Unix, Network, Security, University
Tagged Debian, fail, Network, remote, Security, time, trick, Ubuntu, ugly, University
Leave a response

Bash Wildcards

By Martin Scharm on September 17, 2012 at 10:48 pm

Vote +1
6
Vote -1

I wanted to publish this summary about wildcards in the bash (and similar shells) some time ago, but didn’t finish it. But finally it gets published.
The shell handles words or patterns containing a wildcard as a template. Available filenames are tested to see if they fit this template. This evaluation is also called globbing.
Let’s have a look at a small example:

1
2
3
4
5
me@kile /tmp/blog $ ls
aaa   aaa2  aaaa1  aaaa3  aaaa5  abbb  bbbb
aaa1  aaa3  aaaa2  aaaa4  aaab   acdc  caab
me@kile /tmp/blog $ ls *b
aaab  abbb  bbbb  caab

In this example * is replaced by appropriate characters, and the list of matching files are passed to the ls command. This set of files will be used in the following examples.

Encode for a single character: ?

The question mark can be replaced by a single character. So if you want to get the files aaa1, aaa2, aaa3 and aaab you can use the following pattern:

1
2
me@kile /tmp/blog $ ls aaa?
aaa1  aaa2  aaa3  aaab

So you see, the ? is replaced by exactly one character. That is, both aaa and aaaa1 won’t match.

Encode for a an arbitrary number of characters: *

To match any number of characters you can use the asterix *. It can replace 0 to n characters, n is limited by the max length of the file name and depends on the file system you’re using. Adapting the previous snippet you’ll now also get aaa and aaaa1:

1
2
me@kile /tmp/blog $ ls aaa*
aaa  aaa1  aaa2  aaa3  aaaa1  aaaa2  aaaa3  aaaa4  aaaa5  aaab

Encode for a set of characters: [...]

Most of the common tasks can be done with the previous templates, but there are cases when you need to define the characters that should be replaced. You can specify this set of characters using brackets, e.g. [3421] can be replaced by 3, 4, 2 or 1 and is the same as [1-4]:

1
2
3
4
5
6
me@kile /tmp/blog $ ls aaaa?
aaaa1  aaaa2  aaaa3  aaaa4  aaaa5
me@kile /tmp/blog $ ls aaaa[3421]
aaaa1  aaaa2  aaaa3  aaaa4
me@kile /tmp/blog $ ls aaaa[1-4]
aaaa1  aaaa2  aaaa3  aaaa4

As you can see aaaa5 doesn’t match [3421], and btw. the order of the specified characters doesn’t matter. And because it would be very annoying if you want to match against any alphabetic character (you would need to type all 26 characters), you can specify character ranges using a hyphen (a-z). Here are some exmaples:

Template Character set
[xyz1] x, y, z or 1
[C-Fc-f] C, D, E, F, c, d, e or f
[a-z0-9] Any small character or digit
[^b-d] Any character except b, c, d
[Yy][Ee][Ss] Case-insensitive matching of yes
[[:alnum:]] Alphanumeric characters, same as A-Za-z0-9
[[:alpha:]] Alphabetic characters, same as A-Za-z
[[:digit:]] Digits, same as 0-9
[[:lower:]] Lowercase alphabetic characters, same as a-z
[[:upper:]] Uowercase alphabetic characters, same as A-Z
[[:space:]] Whitespace characters (space, tab etc.)

Btw. the files that match such a template are sorted before they are passed to the command.

Posted in Shell, Software
Tagged Bash, explained
Leave a response

Validating XML files

By Martin Scharm on September 12, 2012 at 11:17 pm

Vote +1
2
Vote -1

In the scope of different projects I often have to validate XML files. Here is my solution to verify XML files using a schema.
First of all to validate XML files in Java you need create a SchemaFactory of the W3C XML schema language and you have to compile the schema (let’s assume it’s located in /path/to/schema.xsd):

1
2
SchemaFactory factory = SchemaFactory.newInstance ("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema (new File ("/path/to/schema.xsd"));

Now you’re able to create a validator from the schema.

1
Validator validator = schema.newValidator ();

In order to validate a XML file you have to read it (let’s assume it’s located in /path/to/file.xml):

1
Source source = new StreamSource (new File ("/path/to/file.xml"));

Last but not least you can validate the file:

1
2
3
4
5
6
7
8
9
10
try
{
  validator.validate (source);
  System.out.println ("file is valid");
}
catch (SAXException e)
{
  System.out.println ("file is invalid:");
  System.out.println (e.getMessage ());
}

Here you can find my implementation:

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
package de.binfalse.martin;

import java.io.File;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.xml.sax.SAXException;



/**
 * The XMLValidator to validate XML files.
 *
 * @author martin scharm
 */

public class XMLValidator
{
   
    /** The validator. */
    Validator   validator;
   
   
    /**
     * Instantiates a new XML validator.
     *
     * @param schemaFile
     *          the schema file
     * @throws SAXException
     */

    public XMLValidator (File schemaFile) throws SAXException
    {
        validator = SchemaFactory.newInstance ("http://www.w3.org/2001/XMLSchema")
            .newSchema (schemaFile).newValidator ();
    }
   
   
    /**
     * Validate a file.
     *
     * @param xmlFile
     *          the XML file to validate
     * @return true, if file is valid
     */

    public boolean validateFile (File xmlFile)
    {
        try
        {
            Source source = new StreamSource (xmlFile);
            long time = System.currentTimeMillis ();
            validator.validate (source);
            time = System.currentTimeMillis () - time;
            System.out.println ("took: " + time / 1000 + "s");
            return true;
        }
        catch (Exception e)
        {
            e.printStackTrace ();
        }
        return false;
    }
   
   
    /**
     * The main method for testing purposes.
     *
     * @param args
     *          the arguments
     */

    public static void main (String[] args)
    {
        args = new String[] { "/tmp/schema.xsd", "/tmp/testfile.xml" };
        try
        {
            System.out.println ("creating val");
            XMLValidator validator = new XMLValidator (new File (args[0]));
            System.out.println ("validating");
            if (validator.validateFile (new File (args[1])))
            {
                System.out.println ("file is valid!");
                return;
            }
            else
                System.out.println ("file is invalid!");
        }
        catch (SAXException e)
        {
            System.out.println ("sax error:");
            e.printStackTrace ();
        }
        System.exit (1);
    }
   
}
Download:
JAVA: XMLValidator.java
(Please take a look at the man-page. Browse bugs and feature requests.)

Posted in Java, Snippet, Software
Tagged explained, Java, Programming, Snippet
Leave a response

Next »

Search

Calendar

May 2013
MonTueWedThuFriSatSun
« Jan  
 12345
6789101112
13141516171819
20212223242526
2728293031 

Pages

  • /media
  • /opt
    • Eclipse
    • Firefox
    • Java
  • /usr/local
    • $SHELL
    • adjustPKL
    • conf.rc
    • iso2l
    • Jabber -vs- Twitter
    • Monitoring plugins
    • MS-Mapper
    • ParseAble BioData
    • Snippets
    • UserScripts
    • WP Link target XHTML
    • XTB
    • YOURLS Firefox extension
  • ls -alh
  • man
  • more
  • ping
  • top
  • whoami

Categories

  • Administration (125)
    • Hardware (12)
    • Mail (5)
    • Media (43)
    • Network (39)
    • Operating system (30)
      • Linux/Unix (21)
        • Debian (14)
      • Unix (6)
    • Security (16)
    • Software (100)
  • Bioinformatics (18)
  • HowTo (2)
  • Junk (16)
  • Private (25)
  • Programming (78)
    • C/C++ (3)
    • HTML (3)
    • Java (21)
    • JavaScript (12)
    • Perl (10)
    • PHP (7)
    • R (16)
    • Shell (8)
    • Snippet (2)
    • tex (1)
  • ShortCut (7)
  • University (32)
  • Web (64)
    • Website (8)
    • Wordpress (10)

Bookmarks

  • AG Elastin
  • heise
  • 3dfxatwork
  • me @ sourceforge
  • One R Tip A Day
  • complete Blogroll

Archives

  • January 2013 (3)
  • September 2012 (5)
  • April 2012 (4)
  • November 2011 (4)
  • August 2011 (4)
  • July 2011 (3)
  • June 2011 (9)
  • May 2011 (5)
  • April 2011 (8)
  • February 2011 (13)
  • January 2011 (10)
  • December 2010 (13)
  • November 2010 (4)
  • October 2010 (7)
  • September 2010 (9)
  • August 2010 (11)
  • July 2010 (8)
  • June 2010 (1)
  • May 2010 (10)
  • April 2010 (4)
  • August 2009 (2)

Meta

  • Register
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Tags

Ajax analyzed apache aptitude aptosid Baltic Sea Bash Bioinformatics Blog Bonn c++ chemistry Clustering contest crazy CSS Cups DBus Debian debug DNA DNS explained fail Firefox Flash game git GNU Google grml hacked Halle Iceweasel Jabber Java journals Junk kernel keyboard LaTeX LDAP Lenovo log Mail Media mensa Microarrays microscope MS MTP MySQL NAT Network NGS Notebook OpenCV pattern Poland Printer Private Programming Proxy puzzle remote Rumpel search Security ShortCut Sid Sidux SIGINT simplification Snippet spaughts SSH sshfs SSL SunRay SUN Spot Thunderbird Tree trick Trip twitter Ubuntu ugly University Usedom user interaction userscript vim virtual Waters wife Windows Wordpress wort X Zen

Copyright © 2009-2013 Martin Scharm. Powered by WordPress.

This work is licensed under Creative Commons by-nc-sa 3.0.