• top|support|docs|iworx-cp|developer

Overview

This guide is designed to help a web developer add a script to the ScriptWorx system within InterWorx-CP. The guide will take the developer on a (mostly) step-by-step process that will lead to a working script install. If you have already added your script but it’s not working, see Debugging your Custom Script.

Prerequisites

In order to be able to successfully add a custom script to ScriptWorx you must have the following:

  1. Working knowledge of PHP
  2. Basic understanding of Object-Oriented Principles.

How ScriptWorx Works

The installation of a script via ScriptWorx happens in a very systematic manner. The Script base class has an install function that runs and executes a series of functions that can be overridden in the subclass. If any of the steps in the process fail, the installation is aborted and the script files and database entries are removed. The following is the flow of functions during the installation process:

    // $this refers to a ScriptWorx object.
    // $args is the array of user input from the interface.
 
    // unpack the archive
    // The archive is decompressed into a location in the temporary directory.
    $this->_unpack( $args )
 
    // Perform any necessary preinstall tasks.
    $this->_preInstall( $args );
 
    // install the dbs
    // This step imports any .sql files to setup the database tables needed by the script.
    $this->_installDBs();
 
    // Configures/Updates the database tables (if necessary) for the script
    // Typically, this involves adding the administrator information to the proper fields in 
    // the database. 
    $this->_installDBConfig( $args );
 
    // Configure the config file for the script.
    // Writes out the proper config values to the configuration file(s).
    $this->_installFileConfig( $args );
 
    // Remove any files/dirs that are only used for installation
    $this->_removeInstallFiles();
 
    // Set any permissions on files/directories the script needs
    $this->_setPermissions();
 
    // post_install- take care of any oddities, creation of dirs, etc
    function _postInstall() {
 
    $temp_install_dir    = $this->_getInstallDir();
    $main_dir_htaccess   = "$temp_install_dir/sample.htaccess";
    $admin_dir_htaccess  = "$temp_install_dir/admin/sample.htaccess";
    $mvto_admin_htaccess = "$temp_install_dir/admin/.htaccess";
 
 
    $retval = $this->scriptworx_mv( $main_dir_htaccess,
                                    "$temp_install_dir/.htaccess",
                                    true );
 
    $retval2 = $this->scriptworx_mv( $admin_dir_htaccess,
                                     $mvto_admin_htaccess,
                                     true );
 
    if( $retval  !== true ) {
      return( $retval );
    } else if( $retval2 !== true ) {
    	return( $retval2 );
   	} 
 
    return( true );
 
    // Move the Script to its final location
    function _moveToFinalLocation( $args ) {
 
    $final_location   = $this->getDirLocation();
    $temp_install_dir = $this->_getInstallDir();
 
    $retval = $this->scriptworx_mv( $temp_install_dir . '/*',
                                    $final_location,
                                    true );
 
    if( $retval !== true ) {
      return( $retval );
    }
 
    return( true );
  }
    
    // Create an .htaccess file if needed by the script
      $this->_unpack( $args )
        if( $retval !== true ) {
             return( $retval );
          } else if( $retval2 !== true ) {
          return( $retval2 );
          }
 

 If any of the functions do not return true, the installation will fail and the partially installed script will be removed.

Adding a Custom Script

There are three steps involved in adding a custom script to ScriptWorx.

  1. You must place your script in the correct place within the InterWorx-CP file tree.
  2. You must write a class that extends the Script base class and implements the necessary functions.
  3. You must place an entry in the language file that will be displayed when the script has been succesfully installed.

Placing the Script Archive in the Correct Place

The script you wish to add needs to be placed in a specific location so that it will be recognized by the ScriptWorx system. The following steps will guide you in placing the script in the proper location.

  1. SSH into the server
  2. cd to the /home/interworx/lib/scriptworx directory.
  3. Make a directory for your script in /home/interworx/lib/scriptworx. The directory should match the name of the script and should be all lowercase.
  4. cd to the newly created directory and make a version number directory for your script.
  5. cd to the version directory and place the script archive and any additional files you may need (such as an exported .sql file)
  6. The final directory structure should look something like this: /home/interworx/lib/scriptworx/<yourscript>/<version>

Example: Adding MediaWiki 1.5.2 to ScriptWorx

The archive name is mediawiki-1.5.2.tar.gz. We would create the following directories:

  • /home/interworx/lib/scriptworx/mediawiki
  • /home/interworx/lib/scriptworx/mediawiki/1.5.2/.

We would then move/copy the tarball to the /home/interworx/lib/scriptworx/mediawiki/1.5.2/ directory.

Placing the Custom Script Class in the Correct Place

  1. SSH into the server
  2. cd to the /home/interworx/include/scriptworx directory.
  3. Place <nameofCustomScript>.php in this directory.
  4. The final path your script should be: /home/interworx/include/scriptworx/<nameofCustomScript>.php

Example: Adding MediaWiki 1.5.2 Class to ScriptWorx

  1. Using your favorite editor, create MediaWiki.php.
  2. Copy or move MediaWiki.php to the /home/interworx/include/scriptworx directory.
  3. The final path to the script will be: /home/interworx/include/scriptworx/MediaWiki.php

Extending the Script Base Class

Adding a custom script to ScriptWorx is a relatively simple process. There are 11 functions that may need to be implemented in a your Script sublcass. You must also implement a constructor for you extension of the Script class. These are as follows:

function constructor();
function getCustomParams( $input = false );
function validateScript( $input );
function _unpack();
function _preInstall();
function _installDBConfig();
function _installFileConfig();
function _removeInstallFiles();
function _setPermissions();
function _postInstall();
function _moveToFinalLocation();
function _createHtaccessFile();
function _getRequiredDBs();
function _getRequiredDBUsers();

If any function does not need to be implemented, simply omit it from the class. For example, in many scripts, there are no pre-install or post-install tasks, so those functions would be omitted. Conceptually, extending the Script class falls into three separate steps:

  1. Defining and validating the interface.
  2. Installing the Script (unpacking the files, importing the database(s), modifying the configuration values).
  3. Cleaning up (Setting the proper permissions and extra files, deleting any unnecessary files, moving the script to the final location).

Implementing the Functions

All code comes from /home/interworx/include/scriptworx/sampleScript.php.

Constructor

The constructor sets a few vital pieces of information. The _package_glob and _package_ver_regex are essential in installing and getting your script to be properly listed within ScriptWorx.

 
  /**
   * create sampleScript Object
   */
 
  function sampleScript( $siteworx = false,
                         $version  = false,
                         $location = false ) {
 
    parent::Script( $siteworx,
                    $version,
                    $location );
 
    // Set up the initial variables.  The _name,
    // _package_glob, and _package_ver_regex all used to generate lists
    // in NodeWorx/SiteWorx and when unpacking archives.  It is essential
    // that these are correct or the script installation will not succeed.
 
    $this->_name              = "sampleScript";
    $this->_package_glob      = "sampleScript_*.tar.gz";
    $this->_package_ver_regex = "sampleScript_(.*).tar.gz";
 
    // if the archive you are using decompressses into one top
    // level directory, _dirHint should be set to a substring of that
    // directory name.  _dirHint defaults to false, so if it not set,
    // getScriptBaseDir will simply return the unpack location.
 
    $this->_dirHint           = "sampleScript"
    $this->_db_prefix         = "sampleScript_";
 
  }

getCustomParams()

This function dictates what is shown on the smarty install template. Basic information such as the location (directory to install to) and adminstrator user settings (user name, administrator e-mail, password) are provided by the base Script class. If you need to specify input fields for additional information, this is where they go. Below is a sample getCustomParams() function.

function getCustomParams( $input = false ) {
 
    // In here go the fields that will be used in smarty when displaying the
    // install screen.  These should be things that are essential to the
    // installation of the script and will need to be updated in the config
    // files/databases.
 
    $fields = array();
 
    // Get the admin fields from the parent class.  This can be
    // overridden if desired.
    // The admin fields are username, email address and password.
    $fields = parent::getAdminFields( $input );
 
    // Add our custom fields here.
    // custom fields need to go in the 'custom' array or they
    // will not be displayed.
 
    // These are two text fields that were added for the first and last name
 
    $fields['custom']['first_name'] =
      array( 'text'     => '##LG_SCRIPT_FIRSTNAME##',
             'name'     => 'first_name',
             'type'     => 'text',
             'size'     => '25',
             'value'    => $input === false ? '' : $input['first_name'],
             'required' => true,
             'disabled' => 0 );
 
    $fields['custom']['last_name'] =
      array( 'text'     => '##LG_SCRIPT_LASTNAME##',
             'name'     => 'last_name',
             'type'     => 'text',
             'size'     => '25',
             'value'    => $input === false ? '' : $input['last_name'],
             'required' => true,
             'disabled' => 0 );
 
 
    // Here is an example of adding a text area as a custom field
    // Note that the 'type' variable in the array changes to textarea.
 
    $fields['custom']['mission'] =
      array( 'text'       => '##LG_SCRIPT_MISSION##',
             'name'       => 'mission',
             'type'       => 'textarea',
             'size'       => '25',
             'value'      => '',
             'required'   => true,
             'disabled'   => 0 );
 
 
    // Here is an exmaple of adding a checkbox as a custom field
    // Note that the type is checkbox.
 
 
    $fields['custom']['zipcodes'] =
      array( 'text'       => '##LG_SCRIPT_ZIPCODES##',
             'name'       => 'zipcodes',
             'type'       => 'checkbox',
             'size'       => '25',
             'value'      => 'install_zipcodes',
             'required'   => false,
             'disabled'   => 0 );
 
 
    // And here is an exmaple of adding a drop-down box as a custom field.
 
    // Create and populate the array of options to be used for the dropdown.
    $options = array();
    $options[] = "Single User";
    $options[] = "Multi-User";
 
    // Note that the 'type' is select.
    $fields['custom']['single_user'] =
      array( 'text'       => '##LG_SCRIPT_SINGLE_USER##',
             'name'       => 'single_user',
             'type'       => 'select',
             'size'       => '25',
             'options'    => $options,
             'required'   => true,
             'disabled'   => 0 );
 
    return( $fields );
  }

 This function only defines the fields to display when installing the script. It does not validate any of the values/data submitted.

validateScript()

This function is used to validate the custom parameters defined in the getCustomParams() function. The POST array is taken as input. Values provided as input must be validated. Three helper functions should be used in order to validate the location, administrative options (username, email, and password) and basic options such as storage, databases needed and database users needed. Examples follow:

  function validateScript( $input ) {
 
    $errors = array();
 
    // Call the parent class function to validate the
    // Admin Options input values.
 
    $admin_ok = $this->_validateAdminOptions( $input );
 
    if( $admin_ok !== true ) {
      $errors = array_merge( $admin_ok, $errors );
    }
 
    // Call the parent class function to validate the location input value.
    
    $loc_ok = $this->_validateLocation( $input['location'] );
 
    if( $loc_ok !== true ) {
      $errors = array_merge( $loc_ok, $errors );
    }
 
    $opt_ok = $this->_validateOptions();
 
    if( $opt_ok !== true ) {
      $errors = array_merge( $errors, $opt_ok );
    }
 
    // Now we have to validate the custom fields we defined in getCustomParams()
    // Usually this means verifying that the value is set and not equal to null
    if( !isset( $input['first_name'] ) || $input['first_name'] == '' ) {
      $errors[] =
        array( 'name'   => 'first_name',
               'status' => false,
               'reason' => "##LG_EMPTY_REQUIRED_FIELD##" );
    }
 
    if( !isset( $input['last_name'] ) ||
        $input['last_name'] == '' ) {
      $errors[] =
        array( 'name'   => 'last_name',
               'status' => false,
               'reason' => "##LG_EMPTY_REQUIRED_FIELD##" );
    }
 
    if( !isset( $input['mission'] ) || $input['mission'] == '' ) {
      $errors[] =
        array( 'name'   => 'mission',
               'status' => false,
               'reason' => "##LG_EMPTY_REQUIRED_FIELD##" );
    }
   
    // We don't need to validate the checkbox
 
    // Validate the drop down
 
    if( !isset( $input['single_user'] ) ||
        $input['single_user'] == '' ) {
 
      $errors[] =
        array( 'name'   => 'single_user',
               'status' => false,
               'reason' => "##LG_EMPTY_REQUIRED_FIELD##" );
    }
 
    return( count( $errors ) == 0 ? true : $errors );
  }
 

_unpack()

The purpose of this function is to unpack the script archive into a temporary location. In this function, you must call generateTempDir() and setUnpackLocation( generated_temp_location ) for the script installation to behave properly. The unpack location is used later on when you need to reference the files of the script installation. Below is the contents of a sample unpack function:

 function _unpack() {
    global $IWORX_INI;
    // We need $IWORX_INI so we know where the tar and zip binaries are.
 
    // Index into the array of _scripts to pull out the
    // necessary information to build a path to the compressed archive.
    $file       = $this->_scripts[ $this->_version ]['file'];
    $base       = $this->_scripts[ $this->_version ]['base'];
    $version    = $this->_scripts[ $this->_version ]['version'];
 
    // Generate the temporary directory to unpack the archive into
    $unpack_dir = $this->generateTempDir();
 
    if( $unpack_dir === false ) {
      $error =
        array( 'name'   => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_UNTAR_ERROR##' );
      return( $error );
    }
 
    // Set the unpackLocation variable so that we can reference the 
    // unpack location in the future.
 
    $this->setUnpackLocation( $unpack_dir );
 
    // Build a path where we can find the tarball:
    $tarball_path = "$base/$version/$file";
 
    $cmd = $IWORX_INI['bin']['tar'] .
      " -xz" .
      " -C $unpack_dir" .
      " -f $tarball_path ";
 
    // If you have a zip archive, you need to use unzip.
    // $cmd = $IWORX_INI['bin']['unzip'] .
    //  " $tarball_path " .
    //  " -d $unpack_dir";
 
 
    // Decompress the Archive
    IWorxExec::exec( $cmd, $result, $retval );
   
    if( $retval != 0 ) {
      $error =
        array( 'name'   => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_UNTAR_ERROR##' );
      return( $error );
    }
 
    return( true );
}

 This will unpack the archive into a location on the /tmp partition. You will need to reference this location later on in the installation process ( via the getUnpackLocation() function).

_preInstall()

The _preInstall() function can be used to take care of any pre-installation tasks that are involved with script installation. It is called just after the _unpack() function but just before you install any necessary databases.

_installDBs()

The _installDBs() function is used to set up any necessary databases/tables for the script being installed. Typically, this is done by importing a .sql file distributed with the script or using a .sql file export created from a successfully installed script. Below is a sample _installDBs() function:

  function _installDBs() {
    global $IWORX_INI;
 
    // Get the top level directory within the temporary unpack location where 
    // the compressed script was decompressed. so we can build the proper path 
    // to our .sql data files we need to import.
    $dir = $this->_getInstallDir();
 
    // Create an array to hold the .sql files we are importing.
    $dbs_array = array();
    
    $dbs_array[] = "$dir/install/schemas/mysql_schema.sql";
    $dbs_array[] = "$dir/install/schemas/mysql_basic.sql";
 
    //Do the actual importing of the .sql files.
    if( ($ok = $this->_importDBs( $dbs_array )) !== true ) {
      return( $ok );
    }
 
    return( true );
  }

_installDBConfig()

After _installDBs() successfully creates the database structure, you will most likely need to update values in the database tables. The _installDBConfig() function is the place to do this. Below is a sample from a _installDBConfig() function:

 function _installDBConfig( $args ) {
 
    $dsn = $this->_getSystemDSN();
    $db =& db_connect( $dsn );
 
    // These are the values that we are going to update in the database
    $board_email = $args['email_address'];
    $script_path = $args['location'];
    $first_name  = $args['first_name'];
    $last_name   = $args['last_name'];
    $mission     = $args['mission'];
    $admin_name  = $args['username'];
    $md5_pass    = md5( $args['password'] );
    $server_name = $this->_siteworx->getWorkingDomainName();
    $time = time();
 
    $sql = array();
 
    // Create SQL queries and add them to an array to be executed on the 
    // script's database tables.
 
    $sql[] = "INSERT INTO sample_config
                   (config_name, config_value)
              VALUES ('board_startdate','$time' )";
 
    $sql[] = "INSERT INTO sample_config
                   ( config_name, config_value)
              VALUES ('default_lang', 'english' )";
 
    $sql[] = "UPDATE sample_users
              SET user_login     = '$admin_name',
                  user_pass      = '$md5_pass',
                  user_firstname = '$first_name',
                  user_lastname  = '$last_name',
                  user_email     = '$board_email'
              WHERE ID = '1'";
 
    // Actually execute the $sql
    foreach( $sql as $sql_query ) {
      // look for other query, return error bundle
      $ret = db_query( $db, $sql_query );
    }
 
    return( true );
  }

  A few things are noteworthy here.

  1. The $args array is populated with the values from the installation screen.
  2. We use _getSystemDSN() to get the dsn needed to connect to the system instance of MySQL.
  3. We use the InterWorx db_connect function to connect, not php’s mysql_connect.

_installFileConfig()

This function is used to modify the configuration file for the script. Typically, there are two ways to accomplish modifying the configuration file. You can write out an entirely new configuration file with new content, or you can use regular expressions and only replace the necessary bits of information. Below is a snippet from an _installFileConfig() function.

function _installFileConfig( $args ) {
 
    // get the install dir so we can build a path to the config_file 
    $install_dir = $this->_getInstallDir();
 
    // build a path to the config file we're going to modify
    $config_file = "$install_dir/config.php";
 
    // Gather up all of the values we need to write to the config file
    $DBUser        = $this->getFullyQualifiedDBUser();
    $DBName        = $this->getFullyQualifiedDBName();
    $DBPass        = $this->getDBPwd();
    $mysql_version = $this->getDBVersion();
    $host          = $this->_getHost();
 
    // sampleScript needs to know if it is running on a MySQL 3.x or MySQL 4.x box.
    if ( $mysql_version >= 4 ) {
      $mysql_ver_string = 'mysql4';
    } else {
      $mysql_ver_string = 'mysql';
    }
    
    // Create the content for the config file.
    $config_data = array();
 
    $config_data[] = "<?php";
    $config_data[] = "// sampleScript 2.x auto-generated config file";
    $config_data[] = "// Do not change anything in this file!";
    $config_data[] = '$dbms = "' . $mysql_ver_string . '";';
    $config_data[] = '$dbhost = "' . $host . '";';
    $config_data[] = '$dbname = "' . $DBName . '";';
    $config_data[] = '$dbuser = "' . $DBUser . '";';
    $config_data[] = '$dbpasswd = "' . $DBPass . '";';
    $config_data[] = '$table_prefix = "sampleScript_";';
    $config_data[] = "define('SAMPLE_SCRIPT', true);";
    $config_data[] = "?>";
 
    $data = implode( "\n", $config_data );
 
 
    // Because we are creating a new file, we use 
    // iworx_barf instead of iworx_lock_barf
    $retval = IWorxFileSys::iworx_barf( $config_file,
                                        $data,
                                        false,
                                        false,
                                        0644 );
 
    // The next section is an example of modifying an existing 
    // file using regular expressions.
    
    // Pointer to the file to be modified
    $secondary_config_file = "$install_dir/admin/config.php";
    $s_config    = "$install_dir/admin/config.php";
    
    // Get the contents of the file as a string
    $config_data = file_get_contents( $s_config );
 
    // Replace the necessary values using regexp
 
    $config_data = preg_replace( '/\$database_name[\s]*=[\s]*"[^"]*"/',
                                 '$database_name = "' . $DBName . '"',
                                 $config_data );
 
    $config_data = preg_replace( '/\$database_user[\s]*=[\s]*"[^"]*"/',
                                 '$database_user = "' . $DBUser . '"',
                                 $config_data );
 
    // Because we are "editing" an existing file, we use lock_barf.
    $retval2 = IWorxFileSys::iworx_lock_barf( $config_file,
                                              $config_data,
                                              false );
    if( $retval  != 0 ||
        $retval2 !== true ) {
      $error =
        array( 'name' => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_INSTALL_FILE_CONFIG_ERROR##' );
      return( $error );
    }
 
    return( true );
  }

 Very Important: If you are updating an existing config file, you need to use the IWorxFileSys::iworx_lock_barf() function. This function will create and save a backup of the file you are modifying before writing out the new content. If you are creating a new file, you must use the IWorxFileSys::iworx_barf() function. Below is an example of using IWorxFileSys::iworx_barf() to create a new config file for a script.

 
    // $config_file is the location/container of the file.
    // $config_data is the content to be written to the file.
    // The next two parameters are owner and group.  Defaulting them to false will 
    // set the owner/group to iworx/iworx, typically this is what you want.
    // The final parameter is the OCTAL mode permissions for the new config file.
 
    return( IWorxFileSys::iworx_barf( $config_file,
                                      $config_data,
                                      false,
                                      false,
                                      0644 ) );

 iworx_barf will return true on success and false on failure. This is different than iworx_lock_barf which returns 0 on success.

_removeInstallFiles()

This function should be used to remove any files that should not remain in the final file tree of the script. Leaving around temporary install files can often lead to security issues. Below is a sample _removeInstallFiles() function.

  function _removeInstallFiles( $args ) {
 
    $sampleScriptDir = $this->_getInstallDir();
 
    // remove the install dir
    // See note below for more information on iworx_rm.
    $retval = IWorxFileSys::iworx_rm( $sampleScript2Dir . "/install", true, true );
 
    if( $retval != 0 ) {
      $error =
        array( 'name' => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_DELETING_INSTALL_FILES_ERROR##');
        return( $error );
    }
 
    // remove the contrib dir
    $retval = IWorxFileSys::iworx_rm( $sampleScriptDir . "/contrib", true, true );
 
    if( $retval != 0 ) {
      $error =
        array( 'name' => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_DELETING_INSTALL_FILES_ERROR##');
        return( $error );
    }
 
    return( true );
  }

 iworx_rm should be used to safely remove files, as it performs a lot of basic error checking that should prevent you from removing /etc, /home, etc. The second and third boolean parameters represent the r(ecursive) and f(orce) options to the rm command, respectively. Specifying true for both will lead to rm -rf.

_setPermissions()

This function should be used to set the proper permissions for files that need to have specific permissions. For example, sampleScipt.php needs to have an uploads directory that is set to 777.

  function _setPermissions( $args ) {
 
    $temp_install_dir = $this->_getInstallDir();
    
    // Chmod the uploads directory to 777
    $retval = IWorxFileSys::iworx_chmod( 0777,
                                         $temp_install_dir . '/uploads' );
 
    if( $retval != 0 ) {
      $error =
        array( 'name' => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_ERROR_INSTALLING##' );
      return( $error );
    }
 
    return( true );
  }

_postInstall()

This is a generic function that can be used for any additional tasks that need to be performed (making additional directories/files, copying files etc) It is called after _setPermissions but before _moveToFinalLocation. Below is a sample _postInstall function that creates two .htaccess files from the sample .htaccess files provided. This is done in the post install because it doesn’t fall within the scope of any other functions.

  function _postInstall() {
 
    $temp_install_dir    = $this->_getInstallDir();
    $main_dir_htaccess   = "$temp_install_dir/sample.htaccess";
    $admin_dir_htaccess  = "$temp_install_dir/admin/sample.htaccess";
    $mvto_admin_htaccess = "$temp_install_dir/admin/.htaccess";
 
 
    $retval = IWorxFileSys::iworx_mv( $main_dir_htaccess,
                                      "$temp_install_dir/.htaccess",
                                      true );
 
    $retval2 = IWorxFileSys::iworx_mv( $admin_dir_htaccess,
                                       $mvto_admin_htaccess,
                                       true );
 
    if( $retval  != 0  ||
        $retval2 != 0 ) {
      $error =
        array( 'name' => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_ERROR_INSTALLING##');
      return( $error );
    }
 
    return( true );
  }

_moveToFinalLocation

This function is used to move the script files from the temporary location to the final install location specified by the user. Below is a sample function.

  function _moveToFinalLocation( $args ) {
 
    $final_location   = $this->getDirLocation();
    $temp_install_dir = $this->_getInstallDir();
 
    $retval = IWorxFileSys::iworx_mv( $temp_install_dir . '/*',
                                      $final_location,
                                      true );
 
    if( $retval != 0 ) {
      $error =
        array( 'name' => '',
               'status' => false,
               'reason' => '##LG_SCRIPTWORX_ERROR_INSTALLING##');
               return( $error );
    }
 
    return( true );
  }

_createHtaccessFile

This function is used to create a .htaccess file (if required by the script). It is performed as the last step so that everything else is in place and the .htaccess file can be created in the proper location. The .htaccess file is created and specific options such as register_globals can be set.

  function _createHtaccessFile() {
 
    $webroot      = $this->_siteworx->getWebRoot();
    $dir_location = $this->getDirLocation();
    $success      = false;
    $ret          = true;
 
    //Turn on register_globals
 
    $htaccess =& new HtaccessFile( $this->_siteworx );
    $htaccess->setHtaccessDir( $dir_location );
 
    $success = $htaccess->setPHPFlag( 'register_globals',
                                      HtaccessFile::HTACCESS_ON() );
 
    // Set the memory_limit php value
    $success = $htaccess->setPHPValue( 'memory_limit',
                                       '16M' );
 
    // if we are installing into webroot, inject the .htaccess into the
    // manifest file.
    if( $webroot == $dir_location ) {
      $ret = $this->addHtaccessToManifest();
      // if we couldn't write to the manifest file for whatever reason,
      // return the error bundle
      if( $ret !== true ) {
        return( $ret );
      }
    }
 
    return( $success !== true ? $success : true );
  }

Locations, Locations, Locations

ScriptWorx has numerous helper functions and variables dealing with different location settings. This section will hopefully alleviate any confusion about the locations and corresponding functions. Locations are essential in building the proper paths to configuration files that need to be modified and to moving the script to its final installation location.

Location Functions

When an archive is unpacked, it is unpacked to a temporary location. Due to different tarball archiving conventions, some scripts unpack into a top level directory within the temporary install directory, others simply unpack all the files into the temporary install directory. Examples of each follow- SMF extracs files into the temporary install directory and phpBB extracts files into a directory within the temporay location.

 getUnpackLocation() returns the temporary directory location and _getInstallDir() returns a subdirectory in the temporary directory location.

Example: Unpacking of SMF via ScriptWorx

During the install process for SMF, the archive is unpacked to a temporary location. If we look at the directory /tmp/smfr11f0c, we see the following:

[root@test3 smfr11fOC]# ls
agreement.txt         index.php         readme.html       Sources
attachments           install.php       Settings_bak.php  ssi_examples.php
avatars               license.txt       Settings.php      ssi_examples.shtml
changelog-themes.txt  news_readme.html  smf_1-0.sql       SSI.php
changelog.txt         Packages          Smileys           Themes

In this case, calling getUnpackLocation() will return /tmp/smfr11f0c. We can use that value to build a path to Settings.php which is the main configuration file for SMF.

 SMF does not unpack into a top level directory, therefore we use getUnpackLocation() to get access to script files.

Example: Unpacking of phpBB via ScriptWorx

During the install process for phpBB, the archive is unpacked to a directory within the temporary location. If we look at the directory /tmp/phpbbr191fcc, we see the following:

[root@test3 phpbbr191fcc]# ls
phpBB2

In this case, we need to use _getInstallDir() to get the path to the phpBB2 directory where all of the script files are contained. Calling _getInstallDir() will return /tmp/phpbbr191fcc/phpBB2,

 phpBB unpacks into a directory (phpBB2) within the temporary location, therefore we use _getInstallDir() to get access to script files.

Adding an Entry to the Language File for Your Script

The entry added to the language file will be displayed when a successful installation of a script is completed. The naming convention of LG_SCRIPTCOMPLETE_SCRIPTNAME must be followed or the string will not be displayed.

  1. Open up the language file for the appropriate language.
    • English /home/interworx/lang/en-us/global.lng
    • French /home/interworx/lang/fr/global.lng
    • Swedish /home/interworx/lang/sv/global.lng
  2. Add an entry to the end of the global.lng file for your script. The entry should provide some basic information about the script being installed.
  3. Save and exit the global.lng file.

Example Language File Entry

LG_SCRIPTCOMPLETE_WORDPRESS=WordPress was successfully installed.  You can log \
in and start blogging with the link provided below.

Helper Functions

The following section details the helper functions that are available from the Script base class.

_getSystemDSN()

Function Name: _getSystemDSN
Returns: The DSN to use for system MySQL connections.
Comments: This function will return the full system DSN that can be used to connect to the system MySQL.

_getInstallDir()

Function Name: _getInstallDir
Returns: The top level directory within the temporary unpack location where the compressed script was decompressed.
Comments: This function is useful for building the path to configuration files that will need to be modified during installation of the script.

getUnpackLocation()

Function Name: getUnpackLocation
Returns: The directory where the compressed script was decompressed.
Comments: This function is useful for building the path to configuration files that will need to be modified during installation of the script.

getDirLocation()

Function Name: getDirLocation
Returns: The directory where the script is to be installed.
Comments: This function is useful for moving the script to the final location and for putting the proper values in script configuration files.

 If installing a script into the web root, getDirLocation will return the path with a trailing slash, for example /home/testfour/test4.net/html/

getURLLocation()

Function Name: getURLLocation
Returns: The url that can be used to access the script.
Comments: This function is useful for putting the proper values in script configuration files.

 This will return the part of the url after http:// so if you need to reference the entire url, you must prepend http:// to the string returned by getURLLocation()

_getSystemDBHost()

Function Name: _getSystemDBHost
Returns: The hostname to use for DSN connections.
Comments: This determines what type of connection MySQL is using and will return

_getHost()

Function Name: _getHost
Returns: The IP address of the manager if the server is in a cluster (will return “localhost”) if the server is not clustered
Comments: This function should be used only when installing a custom script into a clustered setup.

_validateOptions()

Function Name: _validateOptions
Returns: true on success, an array of errors on failure.
Comments: This function validates 3 basic options needed for script install: number of database users, number of databases, and storage space.

_validateLocation()

Function Name: _validateLocation
Returns: true on success, an array of errors on failure.
Comments: This function validates the location that the script is trying to be installed to. Below is the list of criteria.

5 Conditions must be met in order for a location to be valid:

  1. The installation directory must be the webroot or below of the user.
  2. A ScriptWorx installation must not exist in the target directory.
  3. A ScriptWorx installation must not exist in any parent directory (webroot is the one exception)
  4. No .s must be present in the location being passed in.
  5. No symlinks to directories or files outside of the webroot are allowed.

_importDBs()

Function Name: _importDBs
Returns: true on success, an array of errors on failure.
Comments: This function should be used to import any .sql files needed to set up the script.

getDBVersion()

Function Name: getDBVersion()
Returns: The version of the database to be used by the installed script.
Comments: This function is useful when a script needs to know what version of MySQL it is running on.

generateTempDir()

Function Name: generateTempDir
Returns: A temporary directory that a script can be decompressed to.
Comments: This function must be used in the _unpack function when creating a Script subclass to generate a temporary directory for the script to be unarchived into.

COPYRIGHT © InterWorx L.L.C. 2004-2008 PRIVACY POLICYEULA