Archive

Archive for the ‘Archive Post’ Category

Google Apps, HFSExplorer, Ajax modal window

March 24th, 2009 edlong No comments

Hi,

I’ve recently upgraded to Google Apps for my site. It allows me to use Google Mail for my own personal site and I can use all the Google Documents, Spreadsheets and the rest of their free applications. I just had to modify my MX records for my site to point at Googles MX server(which takes a while to go through). Check it out if you’re a webmaster, I was previously using SquirrelMail so using Gmail is a massive improvement!

http://www.google.com/a/help/intl/en/admins/editions.html

Recently when I booted up into the Windows XP partition using bootcamp of the Intel Mac I’m using I needed to access the files on the Leopard OSX partition of the hard-drive. After looking around for a bit I found HFSExplorer which can read from a HFS partition(i.e. Mac OS filesystem) and copy from it if needed. It is read-only though which is a bit of a bummer but is open-source and worked pretty well when I used it.

I see that bots have cracked both Gmail and Hotmail Live’s captcha methods. Not only that but did it in 60 seconds, very impressive. Read about it here and more in depth here.

I’ve also been playing around with some Ajax stuff recently. I had to make a modal window that contains a form, the form set a session variable that is set just once for a user’s session. I looked around for a bit, tried a few samples and found Control Modal which is a pretty lightweight, easy to use Modal window Ajax API built on top of Prototype. Check out the demos and grab a version at the Control Modal site. Below is some code I wrote to place the form in the Modal window.


Select an option


Note: Took us ages to figure that onclick was the right Prototype JS event to fire the click event, we were previously using click() but it wasn’t working. So now when the page loads a dom loaded event is triggered which then goes and creates a click event on the modal_link_one id which creates the Ajax modal window.

Categories: Archive Post, Mac, Prototype Tags:

No SVN icons with Aptana Studio/Eclipse

March 24th, 2009 edlong No comments

I had a strange problem with Aptana Studio for the last week. I have Subclipse installed as a plugin and previously all my icons appeared fine, all the repository information showed up. I was able to perform Update and all the other typical SVN commands. However in the last week all the icons disappeared and were replaced by question marks. Nothing had appeared to have changed so I was confused with it! Aptana had previously performed an update so I decided to uninstall it and re-installed Aptana, same problem. I uninstalled it again and put in Eclipse but same problem. Finally after fishing around a bit I saw that my workspace directory i.e. ~/Sites/ had an .svn directory in it. I had no idea why it was there so I deleted it and the subdirectories, restarted Aptana and all the icons showed up agan! I’ve no idea how it got in to begin with but I’ve seen it again since on a Ubuntu machine so its not just me!

I needed a command to see what packages were installed in Ubuntu, found this after a little searching:

    dpkg –get-selections

Does the job nicely.

Categories: Archive Post, Linux, Mac Tags:

Ajax forays

March 24th, 2009 edlong No comments

I’ve began playing with Ajax for the first time in the last week. I wanted to load up a page and display it within the current page. So I decided to use an Ajax request to get the page but I also needed to pass in some parameters to this page from a form on the current page. After spending a bit of time messing around trying to convert the parameters and pass them in through the url of the request, Michael Sharman who I work with showed me a nice Prototype function serialize(). This takes in a form element and converts it to a string of parameters e.g. id=4&class=five&test=yes. It can also convert to form to key value pairs but I didn’t need that at the time. I then just called the page like so:

var ajax = Ajax.Update('myDiv','test.cfm',{method:'get',params:$('myFormID').serialize(true)});

This places the content from the ajax request into the div of id ‘myDiv’.
The funny thing is that I had used the request to place the div within a form which was then submitted but the content obtained from the Ajax request doesn’t seem to register with the DOM and didn’t appear when the form was submitted.

So I had

So the div within the form would be filled from the Ajax request but when the form was submitted and the form variable dumped, the div elements wouldn’t show up even though they are inputs, selects etc.
I wonder is there a way to register content got from an Ajax call with the DOM?

Turns out what I was doing was quite stupid idea anyway and was better suited to a CF custom tag so I did that instead but would be interested in the solution.

