Apr 16

Zend has a great tool for debugging ajax code. It allows error messages to be displayed directly in firebug via an additional plug-in called FirePHP.

First, visit the mozilla plug-in site and install FireBug and FirePHP.

Then add this to your zend framework projects bootstrap file.

<?php

// Place this in your bootstrap file before dispatching your front controller
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);

 

// Use this in your model, view and controller files
$logger = Zend_Registry::get(‘logger’);
$logger->log(‘This is a log message!’, Zend_Log::INFO);

?>

This plug-in saved my bacon on a recent project which has a ton of ajax parts.
There is also an adapter for zend_db_profiler which will log all queries to firebug which is also very useful.

More details here. Thanks Chris for all your hard work.

Tagged with:
Apr 15

Problem:

Webalizer produces a cache file for DNS to speed up the process for resolving addresses to names but no utilities exist to browse this kind of file.

Background:

Webalizer is a log file analyser which can provide basic site usage stats by processing your apache log files. Its a standard utility in a RHEL envirnment. One feature of it is caching DNS information to speed up resolving addresses for reporting purposes. It uses a Berkeley DB to store these key/value pairs for quick lookup. Unfortunatly there really arn’t an gui tools for getting a look at this data. On my machine, its a 70MB file and I’d really like to get a look at that data.

So there are a couple of ways to do this.
MySQL comes with a bdb storage engine which can read this kind of file.

Or, you could use PHP and its driver to load this information.
I chose the latter.

Environment:
I’m starting with a base install of ubuntu 11 and zend server.
Using zend server makes the process more complicated but makes the process more standardized.  ZS uses the same paths for files on every OS it installs on.

Install dependent software.

Zend doesn’t come with this module by default, so we’ll need to compile it.
Make sure you’ve got the basics needed to compile under ubuntu installed.


aptitude install install build-essential checkinstall autoconf

Next we need to make sure that libdb4 is installed so we can reference it in php.

aptitude install libdb4.8-dev db4.8-util db4.8-doc libdb4.8

And finaly, we need the header files for zend server’s php.

sudo aptitude install php-5.3-source-zend-server

Sanity check – Lets make sure that the module isn’t installed.


php --ri dba
Extension 'dba' not present.

Great. Lets build it.


cd /usr/local/zend/share/php-source/php-5.3.9/ext/dba/
/usr/local/zend/bin/phpize
./configure --with-php-config=/usr/local/zend/bin/php-config --with-db4
make
make install
echo "extension=dba.so" > /usr/local/zend/etc/conf.d/dba.ini

lets check that again


php --ri dba
dba

DBA support => enabled
Supported handlers => gdbm cdb cdb_make db4 inifile flatfile

Directive => Local Value => Master Value
dba.default_handler => flatfile => flatfile

Done. We can now access the dba functions from the command line.
They’ll also get picked up by apache the next time you restart.

Build a quick script to read the dns cache and output it as a comma separated list.


<?php
/**
* Requires the dba module be enabled with db4 support.
*/
$path = dirname(__FILE__) . '/dns_cache.db';
$logPath = $path . '.txt';
echo 'Loading ' . $path . chr(10);

$row = 0;
$h = dba_open($path,'r','db4');
$fh = fopen($logPath,'w+');

if(!$h){
echo 'Failed to open db';
die();
}

echo "Exporting Key/Values pairs...\n";
$key = dba_firstkey($h);
$value = dba_fetch($key,$h);
$value = filter_var($value,FILTER_SANITIZE_URL);
$key = filter_var($key,FILTER_SANITIZE_URL);
fwrite($fh, "$key,$value\n");
$row++;

while($key = dba_nextkey($h)){
$value = dba_fetch($key,$h);
$value = filter_var($value,FILTER_SANITIZE_URL);
$key = filter_var($key,FILTER_SANITIZE_URL);
fwrite($fh, "$key,$value\n");
$row++;
}
echo "Printed $row key/value pairs." . chr(10);
echo 'Done' . chr(10);
dba_close($h);

I called my script test.php.
Then run it from the command line.


php -r ./test.php

Loading /home/{MASKED}/dns_cache.db
Exporting Key/Values pairs...
Printed 703268 key/value pairs.
Done

