Archive

Archive for the ‘Web Tools’ Category

IP to country conversion

October 18, 2010 1 comment

Though there are a lot of available solutions to tackle this problem but the one reside in the Google Code is the perfect one with simplicity and ease of use. Below is the work around to setup a test case; –

Explore the code:

Visit the project’s profile and read about the documentation.

Download the code;

Get the latest code from the repo and extract it to the root directory of the web server. Linux – /var/www/phpip2country Windows – C:\xampp\htdocs\phpip2country

Test the code:

Browse the directory in the browser. http://localhost/phpip2country/index.php

You need to upload the sql file which is actually a mapper for IP and Countries.

Results:

IP: 127.0.0.1
IP numerical Value: 2130706433
IP registry: IANA
IP assigned (Y-m-d H:i:s): 1983-01-01 05:00:00
IP country RIR (Regional Internet Registry) representation: ZZ
IP Country Abbreviation: ZZZ
IP country name: RESERVED
IP range: array (
‘FROM’ => ‘127.0.0.0’,
‘TO’ => ‘127.255.255.255’,
)
IP range numerical: array (
‘FROM’ => ‘2130706432’,
‘TO’ => ‘2147483647’,
)
full IP informations array: array (
‘IP_FROM’ => ‘2130706432’,
‘IP_TO’ => ‘2147483647’,
‘REGISTRY’ => ‘IANA’,
‘ASSIGNED’ => ‘410227200’,
‘CTRY’ => ‘ZZ’,
‘CNTRY’ => ‘ZZZ’,
‘COUNTRY’ => ‘RESERVED’,
‘IP_STR’ => ‘127.0.0.1’,
‘IP_VALUE’ => 2130706433,
‘IP_FROM_STR’ => ‘127.0.0.0’,
‘IP_TO_STR’ => ‘127.255.255.255’,
)

Below is the output when the code has been set on a live server.

IP: 116.58.42.211
IP numerical Value: 1949969107
IP registry: APNIC
IP assigned (Y-m-d H:i:s): 2007-03-27 19:00:00
IP country RIR (Regional Internet Registry) representation: PK
IP Country Abbreviation: PAK
IP country name: PAKISTAN
IP range: array (
‘FROM’ => ‘116.58.0.0’,
‘TO’ => ‘116.58.127.255’,
)
IP range numerical: array (
‘FROM’ => ‘1949958144’,
‘TO’ => ‘1949990911’,
)
full IP informations array: array (
‘IP_FROM’ => ‘1949958144’,
‘IP_TO’ => ‘1949990911’,
‘REGISTRY’ => ‘APNIC’,
‘ASSIGNED’ => ‘1175040000’,
‘CTRY’ => ‘PK’,
‘CNTRY’ => ‘PAK’,
‘COUNTRY’ => ‘PAKISTAN’,
‘IP_STR’ => ‘116.58.42.211’,
‘IP_VALUE’ => 1949969107,
‘IP_FROM_STR’ => ‘116.58.0.0’,
‘IP_TO_STR’ => ‘116.58.127.255’,
)

Categories: Web Tools Tags: , ,

OpenInviter let’s drag friends

September 3, 2010 1 comment

OpenInviter is a fantastic edition to the open source widget domain. The purpose is pretty simple and straight forward that is dragging friends instantly.

Below is my 15mins interaction with that widget.

  • Get yourself register with the service. This is mandatory because the widget will use the private key generated for a particular user.
  • Extract the compress file in webserver root directory

#sudo tar zxvf openinviter-*.tar.gz

  • Fullfill the dependencies like wget and curl packages

$sudo apt-get install wget curl

  • Navigate the postinstall.php and look for the following output;-

Checking username and private key… *OK*
Checking PHP version… *OK*
Checking DOMDocument support… *OK*
Checking transport method… libcurl is installed. Using cURL to handle requests
SQLite is NOT installed. Unable to keep stats. This will not affect the OpenInviter modules since they will run without keeping any stats.
Checking write permisions… /tmp is writable. Using /tmp to store cookie files and logs
Checking for new versions of OpenInviter… Your OpenInviter software is up-to-date
Checking Abv… *OK*
Checking AOL… *OK*
Checking Apropo… *OK*
Checking Atlas… *OK*
Checking Aussiemail… *OK*
Checking Azet… *OK*
Checking Bigstring… *OK*
Checking Bordermail… *OK*
Checking Canoe… *OK*
Checking Care2… *NOT OK* – This plugin might not work correctly on your system
Checking Clevergo… *OK*
Checking Doramail… *OK*
Checking Evite… *OK*
Checking FastMail… *OK*
Checking 5Fm… *NOT OK* – This plugin might not work correctly on your system
Checking Freemail… *OK*
Checking Gawab… *OK*
Checking GMail… *OK*

  • Once done either delete the postinstall.php file or rename it.

# sudo mv /var/www/jump4tmp/openinviter/postinstall.php /var/www/jump4tmp/openinviter/postinstallDONE.php

  • For detail install instructions look for the install.txt file.
  • Navigate the openinviter root directory and look for config.php file while will set the settings of the widget

# sudo gedit /var/www/jump4tmp/openinviter/config.php

<?php
$openinviter_settings=array(
‘username’=>”register_user”, ‘private_key’=>”801cb788f47075fd3cf57328b7948527″, ‘cookie_path’=>”/tmp”, ‘message_body’=>”You are invited to http://website.com&#8221;, ‘message_subject’=>” is inviting you to http://website.com&#8221;, ‘transport’=>”curl”, ‘local_debug’=>”on_error”, ‘remote_debug’=>””, ‘hosted’=>””, ‘proxies’=>array(),
‘stats’=>””, ‘plugins_cache_time’=>”1800″, ‘plugins_cache_file’=>”oi_plugins.php”, ‘update_files’=>”1″, ‘stats_user’=>””, ‘stats_password’=>””);
?>

  • Adjust the file content according to you need like stayed above.
  • Finally navigate to the example.php in the browser to play around with the widget LIVE!

http://localhost/jump4temp/openinviter/example.php

 

example.php

openinviter/example.php

 

Flex development on Linux

September 2, 2010 1 comment

Hey guys, I hope there are lot of guys who are relying on linux distro like Ubuntu, centos or fedora to name some. As far as the developers, geeks and machine fanatics are concerned. Aftyer such an addiction it’s quite difficult to work back on Windows system for some specific reasons like previous was the case as flash development is restricted to windows based machines. But now as adobe took a nice decision to move to bit to open source society with their new open source flexsdk the dream to develop flash based application on the linux island come true. Now with a handful of simple plugins our distro will be up and ready to develop application in flash and actionscript.

1. Download the eclipse euorpa with JEE support (v3.2 or higher)
Visit the following link http://www.eclipse.org/downloads/
Look for Eclipse IDE for Java EE Developers
32bit: http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/helios/R/eclipse-jee-helios-linux-gtk.tar.gz
64bit: http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/helios/R/eclipse-jee-helios-linux-gtk-x86_64.tar.gz

or get a torrent: http://build.eclipse.org/technology/phoenix/torrents/jee/eclipse-jee-helios-linux-gtk.tar.gz.torrent

Move the tar file into /opt dir
# sudo mv eclipse-*.tar /opt

Untar the eclipse compress file
# sudo tar zxvf eclipse-*.tar
# sudo cd eclipse
# ./eclipse &

2. Install the following plugins

In the menu, we choose Help -> Install new software…

Click on the “Add…” button, and type the following:

Name: Eclipse IMP
Location: http://download.eclipse.org/technology/imp/updates/

Name: AXDT
Location: http://update.axdt.org/

Choose (at least) the following packages:
Axdt AS3 Feature
Flex3SDK Feature

Then click on the “Next >” button, accept the licence and proceed to install the AXDT + Flex SDK framework.

Once installed, restart Eclipse

Go to the menu: Window -> Open perspective -> Other… -> AXDT

That’s all what you need to get started with Flas application development.

Coming soon

Tutorial: Write and compile you first flex application

Mail parsing via Ez Components

April 18, 2010 3 comments

Get started with EZ Components:

After spending ma 24hrs I landed on a blog where the guys have an excellent tutorial series to get started with Ez components in detail so skim it first here you go [1] Hello World![2]  Send an Email[3] RSS feed creation.

sudo apt-get install apache2

sudo apt-get install php5

sudo apt-get install libapache2-mod-php5

sudo /etc/init.d/apache2 restart

Pear Package Manager installation on Linux:

lynx -source http://pear.php.net/go-pear | php

sudo apt-get install lynx-cur

sudo apt-get install php5-cli

Ez Component using Pear Installed

pear channel-discover components.ez.no
pear install -a ezc/eZComponents

Setup include_path

Navigate to the following files and append the root PEAR directory.

/etc/php5/apache2/php.ini
/etc/php5/cli/php.ini

include_path=”.:/var/www/path/to/root/PEAR”

At the top of the code you wrote using ez libs

require_once(“ezc/Base/base.php”);  //depend of the installation method either pear or svn
function __autoload( $className )
{
ezcBase::autoload( $className );
}