I was getting a lot of spam on certain WordPress posts in the last couple of weeks. You may remember the problem I was having the stylesheet a few weeks back and my solution was to let unregistered users to post. An unregistered user only needed to enter their username and comment and that was it. Obviously this meant it was vulnerable to spamming and indeed I was moderating about 10 posts a day and marking them as spam. Getting annoyed with having to do this I looked around for free captchas for WordPress and found this site - http://www.protectwebform.com/plugin_wordpress. You need to register which is a bummer but after following the steps it seems to be working nicely after one day, no more spam :)

Categories: Archive Post, Javascript Tags:

Google news and Acid3 testing

March 24th, 2009 edlong No comments

Hi there,

Google have been at it again, this year with a little more unbelievable April fools jokes..

http://www.google.com.au/intl/en/gday/index.html

http://mail.google.com/mail/help/customtime/index.html

On a more serious Google matter….they have began to release offline version of Google Docs to a limited number of users to begin with, not me yet unfortunately :( Need to install Google Gears and if you see an offline icon on the top right at docs.google.com you’ve got it. Only support for Wordprocessor so far, support for Spreadsheets and Presentations coming soon.

http://googledocs.blogspot.com/2008/03/bringing-cloud-with-you.html

I’ve only recently heard of the Acid3 test, which is a test to see how well your browser complies with web-standards
http://acid3.acidtests.org/

The new Windows/Linux versions of Opera claim to have 100% compliance..
http://labs.opera.com/news/2008/03/28/

I ran a couple of more tests on a Macbook Pro for the browsers I have on my machine out of curiosity.
FireFox 3.0b4 – 67/100
FireFox 2.13 – 53/100
Safari 3.0.4 – 41/100

Categories: Archive Post Tags:

Jailbreaking the ver 1.1.4 iTouch(Intel based Mac OSX)

March 24th, 2009 edlong 1 comment

Hi all,
Up until recently I had a 1.1.1 firmware version of the iTouch jailbroken but kinda wanted the new mail, weather, stocks, maps apps. So I decided to upgrade the touch. I found this site iJailbreak and downloaded the 0.6 version. I upgraded the iTouch in iTunes and then unzipped the app, dragged it into my Applications folder and executed it. Jailbreaking it is very simple, just press the jailbreak button and you’ll get a prompt to install the $20 apps from Apple for free and now I’ve got a nice pretty springboard with all the new apps. I like the mail and maps apps very much, will find them very handy when travelling. I’ve got all my Google mail accounts setup and they’re all working pretty well so far.

Categories: Archive Post Tags:

Wget, Bootcamp and ColdFusion setup

March 24th, 2009 edlong No comments

Hi all.

Pretty late now, spent a fair bit of time setting up the new blog and am in the proces of getting the site sorted out a little better.

I’ve been using ftp to get all my websites files, to recursively get files using ftp use mget.

mget -r ftp://username:password@host -p 

Apart from that I’ve a couple of other little tid-bits. Installing Bootcamp on an Intel-based CPU mac is a pain. I’ve tried now 3 times, the biggest problem being that my Media Center 2005 installation has 2 cds and I don’t know how to eject the cd during the install phase when prompted to! The eject button doesn’t work so maybe there’s a shortcut I don’t know or something.Perhaps I’ll have to get a single CD install.

Had the craziest install of ColdFusion/Apache during the week. I had apache working(i.e was able to get to my localhost fine) and so decided to go off and get ColdFusion talknig with apache. I went to /Applications/JRun4/lib/ and executed unzip wsconfig.jar to a local directory. Then I went into the apache/connectors/macos-intel directory and copied out the wsconfig file to /Application/JRun4/lib/wsconfig/1(I created the last 2 directories myself). That was fine I added the ColdFusion code to the end of the httpd.conf file for the CF module and restarted apache. I started getting the NameVirtualHost *.80 has no virtual hosts even though I had about 10 in my users/xxx.conf file. This file was definitely being loaded so I couldn’t figure out why this was happening. After some help from work -colleagues we eventually figured out the problem. We went through the whole copying out of the connector again and got the CORRECT code to enter at the end of the httpd.conf file for the ColdFusion module inclusion and it worked perfectly straight away. Spent about 2 hours figuring this out!

Categories: Archive Post, ColdFusion, Linux Tags:

ColdFusion doesn’t like doublequotes in Query of Queries

March 24th, 2009 edlong No comments

Hello to anyone reading this!

I’ve decided to take my blog in a new direction, as I am now in web-development I’m going to begin to post problems I encounter and solutions I find(hopefully I find them) and try and breathe a little more life into the site, its been pretty stagnant of late!

Today I’ve discovered that ColdFusion really doesn’t like have quotation marks in query of queries. I got this rather unhelpful error:

Incorrect conditional expression,  Incorrect conditional expression,  Lexical error at line 0, column 0.  Encountered: "\"" (34), after : ""

Replacing the double quotes with single quotes fixed that problem, hope that helps someone!

Query of queries are great but are lacking in functionality, can’t do updates or deletes in them(I can see why but it is annoying!). I’ve found that I need to append the table name onto the start of each item in the query for it to work e.g.

SELECT test.username, test.id
FROM test
WHERE 1=1
GROUP BY test.id,test.username
Categories: Archive Post, ColdFusion Tags:

SSH onto iTouch, PHP AGI optimisation and hangup code for Asterisk

March 24th, 2009 edlong No comments

Hi all,

Have been back on the php trail again recently. On problem I’ve had is to do with executing a certain piece of code every 20 seconds. One way in which I was doing it was:

[code lang="php"]
startTime = time();

while(true)

{ endTime = time();

if(endTime - startTime > 20)

{ startTime = time();

//Code

}

}
[/code]

This however is quite harsh on the CPU. If came up with a better and more obvious way to do time-based looping

[code lang="php"]
while(true)

{ sleep(20);

//Code

}
[/code]

This loops around every 20 seconds and runs the piece of code and is much nicer on the CPU :)

