Jump To …

iWare.php

We expect (but do not insist) the file to be PSR-compatible.

The name of the file must be $unique_name.php. If your name happens to be identical to another script, we will notify you and you must modify suitably.

The name of the class must be Netenberg_Script_$unique_name.

The class must derive from Netenberg_Script.

class Netenberg_Script_iWare extends Netenberg_Script
{

This function is called as part of the actual installation process (Step 3).

$parameters is a dictionary that contains the values supplied by the user (Step 1) in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function install($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

This is an abstracted cURL object. You may use it for the sake of simplicity and also for ease of debugging. The full extent of this singleton is (will be made) available in the guide.

        $curl = new Netenberg_cURL;

You are encouraged to employ the usage of steps as follows:

 $step = 0;

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...

 log_('DEBUG', sprintf(_('Step %d'), ++$step));
 ...
 ...
 ...
        $step = 0;

In this step, a fresh database is being created via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        list(
            $parameters['mysql_hostname'],
            $parameters['mysql_username'],
            $parameters['mysql_password'],
            $parameters['mysql_database']
        ) = $control_panel->insertMySQL();

In this step, the source archive is being downloaded and extracted to the desired directory via the control panel singleton.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $operating_system->transpose(
            'http://www.iwarecms.nl/downloads/IWARE_5.0.4.zip',
            array(
                'IWARE_5.0.4/*' => sprintf(
                    '%s/%s',
                    $parameters['document_root'],
                    $parameters['directory']
                ),
            )
        );

In this step, we are changing permissions of the whole directory to 777 recursively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        if (!$control_panel->hassuEXEC()) {
            $operating_system->chmod(sprintf(
                '%s/%s',
                $parameters['document_root'],
                $parameters['directory']
            ), 777, true);
        }

In this step, we invoke the iWare installation wizard (step=2).

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install',
                $parameters['domain'],
                $parameters['directory']
            ),
            'GET',
            array(),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=1, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=1',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=2, where %s refer to domain and directory respectively. with POST parameters SLA and SLA_Agree.

POST Parameters will be sent as SLA=contents&SLA_Agree=1 alongwith with URL.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=2',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'SLA' => file_get_contents(sprintf(
                    '%s/%s/admin/docs/License.txt',
                    $parameters['document_root'],
                    $parameters['directory']
                )),
                'SLA_Agree' => '1',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=3, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=3',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=4, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=4',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(

$parameters['mysql_database'] refers to Mysql Database.

                'DB_Database' => $parameters['mysql_database'],

$parameters['mysql_hostname'] refers to MySQL Hostname.

                'DB_Hostname' => $parameters['mysql_hostname'],

$parameters['mysql_password'] refers to MySQL Password.

                'DB_Password' => $parameters['mysql_password'],

$parameters['mysql_username'] refers to MySQL Username.

                'DB_Username' => $parameters['mysql_username'],
                'TB_Docs' => 'docs',
                'TB_Groups' => 'groups',
                'TB_Layout' => 'layout',

iware_ is the table prefix prefixed with names of MySQL tables which will be created during installation.

                'TB_Prefix' => 'iware_',
                'TB_Users' => 'users',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=6, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=6',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'Charset' => 'ISO-8859-1',
                'DB_Database' => $parameters['mysql_database'],
                'DB_Hostname' => $parameters['mysql_hostname'],
                'DB_Password' => $parameters['mysql_password'],
                'DB_Username' => $parameters['mysql_username'],
                'Date_Format' => 'm/d/Y',
                'Language' => 'US_ENGLISH',
                'TB_Docs' => 'docs',
                'TB_Groups' => 'groups',
                'TB_Layout' => 'layout',
                'TB_Prefix' => 'iware_',
                'TB_Users' => 'users',
                'Time_Format' => 'h:i:s',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=7, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=7',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'Charset' => 'ISO-8859-1',
                'DB_Database' => $parameters['mysql_database'],
                'DB_Hostname' => $parameters['mysql_hostname'],
                'DB_Password' => $parameters['mysql_password'],
                'DB_Username' => $parameters['mysql_username'],
                'Date_Format' => 'm/d/Y',
                'Language' => 'US_ENGLISH',
                'Mail_Handler' => 'Linux',
                'Mail_SMTP' => '0.0.0.0',
                'TB_Docs' => 'docs',
                'TB_Docs' => 'docs',
                'TB_Groups' => 'groups',
                'TB_Layout' => 'layout',
                'TB_Prefix' => 'iware_',
                'TB_Users' => 'users',
                'Time_Format' => 'h:i:s',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=8, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=8',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'Charset' => 'ISO-8859-1',
                'DB_Database' => $parameters['mysql_database'],
                'DB_Hostname' => $parameters['mysql_hostname'],
                'DB_Password' => $parameters['mysql_password'],
                'DB_Username' => $parameters['mysql_username'],
                'Date_Format' => 'm/d/Y',
                'Editor' => 'xinha',
                'Language' => 'US_ENGLISH',
                'Mail_Handler' => 'Linux',
                'Mail_SMTP' => '0.0.0.0',
                'TB_Docs' => 'docs',
                'TB_Groups' => 'groups',
                'TB_Layout' => 'layout',
                'TB_Prefix' => 'iware_',
                'TB_Users' => 'users',
                'Time_Format' => 'h:i:s',
            ),
            array(),
            array()
        );

