Esempio n. 1
0
 /**
  * Upgrade any enabled plugins
  * NOTE: Needs a fully working Geeklog, so can only be done late in the upgrade
  *       process!
  *
  * @param  boolean $migration whether the upgrade is part of a site migration
  * @param  array   $old_conf  old $_CONF values before the migration
  * @return int     number of failed plugin updates (0 = everything's fine)
  * @see     PLG_upgrade
  * @see     PLG_migrate
  */
 private function upgradePlugins($migration = false, array $old_conf = array())
 {
     global $_TABLES;
     $failed = 0;
     $result = DB_query("SELECT pi_name, pi_version FROM {$_TABLES['plugins']} WHERE pi_enabled = 1");
     $numPlugins = DB_numRows($result);
     for ($i = 0; $i < $numPlugins; $i++) {
         list($pi_name, $pi_version) = DB_fetchArray($result);
         $success = true;
         if ($migration) {
             $success = PLG_migrate($pi_name, $old_conf);
         }
         if ($success === true) {
             $codeVersion = PLG_chkVersion($pi_name);
             if (!empty($codeVersion) && $codeVersion != $pi_version) {
                 $success = PLG_upgrade($pi_name);
             }
         }
         if ($success !== true) {
             // migration or upgrade failed - disable plugin
             DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $pi_name);
             COM_errorLog("Migration or upgrade for '{$pi_name}' plugin failed - plugin disabled");
             $failed++;
         }
     }
     return $failed;
 }