I’ve been using PHP AGI which hooks into the Asterisk Extensions.conf dialplan.

One of the other problems I’ve been having is that the php scripts weren’t being killed by asterisk when a user hangs up in the middle of the call.

The solution is to register a handler to react to the hangup event

[code lang="php"]
if(function_exists('pcntl_signal'))

{ pcntl_signal(SIGHUP,'sig_handler');

}
[/code]

This registers the function sig_handler to be run when a hangup is detected within the php script execution

[code lang="php"]
function sig_handler($signo)

{ //Other code, CDR and closing MYSQL conns

exit(0);

}
[/code]

The exit closes the php script thus freeing up the CPU.

I ssh’ed onto my iTouch yesterday. I followed the instructions here http://hacktheiphoneitouch.blogspot.com/2007/12/installing-ssh-client-on-112-iphone.html for the MAC, works nicely. Put on Apache and PHP, not tested them as of yet but I’m sure they’ll work nicely as a simple webserver. Haven’t upgraded from 1.1.2 as of yet couldn’t be bothered jailbreaking again but when 1.1.3 is jailbroken out I’ll consider upgrading. Want to get the mail, stocks etc new apps at some stage……free preferably. Thinking of looking for a ColdFusion server for the iTouch, major long shot but would be hilarious if I got it working!

Categories: Archive Post, Asterisk, Mac, PHP AGI Tags:

PHP Agi – beware!

March 24th, 2009 edlong 1 comment

Hi all,

I setup a new install of Asterisk on a Virtual Ubuntu Server this week. As expected I ran into several problems when trying to get the whole thing up and running, mostly to do with CDR. I’m using a mySQL backend to record CDR data. I obtained the asterisk-addons package and the instructions indicate to do the usual ./configure, make and make install to cleanly install the cdr_addon_mysql module which is loaded by Asterisk at startup and is used to connect and write to the MySQL DB. The build goes fine, no problems indicated along the way.

