php

You are currently browsing articles tagged php.

  1. Download the PHP source in according with your environment:
    $ php -v
    PHP 5.2.11 (cli) (built: Dec 12 2009 13:19:08)
    
  2. Extract in a temporary folder
    $ cd ~ && tar zxvf php-5.2.11.tar.gz && cd php-5.2.11
    
  3. Patch the ext/iconv/iconv.c file remove the lib on #define iconv libiconv so that the code reads like this:
    #ifdef HAVE_LIBICONV
    #define iconv iconv
    #endif
  4. Patch the ext/tidy/tidy.c file moving the line 34: #include “tidy.h” to line 24 of tidy.c so that the code reads like this:
    #ifdef HAVE_CONFIG_H
    #include "config.h"
    #endif
    
    #include "tidy.h"
    #include "php.h"
    #include "php_tidy.h"
    
    #if HAVE_TIDY
    
    #include "php_ini.h"
    
  5. Instruct the system to build universal binaries, that will work on both 32 and 64 bit systems by entering the following commands in the terminal console:
    $ MACOSX_DEPLOYMENT_TARGET=10.6
    $ CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
    $ CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
    $ LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
    $ export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET
  6. Configure & make
    $ LIBS=-lresolv ./configure --with-tidy=shared && make
  7. Copy the module in MAMP
    $ cp ./modules/tidy.so /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/
  8. Enable the module in the /Applications/MAMP/conf/php5/php.ini adding the following line in the extension section:
    extension=tidy.so
  9. Restart the webserver
  10. Check with php_info() if the tidy extension is loaded correctly ;-)

Reference Links:

Tags: , , ,

<?php 

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
module_load_include('inc', 'node', 'node.pages');

$node = new stdClass();

//Set up default values, if required.
node_object_prepare($node);

//Specify the content type
$node->type = 'profile';

//Specify an author for the node
$node->uid = 1;

//Add the title
$node->title = 'Test';

//Add the CCK fields data
$node->field_name[0]['value'] = 'Name';
$node->field_surname[0]['value'] = 'Surname';

//Save the node object into the database.
node_save($node);

//Debug the created node
print '<pre>';
print_($node);
print '</pre>';

Tags: ,

I’ m happy to announce Ortro is also used in Telecom Italia now.

An older version of Ortro (updated to the latest version right in these days) was already used in such departments of Telecom Italia as an experimental software for application monitoring.

But in the last time I had a confirm Ortro is, as I like to define it, mainly a “Framework” helping you to solve the daily problems encountered in monitoring and job activities.

Some months ago some people in Telecom Italia asked me if Ortro could be used as a valid alternative to a commercial product specialized in secure file transfer activity.

So I‘ve realized a proof of concept keeping in mind the 80-20 rule and after a second phase of security, performance and functional tests Ortro was result to be a valid choice to replace the commercial product.

At writing time some real pilot projects was identified for an “on the job” final test.

The results of these activities are the actual version of Ortro (1.3.4) and the advanced file transfer plugin.

Following these positive results Telecom Italia asked me to verify if Ortro could be also used as an alternative to some commercial enterprise scheduler software Telecom is using.

So another challenge is started…

Stay tuned… the 1.4 is around the corner :)

Tags: , ,

The Scp Transfer plugin allows Ortro to transfer files between remote hosts in a secure way.

This release add the capability to use compression during transfer and enable the recursive copy of files and folders.
Download
and enjoy ;-)

Tags: , , ,

If you use both Pear and Zend framework you may want to extend the Zend_Auth adapters to use all the containers shipped with the Pear::Auth package.

Let’s go to create the class implements the Zend_Auth_Adapter_Interface starting from the Zend_Auth_Adapter_Ldap class.

Tags: , , ,

The first beta version of Minerva (Ldap Password Changer) at version 0.5 has been released!

Minerva is a very little and simple PHP application with only one scope: permit at your openldap accounts to simply change its password without use other application (such as a webmail) that you can have or not.

Download it and tell us what you think about it!

Tags: , , , , ,

Requirements

Simple ReCaptcha

Zend Form Class

source: application/forms/ReCaptcha.php

<?php
class Form_ReCaptcha extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');
        //Add your elements here...

        $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey);

        $captcha = new Zend_Form_Element_Captcha('challenge',
              array('captcha'        => 'ReCaptcha',
                    'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $recaptcha)));

        $this->addElement($captcha);

        // Add the submit button
        $this->addElement('submit', 'submit', array('label' => 'Submit'));
    }
}
?>

Zend Controller Class

source: application/controller/ReCaptchaController.php

<?php
class ReCaptchaController extends Zend_Controller_Action
{
    public function indexAction()
    {
        require_once APPLICATION_PATH . '/forms/Contact.php';

        $form = new Form_ReCaptcha();

        if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) {
                $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey);

