Samstag, 26. Januar 2008

External Hard Drive

get more gigs

you can not life these days with only 20 gig, so: configuring the External Hard Drive, as recommended in here

a)add in /etc/fstab

/dev/sdb1 pladde/ ntfs-3g defaults,force 0 0

b) After the installation is done, you can optionally add an external hard drive to make it easier to move your data. We'll be using a service called "autofs" to automatically detect your hard drive and make it ready to share on the network each time you plug it in. To install autofs, use this command:

sudo apt-get install autofs

Once that finishes, you'll want to connect your external hard drive and find out what device Ubuntu assigns it. After plugging in the hard drive wait a few seconds and then enter this command:

dmesg | tail

You should see something very similar to this:


[47820.164000] sdb: Write Protect is off
[47820.164000] sdb: Mode Sense: 03 00 00 00
[47820.164000] sdb: assuming drive cache: write through
[47820.164000] SCSI device sdb: 398297088 512-byte hdwr sectors (203928 MB)
[47820.168000] sdb: Write Protect is off
[47820.168000] sdb: Mode Sense: 03 00 00 00
[47820.168000] sdb: assuming drive cache: write through
[47820.168000] sdb: sdb1
[47820.184000] sd 4:0:0:0: Attached scsi disk sdb
[47820.184000] sd 4:0:0:0: Attached scsi generic sg2 type 0

The line "[47820.168000] sdb: sdb1" is what you'll want to pay attention to. This tells us that Ubuntu is assigning the device to "sdb", and it's partition is labeled as "sdb1". "1" being the first and only partition on the disk. Next, we'll what to find out what kind of partition is on the disk. Enter this into the console:

sudo fdisk -l /dev/sdb

The "System" column will display what kind of partition it is. Take note on what type of partition it is for the following instructions. If it's "HPFS/NTFS", you'll want to use the "ntfs-3g" driver. If it contains "FAT", you'll use the "vfat" driver. Finally, if it's "Linux", you can just use the "auto" driver. Note, if it is a NTFS partition, you will have to manually install the new NTFS read/write drivers by using:

sudo apt-get install ntfs-3g

Next, we'll want to add this information to the autofs service. Use to following command to edit to autofs master configuration file:

sudo nano /etc/auto.master

Note: You can replace "nano" with your preferred text editor. To save a file in nano, use the keyboard shortcut Ctrl+O. To exit, press Ctrl+X.

Now, find the line containing:

#/misc /etc/auto.misc

Change it to:

/misc /etc/auto.misc --timeout=60

Save it and edit the autofs "miscellaneous" configuration file next by entering this command:

sudo nano /etc/auto.misc

Add this to the bottom of the file:

external -fstype=ntfs-3g :/dev/sdb1

Remember to replace "ntfs-3g" with the type of driver you found earlier in this section. Note, if you are using "ntfs-3g", you might want to append ",force" , making it "-fstype=ntfs-3g,force". This makes it easier to use uncleanly unmounted drives. This maybe a little risky, but it makes it so much easier to troubleshoot.

Finally, restart the autofs service:

sudo /etc/init.d/autofs restart

Now, every time anything tries to find files in the "/misc/external" directory, Ubuntu will attempt to automatically mount that drive to be used.

accessing mybox from everywhere

Add DynDNS to your router (if your router does not support DynDNS, good luck wit the http://en.wikipedia.org/wiki/DD-WRT fimrware) so you can access your network from outside, even if your provider changes the IP.

A big brother is watching you webcam server

Zoneminder recommended, folllow the instructions here

To make your box squeak when there is an alarm event:
sudo apt-get install mpg321 alsamixer

Adjust volume: alsamixer


To trigger the alarm on the very moment of the event based on this how to

Install perl

Create perl script to monitor DB (alarm_loop.pl)

#!/usr/bin/perl -w

use strict;

use ZoneMinder;

$| = 1;

zmDbgInit( "myscript", level=>0, to_log=>0, to_syslog=>0, to_term=>1 );

my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );

my $sql = "select M.*, max(E.Id) as LastEventId from Monitors as M left join Events as E on M.Id = E.MonitorId where M.Function != 'None' group by (M.Id)";
my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );

my $res = $sth->execute() or die( "Can't execute '$sql': ".$sth->errstr() );
my @monitors;
while ( my $monitor = $sth->fetchrow_hashref() )
{
push( @monitors, $monitor );
}

$sql = "select * from Events where Id = ?";
$sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );

while( 1 )
{
foreach my $monitor ( @monitors )
{
next if ( !zmShmVerify( $monitor ) );

if ( my $last_event_id = zmHasAlarmed( $monitor, $monitor->{LastEventId} ) )
{
$monitor->{LastEventId} = $last_event_id;
# print( "Monitor ".$monitor->{Name}." has alarmed\n" );
$res = $sth->execute( $last_event_id ) or die( "Can't execute '$sql': ".$sth->errstr() );
my $
event = $sth->fetchrow_hashref();

if ( $
event->{Id} ) {
# print( "EventID= ".$
event->{Id} );

my $command = "./alarm1.sh"
# ." --monitor=" .$monitor->{Id}
." --
event=" .$event->{Id}
." --starttime=\"" .$
event->{StartTime} ."\"";
my $output = qx( $command );
my $status = $? >> 8;

# print ("Output(" .$status ."):" .$output);


# Print output if required
# Check status if required
#
# Do your stuff here
#
}
}
}
sleep( 1 );
}

Create bash script with link to alrm file (alarm1.sh)

#!/bin/bash

echo "1=$1 2=$2 3=$3 4=$4"

mpg123 /home/boxuser/www/wav/alarm.mp3

Run perl script:

sudo ./alarm_loop.pl\

Activate 640×480 streaming

You should be able to use a similar procedure with other distributions to modify the shared memory pool without kernel recompilations though in some cases this may be necessary. Note, this error also sometimes occurs if you have an old shared memory segment lying around from a previous run that is too small. Use the ipcs and ipcrm system commands to check and remove it if necessary.'"

You can often find out how much shared memory is available by typing the following :-

cat /proc/sys/kernel/shmall

and the most you can allocate in one go :-

cat /proc/sys/kernel/shmmax

To change these values type (for example) :-

echo 134217728 >/proc/sys/kernel/shmall
echo 134217728 >/proc/sys/kernel/shmmax

Be sure to restart ZoneMinder after this.However be aware that sometimes you will only need to change the shmmax value as shmall is often large enough. Also changing these values in this way is only effective until your machine is rebooted.

To change them permanently you will need to edit /etc/sysctl.conf and add the following lines (for example) :-

kernel.shmall = 134217728
kernel.shmmax = 134217728

To load these settings in the sysctl.conf file type:

sysctl -p

To check your shared memory settings type:

ipcs -l

These changes will now also be set the next time your machine is restarted.


To send an email on event

- install the exim4 according to https://help.ubuntu.com/community/Exim4

- my /etc/exim4/update-exim4.conf.conf looks like this (using the normal smtp server of my provider)

dc_eximconfig_configtype='smarthost'
dc_other_hostnames='nerd.alert'
dc_local_interfaces='127.0.0.1'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='true'
dc_relay_nets=''
dc_smarthost='mail.bluewin.ch::25'
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='false'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'
restart the system.

sudo update-exim4.conf
sudo /etc/init.d/exim4 restart

test if you can mail:

echo test | mail -s test_mail yourmail@yourprovider.com


To send an email on event with video included

chnage in the options sections of ZM

ZM_OPT_MPEG to ffmpeg

ZM_PATH_FFMPEG to /usr/bin/ffmpeg

add the %EV% in the e-mail text: will attach the movie as mail

Check in zmvideo.pl and change ">& ffmpeg.log" to "&> /tmp/ffmpeg.log"



To do:

  • place a script in the /etc/init.d folder (may differ in your distribution) to start it on boot up


Surf anonymously / blocked sites at work (with SQUID)

first on your box at home:

sudo apt-get install squid









- in /etc/squid/squid.conf change the line

# And finally deny all other access to this proxy
#http_access deny all
http_access allow all


In putty (get it here) on your work PC do

In Firefox (IE is similar) on your work machine











Enjoy all the blocked sites...

same same here: http://rdiggle.blogspot.com/2007/12/facebook-blocked-at-work.html



rtorrent+TOR+Windows= bittorrent fun on the easy and save way

After you done all the steps metioned ealrier

Reboot the system (sudo reboot)

Now everything should run already, all what ou have to enjoy the downloaded torrents:

a) mount on your windows the BOX over samba

Do it this way in windows explorer

Tools -> map Network drive and assign a drive letter to the samba share (quite handy)

Browse into the boxuser folder

Then

b) drop the the torrent trackr files (*.torrent) into the folder called torrents

c) as soon as the torrent is finished it apears in the finished folder

you can the copy and delete from your windooze machine whatever you want

- To see the performance of your torrent download, log with putty or similar into the box and call

screen –r

to exit without destroing the downloads do: Ctrl A D

in the .rtorrent.rc you can change

  • the bandwith used on a daily schedule
  • if the torrents can not connect to the tracker: uncomment the last line




TOR

For anonymous bittorent tracking (https://www.torproject.org/)

sudo apt-get install tor

sudo apt-get install privoxy

Once you've installed Privoxy you will need to configure Privoxy to use Tor. Open Privoxy's "config" file look in /etc/privoxy/ and add the line

forward-socks4a / 127.0.0.1:9050 .

to the top of the config file. Don't forget to add the dot at the end.


Privoxy keeps a log file of everything passed through it. In order to stop this you will need to comment out three lines by inserting a # before the line. The three lines are:

logfile logfile

and the line

jarfile jarfile

and (on some systems) the line

debug 1 # show each GET/POST/CONNECT request

turn off enable-remote-toggle, enable-remote-http-toggle, and enable-edit-actions.

Copy the conf file to your homedir

You'll need to restart Privoxy for the changes to take effect.

sudo /etc/init.d/privoxy restart

Having difficulties installing:

http://www.torproject.org/docs/tor-doc-unix.html

Torrent client

Install rtorrent (really really great app)

sudo apt-get install rtorrent

place this configuration file

# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
#max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
max_uploads = 1

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 5

# downlad rate higher at night
schedule = throttle_1,01:00:00,23:00:00,download_rate=0
schedule = throttle_2,08:00:00,23:00:00,download_rate=40


# Default directory to save the downloaded torrents.
directory = /home/mybox/torrents/

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
#session = ./session
session = /home/mybox/session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory,5,5,load_start=/home/mybox/torrents/*.torrent
schedule = untied_directory,5,5,stop_untied=/home/mybox/stopped/


# When the torrent finishes, it executes "mv -n ~/Download/"
# and then sets the destination directory to "~/Download/". (0.7.7+)
#on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,~/Download/ ;d.set_directory=~/Download/"

on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,/home/
mybox/finished/ ;d.set_directory=/home/mybox/finished/"

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=10M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
# schedule = ratio,60,60,stop_on_ratio=200,200M,2000
schedule = ratio,60,60,"stop_on_ratio=2,2M,20"


# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no
#bind = 127.0.0.1


# Port range to use for listening.
#port_range = 6890-6999
port_range = 62000-64000

# Start opening ports at a random position within the port range.
#port_random = no
port_random = yes


# Check hash for hed torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no

# Set whetever the client should try to connect to UDP trackers.
use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10

# Max number of files to keep open simultaniously.
#max_open_files = 128

# Number of sockets to simultaneously keep open.
#max_open_sockets =


# Example of scheduling commands: Switch between two ip's every 5
# seconds.
#schedule = "ip_tick1,5,10,ip=torretta"
#schedule = "ip_tick2,10,10,ip=lampedusa"

# Remove a scheduled event.
#schedule_remove = "ip_tick1"

#TOR & Privoxy proxy
http_proxy = http://127.0.0.1:8118/

in /home/boxuser, rename it to: .rtorrent.rc

to activate rtorrent on startup

copy this filecontent

#! /bin/bash
#############
######
#############
# This script depends on screen.
# For the stop function to work, you must set an
# explicit session directory using absolute paths in your rtorrent.rc.
# If you typically just start rtorrent with just "rtorrent" on the
# command line, all you need to change is the "user" option.
# Attach to the screen session as your user with
# "screen -dr rtorrent". Change "rtorrent" with srnname option.
##############
###
###
##############


#######################
##Start Configuration##
#######################
# You can specify your configuration in a different file
# (so that it is saved with upgrades, saved in your home directory,
# or whateve reason you want to)
# by commenting out/deleting the configuration lines and placing them
# in a text file (say /home/user/.rtorrent.init.conf) exactly as you would
# have written them here (you can leave the comments if you desire
# and then uncommenting the following line correcting the path/filename
# for the one you used. note the space after the ".".
# . /etc/rtorrent.init.conf


#Do not put a space on either side of the equal signs e.g.
# user = user
# will not work
# system user to run as (can only use one)
user=mybox

# the full path to the filename where you store your rtorrent configuration
# must keep parentheses around the entire statement, quotations around each config file
config=("/home/${user}/.rtorrent.rc")
# Examples:
# config=("/home/user/.rtorrent.rc")
# config=("/home/user/.rtorrent.rc" "/mnt/some/drive/.rtorrent2.rc")
# config=("/home/user/.rtorrent.rc"
# "/mnt/some/drive/.rtorrent2.rc"
# "/mnt/another/drive/.rtorrent3.rc")

# set of options to run with each instance, separated by a new line
# must keep parentheses around the entire statement
#if no special options, specify with: ""
options=("")
# Examples:
# starts one instance, sourcing both .rtorrent.rc and .rtorrent2.rc
# options=("-o import=~/.rtorrent2.rc")
# starts two instances, ignoring .rtorrent.rc for both, and using
# .rtorrent2.rc for the first, and .rtorrent3.rc for the second
# we do not check for valid options
# options=("-n -o import=~/.rtorrent2.rc" "-n -o import=~/rtorrent3.rc")

# default directory for screen, needs to be an absolute path
base="/home/${user}"

# name of screen session
srnname="rtorrent"
#######################
###END CONFIGURATION###
#######################
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="rtorrent"
NAME=rtorrent
DAEMON=/usr/bin/$NAME
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

checkcnfg() {
for (( i=0 ; i < ${#config[@]} ; i++ )) ; do if ! [ -r "${config[i]}" ] ; then echo "cannot find readable config ${config[i]}. check that it is there and permissions are appropriate">&2
exit 3
fi
session=$(cat "${config[i]}" | grep "^[[:space:]]*session" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//")
if ! [ -d "${session}" ] ; then
echo "cannot find readable session directory ${session} from config ${config[i]}. check permissions">&2
exit 3
fi
done
}

d_start() {
[ -d "${base}" ] && cd "${base}"
stty stop undef && stty start undef
su -c "screen -ls | grep "\.${srnname}[[:space:]]" > /dev/null" ${user} || su -c "screen -dm -S ${srnname}" ${user}
for (( i=0 ; i < ${#options[@]} ; i++ )) ; do sleep 3 su -c "screen -S "${srnname}" -X screen rtorrent ${options[i]}" ${user} done } d_stop() { for (( i=0 ; i < ${#config[@]} ; i++ )) ; do session=$(cat "${config[i]}" | grep "^[[:space:]]*session" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//") pid=$(cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g") # make sure the pid doesn't belong to another process # skip the pid otherwise if ps -A | grep ${pid}.*rtorrent > /dev/null ; then
kill -s INT ${pid}
fi
done
}

checkcnfg

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0

from wherever to

sudo cp rtorrentInit.sh /etc/init.d/rtorrent


make sure that

ls -l /etc/init.d/rtorrent

returns

-rwxr-xr-x 1 root root 3000 2007-03-06 22:40 /etc/init.d/rtorrent

next do

sudo update-rc.d rtorrent defaults

then restart the beauty

sudo /etc/init.d/rtorrent start

Create directories

In /home/boxuser create


mkdir torrents, stopped, finished,session
(After the webserver has been installed
sudo mkdir /var/www/cam )
To make sure that the files can be edited in the future and optimize the mysql DB (Zoneminder)
Do
Sudo crontab -e
And edit the cronfile
 10 * * * * chmod -R 777 /home/boxuser
 10 * * * * chmod -R 777 /var/www
 * 23 * * * mysqlcheck  -Aao --auto-repair




Install SAMBA

Allows you later access the folders easy from Windooze

sudo apt-get install samba smbfs

sudo smbpasswd -a boxuser

#Password: password

copy the file with following content

[global] workgroup = mybox guest account = nobody security = share keep alive = 30 [maybox] comment = mybox browseable = yes path=/home/mybox writeable = yes public = yes create mode = 0777 directory mask = 0775 force directory mode = 0775 force directory security mode = 0775 inherit permissions = yes allow hosts = 192.168.1.
to

sudo cp smb.conf_final /etc/samba/smb.conf

Router Port Forwarding

Configure your router somewhat like this (see your router manual for details)

For single port forwarding
  • HTTP 80 to 80 to 192.168.1.121
  • SSH 22 to 22 to 192.168.1.121
  • TOR 443 to 443 to 192.168.1.121

Port range forwarding

  • BITTORENT 62000 to 64000 to 192.168.1.121

Static IP for the box

Makes life way more easier

Edit /etc/network/interfaces (NOTE THIS IS FOR the ethernet config)

I suggest to use 192.168.1.121 for the box

# This file describes the network interfaces available on your system

# and how to activate them. For more information, see interfaces(5).

# The loopback network interface

auto lo

iface lo inet loopback

# The primary network interface

auto eth0

iface eth0 inet static

address 192.168.1.121

netmask 255.255.255.0

broadcast 192.168.1.255

gateway 192.168.1.1

Restart the networ

/etc/init.d/networking restart

Install SSH

Install SSH to later connect to you server via terminal

sudo apt-get install openssh-server

sudo apt-get install screen

Install Base System

Get xubuntu 7.10 alternate install
http://se.archive.ubuntu.com/mirror/cdimage.ubuntu.com/xubuntu/releases/7.10/release/xubuntu-7.10-alternate-i386.iso

  • Burn ISO CD
  • Boot from the Ubuntu CD
  • Choose „Command line System“ or similar
  • Complete installation
  • Create a user daevu (or replace in the follwing files the path /home/daevu and user daevu by your choice)
  • Make sure you have internet connection (ping)


How to setup a low cost linux box

Inspired by http://rdiggle.blogspot.com/ (aka dirk diggler) I just put my configuration instructions for non IT people (linux newbies) to this blog, rather than to store it and forget it somewhere in the dungeons of my harddrive.
Idea is to use an old PC /laptop as a headless linux box under the couch to serve you with usefull nerdy and geeky stuff in daily life. In my case this is a Thinkpad T22, 256Megs of RAM and a 20 Gig harddrive....

So let's start: