Posts Tagged sourcecode

How to find a keyword in your WordPress posts using SQL

If you have a lot of WordPress posts and might want to find all posts containing a certain keyword for any reason, you can start by using the following SQL code, which was taken from this post. I used this in phpMyAdmin for a MySQL database. Make sure you are in the correct database first!

You can substitute any keyword for ‘needle’ below, but you must have the single-quotes and percent signs around it.

SELECT ID FROM wp_posts WHERE post_content LIKE '%needle%';

Example: Let’s say you use the NG Gallery plugin, which has you add a tag to all your posts to include said gallery. Now you find to find all posts which have that NG Gallery tag in them. The following query would work:

SELECT ID FROM wp_posts WHERE post_content LIKE '%nggallery%';

This can also be built upon for find-and-replace operations.

Keep in mind, you can really muck things up using SQL. Make a backup first if you don’t know what you’re doing!

Questions, comments, and feedback are always welcome. Thanks!

, , , , ,

Leave a comment

Basic Ubuntu VPS server backup via FTP or SSH SFTP

In my quest for the perfect “in my dreams” backup solution for my Ubuntu VPS, I created this very simple script which can be run as a cron job and can be easily modified to backup any amount of data to any remote FTP or SFTP server.

You could very easily include a database backup by running mysqldump beforehand, but I’m not including it in this script.

This required yafc to be installed, but Ubuntu installations can easily install it by running

sudo apt-get install yafc

And now, for the script:

# format of the open command is proto://username:[email protected]/
# proto is either ftp or ssh
# special characters in the username or password are not well tolerated
# anything in the EOF tags are direct commands to yafc. Test if unsure
DIR=`date +%F`
yafc <<EOF
open ftp://username:[email protected]/
cd backup-dir
mkdir $DIR
cd $DIR
put -p -r *

Enjoy! Questions, comments, and feedback are welcome and appreciated. Thank you!

, , , , , , , , ,

Leave a comment

Ignoring hidden directories in CrashPlan for Linux

