13
Sep 10

Software Patents a RISK to the Jamaican and Caribbean ICT industry

(Reposted from SiliconCaribe) If you haven’t been paying attention billionaire Paul Allen (co-founder of Microsoft) is suing Apple, Google, Facebook, AOL, eBay, Netflix, Yahoo!, Staples, OfficeMax, Office Depot, and YouTube over patent infringements. “A patent is a set of exclusive rights granted by a state (national government) to an inventor or their assignee for a limited period of time in exchange for a public disclosure of an invention.”, Wikipedia.

It is perhaps one of the biggest patent lawsuits to date, and it is one of many patent lawsuits filed since the start of the year. Paul Allen company Interval Licensing has hundreds of patents and has chosen four (4) out of its arsenal to use in the suit. One of the patents mentioned in the suit is the analyzing of a user’s behaviour/action (e.g. search) to suggest a list of related content. Doesn’t this sound like a lot of websites you use? Continue reading →


15
Apr 10

Cut Your Zend Framework Application Upload Time by a Gazillion

Uploading applications built with Zend Framework (or any other Feature Rich Framework) via FTP/SFTP is just boring and takes too long. Not to mention the size of your own application and additional third party files that you may need to upload to your server.

One solution is to roll your own package that only includes the necessary components, another is to zip, upload and unzip.

For the time being I decided to choose the latter.

With just a quick review of the zip extension on php.net/zip, I found in the documentation a possible solution.

I added my two cents and ended up with this



<?php

$file = basename($_GET['file']);

$extractTo = realpath(dirname(__FILE__)) . '/' . time() . '/' ;

echo "Extracting $file to $extractTo";

$zip = new ZipArchive;

if ($zip->open($file) === TRUE) {
    $zip->extractTo($extractTo);
    $zip->close();
    echo ' - done';
} else {
    echo ' - failed';
}
?>


You then do a simple http://www.example.com/unpack.php?file=myapp.zip and your files are extracted in no time.

As you can see nothing fancy.

It creates a new folder within the same location you placed the script . The folder is named after the current timestamp to avoid overwrites.

As per usual, do the necessaries to protect this script.

How do you cut your upload time?


22
Mar 10

Prevent Access to LAN

In writing an app that communicates notifications via HTTP requests, to a user specified URL, it brought up an interesting security question. How do you block them from requesting a URL that accesses the LAN ?.

The function below was created to do just that.



function isOnLAN($url)
{

$urlParts = parse_url($url);

$domainName = $urlParts[‘host’];

$ip = gethostbyname($domainName);

if (ip_in_network($ip,"172.16.0.0", 12))
return true;

if (ip_in_network($ip,"192.168.0.0", 16))
return true;

if (ip_in_network($ip,"10.0.0.0", 8))
return true; //true

return false;

}

// Taken from php.net - http://jm2.php.net/manual/en/function.ip2long.php#92544
function ip_in_network($ip, $net_addr, $net_mask){
if($net_mask <= 0){ return false; }
$ip_binary_string = sprintf("%032b",ip2long($ip));
$net_binary_string = sprintf("%032b",ip2long($net_addr));
return (substr_compare($ip_binary_string,$net_binary_string,0,$net_mask) === 0);
}


Usage:



if (isOnLAN("http://192.168.1.1"))
  echo "Address on LAN";
else
  echo "Address on INTERNET";



27
Jan 09

Translated Time Zone Listing for Zend_Form

Timezones available:

  • timezonetowindows
  • windowstotimezone
  • territorytotimezone
  • timezonetoterritory
  • citytotimezone
  • timezonetocity


$form = new Zend_Form();

$timeZoneList = $locale->getTranslationList("timezonetoterritory");

$timeZone = $form->createElement('select', 'time_zone', array(

'filters'    => array('StringTrim'),
'label'      => 'Time Zone:',
))->addMultiOptions($timeZoneList);

$this->addElement($timeZone);



21
Jan 09

Theme your Zend Framework Application

Allowing users to customize the look of your application is always welcomed. Here is one approach using Zend Framework.

First lets look at the directory structure for creating a themeable application.

Typical Layout:
root

— private

— public

—— css

—— js

—— images

You’ll notice that all our publicly available files for stylesheets, javascript and images are placed in the public folder. We are going to alter this by placing them into a sub-folder under public called ‘default’.

Our structure now looks like this.

root

— private

— public

—— default

——— css

——— js

——— images

What this allows us to do is encapsulate all our files/assets into a single folder that we can now easily reference. All our themes and their assets should now follow the same naming convention as our ‘default’ folder.

Adding a theme to our structure now looks like this
root

— private

— public

—— default

——— css

——— js

——— images

—— modern

——— css

——— js

——— images

In our application bootstrap we add the following line of code (around where you initialize the session)



$session = Zend_Registry::get('Zend_Session'); //change this to match how you store your sessions

if (!isset($session->theme))

$session->theme = 'default';


To easily use this in our application lets create a view helper.



class My_View_Helper_Theme
{
/**
* Returns site base url based on the current theme
*
*
* @return string
*/
public function theme($content = '', $prependBase = true)
{

if ($prependBase)
{
$baseUrl =  Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
}
else
{
$baseUrl = '';
}

$session = Zend_Registry::get('Zend_Session'); //change this to match how you store your sessions

$url = $baseUrl . $session->theme . $content;
}
}

In our view we can now use our view helper to fetch the correct file from the current theme.



<img src="<?php echo $this->theme('/images/blankslate.jpg') ?>" />


We can make our view helper a little more helpful by adding a fallback to the default if the file doesn’t exist in the theme.



class My_View_Helper_Theme
{
/**
* Returns site base url based on the current theme
*
*
* @return string
*/
public function theme($content = '', $prependBase = true)
{

if ($prependBase)
{
$baseUrl =  Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
}
else
{
$baseUrl = '';
}

$session = Zend_Registry::get('Zend_Session'); //change this to match how you store your sessions

$url =  '/public/' . $session->theme . $content;

$location = DOCUMENT_ROOT . $url;

if (file_exists($location))
{
return $baseUrl . $url;
}
else
{

// If theme doesn't exist then use the default theme

$url = '/public/default' . $content;

return $baseUrl . $url;
}
}