16
Jun

Net_Nmap 1.0.2 released

Pear::Net_Nmap is a simple interface for Nmap,
the free and open source utility for network exploration or security auditing.

Net_Nmap can be used to auto discovery hosts and services in your network or simply to parse Nmap XML output.

The 1.0.2 is a small bug fixing release, see below the changelog:
- Fixed. #16268 OS Guess wrong Sort Order
- Fixed. #16336 Error getting OS if the osmatch tag is not present in the XML

Download and enjoy ;-)

23
Apr

ReCaptcha with Zend Form

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'));
    }
}
?>
18
Mar

lighttpd + mod_cache on debian lenny

~# mkdir ~/tmp && cd ~/tmp
~# apt-get install dpkg-dev
~# apt-get source lighttpd
~# apt-get build-dep lighttpd
~# wget http://www.linux.com.cn/modcache/lighttpd-1.4.19.modcache.v.1.6.0.patch
~# cd lighttpd-1.4.19
~# patch -p0 ../lighttpd-1.4.19.modcache.v.1.6.0.patch
~# echo debian/tmp/usr/lib/lighttpd/mod_cache.so > debian/lighttpd.install
~# dpkg-buildpackage  -uc -b
~# ls -l ../*.deb

Install the debian packages with dpkg and enjoy :-)

Reference Links:
- APT HOWTO – Working with source packages

28
Feb

How to print the next line after a matching regexp with sed

~ $ cat example.txt
first line
second line
third line
another line

~ $ sed -n ‘/second/{n;p;}’ < example.txt
third line

~ $ sed -n ‘/second/{n;p;n;p;}’ < example.txt
third line
another line

24
Nov

Ortro 1.3.3 Released!

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

14
Jul

Ortro 1.3.2a available

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.

20
Jun

Enabling fingerprint scanner on ThinkPad running Ubuntu Hardy in four steps

Install the ThinkFinger utilities and the relative PAM module:

~$ sudo apt-get install thinkfinger-tools libpam-thinkfinger

Acquire and test your fingerprint:

~$ sudo tf-tool --acquire
~$ sudo tf-tool --verify

Enable the PAM module:

~$ sudo /usr/lib/pam-thinkfinger/pam-thinkfinger-enable

Enjoy :-)

Resources
- wiki.ubuntu.com/ThinkFinger
- Bug #203973 in thinkfinger (Ubuntu)

19
Jun

Discovery hosts and services with PHP and Nmap

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();
}
?>
04
Jun

Execute SQL script from a file using PHP

The code below allows to retrieve and execute all SQL statements defined in a SQL script file removing all comments.

<?php
$sql_file = 'test.sql';

$contents = file_get_contents($sql_file);

// Remove C style and inline comments
$comment_patterns = array('/\/\*.*(\n)*.*(\*\/)?/', //C comments
                          '/\s*--.*\n/', //inline comments start with --
                          '/\s*#.*\n/', //inline comments start with #
                          );
$contents = preg_replace($comment_patterns, "\n", $contents);

//Retrieve sql statements
$statements = explode(";\n", $contents);
$statements = preg_replace("/\s/", ' ', $statements);

require_once 'MDB2.php';

$mdb2 =& MDB2::connect('mysql://usr:pw@localhost/dbnam');

foreach ($statements as $query) {
    if (trim($query) != '') {
        echo 'Executing query: ' . $query . "\n";
        $res = $mdb2->exec($query);

        if (PEAR::isError($res)) {
            die($res->getMessage());
        }
    }
}
?>

I have used Pear::MDB2 abstraction layer to interact with the database but the code above should work with any other db abstraction layer or PHP built-in functions.

27
May

Ortro 1.3.1 released!

This version includes some enhancements, and one very important security fix, a cross-site scripting (XSS) vulnerability allows remote attackers to inject arbitrary web script or HTML.

We recommend everyone update immediately.

In addition to the security fix, the Net_Nmap library was updated making the autodiscovery without OS detection more faster, the capability to upload files for plugins and the Web Service Test Plugin using SoapUI were added.

The SimpleTest and FCKeditor libraries were updated.

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

Ortro 1.3.1 and the plugins may be downloaded as usual from:
http://www.ortro.net/download