예제 #1
0
/**
 * checks whether the necessary plugins for BLOBStreaming exist
 *
 * @access  public
 * @uses    PMA_Config::get()
 * @uses    PMA_Config::settings()
 * @uses    PMA_Config::set()
 * @uses    PMA_PluginsExist()
 * @uses    PMA_BS_SetVariables()
 * @uses    PMA_BS_GetVariables()
 * @uses    PMA_BS_SetFieldReferences()
 * @return  boolean
*/
function checkBLOBStreamingPlugins()
{
    // load PMA configuration
    $PMA_Config = $_SESSION['PMA_Config'];
    // return if unable to load PMA configuration
    if (empty($PMA_Config)) {
        return FALSE;
    }
    // retrieve current server configuration
    $serverCfg = $PMA_Config->get('Servers');
    if (isset($serverCfg[$GLOBALS['server']])) {
        $serverCfg = $serverCfg[$GLOBALS['server']];
    } else {
        $serverCfg = null;
    }
    // return if unable to retrieve current server configuration
    if (!isset($serverCfg)) {
        return FALSE;
    }
    // if PHP extension in use is 'mysql', specify element 'PersistentConnections'
    if (isset($serverCfg['extension']) && "mysql" == $serverCfg['extension']) {
        $serverCfg['PersistentConnections'] = $PMA_Config->settings['PersistentConnections'];
    }
    // if connection type is TCP, unload socket variable
    if (isset($serverCfg['connect_type']) && "tcp" == strtolower($serverCfg['connect_type'])) {
        $serverCfg['socket'] = "";
    }
    // define BS Plugin variables
    $allPluginsExist = TRUE;
    $PMA_Config->set('PBXT_NAME', 'pbxt');
    $PMA_Config->set('PBMS_NAME', 'pbms');
    $plugins[$PMA_Config->get('PBXT_NAME')]['Library'] = 'libpbxt.so';
    $plugins[$PMA_Config->get('PBXT_NAME')]['Exists'] = FALSE;
    $plugins[$PMA_Config->get('PBMS_NAME')]['Library'] = 'libpbms.so';
    $plugins[$PMA_Config->get('PBMS_NAME')]['Exists'] = FALSE;
    // retrieve state of BS plugins
    PMA_PluginsExist($plugins);
    foreach ($plugins as $plugin_key => $plugin) {
        if (!$plugin['Exists']) {
            $allPluginsExist = FALSE;
            break;
        }
    }
    // end if (!$plugin['Exists'])
    // set variable indicating BS plugin existance
    $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', $allPluginsExist);
    // do the plugins exist?
    if ($allPluginsExist) {
        // retrieve BS variables from PMA configuration
        $bs_set_variables = array();
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_garbage_threshold'] = isset($serverCfg['bs_garbage_threshold']) ? $serverCfg['bs_garbage_threshold'] : NULL;
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_repository_threshold'] = isset($serverCfg['bs_repository_threshold']) ? $serverCfg['bs_repository_threshold'] : NULL;
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_temp_blob_timeout'] = isset($serverCfg['bs_temp_blob_timeout']) ? $serverCfg['bs_temp_blob_timeout'] : NULL;
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_temp_log_threshold'] = isset($serverCfg['bs_temp_log_threshold']) ? $serverCfg['bs_temp_log_threshold'] : NULL;
        // set BS variables to PMA configuration defaults
        PMA_BS_SetVariables($bs_set_variables);
        // retrieve updated BS variables (configurable and unconfigurable)
        $bs_variables = PMA_BS_GetVariables();
        // if no BS variables exist, set plugin existance to false and return
        if (count($bs_variables) <= 0) {
            $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE);
            return FALSE;
        }
        // end if (count($bs_variables) <= 0)
        // switch on BS field references
        if (strtolower($bs_variables[$PMA_Config->get('PBMS_NAME') . '_field_references']) == "off") {
            if (!PMA_BS_SetFieldReferences('ON')) {
                return FALSE;
            }
        }
        // get BS server port
        $BS_PORT = $bs_variables[$PMA_Config->get('PBMS_NAME') . '_port'];
        // if no BS server port exists, set plugin existance to false and return
        if (!$BS_PORT) {
            $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE);
            return FALSE;
        }
        // end if (!$BS_PORT)
        // add selected BS, CURL and fileinfo library variables to PMA configuration
        $PMA_Config->set('BLOBSTREAMING_PORT', $BS_PORT);
        $PMA_Config->set('BLOBSTREAMING_HOST', $serverCfg['host']);
        $PMA_Config->set('BLOBSTREAMING_SERVER', $serverCfg['host'] . ':' . $BS_PORT);
        $PMA_Config->set('CURL_EXISTS', FALSE);
        $PMA_Config->set('FILEINFO_EXISTS', FALSE);
        // check if CURL exists
        if (function_exists("curl_init")) {
            // initialize curl handler
            $curlHnd = curl_init();
            // CURL exists, set necessary variable and close resource
            if (!empty($curlHnd)) {
                $PMA_Config->set('CURL_EXISTS', TRUE);
                curl_close($curlHnd);
            }
            // end if (!empty($curlHnd))
        }
        // end if (function_exists("curl_init"))
        // check if PECL's fileinfo library exist
        $finfo = NULL;
        if (function_exists("finfo_open")) {
            $finfo = finfo_open(FILEINFO_MIME);
        }
        // fileinfo library exists, set necessary variable and close resource
        if (!empty($finfo)) {
            $PMA_Config->set('FILEINFO_EXISTS', TRUE);
            finfo_close($finfo);
        }
        // end if (!empty($finfo))
    } else {
        return FALSE;
    }
    $bs_tables = array();
    // specify table structure for BS reference table
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_reference'] = array();
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_reference']['struct'] = <<<EOD
        CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_reference
        (
         Table_name        CHAR(64) COMMENT 'The name of the referencing table',
         Blob_id           BIGINT COMMENT 'The BLOB reference number - part of the BLOB URL',
         Column_name       CHAR(64) COMMENT 'The column name of the referencing field',
         Row_condition     VARCHAR(255) COMMENT 'This condition identifies the row in the table',
         Blob_url          VARCHAR(200) COMMENT 'The BLOB URL for HTTP GET access',
         Repository_id     INT COMMENT 'The repository file number of the BLOB',
         Repo_blob_offset  BIGINT COMMENT 'The offset in the repository file',
         Blob_size         BIGINT COMMENT 'The size of the BLOB in bytes',
         Deletion_time     TIMESTAMP COMMENT 'The time the BLOB was deleted',
         Remove_in         INT COMMENT 'The number of seconds before the reference/BLOB is removed perminently',
         Temp_log_id       INT COMMENT 'Temporary log number of the referencing deletion entry',
         Temp_log_offset   BIGINT COMMENT 'Temporary log offset of the referencing deletion entry'
        ) ENGINE=PBMS;