Esempio n. 2
0
/**
* Updates a plugin (call its upgrade function).
*
* @param    pi_name   string   name of the plugin to uninstall
* @return             string   HTML for error or success message
*
*/
function PLUGINS_update($pi_name)
{
    global $_CONF, $LANG32, $LANG08, $MESSAGE, $_IMAGE_TYPE;
    $retval = '';
    if (strlen($pi_name) == 0) {
        $retval .= COM_showMessageText($LANG32[12], $LANG32[13], true);
        COM_errorLog($LANG32[12]);
        return $retval;
    }
    $result = PLG_upgrade($pi_name);
    if ($result > 0) {
        if ($result === TRUE) {
            // Catch returns that are just true/false
            COM_setMessage(60);
            $retval .= COM_refresh($_CONF['site_admin_url'] . '/plugins.php');
        } else {
            // Plugin returned a message number
            COM_setMessage($result);
            $retval = COM_refresh($_CONF['site_admin_url'] . '/plugins.php?plugin=' . url_encode($pi_name));
        }
    } else {
        // Plugin function returned a false
        $retval .= COM_showMessage(95);
    }
    CTL_clearCache();
    return $retval;
}
Esempio n. 3
0
/**
* Continue a plugin upgrade that started in plugin_upload()
*
* @param    string  $plugin         plugin name
* @param    string  $pi_version     current plugin version
* @param    string  $code_version   plugin version to be upgraded to
* @return   string                  HTML refresh
* @see      function plugin_upload
*
*/
function continue_upgrade($plugin, $pi_version, $code_version)
{
    global $_CONF, $_TABLES;
    $retval = '';
    $msg_with_plugin_name = false;
    // simple sanity checks
    if (empty($plugin) || empty($pi_version) || empty($code_version) || $pi_version == $code_version) {
        $msg = 72;
    } else {
        // more sanity checks
        $result = DB_query("SELECT pi_version, pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = '" . addslashes($plugin) . "'");
        $A = DB_fetchArray($result);
        if (!empty($A['pi_version']) && $A['pi_enabled'] == 1 && $A['pi_version'] == $pi_version && $A['pi_version'] != $code_version) {
            // continue upgrade process that started in plugin_upload()
            $result = PLG_upgrade($plugin);
            if ($result === true) {
                PLG_pluginStateChange($plugin, 'upgraded');
                $msg = 60;
                // successfully updated
            } else {
                $msg_with_plugin_name = true;
                $msg = $result;
                // message provided by the plugin
            }
        } else {
            $msg = 72;
        }
    }
    $url = $_CONF['site_admin_url'] . '/plugins.php?msg=' . $msg;
    if ($msg_with_plugin_name) {
        $url .= '&amp;plugin=' . $plugin;
    }
    $retval = COM_refresh($url);
    return $retval;
}
Esempio n. 4
0
/**
* Handle uploaded plugin
*
* @return   string      HTML: redirect or main plugin screen + error message
*
*/
function plugin_upload()
{
    global $_CONF, $_TABLES;
    $retval = '';
    $path_admin = $_CONF['path_html'] . substr($_CONF['site_admin_url'], strlen($_CONF['site_url']) + 1) . '/';
    $upload_success = false;
    // If an error occured while uploading the file.
    $error_msg = plugin_getUploadError($_FILES['plugin']);
    if (!empty($error_msg)) {
        $retval .= plugin_main($error_msg);
    } else {
        require_once $_CONF['path_system'] . 'classes/unpacker.class.php';
        $plugin_file = $_CONF['path_data'] . $_FILES['plugin']['name'];
        // Name the plugin file
        $archive = new unpacker($_FILES['plugin']['tmp_name'], $_FILES['plugin']['type']);
        $tmp = $archive->getlist();
        // Grab the contents of the tarball to see what the plugin name is
        $dirname = preg_replace('/\\/.*$/', '', $tmp[0]['filename']);
        if (empty($dirname)) {
            // If $dirname is blank it's probably because the user uploaded a non Tarball file.
            $retval = COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=100');
        } else {
            $pi_did_exist = false;
            // plugin directory already existed
            $pi_had_entry = false;
            // plugin had an entry in the database
            $pi_was_enabled = false;
            // plugin was enabled
            if (file_exists($_CONF['path'] . 'plugins/' . $dirname)) {
                $pi_did_exist = true;
                // plugin directory already exists
                $pstatus = DB_query("SELECT pi_name, pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = '{$dirname}'");
                $A = DB_fetchArray($pstatus);
                if (isset($A['pi_name'])) {
                    $pi_had_entry = true;
                    $pi_was_enabled = $A['pi_enabled'] == 1;
                }
                if ($pi_was_enabled) {
                    // disable temporarily while we move the files around
                    DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $dirname);
                }
                require_once 'System.php';
                $plugin_dir = $_CONF['path'] . 'plugins/' . $dirname;
                if (file_exists($plugin_dir . '.previous')) {
                    @System::rm('-rf ' . $plugin_dir . '.previous');
                }
                if (file_exists($plugin_dir)) {
                    rename($plugin_dir, $plugin_dir . '.previous');
                }
                $public_dir = $_CONF['path_html'] . $dirname;
                if (file_exists($public_dir . '.previous')) {
                    @System::rm('-rf ' . $public_dir . '.previous');
                }
                if (file_exists($public_dir)) {
                    rename($public_dir, $public_dir . '.previous');
                }
                $admin_dir = $path_admin . 'plugins/' . $dirname;
                if (file_exists($admin_dir . '.previous')) {
                    @System::rm('-rf ' . $admin_dir . '.previous');
                }
                if (file_exists($admin_dir)) {
                    rename($admin_dir, $admin_dir . '.previous');
                }
            }
            /**
             * Install the plugin
             * This doesn't work if the public_html & public_html/admin/plugins directories aren't 777
             */
            // Extract the tarball to data so we can get the $pi_name name from admin/install.php
            $archive->unpack($_CONF['path'] . 'data/', array($dirname . '/admin/install.php'));
            $plugin_inst = $_CONF['path'] . 'data/' . $dirname . '/admin/install.php';
            $fdata = '';
            $fhandle = @fopen($plugin_inst, 'r');
            if ($fhandle) {
                $fdata = fread($fhandle, filesize($plugin_inst));
                fclose($fhandle);
            }
            // Remove the plugin from data/
            require_once 'System.php';
            @System::rm('-rf ' . $_CONF['path'] . 'data/' . $dirname);
            /**
             * One time I wanted to install a muffler on my car and
             * needed to match up the outside diameter of the car's
             * exhaust pipe to the inside diameter of the muffler.
             * Unfortunately, when I went to the auto parts store they
             * didn't have a coupling adapter that would perfectly
             * match the two pipes, only a bunch of smaller adapters.
             * I ended up using about 4 small adapters to step down
             * one size at a time to the size of the muffler's input.
             *
             * It's kind of like this regular expression:
             *
             */
            $fdata = preg_replace('/\\n/', '', $fdata);
            $fdata = preg_replace('/ /', '', $fdata);
            $pi_name = preg_replace('/^.*\\$pi\\_name=\'/', '', $fdata);
            $pi_name = preg_replace('/\'.*$/', '', $pi_name);
            // Some plugins don't have $pi_name set in their install.php file,
            // This means our regex won't work and we should just use $dirname
            if (preg_match('/\\<\\?php/', $pi_name) || preg_match('/--/', $pi_name)) {
                $pi_name = $dirname;
            } elseif (empty($pi_name)) {
                $pi_name = $dirname;
            }
            // Extract the uploaded archive to the plugins directory
            $upload_success = $archive->unpack($_CONF['path'] . 'plugins/');
            $plg_path = $_CONF['path'] . 'plugins/' . $pi_name . '/';
            if ($upload_success) {
                if (file_exists($plg_path . 'public_html')) {
                    rename($plg_path . 'public_html', $_CONF['path_html'] . $pi_name);
                }
                if (file_exists($plg_path . 'admin')) {
                    rename($plg_path . 'admin', $path_admin . 'plugins/' . $pi_name);
                }
            }
            unset($archive);
            // Collect some garbage
            // cleanup when uploading a new version
            if ($pi_did_exist) {
                $plugin_dir = $_CONF['path'] . 'plugins/' . $dirname;
                if (file_exists($plugin_dir . '.previous')) {
                    @System::rm('-rf ' . $plugin_dir . '.previous');
                }
                $public_dir = $_CONF['path_html'] . $dirname;
                if (file_exists($public_dir . '.previous')) {
                    @System::rm('-rf ' . $public_dir . '.previous');
                }
                $admin_dir = $path_admin . 'plugins/' . $dirname;
                if (file_exists($admin_dir . '.previous')) {
                    @System::rm('-rf ' . $admin_dir . '.previous');
                }
                if ($pi_was_enabled) {
                    DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $dirname);
                }
            }
            $msg_with_plugin_name = false;
            if ($pi_did_exist) {
                if ($pi_was_enabled) {
                    // check if we have to perform an update
                    $pi_version = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name = '{$dirname}'");
                    $code_version = PLG_chkVersion($dirname);
                    if (!empty($code_version) && $code_version != $pi_version) {
                        $result = PLG_upgrade($dirname);
                        if ($result === true) {
                            PLG_pluginStateChange($dirname, 'upgraded');
                            $msg = 60;
                            // successfully updated
                        } else {
                            $msg_with_plugin_name = true;
                            $msg = $result;
                            // message provided by the plugin
                        }
                    } else {
                        $msg = 98;
                        // successfully uploaded
                    }
                } else {
                    $msg = 98;
                    // successfully uploaded
                }
            } elseif (file_exists($plg_path . 'autoinstall.php')) {
                // if the plugin has an autoinstall.php, install it now
                if (plugin_autoinstall($pi_name)) {
                    PLG_pluginStateChange($pi_name, 'installed');
                    $msg = 44;
                    // successfully installed
                } else {
                    $msg = 72;
                    // an error occured while installing the plugin
                }
            } else {
                $msg = 98;
                // successfully uploaded
            }
            $url = $_CONF['site_admin_url'] . '/plugins.php?msg=' . $msg;
            if ($msg_with_plugin_name) {
                $url .= '&amp;plugin=' . $dirname;
            }
            $retval = COM_refresh($url);
        }
    }
    return $retval;
}