/** * Main driver to handle the uploaded autotag * * Determines if a new style (supports automated installer) or * an old style. * * @return string Formatted HTML containing the page body * */ function processAutotagUpload() { global $_CONF, $_PLUGINS, $_TABLES, $autotagData, $LANG32, $_DB_dbms, $_DB_table_prefix; $retval = ''; $upgrade = false; $errors = ''; if (count($_FILES) > 0 && $_FILES['autotagfile']['error'] != UPLOAD_ERR_NO_FILE) { require_once $_CONF['path_system'] . 'classes/upload.class.php'; $upload = new upload(); if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) { $upload->setLogFile($_CONF['path'] . 'logs/error.log'); $upload->setDebug(true); } $upload->setMaxFileUploads(1); $upload->setMaxFileSize(4194304); $upload->setAllowedMimeTypes(array('application/x-gzip' => '.gz,.gzip,tgz', 'application/zip' => '.zip')); $upload->setFieldName('autotagfile'); if (!$upload->setPath($_CONF['path_data'] . 'temp')) { return _at_errorBox($upload->printErrors(false)); exit; } $filename = COM_sanitizeFilename($_FILES['autotagfile']['name'], true); $upload->setFileNames($filename); $upload->uploadFiles(); if ($upload->areErrors()) { return _at_errorBox($upload->printErrors(false)); exit; } $Finalfilename = $_CONF['path_data'] . 'temp/' . $filename; } else { return _at_errorBox($LANG32[46]); } // decompress into temp directory if (function_exists('set_time_limit')) { @set_time_limit(60); } if (!($tmp = _io_mktmpdir())) { return _at_errorBox($LANG32[47]); } if (!COM_decompress($Finalfilename, $_CONF['path_data'] . $tmp)) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _at_errorBox($LANG32[48]); } @unlink($Finalfilename); // read XML data file, places in $autotagData; $autotagData = array(); $rc = _at_parseXML($_CONF['path_data'] . $tmp); if ($rc == -1) { // no xml file found _pi_deleteDir($_CONF['path_data'] . $tmp); return _at_errorBox(sprintf($LANG32[49], $autotagData['glfusionversion'])); } if (!isset($autotagData['id']) || !isset($autotagData['version'])) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _at_errorBox(sprintf($LANG32[49], $autotagData['glfusionversion'])); } // proper glfusion version if (!COM_checkVersion(GVERSION, $autotagData['glfusionversion'])) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _at_errorBox(sprintf($LANG32[49], $autotagData['glfusionversion'])); } if (!COM_checkVersion(phpversion(), $autotagData['phpversion'])) { $retval .= sprintf($LANG32[50], $autotagData['phpversion']); _pi_deleteDir($_CONF['path_data'] . $tmp); return _at_errorBox(sprintf($LANG32[50], $autotagData['phpversion'])); } if ($errors != '') { _pi_deleteDir($_CONF['path_data'] . $tmp); return _at_errorBox($errors); } // check to see if an auto tag already exists... // removed so we can update existing auto tags /* $result = DB_query("SELECT * FROM {$_TABLES['autotags']} WHERE tag='".DB_escapeString($autotagData['id'])."'"); if ( DB_numRows($result) > 0 ) { _pi_deleteDir($_CONF['path_data'].$tmp); return _at_errorBox(sprintf($LANG32[52],$autotagData['id'])); } */ $permError = 0; $permErrorList = ''; if (function_exists('set_time_limit')) { @set_time_limit(30); } // test copy to proper directories $autotagData['id'] = preg_replace('/[^a-zA-Z0-9\\-_\\.]/', '', $autotagData['id']); list($rc, $failed) = _pi_test_copy($_CONF['path_data'] . $tmp . '/' . $autotagData['id'] . '/', $_CONF['path_system'] . 'autotags/'); if ($rc > 0) { $permError = 1; foreach ($failed as $filename) { $permErrorList .= sprintf($LANG32[41], $filename); } } if ($permError != 0) { $errorMessage = '<h2>' . $LANG32[42] . '</h2>' . $LANG32[43] . $permErrorList . '<br />' . $LANG32[44]; _pi_deleteDir($_CONF['path_data'] . $tmp); return _at_errorBox($errorMessage); } $T = new Template($_CONF['path_layout'] . 'admin/autotag'); $T->set_file('form', 'autotag_upload_confirm.thtml'); $T->set_var(array('form_action_url' => $_CONF['site_admin_url'] . '/autotag_upload.php', 'action' => 'processupload', 'pi_name' => $autotagData['id'], 'pi_version' => $autotagData['version'], 'pi_url' => $autotagData['url'], 'pi_gl_version' => $autotagData['glfusionversion'], 'pi_desc' => $autotagData['description'], 'pi_author' => $autotagData['author'], 'upgrade' => $upgrade, 'temp_dir' => $tmp)); $retval .= $T->parse('output', 'form'); return $retval; }
/** * Main driver to handle the uploaded plugin * * Determines if a new style (supports automated installer) or * an old style. * * @return string Formatted HTML containing the page body * */ function processPluginUpload() { global $_CONF, $_PLUGINS, $_PLUGIN_INFO, $_TABLES, $pluginData, $LANG_ADMIN, $LANG32, $_DB_dbms, $_DB_table_prefix, $_IMAGE_TYPE; $retval = ''; $upgrade = false; if (count($_FILES) > 0 && $_FILES['pluginfile']['error'] != UPLOAD_ERR_NO_FILE) { require_once $_CONF['path_system'] . 'classes/upload.class.php'; $upload = new upload(); if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) { $upload->setLogFile($_CONF['path'] . 'logs/error.log'); $upload->setDebug(true); } $upload->setMaxFileUploads(1); $upload->setMaxFileSize(25165824); $upload->setAllowedMimeTypes(array('application/x-gzip' => '.gz,.gzip,tgz', 'application/zip' => '.zip', 'application/x-tar' => '.tar,.tar.gz,.gz', 'application/x-gzip-compressed' => '.tar.gz,.tgz,.gz')); $upload->setFieldName('pluginfile'); if (!$upload->setPath($_CONF['path_data'] . 'temp')) { return _pi_errorBox($upload->printErrors(false)); exit; } $filename = $_FILES['pluginfile']['name']; $upload->setFileNames($filename); $upload->uploadFiles(); if ($upload->areErrors()) { return _pi_errorBox($upload->printErrors(false)); exit; } $Finalfilename = $_CONF['path_data'] . 'temp/' . $filename; } else { return _pi_errorBox($LANG32[46]); } // decompress into temp directory if (function_exists('set_time_limit')) { @set_time_limit(60); } if (!($tmp = _io_mktmpdir())) { return _pi_errorBox($LANG32[47]); } if (!COM_decompress($Finalfilename, $_CONF['path_data'] . $tmp)) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox($LANG32[48]); } @unlink($Finalfilename); // read XML data file, places in $pluginData; $pluginData = array(); $rc = _pi_parseXML($_CONF['path_data'] . $tmp); if ($rc == -1) { // no xml file found return processOldPlugin($tmp); } if (!isset($pluginData['id']) || !isset($pluginData['version'])) { return processOldPlugin($tmp); } // proper glfusion version if (!COM_checkVersion(GVERSION, $pluginData['glfusionversion'])) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox(sprintf($LANG32[49], $pluginData['glfusionversion'])); } if (!COM_checkVersion(phpversion(), $pluginData['phpversion'])) { $retval .= sprintf($LANG32[50], $pluginData['phpversion']); _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox(sprintf($LANG32[50], $pluginData['phpversion'])); } // check prerequisites $errors = ''; if (isset($pluginData['requires']) && is_array($pluginData['requires'])) { foreach ($pluginData['requires'] as $reqPlugin) { list($reqPlugin, $required_ver) = explode(',', $reqPlugin); if (!isset($_PLUGIN_INFO[$reqPlugin])) { // required plugin not installed $errors .= sprintf($LANG32[51], $pluginData['id'], $reqPlugin, $reqPlugin); } elseif (!empty($required_ver)) { $installed_ver = $_PLUGIN_INFO[$reqPlugin]; if (!COM_checkVersion($installed_ver, $required_ver)) { // required plugin installed, but wrong version $errors .= sprintf($LANG32[90], $required_ver, $reqPlugin, $installed_ver, $reqPlugin); } } } } if ($errors != '') { _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox($errors); } // check if plugin already exists // if it does, check that this is an upgrade // if not, error // else validate we really want to upgrade $result = DB_query("SELECT * FROM {$_TABLES['plugins']} WHERE pi_name='" . DB_escapeString($pluginData['id']) . "'"); if (DB_numRows($result) > 0) { $P = DB_fetchArray($result); if ($P['pi_version'] == $pluginData['version']) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox(sprintf($LANG32[52], $pluginData['id'])); } // if we are here, it must be an upgrade or disabled plugin.... $rc = COM_checkVersion($pluginData['version'], $P['pi_version']); if ($rc < 1) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox(sprintf($LANG32[53], $pluginData['id'], $pluginData['version'], $P['pi_version'])); } if ($P['pi_enabled'] != 1) { _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox($LANG32[72]); } $upgrade = true; } $permError = 0; $permErrorList = ''; if (function_exists('set_time_limit')) { @set_time_limit(30); } // test copy to proper directories list($rc, $failed) = _pi_test_copy($_CONF['path_data'] . $tmp . '/' . $pluginData['id'] . '/', $_CONF['path'] . 'plugins/' . $pluginData['id']); if ($rc > 0) { $permError = 1; foreach ($failed as $filename) { $permErrorList .= sprintf($LANG32[41], $filename); } } list($rc, $failed) = _pi_test_copy($_CONF['path_data'] . $tmp . '/' . $pluginData['id'] . '/admin/', $_CONF['path_html'] . 'admin/plugins/' . $pluginData['id']); if ($rc > 0) { $permError = 1; foreach ($failed as $filename) { $permErrorList .= sprintf($LANG32[41], $filename); } } list($rc, $failed) = _pi_test_copy($_CONF['path_data'] . $tmp . '/' . $pluginData['id'] . '/public_html/', $_CONF['path_html'] . $pluginData['id']); if ($rc > 0) { $permError = 1; foreach ($failed as $filename) { $permErrorList .= sprintf($LANG32[41], $filename); } } if ($permError != 0) { $errorMessage = '<h2>' . $LANG32[42] . '</h2>' . $LANG32[43] . $permErrorList . '<br />' . $LANG32[44]; _pi_deleteDir($_CONF['path_data'] . $tmp); return _pi_errorBox($errorMessage); } USES_lib_admin(); $menu_arr = array(array('url' => $_CONF['site_admin_url'], 'text' => $LANG_ADMIN['admin_home'])); $T = new Template($_CONF['path_layout'] . 'admin/plugins'); $T->set_file('form', 'plugin_upload_confirm.thtml'); $T->set_var('admin_menu', ADMIN_createMenu($menu_arr, $pluginData['id'] . ' ' . $LANG32[62], $_CONF['layout_url'] . '/images/icons/plugins.' . $_IMAGE_TYPE)); $T->set_var(array('form_action_url' => $_CONF['site_admin_url'] . '/plugin_upload.php', 'action' => 'processupload', 'pi_name' => $pluginData['id'], 'pi_version' => $pluginData['version'], 'pi_url' => $pluginData['url'], 'pi_gl_version' => $pluginData['glfusionversion'], 'pi_desc' => $pluginData['description'], 'pi_author' => $pluginData['author'], 'plugin_old_version' => $P['pi_version'], 'upgrade' => $upgrade, 'temp_dir' => $tmp)); $retval .= $T->parse('output', 'form'); return $retval; }