EOD;
    // specify table structure for BS repository table
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_repository'] = array();
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_repository']['struct'] = <<<EOD
        CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_repository
        (
         Repository_id     INT COMMENT 'The repository file number',
         Repo_blob_offset  BIGINT COMMENT 'The offset of the BLOB in the repository file',
         Blob_size         BIGINT COMMENT 'The size of the BLOB in bytes',
         Head_size         SMALLINT UNSIGNED COMMENT 'The size of the BLOB header - proceeds the BLOB data',
         Access_code       INT COMMENT 'The 4-byte authorisation code required to access the BLOB - part of the BLOB URL',
         Creation_time     TIMESTAMP COMMENT 'The time the BLOB was created',
         Last_ref_time     TIMESTAMP COMMENT 'The last time the BLOB was referenced',
         Last_access_time  TIMESTAMP COMMENT 'The last time the BLOB was accessed (read)',
         Content_type      CHAR(128) COMMENT 'The content type of the BLOB - returned by HTTP GET calls',
         Blob_data         LONGBLOB COMMENT 'The data of this BLOB'
        ) ENGINE=PBMS;
EOD;
    // specify table structure for BS custom content type table
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_custom_content_type'] = array();
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_custom_content_type']['struct'] = <<<EOD
        CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_custom_content_type
        (
         Blob_url           VARCHAR(200) COMMENT 'The BLOB URL for HTTP GET access',
         Content_type       VARCHAR(255) COMMENT 'The custom MIME type for a given BLOB reference as specified by the user',

         PRIMARY KEY(Blob_url)
        );
