vrijdag 27 september 2013

A soft reset button for a raspberri pi

scenario

i have a raspberry pi that i want to be able to reboot cleanly without ssh-ing into it


sollution

we're going to use a GPIO pin with a button wired up like this

picture from adafruit's website
3.3 volt is pin 1 (the pin nearest to the port where you plug in the power addaptorGND  is pin 6 (2 down and one over from pin 1)
and i'll be using gpi 23 .. that's pin 16 (nr 8 on the same line as pin 6)

My buton is actually a different setup from the on in this picture (mine breaks contacet when pressed



next we make a script
$ sudo nano /etc/softresetbutton.py




#!/usr/bin/env python
from time import sleep
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
while True:
        if ( GPIO.input(23)== True ):
             # tue or false here depends on your button type
             # when in doubt replace 'reboot &' in the following line with 'echo "pushed" &'
                os.system('reboot &')
        sleep(0.1);



next we make this script executable
$sudo chmod +x /etc/softresetbutton.py

and test-run it
$sudo /etc/softresetbutton.py

push the button to test it
works ok ??
now we need to make it run at startup

$sudo nano /etc/rc.local

and add the line
/etc/softresetbutton.py &
just above the " exit 0 "


reboot and you'll have a soft-rest button

if you would prefer a "clean halt" button .. replace the reboot command in the script with  halt

woensdag 25 september 2013

Stupid but sometimes usefull IP-tables trick

OK so you want to secure your off-site server using IP tables .. this is always a good thing to do


on of the things that i highly recommend is to restrict the incomming IP's to  whatever port you are using for management so that you can only access it from your networks

but if you start messing with the iptables for port 22 (for example) and you make a tiny tiny slip-up you might lose connection yourself. if the machine is sitting next to you (under your desk or in your on-site server-rack, yu can walk over hook up a screen and keyboard and fix it .... but if it's in a datacenter somewhere... yu've got a problem. (with a physical machine all you can do is get an engineer to help you out (expensive) or hard reboot the machine (not nice))

the trick is .. let's say we're starting at 2 in the afternoon, and we think we might have 15 minutes of work.
so we'll shedule a restore f the current situation in 20 minutes
as root (obviously) do

$iptables-save > /home/user/iptables.conf
$at 14:20
at>iptables-restore < /home/user/iptables.conf
   ctrl-D to save the job and quit

now check your job is scheduled
$atq
1       Wed Sep 25 14:20:00 2013 a root


start messing with your iptables
if something goes wrong .. wait for the scheduled restore

if nothing goes wrong (congrats)
you can remve the job with
$atrm 1

woensdag 10 april 2013

Raspberry PI Checkin devices

the brief

We have a project at work called the "uitpas" it's sort of a point card for cultural events. (more info about the uitpas can be found at http://www.uitpas.be/ ) when you have a certain ammount of points, you can exchange it for ceratin prizes (movie tickets, hiking maps ... )

There are a lot of events however where people either buy their tickets before hand or where no tickets are needed. So  there was a need for a check-in device that could opperate without a person manning it. 

The Uitpas cards are rfi cards (DESfire mifare to be exact) 

the sollution  

hardware 

ingredients 
  * Raspberry pi (orignally i used the 256mb kind, currently we are using the the 512mb) 
  ** 4 gig SD card 
  ** case for the raspberry pi  (i chose this one because it still allows me access if one side is glued to the backplate of our setup)
  * powerd usb hub 
  * a small screen that we got from adafruit http://www.adafruit.com/products/946 
   * short mini usb cables
Optional
  * sme small wifi adaptors (i got an edimax one from amazon , but i guess any would do .. check the raspberry pi wifi compatibility page for details)

testing setup

you can see everything (exept the screen) hooked to the left here. In this example it was hooked up via HDMI to a PC screen because that was easier to debug on (A 4 inch screen makes the console hard to read)

The raspberry pi is hooked up to the USB hub twice, once as it's host, and once in order to be fed some yummy yummy electricity
the reason for hooking up like this is that the raspberry pi does not supply enough amps on it's usb ports to power the RFID reader.




the card reader required these packages to be added

libccid : PC/SC driver for USB CCID smart card readers
libpcsclite1:armhf : Middleware to access a smart card using PC/SC (library)
pcscd : Middleware to access a smart card using PC/SC (daemon side)


we have a software partner ( lodgon ) that writes all the clients and they supplied us with a java application that reads the card does the oauth handshake with the server and writes directly to the frame buffer.

in order to run that software the PI user has to lgin automatically at boot-time

to do this you have to edit  /etc/inittab  end replace the line
1:2345:respawn:/sbin/getty --noclear 38400 tty1
with
1:2345:respawn:/bin/login -f pi tty1
/dev/tty1 2>&1

Autorunning the java application is done by adding the command that starts it to the end of the /home/pi/.bashrc file.


Accessing them remotely

They willl be dropped at locatios where they will not have a public IP adress. but i still need to be able to access them remotely. mainly for trouble-shoting, but also for monitoring them and seeing that they do OK.
i could set up VPN tunnels but that's a hasslte to maintain on my end and can cause "issues". So i requested a bunch of IPv6 tunnels from the nice people at Sixxs.
Because the raspberry pi does not have a battery for it's onboard clock the tunnels did not start reliably at bootup
so i have a script that runs at bootup that checks wether or not the tunnel is up. (by calling ifconfig and checking if the sixxs interface is present) .. if it is not i runt "ntpd -qg" and restart the tunnel. it's a little dirty, but it works.

The casing 

We have a previous version that's running an arduino ... the new Raspberry pi version should be recognizable and be able to use the "pedestals" of the arduino version, but obviously it should be bigger (more stuff inside, bigger screen ). and it should also solve a few "usability problems". 
I feel compelled to write here that the "industrial design" on the arduino version was done by an external partner .. all i did was the electronics. and they placed the rfid antenna behind 1 cm of plexy and a working 16*2 lcd screen .. so it does not read to well , and to add to the troubles your card blocks the screen if you present it to the reader. 

siblings
the small one on the right is the old version 
the one on the right is the new version. 



metal piece of the casing
so we made some basic design (in cardboard) had some meetings and found someone to build us a piece of metal as a frame. we also found someone to print and cut the frontplate as well as bend and cut a piece of plastic to cover the back.




screen and rfid reader inside


using some double-sided 3M tape to paste it all together. ANd adding some short USB cables where possible to keep it from becomming a big cable-knot.
All the electronics inside

So We've had about 10 of them in the field now and they seem to be performing well.
one Check-in device in the public library in Lede





donderdag 28 februari 2013

watching a logfile and doing stuff

I needed to watcha logfile and trigger an action if a specific line appeared in the logs


    #!/bin/sh
    #tail the file you want to watch
    tail -fn0 /var/log/logfile | while read line ; do
            echo "$line" | grep 'line to react to' | grep -v 'things to block the reaction' 
            if [ $? = 0 ]
            then
                    # do things
                    echo "just saw $line"
                    mpg123 triomph.mp3
            fi
    done


save this as script.sh
make it exectuable (chmod +x script.sh) 
and let it run in the background ./script.sh & 




maandag 7 mei 2012

Moving mysql data folder


check your mysql setup , and maybe take a backup

stop mysql
$/etc/init.d/mysql stop

move the data folder

$mv /var/lib/mysql /var/db/

create a symlink so everything can find teh new data folder

$ln -s /var/db/msql /var/lib/mysql


edit the apparmor file

$nano /etc/apparmor.d/usr.sbin.mysqld

find the  2 entries that point to /var/lib/mysql and change the appropriately (in my case /var/db/mysql)

restart apparmor
$/etc/init.d/apparmor restart 

start mysql
/etc/init.d/mysql start 


check if everything is ok 













maandag 5 maart 2012

Mobistar USB modem on debian

Hi


I got a hold of a Mobistar USB modem for mobile internet
thought it would make a great addition to my Thikpad x200S running Debian unstable
installing it was easy, but i thought i'd document the steps anyway since i also haven't written anything here for a while .

plugging it in an doing ls-usb
it identifies as a huawei e173
Bus 001 Device 022: ID 12d1:1c0b Huawei Technologies Co., Ltd. E173 (modem off)

this is the built in storage device

i googled a bit and found instructions here
http://sussexcomputerworks.co.uk/Linux/kubuntu-1004-and-the-t-mobile-broadband-615-usb-device.html


long story short
install usb-modeswitch and wvdial
$apt-get install usb-modeswitch wvdial

make a config file
nano /etc/usb_modeswitch.d/12d1:1c0b


and add the following to it

########################################################
# Huawei E173s

DefaultVendor= 0x12d1
DefaultProduct= 0x1c0b

TargetVendor= 0x12d1
TargetProduct= 0x1c05

CheckSuccess=20

MessageEndpoint= 0x0f
MessageContent= "55534243123456780000000000000011062000000100000000000000000000"





then do the necessary modprobes

$ usb-modeswitch -c /etc/usb_modeswitch.d/12d1:1c0b
$ modprobe usbserial vendor 0x2d1 product 0x1c05


i also had to unplug the usb device and plug it back in


now if i do

$wvdialconf

wvdial finds my modem and creates a /etc/wvdial.conf file
edit this file to add your login and password for the sim card

i don't have an extra active sim here at the moment ... will p update this post when i've tested with that too

Greetz

WOuter

vrijdag 29 juli 2011

restoring couchdb database from backup .couch file

hi

at my work we're using couchdb running on ubuntu server 10.04 to log some stuff
the db was growing near the disk space, and the person responsible was absent (due to the holiday season).
so i shut down couchdb.. moved the .couch file to a diferent location and recreated the database as an empty db so the logging of data would continue.

when the person returned from holiday they needed the data, so they first took what they needed from the new db file.
After this they asked to restore the big DB file.



make sure in the new instance of couch the appropriate database has been created

shut down couchdb (/etc/init.d/couchdb stop )

restore the file to it's original location (if there is data in the new file you might want to make a backup of that first)
make sure the .couch file has the correct owner & group .. (in my case both couchdb, look at the new file to know for sure)
restart couchdb (/etc/init.d/couchdb start)


should be all done


Greetz

Wouter

vrijdag 24 juni 2011

restoring the firmware to a nslu2 from a linux PC

ok i bought a new nslu2 from ebay, and it had either a corrupt firmware, or i corrupted it trying to reset it to factory default (cause i could not figure out what ip adress it was set to, all i know is, it was not in the common ranges, and was not using dhcp)
sollution.... reflash the firmware
problem: all step by step in one document i could find online assume either windows OR Mac... i wanted to use my desktop (a debian machine) so i wrote it up.


preparation
1. get the original firmware from linksys, or an alternative firmware from where-ever. (with "might be broken" hardware i always prefer to first flash the original firmware, just to check)

2. install upslug2
apt-get install upslug2
3. set your fixed ip to something in the 192.168.0.0/24 range, but NOT 192.168.0.1 (make sure that that's free)


redboot the machine

when the nslu2 boots, for a few seconds you can telnet into it on port 9000
so boot the nslu2, and start executing the following command on your pc
telnet 192.168.0.1 9000

once you'r in you have maybe 2 seconds to press ctrl-c and interrupt the normal boot .. so be prepared

once in redboot, erase the existing bootloader ...
redboot> fis erase -f 0x50040000 -l 0x20000
and put the nslu2 in upgrade mode
redboot> upgrade
you'll see the satus led start flashing orange-green-orange-green



upslug2
run upslug2 without any switch to find your nslu2 you'll get back some info one of witch is the mac-adress (note: upslug has to be rone as root)

next use upslug2 to flash the firmware

upslug2 --target="00:00:00:00" --image="someimage.bin"

go have a coffee or thee or chocolate milk, or whatever .. it'll take 5-10 min

maandag 20 juni 2011

Opening pages documents on Debian

Hi

co-worker mailed himself a pages document from his mac .. wich he could (of course) not open on his MS Office at work
I found out that the pages document is actually a Zip format.. so
unzip document.pages

(this should also work with winzip or winrar http://www.win-rar.com/ )

it unpacked a number of files one of witch was a "preview.pdf"
note that anny images seem to be saved as seperate PDF's

if you need to edit the text you can copy paste it to your favorite editor from here ..

woensdag 1 juni 2011

encoding video for ipad with ffmpeg

Hi


I have an ipad at work , but encoding video for it using gaphicla tools is a hassle, and often turns out bad. and itunes (on my mac mini) doesn't reencode the videos... so i made a script

now my debian box can do it
(you need to install libfaac .. on my debian box i folowed the instructions here
for ubuntu users .. i know option C from this post works)

the ffmpeg command i use is
ffmpeg -i input.avi -f mp4 -vcodec libxvid -maxrate 1000 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec libfaac -mbd 2 -s 640x480 -ab 128 -b 400 output.mp4


still meaning everthing has to be done one by one .. still cumbersome
so i made a quick and dirty looping script

so the script becomes

#!/bin/bash

#create a folder for the encodes
mkdir $1/encodedforipad/

#encode away
for i in $(ls $1);
do

ffmpeg -i $dir/$i -f mp4 -vcodec libxvid -maxrate 1000 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec libfaac -mbd 2 -s 640x480 -ab 128 -b 400 $1/encodedforipad/$i.mp4
done

make it executable and call it with the first argument being the folder where you host your video files. (attention: the script is not recursive and does not handle spaces in names well).

woensdag 30 maart 2011

checking remote server with nrpe

assuming you know the comamnd you want to use on the remote server.
Usually something like:
//usr/lib/nagios/plugins/check_log-F logfile -O oldlog -q query


on the machine you want to monitor :
edit the /etc/nagios/nrpe.cfg file to include the command you want to execute (there should be a number of examples)

in my example:
command[check_login]=/usr/lib/nagios/plugins/check_log -F /var/log/messages -O /home/nagiosuser/logs/check_log.badlogins.old -q "LOGIN FAILURE"


restart the nrpe daemon:
/etc/init.d/nagios-nrpe-server restart




on the nagios server:
edit your commands.cg file to include the nrpe command

for example
define command{
command_name check_login
command_line /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c check_login

}

edit the config file for the remote host you're monitoring to add this command

in my example:
define service{
use generic-service
host_name remotehost
service_description Failed login check
check_command check_login
}

zondag 30 januari 2011

encoding video for my adroid phone (betouch e130)

hi

i've bought a acer betouch e130 a few days ago and all is well so far
have been looking how to encode video for it thou (using ubuntu)
the ffmpeg line is below ..

greetz

WOuter


ffmpeg -y -i input.avi -vcodec h263 -s 176x144 -r 15 -b 700k -acodec libfaac -ac 2 -ar 32000 -ab 64k -f 3gp output.mp4

dinsdag 6 oktober 2009

Command line fu

Hi
these are a list with more complex commands i regularly use with a description of what it does

execute the last command but with sudo priveliges
sudo !!



download the entire site www.example.com as it is presented to an anonymous user using a mozilla browser

wget --random-wait -r -p -e robots=off -U mozilla http://www.example.com





get stats on the network-speed to a host


mtr hostname





twitter from command line (very usefull to keep track of machines)
this twitters the output of the command "uptime"

curl -u mytwitterusername:mypassword -d status="my uptime:`uptime`" http://twitter.com/statuses/update.json


more info here: http://mark.koli.ch/2009/05/howto-tweet-from-the-command-line-with-curl.html

enable passwordless ssh the easy way

ssh-copy-id user@remote-machine



make shift alarm clock

sleep 8h; cat /dev/urandom > /dev/dsp

maandag 5 oktober 2009

Securing a drupal development enviroment

Sometimes After a sync with production our testing site needs to be re-secured (since it's testing we don't want people using it)



install the securesite module

http://drupal.org/project/securesite
obviously you don't need to do this every time if you also install the module on your production enviroment, but switch it off overthere.



Activate the module
on http://yourURL/admin/build/modules

Change the Settings
: http://yourURL/admin/settings/securesite (Force authenticatoin ‘Always’)

That should do it

Props to my good friend Sven

vrijdag 2 oktober 2009

ssh-fu

Ok this is basicly a post were i keep track of some much used ssh commands,
there will probably be things added to this post as time goes by.

use x2x to share keyboard and mouse between 2 computers


Both PC's have to be running X and be logged in
from a shell within X on the PC that has the keyboard and mouse do
 ssh -XC remoteuser@remoteip  x2x -east -to :0.0 




Use SSH tunnel to secure your webtraffic


on the local machine configure firefox to use localhost & port 7070 as a proxy
then log into a shell and execute
ssh -D 7070 username@remote-host




connect over SSH to a computer behind a NAT firewall using a reverse SSH tunnel


on the remote machine (the one behind the firewall) do
ssh -R 19999:localhost:22 sourceuser@138.47.99.99 


Where 19999 can be anny random unused port
138.47.99.99 is the IP of the machine from where you want to access the "remote machine"

now on your server (theone at 138.47.99.99) do

 ssh localhost -p 19999 

and you should log into the machine behind the nat

dinsdag 15 september 2009

automating a drupal backup

automating a drupal backup



hi

I use following script to run a daily backup of several drupal sites




DOW = 'date +%a'
SITE = /var/www
BACKUPLOC = /home/backups/
MYSQLPASS = *******
DBNAME = drupaldb



rm $BACKUPLOC/$DOW.*
tar cf $BACKUPLOC/$DOM.tar $SITE
cd $BACKUPLOC
mysqldump -u root -p $MYSQLPASS $DBNAME > $DOW.dump

woensdag 9 september 2009

ftp backup script

Hi

i've created a ftp backup script a while ago, thought i should start posting stuff here again... seems like a good thingto start with


this scrip will take all the files from the remote site and dump them in a local dir (/home/wouter/temp in this case)


you'll need to remove the space between << and EOF in the first actual line of the script (code tags are not working to well on blogger apperantly)


#!/bin/bash

remote=ftp-site-to-backup
username=your-username
passwd=Password
localdir=/home/wouter/temp
remotedir=/home/wouter/

ftp -ipn << EOF
open $remote
user $username $passwd
lcd $localdir
cd $remotedir
binary
mget gale*
bye
EOF


please take into account that this means the data goes over clear-text and is visible to annyone on the network.



thank you joren from http://www.0110.be for the assistence

dinsdag 13 januari 2009

Fixing Timedrift In debian VM-Ware Virtual machines

Hi All


I had debian server who had 30 sec+ timedrift per minute
As a consequence certain cron jobs where passed over. (cron job scheduled at 17:00 and server jumps from instance from 16:59:47 to 17:00:29, missing the 17:00 slot)

Fixing it ended up being not that hard to actually do. figuring out how to was. Note that You do need a recent kernel that supports clocksource in order to do this.

First off set the ntp for both the host and the vm to the same source by editing the /etp/ntp.conf file



Stop the Virtual Machine
on the host machine search for your VM's .vmx file. Open it in an editor (i use nano)

search for the tools.SyncTime string, it should be set to FALSE, change it to TRUE

Next start up the Virtual Machine again and look for the file /boot/grub/menu.lst

and edit the line for the kernel you boot into
kernel /boot/vmlinuz-2.6.18-5-686 root=/dev/sda1 ro clocksource=pit nosmp noapic nolapic nohz=off


reboot the machine and the time offset should be greatly reduced (a couple of microseconds for me)

woensdag 15 oktober 2008

INstalling coldfusion 701 on Debian using Apach2

I Recently had to do this, it was not easy, but in the end i leaned heavily on the manual found at http://www.compoundtheory.com/?ID=233&action=displayPost


Install debian

login and become root
Install apache2 unzip and the Build essentials package

apt-get install apache2 build-essentials unzip

Create a user for the coldfusion enviroment
adduser coldfusion

Change the ownership of the /var/www to the coldfusion user
chown coldfusion /var/www


Get you coldfusion.bin file overto the machine (i used SCP but you can use wget or whatever)
there is a compatibilty issue but you can solve it like this :
Rename the coldfusion-7.0*-lin.bin to coldfusion-70*-lin.bak
and execute the following command

cat coldfusion-702-lin.bak | sed "s/export LD_ASSUME_KERNEL/#xport LD

Run the newly made installer (be sure to do this as root)
./coldfusion-70*-lin.bin
1. Choose Server Configuration
2. Add web server Configuration
1. Apache
1. What directory contains your Apache configuration file:
/etc/apache2
2. Where is the Apache program binary file?:
/usr/sbin/apache2
3. Where is the control file that you use to start and stop the Apache web server?:
/etc/init.d/apache2
3. Choose ColdFusion MX Administrator Location:
/var/www
4. Enter the name of the runtime user:
Enter the name of the user that you created and set to own /var/www



Then we need to install and download the hotfix
You can download it here but the instructions are not entirely correct
You need to indeed unzip the file in /opt/coldfusion7.0*/runtime/lib but the command is not suited for a debian enviroment.
It should be

java -Dtrace.ci=1 -jar wsconfig.jar -server coldfusion -ws apache -dir /etc/apache2 -bin /usr/sbin/apache2 -script /usr/sbin/apache2ctl -coldfusion -v



edit /opt/coldfusionmx7/bin/connectors/apache_connector.sh and change the wsconfig
nano /opt/coldfusionmx7/bin/connectors/apache_connector.sh
to:
../../runtime/bin/wsconfig \
-server coldfusion \
-ws apache \
-dir /etc/apache2 \
-bin /usr/sbin/apache2 \
-script /etc/init.d/apache2 \
-coldfusion

exit $#

now you'll need to start coldfusion

/opt/coldfusion/bin/coldfusion start


There will be an error about the connector - do not worry about it we can fix it by running the appache connector

cd /opt/coldfusionmx7/bin/connectors/
sudo ./apache_connector.sh

Browser to: http://your-machine/cfide/administrator/index.cfm



There you go, done and over with

vrijdag 3 oktober 2008

Help My xp box is running slow

We've all had users with the problem in the titel
what can be done
well there are a couple of things that can be done

Check out any obvious problems with the machine

first off have a look in the system tray and the process list to see if anny programs are taking a lot of the system's recources. (the process list can be acessed thru ctrl alt del)
second go thru the installed software and remove anything that the user does not need (notice the distinction between "need" and "use", be careful with this. Some software that the user does use might depend on software that he or she does not use)


Also check how much hard drive space is available. Xp should have at least 500 mb drive space free in order to function optimally

run and install spyware scanners

personally i like the combo of adaware and spybot search & destroy, but to eatch his (or her) own. the reason i like these are a. i've been using them for a long while.
they work really well and complement each other. And to add to tat, both are free.
http://www.adaware.be/
spybot search & detroy


install and run ccleaner.

ccleaner cleans out the temp files and other crap your computer gathers over the years. it's a great tool for doing a quick cleanup

http://www.ccleaner.com



Clean out the registry errors


CCleaner also has an option to scan for & fix registry errors (on the left, the icon of the brick beeing assembled from smaller bricks .
hav it scan for errors. after the scan is complete there will be a button to fix the errors that are selected. (normally all errors are automaicly selected) press that button.




scan for virussen


With whatever your favourite virusscanner is
I like the widows version of ClamAV http://w32.clamav.net/
and the free version of avg http://free.avg.com/
to scan pc's where there is a virus scanner or you can't install a virus scanner you can use Housecall http://housecall.trendmicro.com/emea/ (an online virus scanner)



defragment the disk

As you move files around on your disk the files end up beeing fragmented on the disk. this can have dramatic impact on the performance on the pc
to correct this open "my computer" right clicking the system drive (generally c:) choosing the "extra" tab and pushing the button defragment. you can than analyse the drive and if needed defragment it.


And if all else fails Reinstall the machine

When you are done reinstalling use clonezilla to take an image of the HD. that way , next time you don't need to reinstall from scratch.