Not sure if this is the best way to get at this data but its the route I chose and it worked.
Your mileage may vary.

Tagged with:
Dec 21

Getting the wireless to work on a Dell Latitude D600 under ubuntu or debian is a pain.

Problem:

The network manager under gnome says ‘firmware missing or not installed’.
and “sudo dmesg | grep ERROR” returns a message like


b43legacy-phy3 ERROR: Firmware file "b43legacy/ucode4.fw" not found or load failed.
b43legacy-phy3 ERROR: You must go to http://linuxwireless.org/en/users/Drivers/b43#devicefirmware and download the correct firmware (version 3).

Solution:

Go here:
http://linuxwireless.org/en/users/Drivers/b43#Ubuntu.2FDebian and download the ‘b43legacy’

sudo su
cd ~
wget http://downloads.openwrt.org/sources/wl_apsta-3.130.20.0.o

Install the b43-fwcutter utility.

apt-get install b43-fwcutter

Use the utility to extract the firmware.


b43-fwcutter ./wl_apsta-3.130.20.0.o

This will create a directory in the current directory with the firmware files. It will be called “b43legacy”.

Move the folder into your /lib/firmware directory and reboot and you should find the firmware needed by your wireless card.


mv ./b43legacy /lib/firmware/
reboot

And enjoy wifi goodness on your linux powered laptop.

Dec 19

xrdp.org hosts an open-source implementation of Microsoft’s remote desktop protocol server. This is a great tool long overdue on GNU/Linux.

Remote Desktop Protocol (RDP) is a proprietary protocol developed by Microsoft, which provides a user with a graphical interface to another computer. Unlike VNC which simply forwards screen shots and keyboard input from another computer, A RDP session is a virtual terminal creating a separate instance of X.org server running a desktop separate from other logged in users. No users need to be logged in to create a new RDP session.
This means the session can be configured by the client so the screen is displayed in the native resolution of the client. Using a RDP client at full screen feels like your using a native operating system. Its also more efficient in terms of bandwidth needed to communicate video and keyboard data.

Installing in ubuntu 11.10 is easy. Its a package which can be installed with apt-get.

sudo apt-get install xrdp

Great, but I encountered a couple of minor issues.
For one after connecting with a client, I was only able to see the desktop. I did not get tool bars or any way to interact with the terminal.
Turns out its an easy fix.

cd /home/youruser
echo "gnome-session --session=ubuntu-2d" > .xsession
sudo /etc/init.d/xrdp restart

This tells xrdp to use ubuntu-2d for your remote session.
This is all I needed to get my menus to show up. Note that restarting xrdp will disconnect your session.

The next issue is pressing the ‘d’ key causes all active windows to be hidden. This can be corrected from the GUI.

  • Click on the ubuntu menu and search for ‘system settings’.
  • Click on ‘keyboard’.
  • Click on the ‘shortcuts’ tab, then the ‘navigation’ tab and find ‘Hide all normal windows’. I changed mine to be ‘alt + d’ .

Once these easy tweaks are done, you’ll have your self a very usable remote desktop server.

Tagged with:
Dec 19

Google charts is a wonderful tool for generating all kinds of graphs and charts. It provides two methods for supplying data, either in the URL or via POST.
The URL version is limited to 2048 characters and the POST version is limited to 16K characters. I wish the FAQ explained a little more about why the limitation exists.

I’ve run into two problems using it in my applications. SSL applications complain if any non-ssl content is pulled into the page and occasionally, I have tables too large for the URL api but that really is the only way to retrieve the image in my application.

I’ve got a simple php-curl based proxy which solves both issues. https://github.com/derak-kilgo/google-chart-proxy Its a drop in replacement for the google’s chart URL.

http://chart.apis.google.com/chart?chs=350x225&cht=p3&chd=s:Mx&chdl=Charts+Users|Should+Use+Charts&chl=Users|Don't+Use&chtt=Google+Charts&chts=676767,20

becomes

http://your-domain.com/proxy.php?chs=350x225&cht=p3&chd=s:Mx&chdl=Charts+Users|Should+Use+Charts&chl=Users|Don't+Use&chtt=Google+Charts&chts=676767,20

Its just that simple.

Tagged with: