2012-07-23

blog relocation

I relocated my blog to my own server. It is now based on octopress, so code should look waaaaaay prettier :)
please follow the link and don't forget to update your rss feed:

no-trust.org/flatline/blog

2012-07-07

webapps and language

hello socializing people,


i was just playing around with a social integration chain of youtube -> twitter -> facebook which works pretty neat now. There was just one problem: Since youtube is displayed in german by default since I life in germany, so are the automated posts that say i liked / favorited / whatevered a video that get sent to twitter and from there to facebook. But I have some friends who don't speak german and I generally like to use english anyways when it's public. The trick was to tell youtube to display itself in english, which claims to only affect the interface but as I guessed right: It also affects the text that's auto posted :)

2012-07-05

getting Command & Conquer: Red Alert 3 (Steam) to start up

Hello gamers,

yesterday I bought C&C: Red Alert 3 on steam sale. After downloading though it wouldn't start. It just sat there with its fancy splash screen, occupied 25% of my cpu (conquer alright!) but didn't start up. At first I thought it may be a problem with the steam version, but there were only problem reports about multiplayer and mods. Someone with Windows 7, 64bit version also claimed to have it running, so that couldn't be it either. *But* the game was build for Windows XP / Vista (32bit only!) which gave me the idea to screw around a little with the compatibility settings.

SOLUTION:
Start as Administrator / Set it to do so every time:
go to your steam folder, then to RA3, i.e.:
C:\Program Files (x86)\Steam\steamapps\common\Command and Conquer Red Alert 3\RA3.exe
right click -> properties -> compatibility -> run as an administrator
then you can just start it right from steam



2012-06-28

zombie screen / irc difficulties

hey there,

today I was unable to log into my private irc server. Really strange, since I changed nothing, the server was still running and all. Also my screen session seemed to have vanished.
After I asked another user I heard I was still in the channel... somehow my screen session was off the radar but still running, so I could not connect to it. Also since in this session I already was logged into the irc server, I could not log in again.
Well, killing the session and opening a new one was easy, but had I not asked my friend I could have been debugging for days without ever getting the idea I would still be logged in from somewhere.
So, every detail matters, even a "crashed" screen session :D

2012-06-03

backup script (NO, not data-backups, small configuration file backups)

Hello again,

after some time finally something usefull for more of you: a small bash script that came out of configuration work. The scenario is, you want to test a new configuration file, but want to backup the old or standard one. Sometimes it's a hole directory you want to exchange. And ofter some testing one has a couple of backup files, all with different names and naming conventions, somtimes maybe a date, sometimes a tag...
So I wrote the following script. Probably most admins do something like this and probably there are already a quadrillion tools out there, that do this or can do this. But I like to have a simple command that does exactly what I want without the need to supply the same options everytime, that I can't remember. So if you have a tool already, just make an alias. But here's the script, for everyone who wants to use it:



