Tuesday, April 24, 2012

ZyXEL NSA310, Disabling FTP Clear Text Access

NSA310 is a nice NAS with impressive amount of access options. Mainly thanks to Linux which runs it. Besides it is cheap.

There is one caveat: FTP access. While enabling it there is no way to force FTPES mode only. A client can connect either using clear text or SSL.

Forcing NSA310 into FTPES only mode requires some hacking.

First, you need to enable sshd on your box to be able to hack it remotely. Use your web interface to log-in as admin. After that go to the following address (it enables sshd):

Now, ssh to your box using root as the username and admin's password.

Go to the following directory:


and create a file named: pureftpd-tweak which contains the folowing code:

DATA=`cat $CONF`
echo ' -Y 2' $DATA > $CONF
kill `cat /var/run/pure-ftpd.pid`
sleep 1
/usr/local/sbin/pure-ftpd `/bin/cat $CONF`
exit 0

Now tell NSA310 to actually use this file upon boot.
Edit ZYPKG_DEPS file and add the following line in the START-UP section:


ZYPKG_DEPS should look like this now:

# Dependency for zypkgs



Reboot, and that's it.

You can FTPS but not FTP to your box now.

For more information take a look at: ZyXEL Forum and NAS-central.

Sunday, January 9, 2011

XBMC and NVidia's TwinView

I was looking for a decent media center - mostly to watch movies with an overhead projector connected to a PC. The PC is running Linux and I would like to be able to select a movie, change the volume, pause etc with my Medion (read: cheap, RF, USB connected) remote. One day I stumbled upon XBMC. It turned out to be a decent piece of software. Configuring the remote was easy. But...

I must mention here that my display setup uses the NVidia's TwinView, which serves me well. My main LCD monitor is connected through a D-Sub while the beamer via HDMI. They form a dual-screen setup with the beamer on the right of the LCD.

But there is always a catch... Actually two of them.
  1. XBMC's fullscreen ignores TwinView, so it spans both displays, or the other display is turned off. 
  2. There is video tearing visible while XBMC is running on the beamber, there is no tearing if it runs on the LCD.
The first issue can be fixed by making XBMC use so-called windowed mode. It appears as a window then. Having a window and using wmctrl it is possible to make it look like fullscreen.
The second issue regard configuring the NVdia in a proper way which makes OpenGL sync to the specified display instead of the first one. It can be achieved by exporting two environment variables __GL_SYNC_TO_VBLANK=1 and __GL_SYNC_DISPLAY=name_of_the_display_to_sync_to.

So here comes my magical bash script which launches the XBMC with a proper syncing enabled and shifts it to the beamer making the window fullscreen (mind that the beamer is on the right of the LCD, and the LCD is 1280x1024).


  NAME='XBMC Media Center'

  while [ -z "`wmctrl -l | grep \"$NAME\"`" ]
      sleep 1

  wmctrl -r "$NAME" -e '0,1280,-1,-1,-1'
  wmctrl -r "$NAME" -b toggle,fullscreen

move_and_fullscreen &

Update: As of XBMC 10.1 I had to add SDL_VIDEO_ALLOW_SCREENSAVER=0 to disable screensaver while running XBMC. The above approach uses the windowed mode of XBMC which enables system screensaver now - it kicks in while watching movies :( (the screensaver is disabled in the fullscreen mode only).

Monday, November 15, 2010

Linux and a newborn.

Have you ever tired to put a newborn to sleep? It's tough. However it seems that linux can do it for you - actually it works pretty good for my son. Just turn the volume up and issue:

while true ; do cat /boot/vmlinuz-2.6.32-25-generic > /dev/dsp ; done

Good luck.

Sunday, September 26, 2010

C, Java, Erlang, Prolog, Haskell: naive banchmark

Here comes a naive benchmark for C, Java, Erlang, Prolog and Haskell. The benchmark is to compute Pythagorean triples. The triple consists of three positive integers a, b, and c, such that a*a + b*b = c*c and additionally a+b+c<=n, where n=500.


f :: Int -> [ (Int, Int, Int) ]
f n = [ (x, y, z) | 
    x <- [ 1 .. n ],
    y <- [ 1 .. n ],
    z <- [ 1 .. n ],
    x + y + z <= n,
    (x * x) + (y * y) == (z * z) ]
    A + B + C =< N ,
    A*A + B*B =:= C*C.

pythag(N) ->
    [ {A,B,C} ||
        A <- lists:seq(1,N),
        B <- lists:seq(1,N),
        C <- lists:seq(1,N),
        A+B+C =< N,
        A*A+B*B =:= C*C
int main(int argc,char *argv[]){
    int a,b,c,n;

    for (a=1; a<=n; a++) {
        for (b=1; b<=n; b++) {
            for (c=1; c<=n; c++) {
                if ((a+b+c <= n) && (a*a + b*b == c*c)){
    return 0;
public class triangles
    public static void main(String [] args)
        int a,b,c,n;

        for (a=1; a<=n; a++) {
            for (b=1; b<=n; b++) {
                for (c=1; c<=n; c++) {
                    if ((a+b+c <= n) && (a*a + b*b == c*c)){

Here comes the results (in seconds).

Haskell (GHCi, version 6.12.1): 380
Haskell compiled (GHCi, version 6.12.1): 32
Prolog (SWI Prolog 5.7.4): 197.2
Erlang (R13B03): 59.5
Erlang HiPE (High Performance Erlang), native: 13.2
C (gcc 4.4.3): 0.8
Java (IcedTea6 1.8.1): 2.2 (with output redirected to /dev/null: 1.3)

The winner was obvious from the begining. But it's quite interesting how the declarative languages perform... hmmm. Kudos to Erlang.

By the way, have you noticed that the code is far better readable with the declarative approach?

Sunday, September 5, 2010

Command line might: useful aliases; BASH tips

I'm a command-line-guy I guess. I use a terminal quite often (mostly with BASH), either for file management, or while working on my projects, just to launch proper application, and optionally to make it read some contents from a given file.

I found myself using quite often two particular functions:
  1. searching for a file which name contains a keyword, and
  2. figuring out what files I recently modified in the current directory.
These two functions can be easily written down as:

ls -l | grep -i some_keyword
ls -lt | head

Right, but since I use them quite often and being rather lazy I wouldn't want to type these every time... So here come aliases.
You can define an alias for a command you often type and use it instead.  So I decided to define two aliases: lsg and lst for searching for a file name containing a keyword and displaying the recently modified files respectively.

So if you type at your command prompt:

alias lsg='ls -l | grep -i'
alias lst='ls -lt | head'

From now one you can use lsg and lst freely.

If you want to make the change permanent you could add the above lines to your ~/.bashrc file, so the aliases would be accessible any time you log in.

Oh one more thing... how to use it.
If I want to find out what files I modified recently in the current directory I just type:

$ lst

and it gives me a list of recntly modified files. If I'm looking for a file which name contains a keyword "book" I issue:

$ lsg book

And I get a list of files which names contain "book" (case insensitive). It's quite useful - at least for me.

PS. Dont forget about: cd -
It will bring you up to the directory you were previously in.

Monday, August 30, 2010

Home DVD, non interlaced

This nice tiny DVD camera of mine captures footage which turns to be interlaced... While it is nice while watching on a TV, it turns to be at least annoying to watch on a computer. There are some so called comb (or mouse teeth) artifacts which annoy a lot. Of course many video players can deinterlace video on-the-fly however it turns that they do that with very different results especially concerning overall video quality.

So I poked around and it seems that one of the nicest deintralcers available is compiled into MPlayer. It is called yadif. So it's really easy to use. I fidlled with some settings for a while and ended up with a command as follows:

mencoder source.mpg -of mpeg -mpegopts tsaf:format=mpeg2:muxrate=30000 -noskip -vf yadif -o dest.mpg -oac copy -ovc lavc -lavcopts vcodec=mpeg2video:mbd=1:aspect=16/9:vbitrate=9100

It turns a file called source.mpg into a nice deinterlaced dest.mpg.

Monday, June 7, 2010

Printing and Acrobat Reader

Have you ever had problems with printing a PDF document with the Adobe Acrobat Reader? Have you seen a non-informative message:"The document could not be printed"?
I have... and it was surprising, frustrating and... well you know how it is.... especially when the printout is due yesterday...
I stumbled upon this issue when I was to print some stuff in a print shop. I made a PDF went to the shop and ordered a color laser printout (70 pages). I was quite surprised when the guy behind the counter, told me that there is no way to print this document, since Adobe Acrobat displayed that wierd message. Surprisingly nobody at the shop knew what the message ment. I went back to my computer (yes, yes, yes, a desktop...) took a look, and everything was fine I could see it and print it... mind that I use mainly Evince or xpdf for PDFs. Desperatelly I converted the document into Postscript and back to PDF (glorious pdftops and ps2pdf) and took it back to the print shop. Surprisingly they could print it now - without any complains from the Acrobat.

I made some reasearch to make sure that such an event won't take place again. And it turns out that guys at Adobe don't know what they are doing (and they don't care for their customers either) and guys at the print shop have no idea how to handle the Acrobat. There is a web forum I stumbled upon, which deals with this issue, especially one message. It turns out that the printing problem appears for some PDF files - however it's hard to tell what exactly causes it.

Anyway, if you ecaountered this issue take a look at the top, right corner of the print dialog window. If you see an option like below (Comments and Forms: Document and Markups) the Acrobat presumably won't print your file.
Just change it to Document, and you should be allowed to print your stuff (see below)!
Bottom line. Adobe is worse and worse. The Acrobat is bloated. Users dont't know how to use it. Solution? Don't use it! There is plenty of other PDF browsers avaliable: evince, xpdf... Long live the free software!!!