In this step we are making a POST Request to the URL http://%s/%s/admin/install/index.php?inst_pg=9, where %s refer to domain and directory respectively.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));
        $curl->request(
            sprintf(
                'http://%s/%s/admin/install/index.php?inst_pg=9',
                $parameters['domain'],
                $parameters['directory']
            ),
            'POST',
            array(
                'Charset' => 'ISO-8859-1',
                'DB_Database' => $parameters['mysql_database'],
                'DB_Hostname' => $parameters['mysql_hostname'],
                'DB_Password' => $parameters['mysql_password'],
                'DB_Username' => $parameters['mysql_username'],
                'Date_Format' => 'm/d/Y',
                'Editor' => 'xinha',
                'Install_Type' => 'NORMAL',
                'Language' => 'US_ENGLISH',
                'Mail_Handler' => 'Linux',
                'Mail_SMTP' => '0.0.0.0',
                'TB_Docs' => 'docs',
                'TB_Groups' => 'groups',
                'TB_Layout' => 'layout',
                'TB_Prefix' => 'iware_',
                'TB_Users' => 'users',
                'Time_Format' => 'h:i:s',
            ),
            array(),
            array()
        );

In some cases installed script dumps some pre-defined values as username and/or password and/or email and/or FirstName and/or LastName to the database. It needs to be changed to user-defined values. Then we have to update the desired table using UPDATE queries.

        log_('DEBUG', sprintf(_('Step %d'), ++$step));

This statement makes connection to the installtion database using mysqli_connect function.

        $mysqli_connect = mysqli_connect(
            $parameters['mysql_hostname'],
            $parameters['mysql_username'],
            $parameters['mysql_password']
        );

This statement selects the desired database using mysqliselectdb function.

        mysqli_select_db($mysqli_connect, $parameters['mysql_database']);

This statement updates desired table(here it is iware_users) and dumps the user-defined values to the database instead of pre-defined values using mysqli_query function.

        mysqli_query($mysqli_connect, sprintf(
            "UPDATE iware_users SET username = '%s', password = '%s' WHERE id = 1",

mysqli_real_escape_string escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.

            mysqli_real_escape_string(
                $mysqli_connect, $parameters['username']
            ),
            mysqli_real_escape_string(
                $mysqli_connect,

Here password encryption message used is crypt.

Different types of encryptions may be used in the installation scripts are md5 or sha1 etc.

                crypt($parameters['password'], $parameters['password'])
            )
        ));

mysqli_close function closed previously established mysql connection.

        mysqli_close($mysqli_connect);

This indicates a success status (and is mandatory).

        log_('DEBUG', 'Success');

This allows the core system to register this installation within the user account (and is mandatory).

        return parent::install($parameters);
    }

This function provides the category (and is mandatory).

    public function getCategory()
    {
        return _('Portals/CMS');
    }

This function provides the description (and is mandatory).

    public function getDescription()
    {
        return _('iWare is a powerful and versatile web based content management system designed to make creating a professional web presence easy  without the associated hassles of learning to program or master a 3rd party application.');
    }

This function provides the details of an installed copy (and is mandatory).

$parameters is a dictionary that contains domain, directory, and document_root.

    public function getDetails($parameters)
    {
        $iware_php = sprintf(
            '%s/%s/admin/iware.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($iware_php)) {
            return false;
        }
        $contents = file_get_contents($iware_php);

This statemnt performs a regular expression match on version, subversion and minorversion of the installed copy on the contents of iware.php file.

        preg_match('#Professional\s*([\d+\.]+)#', $contents, $version);

        return array(
            'version' => $version[1],
        );
    }

This function builds the form presented to the user (Step 1) (and is mandatory). It is built upon the Zend_Form component of Zend Framework.

    public function getForm()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is an abstracted form object derived from Zend_Form. The full extent of this class is (will be made) available in the guide.

        $form = new Netenberg_Form();

This statement adds the domain selector (and is mandatory).

        $form->addElement('select', 'domain', array(
            'label' => _('Domain'),
            'multiOptions' => $control_panel->getDomains(),
            'required' => true,
        ));

This statement adds the directory selector (and is mandatory).

        $form->addElement('text', 'directory', array(
            'description' => _('Leave this field empty if you want to install in the web root for the domain you\'ve selected (i.e., http://domain.com/ ). If you\'d like to install in a subdirectory, please enter the path to the directory relative to the web root for your domain. The final destination subdirectory should not exist, but all others can exist (e.g., http://domain.com/some/sub/directory - In this case, "directory" should not already exist).'),
            'filters' => array(new Netenberg_Filter_Directory()),
            'label' => _('Directory'),
            'validators' => array(new Netenberg_Validate_Directory()),
        ));

This statement adds the username textfield (and is mandatory).

        $form->addElement('text', 'username', array(
            'label' => _('Username'),
            'required' => true,
        ));

This statement adds the password textfield (and is mandatory).

        $form->addElement('password', 'password', array(
            'label' => _('Password'),
            'required' => true,
        ));

This statement adds the password repeat textfield (and is mandatory).

        $form->addElement('password', 'password_', array(
            'label' => _('Password (Repeat)'),
            'required' => true,

This validator statement checks whether this field is identical to value of Password Textfield.

            'validators' => array(
                array('Identical', false, array(
                    'token' => 'password',
                )),
            ),
        ));

This statement adds the Submit button to the form (and is mandatory).

        $form->addElement('button', 'submit');

This statement adds the Reset button to the form (and is mandatory).

        $form->addElement('button', 'reset');

This statement places the domain and directory selectors under the display group Location Details.

        $form->addDisplayGroup(
            array('domain', 'directory'),
            'location_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => 'Location Details',
            )
        );

This statement places username, password and passsword_ under the display group Administrator Details.

        $form->addDisplayGroup(
            array(
                'username',
                'password',
                'password_',
            ),
            'administrator_details',
            array(
                'decorators' => $form->getDefaultGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
                'legend' => _('Administrator Details'),
            )
        );

This statement places the Submit and Reset buttons at the end of the form.

        $form->addDisplayGroup(
            array('submit', 'reset'),
            'buttons',
            array(
                'decorators' => $form->getButtonGroupDecorator(),
                'disableLoadDefaultDecorators' => true,
            )
        );

        return $form;
    }

This function provides the image (and is mandatory).

    public function getImage()
    {
        return 'http://www.iwarecms.nl/images/logo.jpg';
    }