So I went and got all the sql conf files up to speed(add cdr_addon_mysql to modules.conf, set enabled to yes in cdr.conf and add a mysql module to the end of it and altered cdr_mysql.conf & res_mysql.conf to match my DB settings) but nothing happened to my CDR table. After looking at the modules loaded in Asterisk I saw that the cdr_addon_mysql.so wasn’t being loaded. Seeing that I went back to the Makefile in the asterisk-addons directory and saw that asterisk.h was missing. Looking at the Asterisk wiki I was indicated to create a symbolic link to /usr/src/asterisk so that the build could find Asterisk. I did this but the error persisted. I placed the asterisk.h in the same directory but still the same problem.

Become impatient I looked for other ways to get the mysql module installed. I added the lines deb:ftp://ftp.us.debian.org/debian unstable main and deb-src ftp://ftp.us.debian.org/debian unstable main to /etc/apt/sources.list and did an apt-get update. Now I was able to do apt-get install asterisk-mysql and the addon was automatically got and placed in my /usr/lib/asterisk/modules and loaded up at startup of Asterisk :) Still isn’t working though my settings must be wrong somewhere.

Here is what I did to install Asterisk….

 Need to get install seperately :
    apt-get install Asterisk
    apt-get install Build-essential
    apt-get instal subversion

    Setup Call Logging CDR - still not working fully
    MySQL - cmd MySQL for CDR
    apt-get instal Mysql-server
    apt-get install Mysql-devel
    Download asterisk-addons from digium svn and compile, this is whats giving me bother building is failing. Follow instructions above.

    Execute MYSQL scripts to create database tables. Grant privileges to asterisk@localhost user.

    apt-get Install PHP5-cli php5-common php5-pear php5-mysql

    Install SOX and Lame for mp3 playback and file conversions
    apt-get install sox lame mpg123

    For TTS:
    apt-get festival festvox-8k
    Change /etc/Festival.scm to match one at http://www.voip-info.org/wiki/view/Asterisk+festival+installation

    Update festival.scm to set the default to be voice_rab_diphone
    Change the .scm /usr/share/festival/voices/whatever the voice is called/festvox/voicename.scm. Search for Duration_Stretch and change this value. Restart festival and test. I used 1.4 for rab_diphone.

    Get PHPAGI.php and the other agi modules at http://phpagi.sourceforge.net/ put them in /usr/share/asterisk/bin directory
    Get Magpie RSS for podcast reader and place MagpieRSS directory in /usr/share/asterisk/bin
    Create a cache directory that is writable by Asterisk in the /usr/share/asterisk/bin directory

    Copy existing iax.conf,sip.conf, extensions.conf over to /etc/asterisk

    Also copy existing cdr.conf, jabber.conf, gtalk.conf, festival.conf, dsnmgr.conf,cdr_custom.conf,res_mysql_conf

    Need to get new sound files and put in /usr/share/asterisk/sounds
    Get php scripts and put in /var/lib/asterisk/agi-bin OR /usr/share/asterisk/bin

    Disable res_pgsql and res_odbc

Have been doing a lot of work with PHP AGI in the last week. I’ve been charged with the job of grabbing some XML from a database, parsing it and then playing back a bunch of files whilst recording user input. So looking around I saw that SimpleXML is a nice easy way of parsing XML with PHP and is built into PHP5. Sweet. So I began to go parse some of the xml using SimpleXML…below is an XML snippet like what I had:


    xyz

So I basically created the SimpleXMLElement

$theXML = new SimpleXMLElement('xyz');

Then to access the child of the root element I did this:

$child = $theXML->child;

All good so far. To see what was coming back I used the ‘verbose’ function of phpagi. As all that was being saved in the child variable was a string I was suprised to see what was being output on the Asterisk console:

SimpleElement Object
{
    [0] -> xyz
}

So I began to think an array was being saved in ‘child’ and tried accessing and outputting $child[o]. Again the verbose function output the EXACT same output for the $child[0] and $child. Confused I was going around in circles and doing lots of tutorials to see where I was going wrong but couldn’t find it, it is very simple after all its hard to get wrong!

The problem was to do with the php agi VERBOSE function which does a print_r on the passed in information. I decided to test if Asterisk would convert the ‘array’ in $child to text so I used the text2wav function to output the variable. Funny thing was it would just say ‘xyz’ which is exactly what I wanted in $child. So essentially I was troubleshooting a problem that didn’t exist all because of some funky output from the verbose function.

All in all my advice to any php agi Asterisk programmers would be : DON’T TRUST THE PHP AGI VERBOSE FUNCTION!!

Categories: Archive Post, Asterisk, PHP AGI Tags:

Strings and Singletons in PHP

March 24th, 2009 edlong No comments

Hi all haven’t posted in a while.

Been doing a fair bit of PHP recently and have come across some useful PHP snippets.

I was looking to perform multiple MySQL queries but the plain old mysql_query doesn’t allow it unfortunately. After doing a little bit of digging around I found that you need to use mysqli_multi_query to perform multi-queries. Of course you need to connect to your MySQL database using mysqli_connect(and I believe you need to have enabled a seperate mysqli module for php).

I’ve also been doing quite a bit of string manipulation with php. I was looking for a similar function to Coldfusion’s ListContainsNoCase whereby I needed to search a comma seperated list for a specific value. Didn’t find anything especially useful so learnt that using the explode function converts a string separated by a specified delimiter into an array which can then be searched using the in_array function. The strict flag is especially useful if you require an element of the array to match exactly the original term you’re looking for in the list.

String comparison was another sticking point last week. I had a string containing a single character, “*” and attempted compare this string variable using the double equality operator(i.e. $myVar == “*”) but was getting a false match every time. After printing out the variable many times and ensuring that it did indeed have the right value I began to think something else was wrong and had a look at the php documentation. After trying out the Strcasecmp function I began getting the matches I expected. strcasecmp is a binary safe case-insensitive string comparison. A binary-safe function is essentially one that treats its input as a raw stream of data without any specific format. It should thus work with all 256 possible values that a character can take (assuming 8-bit characters). Most functions are not binary safe when using any special or markup characters, such as escape codes or those that expect null-terminated strings. A possible exception would be a function whose explicit purpose is to search for a certain character in a binary string.(thank you Wikipedia). As I was working with a special character my string comparison was crapping out, now I know why.

Creating a singleton class in PHP is something that is a very common operation and after looking at a handy tutorial I came up with a handy singleton class which is used to obtain and instantiate singleton objects. Further work needs to be done on this to allow for multiple objects to be instantiated but it works pretty well for me.(sorry about the indentation, WordPress screwed it up on pasting it in)

class Singleton
// ensure that only a single instance exists for each class.
{
	function getDBConnection()
	{	static $db = null;
		global $dbLocation;
		global $dbusername;
		global $dbpassword;
		global $cstdatabase;

		if($db == null)
		{	$db = mysql_connect($dbLocation,$dbusername,$dbpassword);
			mysql_select_db($cstdatabase) or die( "Unable to select database");
		}

		return $db;

	}

	//TODO: Make this more flexible for parameters into inited functions, possibly an array
    public function &getInstance ($class, $classPath=null,$arg1=null)
    // implements the 'singleton' design pattern.
    {	$lowerClassName = strtolower($class);
        static $instances = array();  // array of instance names

        if (array_key_exists($lowerClassName, $instances)) {
            // instance exists in array, so use it
            $instance =& $instances[$lowerClassName];

        } else {
            // load the class file (if not already loaded)
            if (!class_exists($lowerClassName)) {
                if($classPath)
				{
					require_once "$classPath/$class".".php";
				}
				else
				{
					switch ($lowerClassName) {
	                    case 'object1':
	                        require_once 'object1/Object1.php';
	                        break;

	                    case 'object2':
	                        require_once 'object2/Object2.php';
	                        break;
	                    default:
	                        require_once "$class".".php";
	                        break;
	                } // switch
				}

            } // if

            // instance does not exist, so create it
            $newClass = new $class();

	    $instances[$lowerClassName] = $newClass;	

	    if(method_exists($newClass,"init"))
	    {	  if($arg1 != null)
		 {	$newClass->init($arg1);
		 }
		 else
		 {
			$newClass->init();
		 }
	   }

	   $instance =& $newClass;
        } // if

        return $instance;

    } // getInstance

} // singleton
Categories: Archive Post, PHP Tags: