Ubuntu Apache2 – run VHOST as different user

There are several reasons why you might want to run different Apache Virtual Hosts as separate users from the Apache user account. My most frequent usage is on my development machine to allow running from my home directory.

The most commonly recommended option for this purpose is MPM-ITK (a quick hack would be to add yourself to the www-data group using “sudo usermod -a -G www-data USERNAME”)

sudo apt-get install apache2-mpm-itk
sudo a2enmod mpm_itk

Modify the virtual host config file in /etc/apache2/sites-available

<Virtualhost *:80>
ServerName HOSTNAME
ServerAdmin webmaster@domain.com
<ifmodule mpm_itk_module>
AssignUserID USERNAME GROUPNAME
</ifmodule>
DocumentRoot /home/USERNAME/www/docs
ErrorLog /home/USERNAME/www/logs/error.log
CustomLog /home/USERNAME/www/logs/access.log combined
</Virtualhost>

PLEASE NOTE:

If you doing this on a machine that already had a default install where MPM-PREFORK is enabled you have to disable

sudo a2dismod mpm_prefork
sudo a2enmod mpm_itk

Re-index media files on Synology NAS servers

One of the annoying things with Synology NAS servers is the fact that a video file moved to the filesystem does not automatically appear on the DNLA share on client devices. It needs a re-index of the media files.

You can log into the HTML Admin Console and start a re-index, however this will be a full re-index and most likely take ages to complete. A quicker way is to connect to the SSH Console and issue the following command:

synoindex -R video

This will only re-index video files. This can also be used for photos and other media types.

As per documentation here are the other command options.
synoindex -R {all|photo|music|video|thumb} )

Installing libdvdcss on Ubuntu 13.10

With the demise of the Medibuntu repository and libdvdcss not being hosted in the main Ubuntu repos due to licensing issues a new repository is needed from 13.10 upwards. Thanks to the good folks at VideoLAN (makers of the awsome VLC Video Player) there is a ready and updated source available.

wget ftp://ftp.videolan.org/pub/debian/videolan-apt.asc | sudo apt-key add -
echo "deb ftp://ftp.videolan.org/pub/debian/stable ./" | sudo tee /etc/apt/sources.list.d/libdvdcss.list
sudo apt-get update
sudo apt-get install libdvdcss2

Ubuntu – paperless office on a budget

Since paper and myself have never gotten on well I have always been dreaming of a paperless office. A while ago I purchased a Fujitsu ScanSnap S1500 scanner for the office. I did this after doing some research on which Automatic Document Feed (ADF) multipage & duplex scanners were both affordable as well as supported on Linux.

It took a while for me to get around to set all of this up, but the result now is that this scanner is connected to a headless Ubuntu VM and the press of the scanner button will:

  1. scan the document
  2. perform OCR to convert to text
  3. combine the text with PDF to create a searchable PDF
  4. OPTIONAL – send the resulting document into Alfresco Document Management Server via FTP

Install dependencies

NOTE: PPA is only required for support of Fujitsu ScanSnap S1500
sudo apt-add-repository ppa:rolfbensch/sane-git
sudo apt-get update
sudo apt-get install sane sane-utils imagemagick tesseract-ocr pdftk libtiff-tools libsane-extras exactimage wput

Install scanbuttond

Download the “Debian Experimental” package from http://pkgs.org/download/scanbuttond
sudo dpkg -i scanbuttond_0.2.3.cvs20090713-14_i386.deb

This step is only for the Fujitsu ScanSnap support. For other scanners you can probably install from the Ubuntu Repository

Scanner config

vim 40-libsane.rules
#add this line
ATTRS{idVendor}=="04c5", ATTRS{idProduct}=="11a2", ENV{libsane_matched}="yes"

Permissions

sudo adduser saned scanner

Useful command lines for troubleshooting

Since I had a few trouble getting this scanner to work properly I found the following commands highly useful in locating the issue.
man sane-usb
sane-find-scanner
scanimage -L
dmesg
tail /var/log/udev