EOD;
    // add BS tables to PMA configuration
    $PMA_Config->set('BLOBSTREAMING_TABLES', $bs_tables);
    return TRUE;
}
예제 #2
0
/**
 * checks whether the necessary plugins for BLOBStreaming exist
 *
 * @access  public
 * @uses    PMA_Config::get()
 * @uses    PMA_Config::settings()
 * @uses    PMA_Config::set()
 * @uses    PMA_BS_SetVariables()
 * @uses    PMA_BS_GetVariables()
 * @uses    PMA_BS_SetFieldReferences()
 * @uses    PMA_cacheSet()
 * @uses    PMA_cacheGet()
 * @return  boolean
*/
function checkBLOBStreamingPlugins()
{
    // load PMA configuration
    $PMA_Config = $_SESSION['PMA_Config'];
    // return if unable to load PMA configuration
    if (empty($PMA_Config)) {
        return FALSE;
    }
    // At this point we might already know that plugins do not exist
    // because this was recorded in the session (cache).
    if (PMA_cacheGet('skip_blobstreaming', true)) {
        return false;
    }
    // If we don't know that we can skip blobstreaming, we continue
    // verifications; anyway, in case we won't skip blobstreaming,
    // we still need to set some variables in non-persistent settings,
    // which is done via $PMA_Config->set().
    /** Retrieve current server configuration;
     *  at this point, $PMA_Config->get('Servers') contains the server parameters
     *  as explicitely defined in config.inc.php, so it cannot be used; it's
     *  better to use $GLOBALS['cfg']['Server'] which contains the explicit
     *  parameters merged with the default ones
     *
     */
    $serverCfg = $GLOBALS['cfg']['Server'];
    // return if unable to retrieve current server configuration
    if (!$serverCfg) {
        return FALSE;
    }
    // if PHP extension in use is 'mysql', specify element 'PersistentConnections'
    if ($serverCfg['extension'] == "mysql") {
        $serverCfg['PersistentConnections'] = $PMA_Config->settings['PersistentConnections'];
    }
    // if connection type is TCP, unload socket variable
    if (strtolower($serverCfg['connect_type']) == "tcp") {
        $serverCfg['socket'] = "";
    }
    $allPluginsExist = false;
    if (PMA_MYSQL_INT_VERSION >= 50109) {
        $PMA_Config->set('PBXT_NAME', 'pbxt');
        $PMA_Config->set('PBMS_NAME', 'pbms');
        $required_plugins[$PMA_Config->get('PBXT_NAME')]['Library'] = 'libpbxt.so';
        $required_plugins[$PMA_Config->get('PBMS_NAME')]['Library'] = 'libpbms.so';
        $number_of_required_plugins_found = 0;
        // Retrieve MySQL plugins
        $existing_plugins = PMA_DBI_fetch_result('SHOW PLUGINS');
        foreach ($existing_plugins as $one_existing_plugin) {
            // check if required plugins exist
            foreach ($required_plugins as $one_required_plugin) {
                if (strtolower($one_existing_plugin['Library']) == strtolower($one_required_plugin['Library']) && $one_existing_plugin['Status'] == "ACTIVE") {
                    $number_of_required_plugins_found++;
                }
            }
            if (2 == $number_of_required_plugins_found) {
                $allPluginsExist = true;
                break;
            }
        }
        unset($required_plugins, $existing_plugins, $one_required_plugin, $one_existing_plugin, $number_of_required_plugins_found);
    }
    // set variable indicating BS plugin existence
    $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', $allPluginsExist);
    if ($allPluginsExist) {
        // retrieve BS variables from PMA configuration
        $bs_set_variables = array();
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_garbage_threshold'] = isset($serverCfg['bs_garbage_threshold']) ? $serverCfg['bs_garbage_threshold'] : NULL;
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_repository_threshold'] = isset($serverCfg['bs_repository_threshold']) ? $serverCfg['bs_repository_threshold'] : NULL;
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_temp_blob_timeout'] = isset($serverCfg['bs_temp_blob_timeout']) ? $serverCfg['bs_temp_blob_timeout'] : NULL;
        $bs_set_variables[$PMA_Config->get('PBMS_NAME') . '_temp_log_threshold'] = isset($serverCfg['bs_temp_log_threshold']) ? $serverCfg['bs_temp_log_threshold'] : NULL;
        // set BS variables to PMA configuration defaults
        PMA_BS_SetVariables($bs_set_variables);
        // retrieve updated BS variables (configurable and unconfigurable)
        $bs_variables = PMA_BS_GetVariables();
        // if no BS variables exist, set plugin existence to false and return
        if (count($bs_variables) <= 0) {
            $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE);
            PMA_cacheSet('skip_blobstreaming', true, true);
            return FALSE;
        }
        // end if (count($bs_variables) <= 0)
        // switch on BS field references
        if (strtolower($bs_variables[$PMA_Config->get('PBMS_NAME') . '_field_references']) == "off") {
            if (!PMA_BS_SetFieldReferences('ON')) {
                PMA_cacheSet('skip_blobstreaming', true, true);
                return FALSE;
            }
        }
        // get BS server port
        $BS_PORT = $bs_variables[$PMA_Config->get('PBMS_NAME') . '_port'];
        // if no BS server port exists, set plugin existance to false and return
        if (!$BS_PORT) {
            $PMA_Config->set('BLOBSTREAMING_PLUGINS_EXIST', FALSE);
            PMA_cacheSet('skip_blobstreaming', true, true);
            return FALSE;
        }
        // end if (!$BS_PORT)
        // add selected BS, CURL and fileinfo library variables to PMA configuration
        $PMA_Config->set('BLOBSTREAMING_PORT', $BS_PORT);
        $PMA_Config->set('BLOBSTREAMING_HOST', $serverCfg['host']);
        $PMA_Config->set('BLOBSTREAMING_SERVER', $serverCfg['host'] . ':' . $BS_PORT);
        $PMA_Config->set('CURL_EXISTS', FALSE);
        $PMA_Config->set('FILEINFO_EXISTS', FALSE);
        // check if CURL exists
        if (function_exists("curl_init")) {
            // initialize curl handler
            $curlHnd = curl_init();
            // CURL exists, set necessary variable and close resource
            if (!empty($curlHnd)) {
                $PMA_Config->set('CURL_EXISTS', TRUE);
                curl_close($curlHnd);
            }
            // end if (!empty($curlHnd))
        }
        // end if (function_exists("curl_init"))
        // check if PECL's fileinfo library exist
        $finfo = NULL;
        if (function_exists("finfo_open")) {
            $finfo = finfo_open(FILEINFO_MIME);
        }
        // fileinfo library exists, set necessary variable and close resource
        if (!empty($finfo)) {
            $PMA_Config->set('FILEINFO_EXISTS', TRUE);
            finfo_close($finfo);
        }
        // end if (!empty($finfo))
    } else {
        PMA_cacheSet('skip_blobstreaming', true, true);
        return FALSE;
    }
    // end if ($allPluginsExist)
    $bs_tables = array();
    // specify table structure for BS reference table
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_reference'] = array();
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_reference']['struct'] = <<<EOD
        CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_reference
        (
         Table_name        CHAR(64) COMMENT 'The name of the referencing table',
         Blob_id           BIGINT COMMENT 'The BLOB reference number - part of the BLOB URL',
         Column_name       CHAR(64) COMMENT 'The column name of the referencing field',
         Row_condition     VARCHAR(255) COMMENT 'This condition identifies the row in the table',
         Blob_url          VARCHAR(200) COMMENT 'The BLOB URL for HTTP GET access',
         Repository_id     INT COMMENT 'The repository file number of the BLOB',
         Repo_blob_offset  BIGINT COMMENT 'The offset in the repository file',
         Blob_size         BIGINT COMMENT 'The size of the BLOB in bytes',
         Deletion_time     TIMESTAMP COMMENT 'The time the BLOB was deleted',
         Remove_in         INT COMMENT 'The number of seconds before the reference/BLOB is removed perminently',
         Temp_log_id       INT COMMENT 'Temporary log number of the referencing deletion entry',
         Temp_log_offset   BIGINT COMMENT 'Temporary log offset of the referencing deletion entry'
        ) ENGINE=PBMS;
