Beispiel #1
0
/**
* Deletes a directory (with recursive sub-directory support)
*
* @parm     string            Path of directory to remove
* @return   bool              True on success, false on fail
*
*/
function _pi_deleteDir($path)
{
    if (!is_string($path) || $path == "") {
        return false;
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    if (@is_dir($path)) {
        if (!($dh = @opendir($path))) {
            return false;
        }
        while (false !== ($f = readdir($dh))) {
            if ($f == '..' || $f == '.') {
                continue;
            }
            _pi_deleteDir("{$path}/{$f}");
        }
        closedir($dh);
        return @rmdir($path);
    } else {
        return @unlink($path);
    }
    return false;
}
Beispiel #2
0
/**
* Copies and installs new style plugins
*
* Copies all files the proper place and runs the automated installer
* or upgrade.
*
* @return   string              Formatted HTML containing the page body
*
*/
function post_uploadProcess()
{
    global $_CONF, $_PLUGINS, $_TABLES, $autotagData, $LANG32, $_DB_dbms, $_DB_table_prefix;
    $retval = '';
    $upgrade = false;
    $masterErrorCount = 0;
    $masterErrorMsg = '';
    $autotagData = array();
    $autotagData['id'] = COM_applyFilter($_POST['pi_name']);
    $autotagData['name'] = $autotagData['id'];
    $autotagData['version'] = COM_applyFilter($_POST['pi_version']);
    $autotagData['glfusionversion'] = COM_applyFilter($_POST['pi_gl_version']);
    $tdir = COM_applyFilter($_POST['temp_dir']);
    $tdir = preg_replace('/[^a-zA-Z0-9\\-_\\.]/', '', $tdir);
    $tdir = str_replace('..', '', $tdir);
    $tmp = $_CONF['path_data'] . $tdir;
    $autotagData = array();
    $rc = _at_parseXML($tmp);
    if ($rc == -1) {
        // no xml file found
        return _at_errorBox($LANG32[74]);
    }
    clearstatcache();
    $permError = 0;
    $permErrorList = '';
    // copy to proper directories
    if (defined('DEMO_MODE')) {
        _pi_deleteDir($tmp);
        echo COM_refresh($_CONF['site_admin_url'] . '/autotag.php?msg=503');
        exit;
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    $autotagData['id'] = preg_replace('/[^a-zA-Z0-9\\-_\\.]/', '', $autotagData['id']);
    $rc = _pi_file_copy($tmp . '/' . $autotagData['id'] . '.class.php', $_CONF['path_system'] . 'autotags/');
    if ($rc === false) {
        $errorMessage = '<h2>' . $LANG32[42] . '</h2>' . $LANG32[43] . $permErrorList . '<br />' . $LANG32[44];
        _pi_deleteDir($tmp);
        return _at_errorBox($errorMessage);
    }
    // copy template files, if any
    if (isset($autotagData['template']) && is_array($autotagData['template'])) {
        foreach ($autotagData['template'] as $filename) {
            $rc = _pi_file_copy($tmp . '/' . $filename, $_CONF['path_system'] . 'autotags/');
            if ($rc === false) {
                @unlink($_CONF['path_system'] . $autotagData['id'] . '.class.php');
                $errorMessage = '<h2>' . $LANG32[42] . '</h2>' . $LANG32[43] . $permErrorList . '<br />' . $LANG32[44];
                _pi_deleteDir($tmp);
                return _at_errorBox($errorMessage);
            }
        }
    }
    $tag = DB_escapeString($autotagData['id']);
    $desc = DB_escapeString($autotagData['description']);
    $is_enabled = 1;
    $is_function = 1;
    $replacement = '';
    DB_query("REPLACE INTO {$_TABLES['autotags']} (tag,description,is_enabled,is_function,replacement) VALUES ('" . $tag . "','" . $desc . "'," . $is_enabled . "," . $is_function . ",'')");
    _pi_deleteDir($tmp);
    CTL_clearCache();
    // show status (success or fail)
    return $retval;
}
Beispiel #3
0
/**
* Copies and installs new style plugins
*
* Copies all files the proper place and runs the automated installer
* or upgrade.
*
* @return   string              Formatted HTML containing the page body
*
*/
function post_uploadProcess()
{
    global $_CONF, $_PLUGINS, $_TABLES, $pluginData, $LANG32, $_DB_dbms, $_DB_table_prefix;
    $retval = '';
    $upgrade = false;
    $masterErrorCount = 0;
    $masterErrorMsg = '';
    $pluginData = array();
    $pluginData['id'] = COM_applyFilter($_POST['pi_name']);
    $pluginData['name'] = $pluginData['id'];
    $pluginData['version'] = COM_applyFilter($_POST['pi_version']);
    $pluginData['url'] = COM_applyFilter($_POST['pi_url']);
    $pluginData['glfusionversion'] = COM_applyFilter($_POST['pi_gl_version']);
    $upgrade = COM_applyFilter($_POST['upgrade'], true);
    $tdir = COM_applyFilter($_POST['temp_dir']);
    $tdir = preg_replace('/[^a-zA-Z0-9\\-_\\.]/', '', $tdir);
    $tdir = str_replace('..', '', $tdir);
    $tmp = $_CONF['path_data'] . $tdir;
    $pluginData = array();
    $rc = _pi_parseXML($tmp);
    if ($rc == -1) {
        // no xml file found
        return _pi_errorBox($LANG32[74]);
    }
    clearstatcache();
    $permError = 0;
    $permErrorList = '';
    // copy to proper directories
    if (defined('DEMO_MODE')) {
        _pi_deleteDir($tmp);
        COM_setMessage(503);
        echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php');
        exit;
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    $rc = _pi_dir_copy($tmp . '/' . $pluginData['id'] . '/', $_CONF['path'] . 'plugins/' . $pluginData['id']);
    list($success, $failed, $size, $faillist) = explode(',', $rc);
    if ($failed > 0) {
        $permError++;
        $t = array();
        $t = explode('|', $faillist);
        if (is_array($t)) {
            foreach ($t as $failedFile) {
                $permErrorList .= sprintf($LANG32[45], $failedFile, $_CONF['path'] . 'plugins/' . $pluginData['id']);
            }
        }
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    if (file_exists($tmp . '/' . $pluginData['id'] . '/admin/')) {
        $rc = _pi_dir_copy($tmp . '/' . $pluginData['id'] . '/admin/', $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id']);
        list($success, $failed, $size, $faillist) = explode(',', $rc);
        if ($failed > 0) {
            $permError++;
            $t = array();
            $t = explode('|', $faillist);
            if (is_array($t)) {
                foreach ($t as $failedFile) {
                    $permErrorList .= sprintf($LANG32[45], $failedFile, $_CONF['path'] . 'plugins/' . $pluginData['id']);
                }
            }
        }
        _pi_deleteDir($_CONF['path'] . 'plugins/' . $pluginData['id'] . '/admin/');
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    if (file_exists($tmp . '/' . $pluginData['id'] . '/public_html/')) {
        $rc = _pi_dir_copy($tmp . '/' . $pluginData['id'] . '/public_html/', $_CONF['path_html'] . $pluginData['id']);
        list($success, $failed, $size, $faillist) = explode(',', $rc);
        if ($failed > 0) {
            $permError++;
            $t = array();
            $t = explode('|', $faillist);
            if (is_array($t)) {
                foreach ($t as $failedFile) {
                    $permErrorList .= sprintf($LANG32[45], $failedFile, $_CONF['path'] . 'plugins/' . $pluginData['id']);
                }
            }
        }
        _pi_deleteDir($_CONF['path'] . 'plugins/' . $pluginData['id'] . '/public_html/');
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    if (file_exists($tmp . '/' . $pluginData['id'] . '/themefiles/')) {
        // determine where to copy them, first check to see if layout was defined in xml
        if (isset($pluginData['layout']) && $pluginData['layout'] != '') {
            $destinationDir = $_CONF['path_html'] . 'layout/' . $pluginData['layout'] . '/';
            fusion_io_mkdir_p($destinationDir);
        } else {
            $destinationDir = $_CONF['path_html'] . 'layout/nouveau/' . $pluginData['id'] . '/';
        }
        $rc = _pi_dir_copy($tmp . '/' . $pluginData['id'] . '/themefiles/', $destinationDir);
        list($success, $failed, $size, $faillist) = explode(',', $rc);
        if ($failed > 0) {
            $permError++;
            $t = array();
            $t = explode('|', $faillist);
            if (is_array($t)) {
                foreach ($t as $failedFile) {
                    $permErrorList .= sprintf($LANG32[45], $failedFile, $_CONF['path'] . 'plugins/' . $pluginData['id']);
                }
            }
        }
        _pi_deleteDir($_CONF['path'] . 'plugins/' . $pluginData['id'] . '/themefiles/');
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    if ($permError != 0) {
        $errorMessage = '<h2>' . $LANG32[42] . '</h2>' . $LANG32[43] . $permErrorList . '<br />' . $LANG32[44];
        _pi_deleteDir($tmp);
        return _pi_errorBox($errorMessage);
    }
    if (isset($pluginData['dataproxydriver']) && $pluginData['dataproxydriver'] != '') {
        if (file_exists($_CONF['path'] . 'plugins/dataproxy/drivers/')) {
            $src = $tmp . '/' . $pluginData['id'] . '/dataproxy/' . $pluginData['dataproxydriver'];
            $dest = $_CONF['path'] . 'plugins/dataproxy/drivers/' . $pluginData['dataproxydriver'];
            @copy($src, $dest);
        }
    }
    _pi_deleteDir($tmp);
    if (is_array($pluginData['renamedist'])) {
        foreach ($pluginData['renamedist'] as $fileToRename) {
            $rc = true;
            if (strncmp($fileToRename, 'admin', 5) == 0) {
                // we have a admin file to rename....
                $absoluteFileName = substr($fileToRename, 6);
                $lastSlash = strrpos($fileToRename, '/');
                if ($lastSlash === false) {
                    continue;
                }
                $pathTo = substr($fileToRename, 0, $lastSlash);
                if ($pathTo != '') {
                    $pathTo .= '/';
                }
                $lastSlash++;
                $fileNameDist = substr($fileToRename, $lastSlash);
                $lastSlash = strrpos($fileNameDist, '.');
                if ($lastSlash === false) {
                    continue;
                }
                $fileName = substr($fileNameDist, 0, $lastSlash);
                if (!file_exists($_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $pathTo . $fileName)) {
                    COM_errorLog("PLG-INSTALL: Renaming " . $fileNameDist . " to " . $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $pathTo . $fileName);
                    $rc = @copy($_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $absoluteFileName, $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $pathTo . $fileName);
                    if ($rc === false) {
                        COM_errorLog("PLG-INSTALL: Unable to copy " . $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $absoluteFileName . " to " . $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $pathTo . $fileName);
                        $masterErrorCount++;
                        $masterErrorMsg .= sprintf($LANG32[75], $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $absoluteFileName, $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id'] . $pathTo . $fileName);
                    }
                }
            } elseif (strncmp($fileToRename, 'public_html', 10) == 0) {
                // we have a public_html file to rename...
                $absoluteFileName = substr($fileToRename, 11);
                $lastSlash = strrpos($absoluteFileName, '/');
                if ($lastSlash !== false) {
                    $pathTo = substr($absoluteFileName, 0, $lastSlash);
                    if ($pathTo != '') {
                        $pathTo .= '/';
                    }
                } else {
                    $pathTo = '';
                }
                $lastSlash++;
                $fileNameDist = substr($absoluteFileName, $lastSlash);
                $lastSlash = strrpos($fileNameDist, '.');
                if ($lastSlash === false) {
                    continue;
                }
                $fileName = substr($fileNameDist, 0, $lastSlash);
                if (!file_exists($_CONF['path_html'] . $pluginData['id'] . $pathTo . $fileName)) {
                    COM_errorLog("PLG-INSTALL: Renaming " . $fileNameDist . " to " . $_CONF['path_html'] . $pluginData['id'] . $pathTo . $fileName);
                    $rc = @copy($_CONF['path_html'] . $pluginData['id'] . $absoluteFileName, $_CONF['path_html'] . $pluginData['id'] . $pathTo . $fileName);
                    if ($rc === false) {
                        COM_errorLog("PLG-INSTALL: Unable to copy " . $_CONF['path_html'] . $pluginData['id'] . $absoluteFileName . " to " . $_CONF['path_html'] . $pluginData['id'] . $pathTo . $fileName);
                        $masterErrorCount++;
                        $masterErrorMsg .= sprintf($LANG32[75], $_CONF['path_html'] . $pluginData['id'] . $absoluteFileName, $_CONF['path_html'] . $pluginData['id'] . $pathTo . $fileName);
                    }
                }
            } else {
                // must be some other file relative to the plugin/pluginname/ directory
                $absoluteFileName = $fileToRename;
                $lastSlash = strrpos($fileToRename, '/');
                $pathTo = substr($fileToRename, 0, $lastSlash);
                if ($pathTo != '') {
                    $pathTo .= '/';
                }
                $lastSlash++;
                $fileNameDist = substr($fileToRename, $lastSlash);
                $lastSlash = strrpos($fileNameDist, '.');
                if ($lastSlash === false) {
                    continue;
                }
                $fileName = substr($fileNameDist, 0, $lastSlash);
                if (!file_exists($_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $pathTo . $fileName)) {
                    COM_errorLog("PLG-INSTALL: Renaming " . $fileNameDist . " to " . $_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $pathTo . $fileName);
                    $rc = @copy($_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $absoluteFileName, $_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $pathTo . $fileName);
                    if ($rc === false) {
                        COM_errorLog("PLG-INSTALL: Unable to copy " . $_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $absoluteFileName . " to " . $_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $pathTo . $fileName);
                        $masterErrorCount++;
                        $masterErrorMsg .= sprintf($LANG32[75], $_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $absoluteFileName, $_CONF['path'] . 'plugins/' . $pluginData['id'] . '/' . $pathTo . $fileName);
                    }
                }
            }
        }
    }
    // handle masterErrorCount here, if not 0, display error and ask use to manually install via the plugin admin screen.
    // all files have been copied, so all they really should need to do is fix the error above and then run.
    if ($masterErrorCount != 0) {
        $errorMessage = '<h2>' . $LANG32[42] . '</h2>' . $LANG32[43] . $masterErrorMsg . '<br />' . $LANG32[44];
        return _pi_errorBox($errorMessage);
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(30);
    }
    if ($upgrade == 0) {
        // fresh install
        USES_lib_install();
        $pi_name = $pluginData['id'];
        $pi_display_name = $pluginData['name'];
        $pi_version = $pluginData['version'];
        $gl_version = $pluginData['glfusionversion'];
        $pi_url = $pluginData['url'];
        if (file_exists($_CONF['path'] . 'plugins/' . $pluginData['id'] . '/autoinstall.php')) {
            require_once $_CONF['path'] . 'plugins/' . $pluginData['id'] . '/autoinstall.php';
            $ret = INSTALLER_install($INSTALL_plugin[$pi_name]);
            if ($ret == 0) {
                CTL_clearCache();
                COM_setMessage(44);
                echo COM_refresh($_CONF['site_admin_url'] . '/plugins.php');
                exit;
            } else {
                return _pi_errorBox($LANG32[54]);
            }
        } else {
            return _pi_errorBox($LANG32[55]);
        }
    } else {
        // upgrade - force refresh to load new functions.inc
        echo COM_refresh($_CONF['site_admin_url'] . '/plugin_upload.php?mode=upgrade&amp;pi=' . $pluginData['id']);
        exit;
    }
    CTL_clearCache();
    // show status (success or fail)
    return $retval;
}