#!/bin/bash
# put it here for example: /usr/local/bin/bak.sh
# don't forget to chmod 755 it
if [[ (($# -ne 1) && ($# -ne 2)) || ($1 == "-h") ]]; then
        echo "usage: bak.sh <file or dir> <optional tag>"
        echo "files will just be copied"
        echo "directories will be archieved as .tgz"
        exit
fi
APPEND="bak-`date +'%Y-%M-%d_%H%M%S'`"
if [ $# -eq 2 ]; then
        APPEND="${APPEND}-${2}"
fi
if [ -d $1 ]; then
        APPEND="${APPEND}.tgz"
        echo "backing up ${1} to ${1}.${APPEND}"
        tar czf $1.$APPEND $1
else
        echo "backing up $1 to ${1}.${APPEND}"
        cp -p $1 $1.$APPEND
fi

SSL Rant

GAAAAAAAAHHHH I HATE SSL

Well, I mean, I cannot live without ssl. Well I mean, I cannot live without encryption. And SSL is the de-facto standard encryption on the internet.
Since I moved to a new server because the old ones uptime rarely gets beyond 24 hours these days, i had to reconfigure some services. Apache was easy, copy the config, everybody's happy.
Mail wasn't that easy, I wanted to have virtual domains. So I had to bake myself a new little setup from ground up. postfix + courier-imap was working before, so I decided to base it on that.
But when I was testing connectivity I noticed SSL warnings. these typical "your certificate is BROKEN" in your face warnings, that would make everybody besides myself check for new viruses on their pc while making sure the abort button is not some evil "sell your soul here" button.
I don't reaaaaaally need to get rid of the warning but I wanted to do it right. It seems I used cacert certificates before. They are really nice, but aren't really compatible with anyone who doesn't go to keysigning parties or at least knows what that is. So I took my already working StartCom SSL certificate, that I use for apache and mumble, pointed the config file to it and then screamed and shed tears of blood for the next couple of hours.
Because supplying your own certificate isn't enough. No, you have get the right combination of internmediate certificates, root certificates, your own public one and your private key. And just as a side note: EVERY program does is differently! So went to the internets and looked, which files I had to cat together four courier-imap, but instead of the gaping abyss of result-less google searches I got about 10 different possiblilites, which certificates to cat together. Also, there is the ascii-style .pem format and the .crt format. Or .crt formats. Because some .crts look exactly like .pems and some are binary garbage. And people are just throwing them together in files and one never knows, if the time they did this, a .crt had a .pem format or not.
Oh, did I mention? The order in which you pack these little freaky buggers together make a difference. Sometimes.

So.
What I want to say. To every body who writes config parsers and ssl apis. PLEASE make this easier. make one option for every kind of file. Try to look up intermediate certificates your self, so we don't have to supply them. To the SSL providers: provide these intermediate certificates!

And for all the lost courier-imap - configurating people out there:
TLS_CERTFILE -> make this point to a file that includes your public and private certificate (.pem)
TLS_TRUSTCERTS -> make this point to a file that includes first the intermediate certificate, then the root certificate (if that order make a differnce - I don't know, I don't care anymore)

2012-05-28

ping tool / debugging a server from afar

hello readers,

sometimes my server is unreachable for no apparent reason. The logs don't really give a clue and my only way of reaching it again is to restart it by sending it an automatic hardware reset.
Since I have no idea whether it is locked up, just unreable *from* the network or completly disconnected from the network I wrote a little script to log pings. This way I can see in the log if it tries to ping at all and if it tries, if it can reach the network from its side or not.
Now all I have to do is to wait for it to crash. Well, I mean, to hope for the script to be a useless effort since it will never crash again ... of course ... ;)

Here's the script:


#!/bin/bash
# filename: pinglog.sh
# set logging dir here
MYDIR=/var/log/ping
# here you can choose a different format, i.e. "$1.log"
# where $1 always is the hostname given to the script
MYFILENAME="$1"
echo `date +'%Y-%m-%d %H:%M: '` `ping -c1 $1 | head -n2 | tail -n1` >>\ $MYDIR/$MYFILENAME

and here's a line for you to enter in in the crontab, if you want it to ping&log every 5minutes:

*/5 * * * * /some/directory/pinglog.sh some.server.com


I know it's not something big or difficult, but sometimes big problems need low-tech solutions. Also small scripts like these can be a good alternative to installing big software packages like nagios, if you don't really need them.

2012-05-15

Android time conversion

Good morning dear readers,

some hours ago I was shocked to noticee there was no good time (zone) conversion app on the android market. At least no good free one. I thought this was easy, but time conversion has some evil caveats, but I think I got it working fine for now. Since I'm not yet ready to invest 25$ so I can distribute an app for free I will just publish it right here. Feedback is of course welcome :)

BTW: For now the easiest way to install the little bugger is to enable installation from unkown sources and get it on the device somehow. I just moved it to dropbox, tapped it, there you go :)

Download toLocalTime.apk


2012-04-21

Mumble (mumurd) nagios plugin

Today I wrote a little nagios plugin to check the state of murmurd (popular mumble server) because the ones out there don't seem to do the job (at least I couldn't make them).
requirements:
-dbus
-murmurd running with dbus interface
-python-dbus bindings
-nagios ;)

define a new command in /etc/nagios/objects/commands.cfg (at least under gentoo that's where to do it):

# murmur (Mumble)
define command{
        command_name check_murmur
        command_line $USER1$/check_murmur.py $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$ 2>/dev/null
}


define the service in i.e. /etc/nagios/objects/localhost.cfg:

define service{
        use                 local-service
        host_name           example.org
        service_description Mumble murmurd
        check_command       check_murmur!servernum!minusers!maxusers!minchannels!maxchannels!minbans!maxbans
}


where servernum starts with 1
all minumums are disabled when <= 0
all maximums except bans are disabled when <= 0
maxbans is disabled when <= -1


now paste the script below in /usr/lib/nagios/plugins/check_murmur.py (you may have to put it in a different directory, but the filename should be the same).
Good luck and have fun :)

#!/usr/bin/python
import sys
import dbus


servernum = '1'
minusers = 0
maxusers = 0
minchannels = 0
maxchannels = 0
minbans = 0
maxbans = -1
warning = False
reportstr = ""
warningstr = ""


if(len(sys.argv) == 1 or sys.argv[1] == '-h' or sys.argv[1] == '--help'):
        print 'usage: ' + sys.argv[0] + ' <server number> <minusers> <maxusers> <minchannels> <maxchannels> <minbans> <maxbans>'
        print 'minimus: <= 0: disabled (except maxbans, only disabled for <= -1); maximums: <= 0 disabled; server numbers start with 1!'
        sys.exit()


servernum = sys.argv[1]
if(int(sys.argv[2]) > 0):
        minusers = int(sys.argv[2])
if(int(sys.argv[3]) > 0):
        maxusers = int(sys.argv[3])
if(int(sys.argv[4]) > 0):
        minchannels = int(sys.argv[4])
if(int(sys.argv[5]) > 0):
        maxchannels = int(sys.argv[5])
if(int(sys.argv[6]) > 0):
        minbans = int(sys.argv[6])
if(int(sys.argv[7]) > -1):
        maxbans = int(sys.argv[7])


bus = dbus.SystemBus()
server = bus.get_object('net.sourceforge.mumble.murmur', '/'+str(servernum))
try:
        players = server.getPlayers()
except dbus.exceptions.DBusException:
        print "Critical: No connection via dbus. If dbus is up this service is probably down."
        sys.exit(2) #Crit
channels = server.getChannels()
bans = server.getBans()




reportstr += "users: " + str(len(players)) + ", channels: " + str(len(channels)) + ", bans: " + str(len(bans))


if(minusers > 0):
        if(minusers > len(players)):
                warning = True
                warningstr += " <less than " + str(minusers) + " users>"
if(maxusers > 0):
        if(maxusers < len(players)):
                warning = True
                warningstr += " <more than " + str(maxusers) + " users>"
if(minchannels > 0):
        if(minchannels > len(channels)):
                warning = True
                warningstr += " <less than " + str(minchannels) + " channels>"
if(maxchannels > 0):
        if(maxchannels < len(channels)):
                warning = True
                warningstr += " <more than " + str(maxchannels) + " channels>"
if(minbans > 0):
        if(minbans > len(bans)):
                warning = True
                warningstr += " <less than " + str(minbans) + " bans>"
if(maxbans > -1):
        if(maxbans < len(bans)):
                warning = True
                warningstr +=" <more than " + str(maxbans) + " bans>"


if(warning):
        reportstr = "WARNING: " + reportstr + ", warnings:" + warningstr
else:
        reportstr = "OK: " + reportstr
print reportstr
if(warning):
        sys.exit(1)
else:
        sys.exit()


UPDATE: The plugin got accepted at nagios exchange.

2012-04-19

Prime numbers in Haskell

Hello again,
last night I couldn't sleep very well, so I tried a new method to calculate prime numbers(from 2 to n), this time in haskell.
I'm not exactly sure on the runtime, i guess O(n^2), maybe lower, but it's hard for me to say, because I believe it depends on the distribution of the prime numbers themselves. But I'm thankfull if anyone wants to analyze this and tell me :)


calcprimes :: Int -> [Int]
calcprimes n = primeh [2..n] []
 where primeh :: [Int] -> [Int] -> [Int]
primeh [] primes = reverse primes
primeh (x:xs) primes = primeh (primeh2 x xs [] ) (x:primes)
where primeh2 :: Int -> [Int] -> [Int] -> [Int]
primeh2 _ [] ys = reverse ys
primeh2 d (x:xs) ys = if mod x d == 0
                                      then primeh2 d xs ys
                                      else primeh2 d xs (x:ys)


UPDATE 1: Woops, it seems I accidentally reinvented (or remembered and just didn't know I saw this this before) the wheel, erm I mean the "Sieve of Eratosthenes" and also that there are shorter implementations of this, which can also handle infinite data structures and stuff - "much more to learn to I have..."


UPDATE 2: With a little lambda magic and "filter" I wrote a little shorter and even faster version of this:



calcprimes :: Int -> [Int]
calcprimes n = primeh [2..n] []
 where  primeh :: [Int] -> [Int] -> [Int]
        primeh [] primes = reverse primes
        primeh (x:xs) primes = primeh (filter (\y -> mod y x /= 0) xs) (x:primes)

2012-04-01

Mumble Server and SSL

Here we are again,

my friendly gentoo server and me, playing "wouldn't be fun without trouble" ;)
Goal:
- murmur as a Mumble server
- startcom / startssl class 1 certificate
Problem:

sslCert=/etc/ssl/startssl/server.pem
sslKey=/etc/ssl/startssl/server_key.pem
did not do the trick. Though it only throws error when you try to connect.
Then I tried different variants of cat-ing together cert and key, cert and intermediate authority, with ca itself, all of it, no luck at all.
Thanks to: http://www.mumb1e.de/de/gemeinde/forum/7-murmur/1151-ssl-zertifikat I tried the right thing:
sslCa=/etc/ssl/startssl/chain.pem
Where chain.pem just contains the ca and the intermediate cert of startcom. sslCert is only my cert and sslKey is only my key.
Hope I saved someone an hour with google ;)