NOTE: If you are using a notebook devices be careful as I spent quite a few hours troubleshooting an error when opening the device from saned. It turned out to be that the USB power-management on the Toshiba notebook caused havoc with saned (http://askubuntu.com/questions/55140/error-during-device-i-o-when-using-usb-scanner). Switching to the desktop that is now housing the error fixed that problem. Thank you VIRTUALBOX !

Configure scanbuttond

vim /etc/default/scanbuttond
#change this line from no to yes
RUN=yes

cd /etc/scanbuttond
sudo cp initscanner.sh.example initscanner.sh
sudo vim initscanner.sh

Uncomment or copy any scanner init command(s).

sudo cp buttonpressed.sh.example buttonpressed.sh
sudo vim buttonpressed.sh

Copy the contents of the scan script below. The script is also hosted on GitHub (https://github.com/leogaggl/misc-scripts/blob/master/buttonpressed.sh)

Scan script

#!/bin/bash
OUT_DIR=/output/directory/name
TMP_DIR=`mktemp -d`
FILE_NAME=scan_`date +%Y%m%d-%H%M%S`
cd $TMP_DIR
echo "################## Scanning ###################"
scanimage --resolution 150 --batch=scan_%03d.pnm --format=pnm --mode Gray --device-name "fujitsu:ScanSnap S1500:67953" --source “ADF Duplex” --page-width 210 --page-height 297 --sleeptimer 1 -y 297 -x 210
echo "################## Cleaning ###################"
for f in ./*.pnm; do
unpaper --size "a4" --overwrite "$f" "$f"
done
echo "############## Converting to TIF ##############"
mogrify -format tif *.pnm
echo "################ OCR ################"
for f in ./*.tif; do
tesseract "$f" "$f" -l eng hocr
hocr2pdf -i "$f" -s -o "$f.pdf" < "$f.html"
done
echo "############## Converting to PDF ##############"
pdftk *.tif.pdf cat output "output.pdf" && rm *.tif.pdf && rm *.tif.html
echo "############## Copy Output File ##############"
cp $FILE_NAME.pdf $OUT_DIR/
echo "############## clean up ##############"
cd ..
rm -rf $TMP_DIR
echo "############## FTP Output File ##############"
#wput $OUT_DIR/$FILE_NAME.pdf ftp://user:pwd@ftp.alfrescoserver.com.au:21/autoscan/pdf/

Credits:

A big thank you & hat tip to the following authors of the following pages:


EDIT (2013-09-16): I found this link describing how to remove empty pages: http://philipp.knechtges.com/?p=190 – might have to investigate this when I have some time.

Quick Adobe Reader install on Ubuntu 13.04

Whilst EVINCE is a very capable PDF Viewer, if you have a need to fill in editable PDF forms it is required to install the Adobe PDF Reader.

sudo add-apt-repository "deb http://archive.canonical.com/ precise partner"
sudo apt-get update
sudo apt-get install acroread

PS: If anybody is aware of an Open Source alternative to the Adobe Reader for editable form please leave a comment !

Installing Custom ROM on Galaxy S4 International from Ubuntu

Or as an alternative title “Liberating your Galaxy S4 Hardware from Samsung Bloatware”.

Unfortunately there is lots of (ad-infested) blogs and forums with dodgy pieces of information on this topic and I found it pretty hard to get descent concise information. So hopefully this might help some poor Linux User liberate their phone. Whilst this has been tested on a Samsung GT-I9505 S4 International LTE device (JFLTEXX series) it should be applicable to other similar Samsung phones that are not fastboot capable (ie. all but the Galaxy Nexus range).

Samsung Galaxy S4 - gap with dust by Janitors, on Flickr
Creative Commons Attribution 2.0 Generic License  by  Janitors 

NOTE: If you have encrypted your device do yourself a favor and do a factory reset BEFORE you start the process (otherwise you will be stuck in a boot-loop as the encryption key will be gone and the device will not start without it). See note below to recover to stock Samsung image if you need to.

Rooting

This area is the hardest to get decent (Ubuntu relevant) information. However (contrary to some forum entries out there) Heimdall is the most workable solution to use from Ubuntu – binary .deb packages are available from https://bitbucket.org/benjamin_dobell/heimdall/downloads. There is both a commandline package as well as a GUI available for Ubuntu 12.10 and 13.04 as well as other Linux distros.

Make sure the device has Developer mode enabled

  • Go to Application > Settings.
  • In the upper-right corner of your screen, tap on “More” button.
  • Navigate to the bottom and select About.
  • Tap “Build number” several times until you see a message that says “Developer mode has been enabled“.
  • Tap the Back button and you will see the Developer options menu under the “System” heading, you can now set Developer options.
  • Check the USB debugging box under Developer options and you are ready to use your Samsung Galaxy S4 in debugging mode.

A very big THANK YOU to Benjamin Dobell from Glass Echidna. Can’t comment on the blog – your work is much appreciated.

Flash cf-auto-root images

Download the I9505 images from http://autoroot.chainfire.eu/ and extract.

Boot the device into download mode (Press POWER ON + VOLUME DOWN + HOME simultaneously and then when the green Android appears VOLUME UP)

This part took me a while to get right as there was not a lot of decent information around (NOTE: CASE-sensitive PIT partition name). You also need to have the “–no-reboot” flag as you need to boot straight into recovery as a reboot will revert back to the Samsung recovery image.
heimdall flash --no-reboot --RECOVERY recovery.img --CACHE cache.img.ext4

Reboot manually into Recovery Mode (Press POWER ON + VOLUME UP + HOME simultaneously) and the rooting process should complete.

Install Recovery Image

As per recommendation from the XDA Forums I used PhilZ recovery. The GT-I9505 files are at http://d-h.st/users/philz_touch/?fld_id=16685#files

Extract the recovery.img file from the ZIP and flash the recovery partition

heimdall flash --no-reboot --RECOVERY recovery.img

Install AOSP Google Play Edition

Boot into the Touch Recovery Boot (Press POWER ON + VOLUME UP + HOME simultaneously) and load the following file with

adb sideload 20130629-GoogleEdition.zip

If you are stuck with an error message that reads: error: closed

adb usb

Resources


EDIT (2013-07-23): Google Play Edtion ROM’s did not work for me (no data connection other than WIFI) – would be great to hear if this works for other people with Australian radios. Ended up using PAC Man ROM – https://plus.google.com/communities/103029729817409918322 which appears the most stable AOKP style firmware. So far looks good – no bloat & squishy noises !


EDIT (2013-08-13): Since the PAC Man ROM had problems with audio on some calls I have switched back to an AOSP Google Play Edition ROM. I have in the meantime worked out that the reason the original Google Play Edition install did not work was simply the missing APN settings for Telstra. D’oh!! I am now running the 4.3 S4 Google Edition ROM from: http://forum.xda-developers.com/showthread.php?t=2348272
image

Here is the TELSTRA (Australia) APN Settings:
Name: Telstra Internet
APN: telstra.internet
Proxy:
Port:
Username:
Password:
Server: wap.telstra.com/wap
MMSC: http://mmsc.telstra.com:8002
MMS Proxy: 10.1.1.180
MMS Port: 80
MCC: 505
MNC: 01
Authentication Type: CHAP
APN Type: default,mms


Reverting back to Samsung Stock ROM

If there are no backups you need to download the Stock ROM’s from http://www.samfirmware.com/ or similar site

heimdall flash --no-reboot --RECOVERY recovery.img --BOOT boot.img --SYSTEM system.img.ext4 --CACHE cache.img.ext4 --HIDDEN hidden.img.ext4

Note: you need to boot into recovery mode and do a facory reset to remove device encryption completely.

https://play.google.com/store/apps/details?id=nl.bvgemert.flasher&hl=en

https://play.google.com/store/apps/details?id=eu.chainfire.triangleaway

SMS Gateway using Sierra Wireless USB Modem on Debian Wheezy

I have been planning to set up a SMS Gateway for sending and receiving SMS messages via a headless utility unit (Raspberry Pi) for a while. Since I had a leftover Sierra Wireless AirCard 880U from Telstra in Australia I wanted to re-purpose this unit with a spare SIM card. Unfortunately it was very hard to find any good setup manual for this particular combination and took some time to fiddle & debug. This is the working setup for future reference and hopefully it helps somebody.

Install dependencies

Note: install usb-modeswitch BEFORE connecting USB Modem
sudo apt-get install usb-modeswitch gsm-utils smstools gammu

Connect the USB Modem

Check if modem is recognised

lsub

Bus 003 Device 002: ID 1199:6855 Sierra Wireless, Inc.

Edit smstools config file

vim /etc/smsd.conf

Change the GSM1 entry
[GSM1]
init = ATE0;+CPMS="SM","SM"
device = /dev/ttyUSB2
incoming = yes
mode = new
baudrate = 115200
smsc = 61418706700
pin = ignore
#rtscts = yes
#cs_convert = yes
report = yes
sending_disabled = no
memory_start = 1
pre_init = yes
primary_memory = SM
secondary_memory = SM
secondary_memory_max = 40

Troubleshooting the modem

I installed gammu purely to have an easier way to test if the modem actually worked. You can use gammu-config to do a GUI config or create a config file manually

vim /etc/gammurc

[gammu]
port = /dev/ttyUSB2
connection = at115200

Testing

gammu-detect

; Configuration file generated by gammu-detect.
; Please check The Gammu Manual for more information.

[gammu]
device = /dev/ttyUSB0
name = Phone on USB serial port Sierra_Wireless__Incorporated AirCard
connection = at

[gammu1]
device = /dev/ttyUSB1
name = Phone on USB serial port Sierra_Wireless__Incorporated AirCard
connection = at

[gammu2]
device = /dev/ttyUSB2
name = Phone on USB serial port Sierra_Wireless__Incorporated AirCard
connection = at

#send sms
sudo echo "sms test" | /usr/bin/gammu --sendsms TEXT +61XXXXXXXX
#check received sms
gammu getallsms

Add your own user account to dialout group if you want to send from your own account for testing (gammu)

sudo adduser $UNPRIVILEGEDUSER$ dialout

Next I will have some fun setting up PlaySMS to allow me to send SMS commands and create some inbound SMS workflows for family.

References
PlaySMS: http://playsms.org/
Gammu: http://wammu.eu/phones/sierra/2551/
smstools: http://smstools3.kekekasvi.com/index.php?p=configure

Twitter RSS Feeds

Now that Twitter has totally killed their V1 API there is no official way to get Twitter feeds via RSS. Which is a real shame as RSS is a well accepted Open Standard for this type of information :-(



The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.

SHAME ON YOU TWITTER !

Currently there seem to be very few third party sites providing RSS services and it appears unlikely many will as Twitter will just kill them with changes to their API and/or terms & conditions as soon as they gain traction.

Here is one I found to get a Users Timeline (which is not all that useful).
http://www.twitter-rss.com/

However Hashtag or Search to RSS services are harder to find and will need a lot more work to implement
http://www.queness.com/post/14004/easiest-way-to-retrieve-twitter-timeline-and-hashtags-twitter-oauth-api-11

Please use the comment section if you are aware of others !

Remove Ubuntu Webapps integration features

One of the most annoying features in Ubuntu from 12.10 onwards are the pesky notifications popping up asking if you want webapps support everytime you visit a supported webpage?

Whilst you can disable this in Firefox’s browser options: Firefox > Preferences > General: Uncheck “Prompt integration options for any website”.

Firefox Webapp Intergration Options

However I prefer to remove the browser extensions entirely.

sudo apt-get remove xul-ext-unity unity-chromium-extension

NOTE: Take care – unfortunatly you can not remove the following as their removal will cause Unity to fail !

  • unity-webapps-common
  • unity-webapps-service

Quick ‘manual’ Eclipse install on Ubuntu

Since I always had trouble with the Eclipse version that is avaialable via the Ubuntu repositories I often need to install Elcipse on new machinery. Hence I am documenting the process for myself and hopefully it might help others as well.

Orion’s Umbra by jah~, on Flickr
Creative Commons Attribution-Noncommercial 2.0 Generic License  by  jah~ 

If you haven’t got the Java dependencies

Java dependencies install

sudo apt-get install openjdk-7-jre openjdk-7-jdk icedtea-7-plugin

Eclipse download

Note: download link needs to be updated – current as of 2014-01-27

cd /tmp
wget http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/M4/eclipse-standard-luna-M4-linux-gtk-x86_64.tar.gz&mirror_id=1051
tar -xzf eclipse-standard-luna-M4-linux-gtk-x86_64.tar.gz
mv eclipse/ /opt
rm -f eclipse-standard-luna-M4-linux-gtk-x86_64.tar.gz

Create symlink

ln -s /opt/eclipse/eclipse /usr/bin/eclipse

Create application launcher

NOTE: (Edit 2014-01-27) as of Ubuntu 13.10 you need to change the ‘exec’ line in the desktop launcher to include “env UBUNTU_MENUPROXY=0″ as you otherwise will not see any of the menu items in the top nav-bar.

sudo touch /usr/share/applications/eclipse.desktop
echo "[Desktop Entry]" >> /usr/share/applications/eclipse.desktop
echo "Version=4.2" >> /usr/share/applications/eclipse.desktop
echo "Name=Eclipse" >> /usr/share/applications/eclipse.desktop
echo "Comment=Integrated Development Environment" >> /usr/share/applications/eclipse.desktop
echo "Exec=env UBUNTU_MENUPROXY=0 /opt/eclipse/eclipse" >> /usr/share/applications/eclipse.desktop
echo "Type=Application" >> /usr/share/applications/eclipse.desktop
echo "Icon=/opt/eclipse/icon.xpm" >> /usr/share/applications/eclipse.desktop
echo "Terminal=false" >> /usr/share/applications/eclipse.desktop
echo "NoDisplay=false" >> /usr/share/applications/eclipse.desktop
echo "Categories=Development;IDE" >> /usr/share/applications/eclipse.desktop
update-desktop-database