Cleaning up files created by the web server

Many times when you are working with a web application on shared hosting, the server will create files. Depending on the server configuration, it is possible those files will be created by a user other than the account holder. If you are using shared hosting, and the server is running as 'nobody', 'apache' or 'www-root' you may not be able to delete the files.

This script determines the web server user with the whoami command, then finds and deletes any files it owns. Bear in mind it will delete them from the current directory down, so files higher up in the directory tree will not be removed.

<?php
$whoami = `whoami`;
echo $whoami;
$find = 'find -delete -user '.$whoami;
`$find`;

Be careful with this script, it may delete files you wanted to keep.

A good practice is to use the whoami display to see which user the server is running as, then use find -user server to find the files that were created. Once you've checked it, you can allow the script to run. Remember to run the script through the browser or using wget.

dojox/gauges/GlossyCircularGauge v1.9.1

Example of a Dojo GlossyCircularGauge

require(["dojox/gauges/GlossyCircularGauge", "dojo/query", "dojo/dom-attr", "dojo/NodeList-dom", "dojo/domReady!"], 
function(Gauge, query, domAttr){
        var rateGauge = document.getElementById("rateGauge");
        var glossyCircular = new Gauge({
                background: [255, 255, 255, 0],
                title: 'Value',
                id: "rateGauge",
                width: 300,
                height: 300,
                min: 0,
                max: 100}, rateGauge);
        glossyCircular.startup();
        glossyCircular.addRanges(
                [{size: 65, low: 0, high: 25, hover: 'Worth doing just because it\'s fun', useTooltip: true,
                        color: { type: 'linear', colors:[{offset:0, color: '#030'}, {offset:1, color: '#090'}]}},
                        {size: 65, low: 25.1, high: 50, hover: 'Fun, but requires skill',
                        color: { type: 'linear', colors:[{offset:0, color: '#090'}, {offset:1, color: '#ff0'}]}},
                        {size: 65, low: 50.1, high: 75, hover: 'Challenging, requiring skill and research, but still fun',
                        color: { type: 'linear', colors:[{offset:0, color: '#ff0'}, {offset:1, color: '#f90'}]}},
                        {size: 65, low: 75.1, high: 100, hover: 'Work, not fun',
                        color: { type: 'linear', colors:[{offset:0, color: '#f90'}, {offset:1, color: '#f00'}]}}]);
});

Putting the ranges in the options when the gauge was created worked, but the hover tooltips didn't appear on hover. Adding the ranges with .addRanges, after .startup made it work.

The range borders are the first of the gradient colors. Looks cool.

Zend Framework 1.12 - Form Decorator settings

I really like the dl/dt/dd output of Zend Framework for forms, but there came a day when I needed a lot more control over the presentation.

In order to remove the dl/dt/dd I used these settings in the form.

In form/model/edit.php

        $this->setDecorators(array(
            array('ViewScript', array('viewScript' => '/model/form/edit.phtml'))));
        $this->setElementDecorators(array(
            'ViewHelper',
            'Errors',
            'Label',
            array('HtmlTag', array('tag' => 'div')),
            'Description'));

In /model/form/edit.phtml



<?php echo $this->element->contact_first_name ?>

Resulting HTML


<div><label for="name" class="required">Name</label>
<input type="text" name="name" id="name" value="" autocomplete="off"></div>

References

http://framework.zend.com/manual/1.12/en/zend.form.standardDecorators.html
http://devzone.zend.com/1240/decorators-with-zend_form/

CentOS 6.4 VirtualBox with Windows 7 (64-bit) Guest

I have an ASUS laptop with a factory installed version of Windows 7 (64-bit) on the internal hard drive, and CentOS 6.4 running off an external USB drive.

My goal was to use Windows 7 to host as many browsers as possible for testing. For that reason, I needed to be able to have both Windows and CentOS running at the same time.

I used the following commands to map the Windows drive for use with VirtualBox:

As root:


chmod a+rw /dev/sda

As the regular user:

VBoxManage internalcommands createrawvmdk -filename /opt/vbox.disks/windows7.vmdk -rawdisk /dev/sda
VBoxManage storagectl 'Windows 7' --name 'SATA' --hostiocache on

Then I created the virtual machine and assigned it to use the VMDK and booted it up.

Windows 7 Dual-Boot CentOS 6.4 on an External USB Drive

Before you do this, make recovery disk(s) for Windows 7. Unless you already have them. You may want to backup anything you have on the Windows 7 drive, but if you’re only using it to run browsers, you haven’t invested that much anyway. Make sure you have some sort of recovery disks or you will either have to buy them or pay someone to fix your disk. Label the disk. Eventually.

The first thing you’ll need for this is a CentOS 6.4 LiveCD. Go to one of the CentOS mirrors (http://www.centos.org/modules/tinycontent/index.php?id=15) and use the following URL pattern: http://mirror.example.com/centos/6/isos/i386/CentOS-6.4-i386-LiveCD.iso. If you have a 64-bit machine, use x86_64. You can also use a USB to boot, I recommend http://unetbootin.sourceforge.net/

Install CentOS on the external drive. I recommend doing a minimal install to get the boot loader set up, then you can either reinstall or add packages to get the system set up the way you want it to.

Once CentOS is on the drive, try to boot from it. You’ll probably have to press a key (on this Asus laptop it is Esc) to choose which drive to boot from. If it won’t boot, you’ll need to adjust the grub settings.

Apparently you can’t change the Windows 7 boot loader. I’m not going to claim this is an authoritative statement, however, installing grub on the Windows 7 drive caused it to fail to boot with a ‘Hard disk error’ (or something similar). This required the Windows 7 recovery disks to recover.

Therefore, you must put the bootloader on the external drive and configure the BIOS to try to boot from the external drive first, with an option to go to Windows.

The problem I had was that by booting off a USB stick the device numbers were a bit off.

Once I had grub loaded on the external drive, I use the find command to determine how the disk was referenced. Then I manually edited the device.map file and grub.conf files after booting into the LiveCD.

For an Asus laptop with Windows 7 on the internal hard disk, and an external USB disk drive, the device.map file looked like this:

It wasn’t really generated by anaconda since I edited it, but that’s okay.

# this device map was generated by anaconda
(hd0)     /dev/sdb

I edited grub.conf using hd0 to refer to the external drive and hd1 to refer to the internal drive.

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_asuslaptopcentos-lv_ro
ot
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda1
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-358.6.2.el6.i686)
	root (hd0,0)
	kernel /vmlinuz-2.6.32-358.6.2.el6.i686 ro root=/dev/mapper/vg_asuslapto
pcentos-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=vg_asuslaptopcent
os/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_asuslaptopcen
tos/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
	initrd /initramfs-2.6.32-358.6.2.el6.i686.img
title CentOS (2.6.32-358.el6.i686)
	root (hd0,0)
	kernel /vmlinuz-2.6.32-358.el6.i686 ro root=/dev/mapper/vg_asuslaptopcen
tos-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=vg_asuslaptopcentos/l
v_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_asuslaptopcentos/
lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
	initrd /initramfs-2.6.32-358.el6.i686.img
title Windows 7
	rootnoverify (hd1,1)
	chainloader +1

What I learned:

Drive references may vary based on how the machine was booted.

You can’t just plug an external drive into a different machine and work with it, you may mess up the other machine.

Don’t change the Windows 7 boot loader, although you can use EasyBCD to recover. Maybe.

Taking the time to read the grub documentation is well worth the investment.