Pre-requisites:

  1. Xampp
  2. Ez Components

Task 1: Receiving and Parsing emails:

In the code below we are going to receive emails from a remote server and parse it’s parts. Moreover we’ll tear down the attached files and move them to a separate directory for later processing.

<?php
$dir = dirname( __FILE__ );
require_once “$dir/../../ezcomponents-2009/Mail/docs/tutorial/tutorial_autoload.php”;

$options = new ezcMailPop3TransportOptions();
$options->ssl = true;
$pop3 = new ezcMailPop3Transport( “pop.gmail.com”, 995, $options  );
$pop3->authenticate( “sendmarks@gmail.com”, “cubesatlover” );
$pop3->status( $num, $size );
$messages = $pop3->listMessages();
$set = $pop3->fetchAll();
$parser = new ezcMailParser();
$mail = $parser->parseMail( $set );

//echo print_r($mail);

for ( $i = 0; $i < count( $mail ); $i++ )
{
echo formatMail( $mail[$i] );
}

function formatMail( $mail )
{
$t = ”;
$t .= “From:      “. formatAddress( $mail->from ). “<br />”;
$t .= “To:        “. formatAddresses( $mail->to ). “<br />”;
$t .= “Cc:        “. formatAddresses( $mail->cc ). “<br />”;
$t .= “Bcc:       “. formatAddresses( $mail->bcc ). “<br />”;
$t .= “Date:      “. date( DATE_RFC822, $mail->timestamp ).
“<br />”;
$t .= “Subject:   “. $mail->subject . “<br />”;
$t .= “MessageId: “. $mail->messageId . “<br />”;
$t .= “<br />”;
$t .= formatMailPart( $mail->body ) . “<br />”;
return $t . “<br /><br />”;
}

function formatMailPart( $part )
{
if ( $part instanceof ezcMail )
return formatMail( $part );

if ( $part instanceof ezcMailText )
return formatMailText( $part );

if ( $part instanceof ezcMailFile )
return formatMailFile( $part );

if ( $part instanceof ezcMailRfc822Digest )
return formatMailRfc822Digest( $part );

if ( $part instanceof ezcMailMultiPart )
return formatMailMultipart( $part );

die( “No clue about the “. get_class( $part ) . “<br />” );
}

function formatMailMultipart( $part )
{
if ( $part instanceof ezcMailMultiPartAlternative )
return formatMailMultipartAlternative( $part );

if ( $part instanceof ezcMailMultiPartDigest )
return formatMailMultipartDigest( $part );

if ( $part instanceof ezcMailMultiPartRelated )
return formatMailMultipartRelated( $part );

if ( $part instanceof ezcMailMultiPartMixed )
return formatMailMultipartMixed( $part );

die( “No clue about the “. get_class( $part ) . “<br />” );
}

function formatMailMultipartMixed( $part )
{
$t = ”;
foreach ( $part->getParts() as $key => $alternativePart )
{
$t .= “-MIXED-
$key——————————————————————
<br />”;
$t .= formatMailPart( $alternativePart );
}
$t .= “-MIXED
END———————————————————-<br />”;
return $t;
}

function formatMailMultipartRelated( $part )
{
$t = ”;
$t .= “-RELATED MAIN
PART———————————————————–<br />”;
$t .= formatMailPart( $part->getMainPart() );
foreach ( $part->getRelatedParts() as $key => $alternativePart )
{
$t .= “-RELATED PART
$key—————————————————–<br />”;
$t .= formatMailPart( $alternativePart );
}
$t .= “-RELATED
END——————————————————–<br />”;
return $t;
}

function formatMailMultipartDigest( $part )
{
$t = ”;
foreach ( $part->getParts() as $key => $alternativePart )
{
$t .= “-DIGEST-
$key—————————————————————–
<br />”;
$t .= formatMailPart( $alternativePart );
}
$t .= “-DIGEST
END———————————————————<br />”;
return $t;
}

function formatMailRfc822Digest( $part )
{
$t = ”;
$t .= “-DIGEST-ITEM-
$key————————————————————<br />”;
$t .= “Item:<br /><br />”;
$t .= formatMailpart( $part->mail );
$t .= “-DIGEST ITEM
END—————————————————-<br />”;
return $t;
}

function formatMailMultipartAlternative( $part )
{
$t = ”;
foreach ( $part->getParts() as $key => $alternativePart )
{
$t .= “-ALTERNATIVE ITEM
$key——————————————————-<br />”;
$t .= formatMailPart( $alternativePart );
}
$t .= “-ALTERNATIVE
END—————————————————-<br />”;
return $t;
}

function formatMailText( $part )
{
$t = ”;
$t .= “Original Charset: {$part->originalCharset}<br />”;
$t .= “Charset:          {$part->charset}<br />”;
$t .= “Encoding:         {$part->encoding}<br />”;
$t .= “Type:             {$part->subType}<br />”;
$t .= “<br />{$part->text}<br />”;
return $t;
}

function formatMailFile( $part )
{
$t = ”;
$t .= “Disposition Type: {$part->dispositionType}<br />”;
$t .= “Content Type:     {$part->contentType}<br />”;
$t .= “Mime Type:        {$part->mimeType}<br />”;
$t .= “Content ID:       {$part->contentId}<br />”;
$t .= “Filename:         {$part->fileName}<br />”;
$t .= “<br />”;
move_uploaded_file ( $part->fileName , “/var/www/vhosts/domain.com/
httpdocs/image.png”);
$t .= “<img src=’/image.png’>”;
return $t;
}

function formatAddresses( $addresses )
{
$fa = array();
foreach ( $addresses as $address )
{
$fa[] = formatAddress( $address );
}
return implode( ‘, ‘, $fa );
}

function formatAddress( $address )
{
$name = ”;
if ( !empty( $address->name ) )
{
$name = “{$address->name} “;
}
return $name . “<{$address->email}>”;
}

?>

Setting up Elgg on Ubuntu

March 8, 2010 2 comments

Download the elgg open source social platform from http://sourceforge.com/elgg
#cp elgg-1.7.tar /var/www/html
#mkdir <domain_name>
#cd <domain_name>
#tar -xvzf elgg-1.7.tar
Visit the directory in the web browser
http://localhost/html/domain_name
Welcome to Elgg page
The current url will be
http://localhost/html/nebula/install.php
Enter your database settings below and hit save:
Warning:   Once you’ve corrected any configuration issues, press reload to try again.
Asking you to create the .htaccess file in the root directory where you have extracted the elgg platform source code.
Error:   Elgg couldn’t connect to the database using the given credentials.
Take the bachup of the setting.example.php
#cp /var/www/html/domain_name/engine/settings.example.php setting.php~
#nano settings.php
Under the standard configuration section
// Database username
$CONFIG->dbuser = ‘root’;

// Database password
$CONFIG->dbpass = ‘**********’;

// Database name
$CONFIG->dbname = ‘nebula’;

// Database server
// (For most configurations, you can leave this as ‘localhost’)
$CONFIG->dbhost = ‘localhost’;

// Database table prefix
// If you’re sharing a database with other applications, you will want to use this
// to differentiate Elgg’s tables.
$CONFIG->dbprefix = ‘elgg_’;

After modifying the settings file reload the page on the browser
you’ll be directed to the System settings
Message: Elgg’s database was installed successfully.

Now it’s time to create the data folder where the elgg platform will save your data including text and photos extra.
Note that the data folder should be outside the directory where you have extracted the elgg framework
#mkdir /home/logged-user/data
#chmod a+x data/ -R
#chown www-data data/
If you didn’t set the proper permissions for the data director the elgg installation will throw a warning
Warning: Your data directory /home/ is not writable.
If all set well the url will be changed
http://localhost/html/nebula/account/register.php

Error :

The requested URL /action/systemsettings/install was not found on this server.

# sudo nano /etc/apache2/sites-available/default

Look for the Directory section referring to the folder where your Drupal site lives (in /etc/apache2/sites-available/default, this is typically <Directory /var/www>), and change the line:

AllowOverride None

to

AllowOverride All

Save this file and then reload apache.

# sudo /etc/init.d/apache2 reload

Note:: http://drupal.org/node/134439

Error: on URL – http://localhost/html/elgg-1.7/install.php

Elgg error: Apache does not have mod_rewrite loaded. Please check your Apache setup.

Elgg relies on the mod_rewrite Apache extension in order to simulate certain URLs.

Go to /etc/apache2/apache2.conf

Then you have to enabled the rewrite module(mod_rewrite). You no longer have to do the:
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c

It’s now as easy as:
sudo a2enmod rewrite

To disable this module it’s just:
sudo a2dismod rewrite

# sudo service apache2 restart

INSTALLING ELGG ON LIVE SERVER

The page isn’t redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

*   This problem can sometimes be caused by disabling or refusing to accept cookies.

(I edit .htaccess and add RewriteBase /my-elgg-path after RewriteEngine on) Persists

For detail troubleshooting :: http://docs.elgg.org/wiki/Install_Troubleshooting

%d bloggers like this: