Misc Hints

Converting an ISO to zISO for Loopback Mounting

$ mkdir src
$ su -c mount -o loop src.iso src
$ mkzftree -v -z 9 src dst
$ file -b src.iso
$ genisoimage -v -r -V 'name from above file cmd' -r -z -o dst.iso dst

Leeching Moodle For an Offline Copy

Moodle is a popular alternative to Blackboard, and rightly so as Blackboard really does suck more than a milking machine (from what I have been told by the poor users and staff forced to use it).

The downside with Moodle (from the student side) is that to get to the course material you have to be online. The type of people who sign up on a remote learning course typically are always be on the road and either unable to afford a 'roaming' Internet connecgtion or the lack of regular access to an Internet connection will affect your studies.

My brother ran into this issue and asked if I could provide him with a 'portable' copy of his course material. Looking to the Internet all I could find was the usual luser whining and the 'official' Moodle response that "sorry Moodle is not kitted out for web crawling".

Being a bright lad I pulled apart, client side, what was going on and worked out that by using wget to do the complicated cookie authentication dance and httrack to do the actual crawling and archiving. The cookie authentication support in 'httrack' is not flexible enough to log in successfully into Moodle, hence why we get wget to do this.

To action the commands below just replace USERNAME with your login username and PASSWORD with your password for the Moodle site. Of course you need to replace www.example.co.uk with the correct hostname and you might need to adjust the path.

The filters passed to 'httrack' limit the leech to just the lessons linked off the starting URL (in the below example, http://www.example.co.uk/mod/lesson/index.php?id=5), hopefully all the forums, messaging, and calendar spiel will be skipped.

So run the following, I suggest you do it from within a directory called 'websites' or 'leech' for tidyness reasons:

wget --spider --keep-session-cookies \
   --save-cookies cookies.txt http://www.example.co.uk/login/index.php
 
# unsure why we cannot use '--spider' here
wget --keep-session-cookies \
   --load-cookies cookies.txt --save-cookies cookies.txt \
   --post-data="username=USERNAME&password=PASSWORD&testcookies=1" \
   http://www.example.co.uk/login/index.php 
 
# we have to fetch the page referred to the above wget otherwise it
# fails :-/  Look at the contents of the previous wget ('login.php')
# to see where you are redirected to and use that URL here.  For me
# it was back to the main homepage, you might find it different for you
#
# unsure why we cannot use '--spider' here
wget --keep-session-cookies \
    --load-cookies cookies.txt --save-cookies cookies.txt \
    http://www.example.co.uk/
 
# tidy up the un-needed files (as '--spider' does not work)
rm index.*
 
# now the actual download
httrack -b1 "http://www.example.co.uk/mod/lesson/index.php?id=5" \
    -* +www.example.co.uk/* -www.example.co.uk/message/* \
    -www.example.co.uk/login/* -www.example.co.uk/index.php?cal_* \
    -www.example.co.uk/calendar/* -www.example.co.uk/help* \
    -www.example.co.uk/user/* -www.example.co.uk/grade/* \
    -www.example.co.uk/mod/* +www.example.co.uk/mod/lesson/* \
    +*.jpg +*.gif +*.png

'Idle' Port Report Generator

This script hopefully can help any Network Sysadmin who finds tedious querying a switch that has no spare ports for patching, on which ports are 'available' as they are idle. The script should work on any Layer2 aware switch that SNMP::Info can talk to; of course I have been only able to test it against Cisco kit. It uses 'standard' MIB data and none of the Cisco specific bits so do let me know how you get along with it.

The following shows a trial running of what the script does on a switch with a mixture of idle and adminstratively 'shutdown' ports:

ac56@node0:~$ idlePortReport 172.16.1.172
querying 172.16.1.172...
uptime: 2w1d1h
  name: LibReadingRm-3548-2
 class: SNMP::Info::Layer2::C2900

int    link admin time   description
Fa0/1  down up    2w1d1h 049
Fa0/2  down up    2w1d1h
Fa0/3  down up    2w1d1h 051
Fa0/4  down up    2w1d1h 052
Fa0/15 down up    2w1d1h 063
Fa0/18 down down  n/a    066
Fa0/19 down down  n/a    067
Fa0/25 down up    2w1d1h 073
Fa0/29 down up    2w1d1h 077
Fa0/33 down up    2w1d1h 081
Fa0/39 down down  n/a    087
Fa0/41 down down  n/a    089
Fa0/43 down down  n/a    091
Fa0/45 down down  n/a    093
Fa0/47 down down  n/a    095
Gi0/1  down up    2w1d1h

The script should work on any Perl enabled machine that has SNMP::Info installed. Simply download idlePortReport and run it as in the above example. To use, remember to configure your SNMP communities/credentials at the top of the script to match your environment. And no, 'megasecret' is not our SNMPv2c community secret...

www: misc (last edited 2009-03-08 00:26:40 by localhost)