2012-03-28

OpenVPN and Windows 7 network location

Suppose you want to make a vpn with OpenVPN and you want the clients to be able to access each other.
There's one common problem I encountered and I just want to share the solution again, though I found it somewhere-on-the-internets(tm).
Problem: Windows doesn't allow to set the network location to "home" or "work".
Cause: Windows doesn't "recognize" the network in some way because there's no default route to the internet.
But would we want to add one? In case we wanted to: problem solved :)
In case not, we do it anyways, but tell Windows to not use it by assigning a very high "cost" to this route.
This has to be done in the configuration in the VPN server and looks like this:


push "route-metric 50"
push "route 0.0.0.0 0.0.0.0"

Hope I could help someone :)

c++ and dynamicly allocated multidimensional arrays

Fancy title huh? Well it sound worse than it is...
suppose we got this:
int myarray[2][4];
Works great right?
But what if we don't know the size when we write the code?
int **myarray = malloc(rows*cols*sizeof(int));
That would be the approach of a C-programmer. So in C++ we got new and don't need malloc, so how about this:
int **myarray = new int[rows][cols];
Well, that doesn't work. In theory we would have to to write new int*[rows] then loop throug all the pointers we just created and assign new int[cols].
Thats a lot of work and possibly a lot of processing depending on how big our array should be.
So my suggestion is to calculate the index ourselves, something the internals of the language would have to do anyways, so we don't waste any processing time there:
int *myarray = new int[rows*cols];
and
myarray[row][col]
becomes
myarray[row*cols + col]
It's just a simple trick that saves a lot of work. And if this becomes more work that than writing the initial loop, one can always write a function for calculating the index or even write an own array class and overwrite the [] operator.

perl command interpreter

Since every fancy new programming language seems to have something called a "command interpreter" which even seems usefull I started thinking how difficult it would be to write something like this for perl.
Turns out a very simple version of this is quite easy to do in perl it'self :)
It's not as mature as its counterparts from ruby or python, but I think for the purpose it serves it's enough.

Oneliner:
perl -e "while(<>){eval;}"

As a script with return value printing:

#!/usr/bin/perl -w
my $command;
my $returnval;
print "welcome to flatline's perl shell.\nPlease do not use \$command or \$returnval as they are being used.\nperlshell> ";
while($command = <STDIN>){
         $returnval = eval $command;
         print "\nreturned: " . $returnval . "\nperlshell> ";
}

init

Welcome hopefully friendly visitor ;) this my brand new *public* blog. For now this is planned as an IT blog, if it stays that way, we will see.