コード例 #1
0
ファイル: lib-install.php プロジェクト: NewRoute/glfusion
function _pi_test_copy($srcdir, $dstdir)
{
    $num = 0;
    $fail = 0;
    $sizetotal = 0;
    $fifail = '';
    $createdDst = 0;
    $ret = '';
    $verbose = 0;
    $failedFiles = array();
    if (!@is_dir($dstdir)) {
        $rc = fusion_io_mkdir_p($dstdir);
        if ($rc == false) {
            $failedFiles[] = $dstdir;
            COM_errorLog("PLG-INSTALL: Error: Unable to create directory " . $dstdir);
            return array(1, $failedFiles);
        }
        $createdDst = 1;
    }
    if ($curdir = @opendir($srcdir)) {
        while (false !== ($file = readdir($curdir))) {
            if ($file != '.' && $file != '..') {
                $srcfile = $srcdir . '/' . $file;
                $dstfile = $dstdir . '/' . $file;
                if (is_file($srcfile)) {
                    if (!COM_isWritable($dstfile)) {
                        $failedFiles[] = $dstfile;
                        COM_errorLog("PLG-INSTALL: Error: File '{$dstfile}' cannot be written");
                        $fail++;
                        $fifail = $fifail . $srcfile . '|';
                    }
                } else {
                    if (@is_dir($srcfile)) {
                        $res = explode(',', $ret);
                        list($ret, $failed) = _pi_test_copy($srcfile, $dstfile, $verbose);
                        $failedFiles = array_merge($failedFiles, $failed);
                        $mod = explode(',', $ret);
                        $imp = array($res[0] + $mod[0], $mod[1] + $res[1], $mod[2] + $res[2], $mod[3] . $res[3]);
                        $ret = implode(',', $imp);
                    }
                }
            }
        }
        closedir($curdir);
    }
    if ($createdDst == 1) {
        @rmdir($dstdir);
    }
    $red = explode(',', $ret);
    if (count($red) > 1) {
        $ret = $num + $red[0] . ',' . ($fail + $red[1]) . ',' . ($sizetotal + $red[2]) . ',' . $fifail . $red[3];
    }
    return array($fail, $failedFiles);
}
コード例 #2
0
ファイル: plugin_upload.php プロジェクト: spacequad/glfusion
/**
* 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;
}