RSS
 

Automatic subtitle downloads for linux

03 Mar

Since I really like to automate everything I find boring and timeconsuming, I’ve created a little ruby application.
It is called SubSearch.

You can find the source on github.

I’ve made a screencast in order to demo the application. Please read the github page for more information :-)

 
No Comments

Posted in Linux, Ruby

 

Iptables subnet nat

26 Dec

I’ve been searching how to implement subnet nat using iptables for some time now and thought it was impossible.
It seems it isn’t though:
iptables -t nat -I OUTPUT -d 192.168.1.0/24 -j NETMAP --to 192.168.2.0/24

 
No Comments

Posted in Linux

 

Incremental rsync backup script linux using ruby

07 Aug

Hi people,

I’ve created a backup script for my own purposes.
What I’d like is incremental backups. I also want some logging and I created a script therefor.
It uses hardlinks and rsync to create a full backup, but is incremental underneath.
Maybe you will find this interesting!

I’ve placed an entry in my crontab to run this daily.
You can adjust the “count” variable to change the amount of backups.
I have made an entry in my /etc/fstab for mountpoint /mnt/backup (which is not automatically mounted).

voyager ~ # grep backup /etc/fstab
/dev/sdg1 /mnt/backup   ext4    noauto  0       0

Change the “directories” array to tell the script which directories you would like to rsync.

I made it in about an hour, so the script might have some bugs, please check it carefully before letting it loose on your filesystem.
If you want to see the logging of your rsyncs, check the files in the log directory.

Output of the program:

voyager ~ # ~/bin/backup.rb
Mounting mountpoint /mnt/backup
Rsyncing directory '/data/tom/*' (25572MB) to /mnt/backup/backup/001/data/tom
Rsyncing directory '/data/linda/*' (401MB) to /mnt/backup/backup/001/data/linda
Rsyncing directory '/data/shared/Photo and Video/*' (8515MB) to /mnt/backup/backup/001/data/shared/Photo and Video
Rsyncing directory '/data/shared/Various/*' (17MB) to /mnt/backup/backup/001/data/shared/Various
Rsyncing directory '/data/shared/Music/*' (96721MB) to /mnt/backup/backup/001/data/shared/Music
Unmounting mountpoint /mnt/backup
#!/usr/bin/ruby

require 'fileutils'

mp = '/mnt/backup' # mountpoint which is defined in /etc/fstab
backupdir = "#{mp}/backup" # the directory where the backups are placed in
count = 365 # the amount of backups you would like to preserve
directories = ['/data/tom', '/data/linda', '/data/shared/Photo and Video', '/data/shared/Various', '/data/shared/Music']

def mounted? dir
	lines = `mount`.rstrip.split("\n")
	lines.each do |line|
		tokens = line.split(/\s+/)
		dev = tokens[0]
		mountpoint = tokens[2]
		return true if mountpoint == dir
	end
	return false
end

def mount args
	mountpoint = args[:mountpoint] || nil
	dev = args[:dev] || nil
	options = args[:options] || nil
	fs = args[:fs] || nil

	cmd = Array.new
	cmd << "mount"
	cmd << "-t #{fs}" unless fs.nil?
	cmd << "-o #{options}" unless options.nil?
	cmd << dev unless dev.nil?
	cmd << mountpoint unless mountpoint.nil?

	`#{cmd.join(" ")}`
end

def umount mp
	`umount #{mp}`
end

# mount if not mounted
if not mounted? mp
	puts "Mounting mountpoint #{mp}"
	mount :mountpoint => mp
else
	puts "Mountpoint #{mp} already mounted"
end
if not mounted? mp
	puts "A failure occured mounting mountpoint #{mp}"
	exit 1
end

if not File.exist? backupdir
	puts "Creating directory #{backupdir}"
	FileUtils.mkdir_p backupdir
end

1.upto(count) do |x|
	s = "%03d" % ([x])
	FileUtils.mkdir_p "#{backupdir}/#{s}" if not File.exist? "#{backupdir}/#{s}"
end

# mv stuff
previous = nil
count.downto(1) do |x|
	s = "%03d" % ([x])
	if x == count
		FileUtils.rm_rf "#{backupdir}/#{s}"
	else
		FileUtils.mv "#{backupdir}/#{s}", "#{backupdir}/#{previous}"
	end
	previous = s
end

`cp -al #{backupdir}/002 #{backupdir}/001`
FileUtils.mkdir_p "#{backupdir}/log" if not File.exist? "#{backupdir}/log"

directories.each do |d|
	size = `du -sBM '#{d}'`.rstrip.split(/\s+/).shift
	size += "B"

	b = "#{backupdir}/001#{d}"
	puts "Rsyncing directory '#{d}/*' (#{size}) to #{b}"

	FileUtils.mkdir_p b if not File.exist? b
	cmd = "rsync -aHuv --delete '#{d}/'* '#{b}'"
	output = `#{cmd}`
	output = "#{cmd}\n#{output}"
	time = Time.now.strftime('%Y%m%d_%H%M%S')
	log = "%s/%s/%s.%s.log" % ([backupdir,'log',d.gsub('/','+'),time])
	File.open(log, 'w') { |f| f.write output }
end

# umount
puts "Unmounting mountpoint #{mp}"
umount mp
if mounted? mp
	puts "A failure occured umounting mountpoint #{mp}"
	exit 1
end
 
 

TCP Treason Uncloaked

03 Aug

I found a very informative article about the issue:

http://www.informedbanking.com/wiki/TCP_Treason_Uncloaked

 
No Comments

Posted in Linux

 

Create a cacert signed certificate

01 Aug

Hi!

I always forget how to create certificates, because it seems to be so complex. What I also really dislike about the openssl command, is that I never understand how the command line options work.
Anyway, I’ve found a nice tutorial here and decided to log the steps I did here.

First create a private key:
voyager cert # openssl genrsa -out ca.key 1024
Generating RSA private key, 1024 bit long modulus
...++++++
..++++++
e is 65537 (0x10001)

Second create CSR to request certificate from external certification authority:
voyager cert # openssl req -new -key ca.key -out wildcard.vleeuwen.eu.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:NL
State or Province Name (full name) [Some-State]:Noord-Holland
Locality Name (eg, city) []:Hoorn
Organization Name (eg, company) [Internet Widgits Pty Ltd]:ToLe
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:*.vleeuwen.eu
Email Address []:postmaster@vleeuwen.eu

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

Third upload the contents of the CSR to Cacert.org (Server Certificates -> New):
Cacert signs your certificate and will provide you with the crt.

I’ve loaded the key and certificate into my nginx installation and it works perfectly.

UPDATE: You can view this site as well by: https://blog.vleeuwen.eu. It’s behind nginx :-)

 
 

Hello world!

28 Jul

Funny sample post this is! Hello world! I’ve never blogged before in my life, but decided to spent some time on this.

I think blogs are a very nice medium to inform other people about the discoveries you make. You run into a problem, try to find it out, googling and there it is, the answer is just sitting on somebodies blog, waiting to be found. I’m really greatful to all the people that take the time to share knowledge.

For that reason I started this blog. I hope it will be useful for you.