This is how I’ve enabled secure SSL login through https on a mediaWiki 1.13.3 installation. This description might work on other versions of mediaWiki, but that has not been tested.
mediWiki doesn’t support SSL login out of the box so a little hack has to be performed.
First you need to tell the webserver, in my case my Apache server that mediaWiki login requests should be redirected to the SSL page
Add the following code lines to your Apache config files or the mediaWiki .htaccess file
Rewrite login url to use httpsRewriteEngine On
RewriteCond %{REQUEST_URI} ^/index.php$
RewriteCond %{QUERY_STRING} ^title=Special:UserLogin
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R]
Rewrite non login url to use normal http
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(?!title=Special:Userlogin)
RewriteRule ^(.*)$ http://%{SERVER_NAME}$1 [R]
Source: http://wiki.epfl.ch/cfavi/mediawiki
In addition to the above configuration you have to create a PHP script to fix some cookies problems since the cookie was made on an https address but normal surfing is done on http mode.
Create a file named ssl_login.php and insert the following code into it
# Secure the login page.
# Secure cookies hurt us because they are set on the https page
# but inaccessible from the http page, so we lose our previous session.
$wgCookieSecure = false;
# Don't process JavaScript and CSS files.
# Otherwise, a secure page will be tagged as "partially secure" because these
# files are being hit via http.
if (checkQS('gen', 'js')) {return;}
if (checkQS('gen', 'css') || checkQS('ctype', 'text/css')) {return;}
# Get page title from query string.
$pageTitle = array_key_exists('title', $_GET)
? $_GET['title']
: "";
# Get server variables
$domain = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
# Are we on the sign-in page or not?
# Logic works for everything except Special pages which apparently don't
# even run LocalSettings.php.
$onSignInPage = false;
$signInPageName = 'special:userlogin'; // lowercase on purpose
if ( strtolower($pageTitle) == $signInPageName ) {
$onSignInPage = true;
} elseif ( strstr(strtolower($uri), "/$signInPageName") ) {
$onSignInPage = true;
} else {
$onSignInPage = false;
}
# Secure only the Special:Userlogin page.
# Un-secure all other pages.
if ( !checkServerVariable('HTTPS', 'on') && $onSignInPage ) {
header('Location: https://' . $domain . $uri);
} elseif ( checkServerVariable('HTTPS', 'on') && ! $onSignInPage ) {
header('Location: http://' . $domain . $uri);
} else {
// nothing
}
function checkQS($key, $value) {
return checkArrayValue($_GET, $key, $value);
}
function checkServerVariable($var, $value) {
return checkArrayValue($_SERVER, $var, $value);
}
function checkArrayValue($arr, $key, $value) {
return array_key_exists($key, $arr) && $arr[$key] == $value;
}
Include this file in your LocalSettings.php file like this
# Fix to use SSL login include '/full/path/to/htdocs/ssl_login.php';
Source: http://www.mediawiki.org/wiki/Manual:Configuration_tips_and_tricks#HTTPS_on_Login_only
Remember to restart your apache webserver to see the changes.
Tags: .htaccess, Apache, https, MediaWiki, PHP, SSL
Posted by Hans-Henry Jakobsen
This is a oneliner to copy files from current directory to another target directory using tar, preserving file attributes, dates etc.
#!/bin/sh fromdir=/path/from todir=/path/to/target echo "cd $fromdir; tar cf - . | (cd $todir; tar xpf -)" cd $fromdir; tar cf - . | (cd $todir; tar xpf -)
Posted by Hans-Henry Jakobsen
This is a simple bash script that is run by crontab every 5 minutes on a linux box.
It e-mails me the new address when a change of IP address is detected.
The script (ipchangemail.sh)
#!/bin/bash
# Check if IP-address has changed. If a change has occured, mail me the new address
# Add the following line to crontab if you would like it to be run every 5 minutes:
# */5 * * * * ./ipchangemail.sh
# The network interface I want to monitor
NET_INTERFACE=eth0
# File to keep the latest IP address
IP_FILE=myip.txt
# Mail to this address when a change occur
MAILTO=mail@example.com
# Read the previous IP address from file
source $IP_FILE
CURRENT_IP=`/sbin/ifconfig $NET_INTERFACE | sed -n "/inet addr:.*255.255.25[0-5].[0-9]/{s/.*inet addr://; s/ .*//; p}"`
if [ "$CURRENT_IP" != "$OLD_IP" ]
then
# Send email about address change
`echo "New IP address detected: $CURRENT_IP" | mail -s "New IP address" $MAILTO`
# Write new address to file
`echo "OLD_IP=$CURRENT_IP" > $IP_FILE`
fi
The script can be downloaded here.
Tags: bash, ifconfig, mail, sed
Posted by Hans-Henry Jakobsen
This post came to life because I had gotten a image file of a 120GB linux ext2 RAID partition that I couldn’t access using Windows software. The partition had been rescued by RAID Reconstructor, a Windows software that can rebuild RAID arrays by combining the disks from the RAID and store it as one image file.
The solution was to use linux and try to mount it as a loop filesystem. My assumption was that the partition itself had an unknown offset, so I used this script to search and mount the partition. The script tries to mount the partition within the first 20000 blocks. I assume the block size is 512 bytes and I already know that the partition is formatted as ext2.
for ((i=0 ; $i < 20000 ; i=$i + 1)) ; do
mount -t ext2 -o loop,offset=$(($i * 512)) diskimage.img /mnt/point && break
done
If it succeeds you can issue the mount command to get the offset value to the mounted partition
# mount | grep diskimage /dev/loop0 on /mnt/point type ext2 (rw,offset=32256)
In my case the offset was 32256.
This script can also be used to mount a partition from a backup of your filesystem.
Example
This is my example disk I'm going to create an image of
# fdisk -l Disk /dev/hda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 14 112423+ 83 Linux /dev/hda2 15 96 658665 83 Linux /dev/hda3 97 3394 26491185 83 Linux /dev/hda4 3395 9729 50885887+ f W95 Ext'd (LBA) /dev/hda5 3395 7218 30716248+ 83 Linux /dev/hda6 7219 8750 12305758+ 83 Linux /dev/hda7 8751 9533 6289416 83 Linux /dev/hda8 9534 9729 1574338+ 83 Linux
Create a backup image of your entire disk
# dd if=/dev/hda of=imagefile.img
To mount one of these partitions as a loop filesystem you can issue a mount command and tell it the right offset. Use the script above if you don't know the offset, it will take the guesswork for you and mount the partition.
Example of mounting /dev/hda3 if the offset is known
# mount -t ext3 -o loop,offset=49664 /dev/hda3 /mnt/point
Determining the offset is easy when you know the disk geometry have access to the file table.
In this case the hda3 partition has an offset of 512 bytes * 96 blocks = 49664.
EDIT
This post could have been avoided if I had known about the linux tool TestDisk. testDisk is a powerful free data recovery software! It was primarily designed to help recover lost partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses or human error (such as accidentally deleting a Partition Table). It could also be used as a forensic tool.
Tags: dd, mount, offset, RAID Reconstructor, testdisk
Posted by Hans-Henry Jakobsen
This post describes how you can resize your VMWare disk in linux using the vmware-vdiskmanager tool, a offline disk manipulation utility.
I’ve been using VMWare Workstation version 6.5 on a Ubuntu 8.10 Intrepid Ibex linux installation.
Shrink a disk image
vmware-vdiskmanager -k diskname.vmdk
Expand the disk to the specified capacity
vmware-vdiskmanager -x <new-capacity> diskimage.vmdk
Example extend a disk to 120GB
vmware-vdiskmanager -x 120GB diskimage.vmdk
You should use a Live-CD or something to resize/expand the filesystem to fill the extended disk. I used gparted on a Ubuntu Live-CD and the operation var quick and painless.
Note
Only local virtual disks may be expanded og shrinked and these features are unavailable if you have used the Snapshot functionality. If you have made a Snapshot, then I recommend creating a clone of the system and then resize the cloned image disk.
Always remember to backup your virtual machine before doing this operation.
Posted by Hans-Henry Jakobsen