EOD;
    // specify table structure for BS repository table
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_repository'] = array();
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_repository']['struct'] = <<<EOD
        CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_repository
        (
         Repository_id     INT COMMENT 'The repository file number',
         Repo_blob_offset  BIGINT COMMENT 'The offset of the BLOB in the repository file',
         Blob_size         BIGINT COMMENT 'The size of the BLOB in bytes',
         Head_size         SMALLINT UNSIGNED COMMENT 'The size of the BLOB header - proceeds the BLOB data',
         Access_code       INT COMMENT 'The 4-byte authorisation code required to access the BLOB - part of the BLOB URL',
         Creation_time     TIMESTAMP COMMENT 'The time the BLOB was created',
         Last_ref_time     TIMESTAMP COMMENT 'The last time the BLOB was referenced',
         Last_access_time  TIMESTAMP COMMENT 'The last time the BLOB was accessed (read)',
         Content_type      CHAR(128) COMMENT 'The content type of the BLOB - returned by HTTP GET calls',
         Blob_data         LONGBLOB COMMENT 'The data of this BLOB'
        ) ENGINE=PBMS;
EOD;
    // specify table structure for BS custom content type table
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_custom_content_type'] = array();
    $bs_tables[$PMA_Config->get('PBMS_NAME') . '_custom_content_type']['struct'] = <<<EOD
        CREATE TABLE {$PMA_Config->get('PBMS_NAME')}_custom_content_type
        (
         Blob_url           VARCHAR(200) COMMENT 'The BLOB URL for HTTP GET access',
         Content_type       VARCHAR(255) COMMENT 'The custom MIME type for a given BLOB reference as specified by the user',

         PRIMARY KEY(Blob_url)
        );
EOD;
    // add BS tables to PMA configuration
    $PMA_Config->set('BLOBSTREAMING_TABLES', $bs_tables);
    return TRUE;
}