By default, CrashPlan backs up everything in your home folder including all hidden directories (directories starting with a dot (.). This would include some directories your probably don’t want backed up, such as ~/.local/share/Trash (your trash) and a bunch of other hidden directories.

Fortunately CrashPlan’s file exclusion feature includes a way to specify exclusions by regular expression. Simply go to Settings > Backup and next to Filename Exclusions click the configure button.

Check the box for Regular Expression and enter this:


Click the plus sign, then ok, then save again.

That will exclude all the dotted directories from your backups.

Reference: CrashPlan Support – Using Regular Expressions (regex)

Have any filename exclusions that you use on your backups? Feel free to share your rationale in the comments below!

, , ,

Leave a comment

Synology DiskStation and Samba mount permissions

So today I was using smbmount to mount a network share from my Synology DiskStation to my Linux PC when I noticed a rather annoying file permissions issue that I couldn’t seem to fix. Why am I using smbmount and not Gnome’s GUI to mount? Because I need root to have access to the file system as well so that CrashPlan can back up to it.

Here’s what happened:

First, I mounted the share (as root):

smbmount //diskstation/mike /mnt/mynas -o credentials=/home/mike/mike.cred,uid=mike,gid=mike

(For more information on the smbmount or the mount.cifs credentials file, see the Ubuntu manpage for mount.cifs)

That worked great, except for when I do this (as root)…

ls -ld /mnt/mynas

… I get the following output:

drwxrwxrwx 17 mike mike 0 2011-05-20 09:25 mynas

I sure didn’t want the directory world-writable. So I tried specifying file_mode and dir_mode as both 0755 using the following (as root):

smbmount //diskstation/mike /mnt/mynas -o credentials=/home/mike/mike.cred,uid=mike,gid=mike,file_mode=0755,dir_mode=0755

Then I checked it:

ls -ld /mnt/mynas

… and got:

drwxrwxrwx 17 mike mike 0 2011-05-20 09:25 mynas

That didn’t do anything at all to help. Why? Because as it turns out the DiskStation is using a Samba server with CIFS extensions and is passing the permissions to smbmount (mount.cifs). The file_mode and dir_mode options are ignored if the remote server is using CIFS extensions.


If the server does not support the CIFS Unix extensions this overrides the default file mode.


If the server does not support the CIFS Unix extensions this overrides the default mode for directories.

Source: Ubuntu manpages.

So there’s a couple of options here. First, I could set it to mount somewhere inside /home/mike, which would generally protect it. But I’d really like to know what’s up with the file permissions. So I did a little more Google-fu.

As it turns out, the CIFS extensions on the DiskStation can be disabled, all it takes is to edit a file. Lepoulpe posted on the Synology forums the following edit:

you can disable “unix extensions” in the ds106’s samba server. To achieve this, you need to add the folowing line in the [global] section of /usr/syno/etc/smb.conf :

unix extensions=no

So, I SSH’d into my DiskStation as root (should be the same password as ‘admin’ if you’re having trouble) and used the vi editor to make the edit. Afterwards, I restarted samba on the DiskStation by doing this:

/usr/syno/etc/rc.d/ restart

Then I remounted the Samba share as root…

smbmount //diskstation/mike /mnt/mynas -o credentials=/home/mike/mike.cred,uid=mike,gid=mike,file_mode=0750,dir_mode=0750

… and checked the permissions:

ls -ld /mnt/mynas

… and got the following output:

drwxr-x--- 17 mike mike 0 2011-05-20 09:25 mynas

Exactly right.

So now I have /mnt/mynas mounted to my share on the DiskStation. If I wanted it to mount on boot, I could add something like the following to /etc/fstab:

//diskstation/mike /mnt/mynas smbfs auto,credentials=/home/mike/mike.cred,uid=mike,gid=mike,dir_mode=0750,file_mode=0750,user 0 0

Questions about my method? Have any feedback or alternate methods to share? Please feel free to do so in the comments below. Thank you!

, , , , , , ,

Leave a comment

How to install BCM4318 Airforce One 54g in Ubuntu Natty

Getting the Broadcom BCM4318 [Airforce One 54g] working under Ubuntu Natty only relies on getting the proper wireless firmware installed. Kudos to NMI who did the in-depth testing on this one.

In Synaptic package manager, install the firmware-b43-installer package. Or, at a terminal, enter the following:

sudo apt-get install firmware-b43-installer

This should install the necessary firmware and enable your wireless device within moments.

It sounds like this may be related to the BCM4328 chipset issue.

Please share any feedback you have in the comments below. Thank you.

, , ,

Leave a comment

How to securely wipe hard drives

I often times get asked by friends and clients to refer them to a good tool for securely wiping their hard drives. If you’re decommissioning, selling, or returning a drive with sensitive or confidential data on it, you are right to take measures to wipe the drive.

Deleting files from a hard drive doesn’t actually delete them. Instead, it merely “marks” them as deleted, leaving the original data intact until the disk space is reused. It may be that even after that space is reused that partial remnants of the files still remain, and can be easily recovered. TechRepublic wrote up a good article backed by solid research that shows just how many drives contained easily-recoverable data. The results are unnerving, but they don’t have to be.

When wiping drives is a concern, you have two choices — completely wiping a drive that you’re no longer using — that is, if you’re going to part with it; or wiping only the “free space” of your computers hard drive that you’re still using, simply to make sure deleted files are actually gone and unrecoverable.

There are many good, free, easy-to-use utilities that do an excellent job of wiping your drives. Here’s are two that I’m most familiar with and can recommend:

Darik’s Boot and Nuke (DBAN) – (website) (download) – Wipes drives completely

Darik’s Boot and Nuke (“DBAN”) is a self-contained boot disk that securely wipes the hard disks of most computers. DBAN will automatically and completely delete the contents of any hard disk that it can detect, which makes it an appropriate utility for bulk or emergency data destruction.

Eraser – (website) (download) – Can do “free space”-only wiping

Eraser is an advanced security tool for Windows which allows you to completely remove sensitive data from your hard drive by overwriting it several times with carefully selected patterns. Eraser is currently supported under Windows XP (with Service Pack 3), Windows Server 2003 (with Service Pack 2), Windows Vista, Windows Server 2008, Windows 7 and Windows Server 2008 R2.

CCleaner – (website) – Free space and full drive wiping for Windows

Besides being an all-around great cleaner for the registry, CCleaner now includes the ability to wipe both full drives and free space only. A great utility for Windows users.

These are just two programs, and there are many more available.

If you’re a *nix user, Engadget points the way to the shred program. In a nutshell, the following command is what you’re looking for:

shred -vz -n 3 /dev/sda

This will write 3 passes of random data to /dev/sda (make sure that’s the right drive before you start!), followed by a 4th pass of zeros.  It takes some time, so if you don’t mind random (suspiciously random) data on the drive, you can skip the zeroing pass by omitting the z flag.

Do you have a suggestion for a utility that can securely wipe hard drive data? Do you have any questions or feedback on the above? Please voice your thoughts in the comments below! Thank you!

, , ,

Leave a comment

Convert VirtualBox (vdi) hard drive image to VMWare (vmdk) format

I’ve been using VirtualBox for my Windows XP VM when I’m in linux to get a handle on those Windows apps that I absolutely need, and to sometimes address a piece of hardware that otherwise won’t work. One of the biggest issues I’ve had is a distinct lack of VirtualBox to address my BlackBerry — I absolutely must use my Windows hard drive to do it.

VMWare Workstation seems to overcome whatever shortfall exists in VirtualBox to address it, and I’m happy to say, it works quite well. However, now I have this VirtualBox hard drive image with all my software already installed, and I want to boot it in VMWare. How to convert it?

Fortunately, the VBoxManage utility of VirtualBox can actually convert a VirtualBox vdi image to the vmdk format used by VMWare. It can do it rather easily, as well.

The command format is:

VBoxManage clonehd          | 
                            [--format VDI|VMDK|VHD|RAW|]
                            [--variant Standard,Fixed,Split2G,Stream,ESX]

Example (Windows):

"c:Program FilesOracleVirtualBoxVBoxManage.exe" clonehd "Win XP.vdi" xp.vmdk  --format vmdk --variant standard

Absolute path to VBoxManage is necessary unless it’s in the Windows $PATH.

Example (Linux):

VBoxManage clonehd "Win XP.vdi" xp.vmdk  --format vmdk --variant standard

Successful run gets this output:

Clone hard disk created in format 'vmdk'. UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Next, open VMWare and select Create a new virtual machine

Select “I will install the operating system later”

Make your OS selection about the OS that’s currently on the vmdk you will be using. (The guest OS, not the host OS).

Later on, you will have the option to use an existing vmdk image as your virtual hard drive. Do so.

You should now be able to finish setup and boot your converted disk image.

Note that creating a new machine and using an existing hard drive image is not a feature of VMWare Player. Workstation or another product is required. However, JoVa has shared a great workaround:

Since my tip for VMWare Player is not very clear on what to do exactly, I have the following, easy steps that you can follow, right after you started VMWare Player.
1) Select: Create new Virtual Machine
2) Select Guest Operating OS “Microsoft Windows” and select the version you have (for example “Windows XP Professional”)
3) Click “Next” and give a the virtual machine a name, for example “XP-pro”.
4) Click “Next” set the maximum disk size to the size of your actual virtual machine (important!)
5) Click “Next”and click “Finish”. The VM is created
6) Copy your VM (the .vmdk file) over the created (empty) .vmdk (e.g. xp-pro.vmdk)
7) Play the virtual machine

