Monday, 10 August 2009

Fix Ubuntu Swap Partition

Find your swap partition:
sudo fdisk -l

Check the disk ID of the swap partition (e.g. /dev/sda8):
sudo vol_id /dev/sda8

Correct the UUID in the fstab file:
sudo nano /etc/fstab

"If Found" Disk Label


We have so much portable data these days on usb drives, satnavs, cameras and mp3 players it's a nightmare and losing a device can mean losing irreplaceable photos and data files. Certainly where possible data should be encrypted and backedup locally or to online services such as Dropbox and Picasa but it isn't always possible or practical - such as on the holiday camera.

One simple approach that can at least identify you to anyone who finds a devices is "If Found" file.

At the very least create a simple text file with contact details and recovery information and save as "If Found.txt". It might help to suggest that you will cover all recovery costs and are interested more in the data card than recovery of the device.

However, to get more attention and especially instantly accessible from camera cards create an image:
  • Create a word processing file with the same contact information, perhaps even a photograph (might identify you in a crowded venue and helps humanise the situation), and formatted to a nice box shape inside a table, and export to PDF. The more the document looks like an ID card the more instantly identifiable as something interesting it will be.
  • Open the PDF in the Gimp, make sure the DPI on the import is good enough to produce a legible image, and use the autocrop tool to create the small box image.
  • Save as a JPEG "If Found.jpg" on the root directory of the media card or device.
  • Include both JPEG and TXT files on all MP3 players, camera data cards, satnavs, and USB disks, etc. On a Garmin savnav you can set an image as the splash screen. This is displayed before the password request. Placing the image in the root of internal memory ensures it is also the first image in the picture viewer tool. On a regular digital camera place the image on the root of the disk to keep a position of image number 1. Place a copy on the internal memory too if available (for my Kodak this meant actually photographing the image from the screen to the internal memory).

Friday, 7 August 2009

PC Security

As I'm often asked for advice on PC security for Windows machines, here is a brief summary of the free and opensource tools available for Windows users.

Windows
Windows itself has its own important defences. Make sure that your auto-update is turned on. Out-of-date system software is going to be more vulnerable to attack.

Windows Defender
http://www.microsoft.com/windows/products/winfamily/defender/default.mspx
"Windows Defender is software that helps protect your computer against pop-ups, slow performance, and security threats caused by spyware and other unwanted software by detecting and removing known spyware from your computer. Windows Defender features Real-Time Protection, a monitoring system that recommends actions against spyware when it's detected, minimizes interruptions, and helps you stay productive."
Anti-Virus Software
There are a number of basic free anti-virus software options.
AVG http://free.avg.com/

"Antivirus and antispyware protection for Windows available to download for free. LinkScanner Active Surf-Shield checks web pages for threats at the only time that matters – when you’re about to click that link. AVG Anti-Virus Free Edition. Award-winning antivirus and antispyware. Real-time safe internet surfing and searching. Quality proven by 80 million of users. Easy to download, install and use. Protection against viruses and spyware. Compatible with Windows 7, Windows Vista and Windows XP. AVG Anti-Virus Free Edition download and installation is only available for single computer use for home and non commercial use."
ClamAV http://www.clamwin.com
"ClamWin is a Free Antivirus program for Microsoft Windows 98/Me/2000/XP/2003 and Vista. ClamWin Free Antivirus comes with an easy installer and open source code. You may download and use it absolutely free of charge. It features: High detection rates for viruses and spyware; Scanning Scheduler; Automatic downloads of regularly updated Virus Database. Standalone virus scanner and right-click menu integration to Microsoft Windows Explorer; Addin to Microsoft Outlook to remove virus-infected attachments automatically."
Confickr Eyechart http://www.confickerworkinggroup.org/infection_test/cfeyechart.html
"Conficker (aka Downadup, Kido) is known to block access to over 100 anti-virus and security websites. If you are blocked from loading the remote images in the first row of the top table above (AV/security sites) but not blocked from loading the remote images in the second row (websites of alternative operating systems) then your Windows PC may be infected by Conficker (or some other malicious software). If you can see all six images in both rows of the top table, you are either not infected by Conficker, or you may be using a proxy server, in which case you will not be able to use this test to make an accurate determination, since Conficker will be unable to block you from viewing the AV/security sites."

Sunday, 19 July 2009

Three Broadband Router Logs

This script automatically updates a local /var/log/ppp.log log from the latest router logs (otherwise the router logs are not timestamped and are deleted on router reboot).

Data from /var/log/ppp.log can be used track and audit broadband usage and to effectively compare with provider billing.

#!/bin/bash
# Retrieve router broadband usage logs.
# See /var/log/ppp.log for results.
# Run automatically ever hour by adding to /etc/cron.hourly as routerlog.
# Unfortunately as the router does not timestamp its entries - exactly duplicate entries will not be added to the log (how likely is this?)
# New entries to the log are sorted alphabetically (necessary for comm) rather than chronologically. It does not effect the overall audit.