This function provides the name (and is mandatory). The name must be unique.

    public function getName()
    {
        return 'iWare';
    }

This function provides the post-installation overview (and is mandatory).

$parameters is a dictionary that contains the values supplied by the user like domain, directory and username and/or password and/or email etc.

    public function getItems($parameters)
    {
        return array(
            _('Backend') => array(

This statement provides the URL for Backend page. Backend page is a login-page which is used to login into Administrator's Account.

                sprintf(
                    '<a href="http://%s/%s/admin/index.php" target="_blank">http://%s/%s/admin/index.php</a>',
                    $parameters['domain'],
                    $parameters['directory'],
                    $parameters['domain'],
                    $parameters['directory']
                ),
                sprintf(_('Username: %s'), $parameters['username']),
                sprintf(_('Password: %s'), $parameters['password']),
            ),
        );
    }

This function provides the requirements (and is mandatory).

    public function getRequirements()
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

        $apache = $control_panel->getApache();
        $mysql = $control_panel->getMySQL();
        $php = $control_panel->getPHP();

        return array(

This statement checks whether enough space is available in your account to install this script.

            'Disk Space' => (
                $control_panel->getSize() >= $this->getSize()
            )? true: false,

This statement checks whether installed Apache's version is greater than 1.

            'Apache 1+' => (
                strpos($apache, 'Apache/1') !== false
                or
                strpos($apache, 'Apache/2') !== false
            )? true: false,

This statement checks whether installed MySQL's version is greater than 5.0.

            'MySQL 5.0+' => (
                strpos($mysql, 'Distrib 5') !== false
            )? true: false,

This statement checks whether installed PHP's version is greater than 5.0

            'PHP 5.0+' => (preg_match(
                '#PHP Version\s*=>\s*(5\.[0-9])#', $php
            ) === 1)? true: false,
        );
    }

This function provides the size (in bytes) (and is mandatory).

    public function getSize()
    {
        return 2936013;
    }

This function provides the slug (and is mandatory). The slug must be unique.

    public function getSlug()
    {
        return 'iware';
    }

This function provides the URLs (and is mandatory).

We expect (but do not insist) URLs for four pages to be part of the array. They are URLs of Home, Community, Documentation and Support or Forum Pages.

    public function getUrls()
    {
        return array(
            _('Home') => 'http://www.iwarecms.nl',
            _('Support') => 'http://www.iwarecms.nl/forum',
        );
    }

This function provides the version (and is mandatory).

    public function getVersion()
    {
        return '5.0.4';
    }

This function is called as part of the actual uninstallation process

$parameters is a dictionary that contains the values supplied by the user in addition to a few system-specific values. The full extent of this dictionary is (will be made) available in the guide.

    public function uninstall($parameters)
    {

This is a singleton that you can use to access control panel-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $control_panel = Zend_Registry::get('control_panel');

This is a singleton that you can use to access operating system-specific functions (see below for examples). The full extent of this singleton is (will be made) available in the guide.

        $operating_system = Zend_Registry::get('operating_system');

        $config_php = sprintf(
            '%s/%s/admin/config.php',
            $parameters['document_root'],
            $parameters['directory']
        );
        if (!is_file($config_php)) {
            return false;
        }
        $contents = file_get_contents($config_php);

This statement performs a regular expression match to fetch database name from the contents of config.php

        preg_match('#IWARE_DATABASE"\s*,\s*"([^"]*)#', $contents, $database);

This statement performs a regular expression match to fetch database username from the contents of config.php

        preg_match(
            '#IWARE_USERNAME"\s*,\s*"([^"]*)#', $contents, $mysql_username
        );

In this step, we remove the database via the control panel singleton.

        $control_panel->deleteMySQL($mysql_username[1], $database[1]);

        $operating_system->dispose(sprintf(
            '%s/%s', $parameters['document_root'], $parameters['directory']
        ));

This allows the core system to unregister this installation within the user account (and is mandatory).

        return parent::uninstall($parameters);
    }
}