Questions, comments, or feedback is appreciated, as always.

, , , ,

Leave a comment

Redirect or deny site visitors based on IP using .htaccess

As a webmaster, there may be times when you want to deny one or more IP addresses or ranges from accessing your website. Be it comment spammers, page scrapers, or various other reasons. For that, you’re welcome to adopt the following code snippets. If you’ve found them helpful, or have something to share, please do so in the comments below.

Deny by IP

Start by looking for the following two lines in your .htaccess file

order allow,deny
allow from all

Add the following directives BETWEEN those lines. If you don’t have the above two lines, add them and the following lines between them.

# Throws a "403 Forbidden" for the matching IP ranges
# Matches 91.46.*.*
Deny from 91.46.
# Matches exactly
Deny from

Redirect by IP

Copy/paste the following code and add to your .htaccess file, changing the RewriteCond and RewriteRule lines to meet your needs. Read the comments.

# Permanently redirect based on IP rage
<IfModule mod_rewrite.c>
RewriteEngine On
# Try uncommenting this line if it doesn't take
# Options +FollowSymlinks
# The following line describe the IP-pattern to match
# If 1 octet is given, it will match the entire Class-A address
# If 2 octets are given, it will match the Class-B address
# if 3 octets are given, will match the Class-C address
# If 4 octets are given, will match the full address
# The NC directive means Not-Case-Sensitive. It's probably not required.
# Matches exactly
RewriteCond %{REMOTE_HOST} [NC,OR]
# Matches 10.2.*.*
# The trailing period is needed to prevent partial-octet matching
# (i.e. matching 10.200. or 10.20. instead of just 10.2.
RewriteCond %{REMOTE_HOST} 10.2. [NC,OR]
# OR statement must be on all but the last IP to match
# It means, literally, "match this rule, or..."
# Matches 10.5.6.*
RewriteCond %{REMOTE_HOST} 10.5.6. [NC]
# Next line format: RewriteRule <regex to match> <destination> <Flags>
# by default, the next line matches all URLs
# and permanently (301) redirects to the destination.
# Use R=302 instead for a temporary redirect.
# L means this is the last rule to process when this condition is met (recommended)
RewriteRule .* [R=301,L]

Thomas indicates that there should be a trailing backslash-period at the end of the 4th octet, if the octet is less than 3 digits. In testing, I haven’t found it necessary (and it behaves as expected), but readers are encouraged to try it both ways. If you find that one way works over another, feel free to share in the comments.

Here’s a simpler, albeit somewhat less flexible method. This doesn’t use the Apache rewrite module, nor pattern matching, and may or may not fit your needs.

# 301 (permanently) redirect requests for /bar to
301 redirect /bar
# Also redirect the web root
301 redirect /

Questions, comments, and feedback regarding these methods are welcome and apreciated. Have something to contribute, or have feedback about the above code? Please feel free to share in the comments below!

, ,

Leave a comment

Correctly Recognize Alps Touchpad on Dell E6510 in Linux

Laptops which use newer Alps touchpad hardware may experience some lack of functionality as a result of a regression in the kernel psmouse driver — the touchpad is detected and works as a pointing device, but only functions with basic features. Scrolling, disabling tap-to-click, off when typing, and multi-touch (on supported devices) are some of the missing functionality. This appears to be the case with E5510, E6410, M6400, and other Dell (potentially all E2) and some non-Dell models.

From Simon Dierl:

Apparently, newer ALPS touchpads use a new, undocumented and unsupported protocol. The touchpad falls back to a legacy emulation mode, resulting in faulty detections. The bug lists some efforts to reverse-engineer the protocol and has some patches based on DELL contributions that enable ImPS/2 emulation (scrolling works). This, however, still does not allow for synaptics support (turn off when typing, horizontal scroll, etc.). Additionally, some people report problems on suspend/resume. [sic]

The best way to notice if you have a machine which is affected by this bug, is to go to System > Preferences > Mouse and look for a Touchpad tab. If it’s absent, you are probably affected by this bug.

Another way to see if you are affected by this bug is to run lsinput and look for something like the following:

bustype : BUS_I8042
vendor  : 0x2
product : 0x1
version : 0
name    : "PS/2 Generic Mouse"
phys    : "isa0060/serio1/input0"
bits ev : EV_SYN EV_KEY EV_REL

The above output shows the touchpad being identified and driven by the PS/2 driver.

This bug has been entered into Launchpad as bug #606238 and has its roots in Kernel bug #14660. Since it’s a mainline kernel bug, it’s likely to affect every Linux distribution. So far, it’s still a work-in-progress and there’s not been an accepted patch submitted to the Linux kernel team. There’s a discussion on that this is a regression, and this was working in older kernel versions.

The below is based on a patch from cmg238 which, at the very least, causes the kernel to correctly recognize the device as a touchpad and enable some missing functionality. I have made adjustments to the instructions for clarity and explanation.

Download kernel source (to /usr/src):

sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)
apt-get source linux-image-$(uname -r)

(Note: in Ubuntu Precise 12.04, do the following instead, based on this LaunchPad comment)

sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)
sudo git clone git://
cd linux
sudo git checkout origin/alps
sudo cp /boot/config-$(uname -r) .config

Also note that on Ubuntu Precise 12.04, you will be asked a bunch of additional questions at make-time. Accept the defaults, unless you have a reason to do otherwise.

Read about how to “undo” an apt-get build-dep and uninstall previously installed packages here.

Patch drivers/input/mouse/alps.c by locating alps_model_info and adding the additional line below, as follows:

static const struct alps_model_info alps_model_data[] = {
	{ { 0x73, 0x02, 0x64 }, 0xcf, 0xcf, ALPS_PASS | ALPS_DUALPOINT | ALPS_PS2_INTERLEAVED }, /* Dell Latitude E6510 */

Compile psmouse.ko module

cd src/drivers/input/mouse
make -C /lib/modules/`uname -r`/build M=`pwd` psmouse.ko

(On Ubuntu Precise 12.04, use the following instead:)

cd /usr/src/linux/drivers/input/mouse
make -C /lib/modules/`uname -r`/build M=`pwd` psmouse.ko

The following steps will cause you to lose mouse functionality until the modprobe psmouse statement. Be prepared. Also, You may want to backup your existing /lib/modules/(kernel version)/kernel/drivers/input/mouse/psmouse.ko before doing this!

rmmod psmouse
cp psmouse.ko /lib/modules/`uname -r`/kernel/drivers/input/mouse/
modprobe psmouse

The last thing to mention is if you update your kernel you will receive the distributed psmouse.ko module. If the kernel does not include a fix for this bug you will need to follow the directions in this post again to recompile the above patch back into the kernel.

Since this is a mainline kernel issue, I would ask that any reader who is able to, please visit the links within this post and contribute where ever you can to help in getting this resolved. You are welcome and encouraged to share your thoughts and feedback in the comments below as well.

, , , , , , , , ,

Leave a comment

Windows, Linux dual-boot system time issues

Multiple Boot Systems Time Conflicts

From The Ubuntu Community:

Operating systems store and retrieve the time in the hardware clock located on your motherboard so that it can keep track of the time even when the system does not have power. Most operating systems (Linux/Unix/Mac) store the time on the hardware clock as UTC by default, though some systems (notably Microsoft Windows) store the time on the hardware clock as the ‘local’ time. This causes problems in a dual boot system if both systems view the hardware clock differently.

The advantage of having the hardware clock as UTC is that you don’t need to change the hardware clock when moving between timezones or when Daylight Savings Time (DST) begins or ends as UTC does not have DST or timezone offsets.

Changing Linux to use local time is easier and more reliable than changing Windows to use UTC, so dual-boot Linux/Windows systems tend to use local time.

Since Ubuntu Intrepid (8.10), the hardware clock is set to UTC by default.

Make Windows use UTC

Note: This method was not initially supported on Windows Vista and Server 2008, but came back with Vista SP2, Windows 7 and Server 2008 R2.

To make MS Windows calculate the time from the hardware clock as UTC.

Via regedit:

Run regedit and navigate to


Right-click in the right-side panel and select New > DWORD Value. Create the key named RealTimeIsUniversal and give it a value of 1.

Using a registry file

Create a file named WindowsTimeFixUTC.reg with the following contents and then double click on it to merge the contents with the registry:

Windows Registry Editor Version 5.00


Make Linux use ‘Local’ time

To tell your Ubuntu system that the hardware clock is set to ‘local’ time:

1. edit /etc/default/rcS

2. Set UTC=yes if your hardware clock is set to UTC (GMT), or UTC=no to have the hardware clock set to local time.

It’s come to my attention that this issue also affects Macs which dual boot via bootcamp or other methods. 

Questions, comments, and feedback is welcome and appreciated.

, , , , , , ,

Leave a comment