user=admin
password=admin
log="/var/log/ppp.log"
search="es\." # happily identifies both lines for connection time and bytes sent and received
router="192.168.1.1"
sleeptime=4 # telnet pause
temp="/tmp/ppp.log"


# get latest router log

(sleep $sleeptime; echo "admin"; sleep $sleeptime; echo "admin"; sleep $sleeptime; echo "cat $log | grep '$search' "; sleep $sleeptime; echo "quit") | telnet $router | grep "$search" | tac | tr -d '\r\n' | sed 's/minutes\./\minutes\.\n/g' | tac | sed 's/Connect/ Connect/g' | sort > "$temp"

# compare overlapping lines in new log entries and complete log

touch "$log"
lines="$(wc -l $temp | cut -f 1 --delimit=" ")"
cat "$log" | grep "$search" | tail -$lines | sort -u > "$temp.0"
comm "$temp" "$temp.0" -2 -3 | cut -f 1- --delimit=" " > "$temp.1"
new="$(wc -l $temp.1 | cut -f 1 --delimit=" ")"
if [ $new -gt 0 ]
then
date +"(%Y/%m/%d %H:%M)" >> $log
cat "$temp.1" >> "$log"
fi
rm "$temp" "$temp.0" "$temp.1"

Saturday, 18 July 2009

Log Broadband Use (Three.ie)

Mobile broadband is often the best we have and is mostly reliable and fast enough - however over quota charges are horrendous. It is important to keep track of usage and remaining data allowance. There is no automatic way to do this on Linux, especially on a network used by multiple machines.

Three provides a web interface to latest data but it isn't always convenient and doesn't record a usage history - essential for tracking down extraordinary usage problems.

This simple script presents a solution, accessing the data from my.three.ie - storing the quota remaining in /var/log/threebroadband.log. Add it to /etc/cron.hourly as "threebroadband". I like to use Wanda-the-Fish on the Gnome panel to be able to quickly check on usage (add the custom command "tac /var/log/threebroadband.log" to the preferences instead of "fortune").

#!/bin/bash
# Check Three.ie broadband limit remaining.
# See /var/log/threebroadband.log for results (or add Wanda-the-Fish to the Gnome panel with the custom command "tac /var/log/threebroadband.log"
# Run automatically ever hour by adding to /etc/cron.hourly as threebroadband

# Login to my.three.ie

curl -s -c /tmp/cookie https://my3.three.ie/myaccount/selfcare.do > /dev/null
curl -s -b /tmp/cookie -c /tmp/cookie "$(curl -s -b /tmp/cookie -c /tmp/cookie https://my3.three.ie/mylogin//login?service=https%3A%2F%2Fmy3.three.ie%2Fmyaccount%2Fselfcare.do | grep Click | cut -f 2 --delimit="\"")" > /dev/null

# Extract limit to logs

echo $(date +"%y/%m/%d %H:%M") MB: $(curl -s -b /tmp/cookie -c /tmp/cookie https://my3.three.ie/myaccount/selfcare.do | grep "Mobile" -A "14" | tail -1 | cut -c 7-) >> /var/log/threebroadband.log

rm /tmp/cookie

Monday, 13 July 2009

BBC iPlayer Download

You can download the BBC iPlayer stream with mplayer (thank you to B. Halpin for the tip) with, for example:

wget http://www.bbc.co.uk/iplayer/aod/playlists/zy/7p/k0/0b/RadioBridge_intl_2000_bbc_radio_fourfm.ram

mplayer -dumpstream -bandwidth 9999999 `cat RadioBridge_intl_2000_bbc_
radio_fourfm.ram`

The URL for the stream is available in the iPlayer page source code (search the text for ".ram").

Wednesday, 1 July 2009

Proxy Server

Even at home a proxy server can be useful and is easy enough to setup: it helps keep track of downloads easily, can be used to limit access to content, and helps minimise download expenses across multiple machines for updates and other downloads.

The proxy server itself is squid. A useful reporting program is sarg.

sudo apt-get install squid sarg

Squid

You will need to edit the /etc/squid/squid.conf file (as superuser) to uncomment, and edit if necessary, down in the custom settings section the lines which read something like:

sudo nano /etc/squid/squid.conf

acl our_networks src 192.168.1.0/24
http_access allow our_networks

(and in my case the visiblehostname (visible_hostname laptop))

Sarg

Sarg is mostly automatic, however you may have to edit /etc/squid/sarg.conf to customise and correct some errors (spelling of "monthly").

sudo nano /etc/squid/sarg-reports.conf

DAILY=Daily
WEEKLY=Weekly
MONTHLY=Monthly

Log rotation for the squid files need to be changed to monthly:

sudo nano /etc/logrotate.d/squid

Reports will be found in /var/www/squid-reports/index.html

With a web server such as Apache installed: reports are available through a browser at: http://server.local/squid-reports or whatever name of the machine is instead of "server.local".

Set Proxy

To apply system-wide proxy edit .bashrc to add an export line:

nano .bashrc

export http_proxy="http://server.local:3128"

iantheteacher

Planet ILUG