                $result = $recaptcha->verify($this->_getParam('recaptcha_challenge_field'),
                                             $this->_getParam('recaptcha_response_field'));
                if (!$result->isValid()) {
                    //ReCaptcha validation error
                    //Your action here...
               }
            }
        }
        $this->view->form = $form;
    }
}
?>

Customized ReCaptcha

You may also want to internationalizing or change colors to ReCaptcha, to do it you need to specify some options for the Zend_Service_ReCaptcha object.
See the ReCaptcha wiki for a complete list of available options.

Zend Form Class

source: application/forms/ReCaptcha.php

<?php
class Form_ReCaptcha extends Zend_Form
{
    public function init()
    {
        $this->setMethod('post');
        //Add your elements here...
        $recaptcha = new Zend_Service_ReCaptcha($publickey, $privatekey);

        //Translate in your language
        $recaptcha_it_translation =
            array('visual_challenge' => "Verifica video",
                  'audio_challenge' => "Verifica audio",
                  'refresh_btn' => "Effettua una nuova verifica",
                  'instructions_visual' => "Scrivi le due parole",
                  'instructions_audio' => "Scrivi quello che ascolti",
                  'help_btn' => "Aiuto",
                  'play_again' => "Riascolto di nuovo l'audio",
                  'cant_hear_this' => "Scarica l'audio come MP3",
                  'incorrect_try_again' => "Incorretto. Prova ancora.");

        $recaptcha->setOption('custom_translations', $recaptcha_it_translation);
        //Change theme
        $recaptcha->setOption('theme', 'clean');

        $captcha = new Zend_Form_Element_Captcha('challenge',
              array('captcha'        => 'ReCaptcha',
                    'captchaOptions' => array('captcha' => 'ReCaptcha',
                                             'service' => $recaptcha)));

        $this->addElement($captcha);

        // Add the submit button
        $this->addElement('submit', 'submit', array('label' => 'Submit'));
    }
}
?>

Tags: , , ,

This version includes some enhancements and fixes.

In evidence the capability to lock a host or a system so to lock all jobs at once such as the possibility to receive notification on job event (i.e. start and end).

In addition the File Watch plugin was added and the Service Check plugin now is able to check multiple services at once allowing to select the most commonly used service directly from a default list.

Help and comments are always welcome, see http://www.ortro.net for full changelog and details.

Ortro 1.3.3 and the plugins may be downloaded as usual from:

http://www.ortro.net/download

Tags: , , ,

This version includes some enhancements and fixes.

Now the Pear::Auth package is used for authentication and the timeout for long running jobs was added.
The memory free and mysql database table check plugins were added.
In addition the installer was improved and FCKeditor library was updated.

Help and comments are always welcome, see http://www.ortro.net for full changelog and details.

Tags: , , , ,

Requirements:

- PHP5
- PEAR::Net_Nmap
- nmap

<?php

/**
 * Scan network to retrieve hosts and services information.
 */

require_once 'Net/Nmap.php';

//Define the target to scan
$target = array('127.0.0.1','www.yourserver.com');

$options = array('nmap_binary' => '/usr/local/bin/nmap');

try {
    $nmap = new Net_Nmap($options);

    //Enable nmap options
    $nmap_options = array('os_detection' => true,
                          'service_info' => true,
                          'port_ranges' => 'U:53,111,137,T:21-25,80,139,8080',//to scan only specified ports
                          );

    $nmap->enableOptions($nmap_options);

    //Scan target
    $res = $nmap->scan($target);

    //Get failed hosts
    $failed_to_resolve = $nmap->getFailedToResolveHosts();

    if (count($failed_to_resolve) > 0) {
        echo 'Failed to resolve given hostname/IP: ' .
             implode (', ', $failed_to_resolve) .
             "\n";
    }

    //Parse XML Output to retrieve Hosts Object
    $hosts = $nmap->parseXMLOutput();

    //Print results
    foreach ($hosts as $key => $host) {
        echo 'Hostname: ' . $host->getHostname() . "\n";
        echo 'Address: ' . $host->getAddress() . "\n";
        echo 'OS: ' . $host->getOS() . "\n";
        echo 'Status: ' . $host->getStatus . "\n";
        $services = $host->getServices();
        echo 'Number of discovered services: ' . count($services) . "\n";
        foreach ($services as $key => $service) {
            echo "\n";
            echo 'Service Name: ' . $service->name . "\n";
            echo 'Port: ' . $service->port . "\n";
            echo 'Protocol: ' . $service->protocol . "\n";
            echo 'Product information: ' . $service->product . "\n";
            echo 'Product version: ' . $service->version . "\n";
            echo 'Product additional info: ' . $service->extrainfo . "\n";
        }
    }
} catch (Net_Nmap_Exception $ne) {
    echo $ne->getMessage();
}
?>

Tags: , , ,

« Older entries